codemirror
4 years ago
jquery-tiptip
5 years ago
select2
5 years ago
how-to.js
8 years ago
how-to.min.js
6 years ago
jquery.colorbox.js
8 years ago
jquery.colorbox.min.js
6 years ago
metabox.js
4 years ago
metabox.min.js
4 years ago
multisite-updater.js
6 years ago
multisite-updater.min.js
6 years ago
welcome-modal.js
3 years ago
welcome-modal.min.js
3 years ago
wp-pages.js
4 years ago
wp-pages.min.js
4 years ago
yit-cpt-unlimited.js
6 years ago
yit-cpt-unlimited.min.js
6 years ago
yit-plugin-panel.js
3 years ago
yit-plugin-panel.min.js
3 years ago
yit-wp-pointer.js
5 years ago
yit-wp-pointer.min.js
5 years ago
yith-bh-onboarding.js
3 years ago
yith-bh-onboarding.min.js
3 years ago
yith-colorpicker.min.js
5 years ago
yith-dashboard.js
7 years ago
yith-dashboard.min.js
6 years ago
yith-date-format.js
5 years ago
yith-date-format.min.js
5 years ago
yith-enhanced-select-wc-2.6.js
5 years ago
yith-enhanced-select-wc-2.6.min.js
5 years ago
yith-enhanced-select.js
3 years ago
yith-enhanced-select.min.js
3 years ago
yith-fields.js
4 years ago
yith-fields.min.js
4 years ago
yith-promo.js
7 years ago
yith-promo.min.js
6 years ago
yith-system-info.js
3 years ago
yith-system-info.min.js
3 years ago
yith-ui.js
4 years ago
yith-ui.min.js
4 years ago
yith-update-plugins.js
7 years ago
yith-update-plugins.min.js
6 years ago
yit-plugin-panel.js
303 lines
| 1 | /** |
| 2 | * This file belongs to the YIT Plugin Framework. |
| 3 | * |
| 4 | * This source file is subject to the GNU GENERAL PUBLIC LICENSE (GPL 3.0) |
| 5 | * that is bundled with this package in the file LICENSE.txt. |
| 6 | * It is also available through the world-wide-web at this URL: |
| 7 | * http://www.gnu.org/licenses/gpl-3.0.txt |
| 8 | */ |
| 9 | |
| 10 | jQuery( function ( $ ) { |
| 11 | // Handle dependencies. |
| 12 | function dependencies_handler( id, deps, values, type ) { |
| 13 | var result = true; |
| 14 | if ( typeof ( deps ) == 'string' ) { |
| 15 | if ( deps.substr( 0, 6 ) === ':radio' ) { |
| 16 | deps = deps + ':checked'; |
| 17 | } |
| 18 | |
| 19 | var depsOn = $( deps ), |
| 20 | depsOnType = depsOn.attr( 'type' ), |
| 21 | val = depsOn.val(); |
| 22 | |
| 23 | switch ( depsOnType ) { |
| 24 | case 'checkbox': |
| 25 | val = depsOn.is( ':checked' ) ? 'yes' : 'no'; |
| 26 | break; |
| 27 | case 'radio': |
| 28 | val = depsOn.find( 'input[type="radio"]' ).filter( ':checked' ).val(); |
| 29 | break; |
| 30 | } |
| 31 | |
| 32 | values = values.split( ',' ); |
| 33 | |
| 34 | for ( var i = 0; i < values.length; i++ ) { |
| 35 | if ( val != values[ i ] ) { |
| 36 | result = false; |
| 37 | } else { |
| 38 | result = true; |
| 39 | break; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | var $current_field = $( id ), |
| 45 | $current_container = $( id + '-container' ).closest( 'tr' ); // container for YIT Plugin Panel |
| 46 | |
| 47 | if ( $current_container.length < 1 ) { |
| 48 | // container for YIT Plugin Panel WooCommerce |
| 49 | $current_container = $current_field.closest( '.yith-plugin-fw-panel-wc-row, .yith-toggle-content-row' ); |
| 50 | } |
| 51 | |
| 52 | var types = type.split( '-' ), j; |
| 53 | for ( j in types ) { |
| 54 | var current_type = types[ j ]; |
| 55 | |
| 56 | if ( !result ) { |
| 57 | switch ( current_type ) { |
| 58 | case 'disable': |
| 59 | $current_container.addClass( 'yith-disabled' ); |
| 60 | $current_field.attr( 'disabled', true ); |
| 61 | break; |
| 62 | case 'hide': |
| 63 | case 'hideNow': |
| 64 | $current_container.hide(); |
| 65 | break; |
| 66 | case 'hideme': |
| 67 | $current_field.hide(); |
| 68 | break; |
| 69 | case 'fadeInOut': |
| 70 | case 'fadeOut': |
| 71 | $current_container.hide( 500 ); |
| 72 | break; |
| 73 | case 'fadeIn': |
| 74 | default: |
| 75 | $current_container.hide(); |
| 76 | } |
| 77 | } else { |
| 78 | switch ( current_type ) { |
| 79 | case 'disable': |
| 80 | $current_container.removeClass( 'yith-disabled' ); |
| 81 | $current_field.attr( 'disabled', false ); |
| 82 | break; |
| 83 | case 'hide': |
| 84 | case 'hideNow': |
| 85 | $current_container.show(); |
| 86 | break; |
| 87 | case 'hideme': |
| 88 | $current_field.show(); |
| 89 | break; |
| 90 | case 'fadeOut': |
| 91 | $current_container.show(); |
| 92 | break; |
| 93 | case 'fadeInOut': |
| 94 | case 'fadeIn': |
| 95 | default: |
| 96 | $current_container.show( 500 ); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | function init_dependencies() { |
| 103 | $( '[data-dep-target]:not( .deps-initialized )' ).each( function () { |
| 104 | var t = $( this ); |
| 105 | |
| 106 | if ( t.closest( '.metaboxes-tab' ).length ) { |
| 107 | // Let meta-boxes handle their own deps. |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | // init field deps |
| 112 | t.addClass( 'deps-initialized' ); |
| 113 | |
| 114 | var field = '#' + t.data( 'dep-target' ), |
| 115 | dep = '#' + t.data( 'dep-id' ), |
| 116 | value = t.data( 'dep-value' ), |
| 117 | type = t.data( 'dep-type' ); |
| 118 | |
| 119 | $( dep ).on( 'change', function () { |
| 120 | dependencies_handler( field, dep, value.toString(), type ); |
| 121 | } ).trigger( 'change' ); |
| 122 | } ); |
| 123 | } |
| 124 | |
| 125 | init_dependencies(); |
| 126 | // re-init deps after an add toggle action |
| 127 | $( document ).on( 'yith-add-box-button-toggle', init_dependencies ); |
| 128 | |
| 129 | //connected list |
| 130 | $( '.rm_connectedlist' ).each( function () { |
| 131 | var ul = $( this ).find( 'ul' ); |
| 132 | var input = $( this ).find( ':hidden' ); |
| 133 | var sortable = ul.sortable( { |
| 134 | connectWith: ul, |
| 135 | update : function ( event, ui ) { |
| 136 | var value = {}; |
| 137 | |
| 138 | ul.each( function () { |
| 139 | var options = {}; |
| 140 | |
| 141 | $( this ).children().each( function () { |
| 142 | options[ $( this ).data( 'option' ) ] = $( this ).text(); |
| 143 | } ); |
| 144 | |
| 145 | value[ $( this ).data( 'list' ) ] = options; |
| 146 | } ); |
| 147 | |
| 148 | input.val( ( JSON.stringify( value ) ).replace( /[\\"']/g, '\\$&' ).replace( /\u0000/g, '\\0' ) ); |
| 149 | } |
| 150 | } ).disableSelection(); |
| 151 | } ); |
| 152 | |
| 153 | //google analytics generation |
| 154 | $( function () { |
| 155 | $( '.google-analytic-generate' ).click( function () { |
| 156 | var editor = $( '#' + $( this ).data( 'textarea' ) ).data( 'codemirrorInstance' ); |
| 157 | var gatc = $( '#' + $( this ).data( 'input' ) ).val(); |
| 158 | var basename = $( this ).data( 'basename' ); |
| 159 | |
| 160 | var text = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n"; |
| 161 | text += "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement( o ),\n"; |
| 162 | text += "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n"; |
| 163 | text += "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n"; |
| 164 | text += "ga('create', '" + gatc + "', '" + basename + "');\n"; |
| 165 | text += "ga('send', 'pageview');\n"; |
| 166 | editor.replaceRange( |
| 167 | text, |
| 168 | editor.getCursor( 'start' ), |
| 169 | editor.getCursor( 'end' ) |
| 170 | ); |
| 171 | } ); |
| 172 | } ); |
| 173 | |
| 174 | |
| 175 | // Prevent the WC message for changes when leaving the panel page |
| 176 | $( '.yith-plugin-fw-panel .woo-nav-tab-wrapper' ).removeClass( 'woo-nav-tab-wrapper' ).addClass( 'yith-nav-tab-wrapper' ); |
| 177 | |
| 178 | var wrap = $( '.wrap.yith-plugin-ui' ).first(), |
| 179 | notices = $( 'div.updated, div.error, div.notice' ); |
| 180 | |
| 181 | // Prevent moving notices into the wrapper |
| 182 | notices.addClass( 'inline' ); |
| 183 | if ( wrap.length ) { |
| 184 | wrap.prepend( notices ); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | // Additional wrapping just in case 'wrap' div is placed within a sub-tab and it's not already wrapped twice. |
| 189 | // TODO: Deprecated usage, it'll be removed, since also custom panels should use the automatic-wrapping through 'show_container' param. |
| 190 | ( function () { |
| 191 | var active_subnav = $( '.yith-nav-sub-tab.nav-tab-active' ), |
| 192 | subnav_wrap = $( '.yith-plugin-fw-wp-page__sub-tab-wrap' ); |
| 193 | |
| 194 | if ( active_subnav.length && !subnav_wrap.length ) { |
| 195 | var mainWrapper = $( '.yith-plugin-fw-wp-page-wrapper' ); |
| 196 | if ( !mainWrapper.length ) { |
| 197 | mainWrapper = $( '#wpbody-content > .yith-plugin-ui' ); |
| 198 | } |
| 199 | |
| 200 | if ( mainWrapper ) { |
| 201 | var defaultWrap = mainWrapper.find( '.yit-admin-panel-content-wrap' ); // at first, search for default wrap. |
| 202 | if ( defaultWrap.length ) { |
| 203 | defaultWrap.addClass( 'has-subnav' ); |
| 204 | } else { |
| 205 | // try to wrap a generic wrap div in main wrapper |
| 206 | mainWrapper.find( '.wrap' ).wrap( '<div class="yith-plugin-fw-wp-page__sub-tab-wrap"></div>' ); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } )(); |
| 211 | |
| 212 | // Float save button. |
| 213 | ( function () { |
| 214 | var floatSaveButton = $( '#yith-plugin-fw-float-save-button' ), |
| 215 | mainForm = $( '#plugin-fw-wc' ), |
| 216 | saveButton = document.querySelector( '#main-save-button' ); |
| 217 | |
| 218 | function updateValuesForSpecialEditors() { |
| 219 | if ( 'tinyMCE' in window && 'triggerSave' in window.tinyMCE ) { |
| 220 | // Trigger saving to serialize the correct value for WP Editors. |
| 221 | window.tinyMCE.triggerSave(); |
| 222 | } |
| 223 | |
| 224 | // Trigger saving to serialize the correct value for each Codemirror Editor. |
| 225 | $( '.codemirror.codemirror--initialized' ).each( function () { |
| 226 | var editor = $( this ).data( 'codemirrorInstance' ) || false; |
| 227 | if ( editor && 'codemirror' in editor ) { |
| 228 | editor.codemirror.save(); |
| 229 | } |
| 230 | } ); |
| 231 | } |
| 232 | |
| 233 | function checkButtonPosition() { |
| 234 | if ( isInViewport( saveButton ) ) { |
| 235 | floatSaveButton.removeClass( 'visible' ); |
| 236 | } else { |
| 237 | floatSaveButton.addClass( 'visible' ); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | function isInViewport( el ) { |
| 242 | var rect = el.getBoundingClientRect(), |
| 243 | viewport = { |
| 244 | width : window.innerWidth || document.documentElement.clientWidth, |
| 245 | height: window.innerHeight || document.documentElement.clientHeight |
| 246 | }; |
| 247 | return ( |
| 248 | rect.top >= 0 && |
| 249 | rect.left >= 0 && |
| 250 | rect.top <= viewport.height && |
| 251 | rect.left <= viewport.width |
| 252 | ); |
| 253 | } |
| 254 | |
| 255 | if ( floatSaveButton.length > 0 && mainForm.length > 0 ) { |
| 256 | checkButtonPosition(); |
| 257 | document.addEventListener( 'scroll', checkButtonPosition, { passive: true } ); |
| 258 | |
| 259 | $( document ).on( 'click', '#yith-plugin-fw-float-save-button', function ( e ) { |
| 260 | e.preventDefault(); |
| 261 | |
| 262 | updateValuesForSpecialEditors(); |
| 263 | |
| 264 | floatSaveButton.block( |
| 265 | { |
| 266 | message : null, |
| 267 | overlayCSS: { |
| 268 | background: 'transparent', |
| 269 | opacity : 0.6 |
| 270 | } |
| 271 | } |
| 272 | ); |
| 273 | $.post( document.location.href, mainForm.serialize() ) |
| 274 | .done( function ( response ) { |
| 275 | floatSaveButton.unblock() |
| 276 | .addClass( 'green' ) |
| 277 | .fadeOut( 300 ) |
| 278 | .html( floatSaveButton.data( 'saved-label' ) ) |
| 279 | .fadeIn( 300 ) |
| 280 | .delay( 2500 ) |
| 281 | .queue( |
| 282 | function ( next ) { |
| 283 | floatSaveButton.fadeOut( |
| 284 | 500, |
| 285 | function () { |
| 286 | $( this ).removeClass( 'green' ); |
| 287 | $( this ).html( $( this ).data( 'default-label' ) ).fadeIn( 500 ); |
| 288 | } |
| 289 | ); |
| 290 | next(); |
| 291 | } ); |
| 292 | |
| 293 | // Prevent WooCommerce warning for changes without saving. |
| 294 | window.onbeforeunload = null; |
| 295 | |
| 296 | $( document ).trigger( 'yith-plugin-fw-float-save-button-after-saving', [response] ); |
| 297 | } ); |
| 298 | } ) |
| 299 | } |
| 300 | } )(); |
| 301 | |
| 302 | } ); |
| 303 |