main.js (4903B)
1 /* global redux, document */ 2 3 (function( $ ) { 4 'use strict'; 5 6 $.redux = $.redux || {}; 7 8 $( document ).ready( 9 function() { 10 var opt_name; 11 var tempArr = []; 12 13 $.fn.isOnScreen = function() { 14 var win; 15 var viewport; 16 var bounds; 17 18 if ( ! window ) { 19 return; 20 } 21 22 win = $( window ); 23 viewport = { 24 top: win.scrollTop() 25 }; 26 27 viewport.right = viewport.left + win.width(); 28 viewport.bottom = viewport.top + win.height(); 29 30 bounds = this.offset(); 31 32 bounds.right = bounds.left + this.outerWidth(); 33 bounds.bottom = bounds.top + this.outerHeight(); 34 35 return ( ! ( viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom ) ); 36 }; 37 38 $( 'fieldset.redux-container-divide' ).css( 'display', 'none' ); 39 40 // Weed out multiple instances of duplicate Redux instance. 41 if ( redux.customizer ) { 42 $( '.wp-full-overlay-sidebar' ).addClass( 'redux-container' ); 43 } 44 45 $( '.redux-container' ).each( 46 function() { 47 opt_name = $.redux.getOptName( this ); 48 49 if ( $.inArray( opt_name, tempArr ) === -1 ) { 50 tempArr.push( opt_name ); 51 $.redux.checkRequired( $( this ) ); 52 $.redux.initEvents( $( this ) ); 53 } 54 } 55 ); 56 57 $( '.redux-container' ).on( 58 'click', 59 function() { 60 opt_name = $.redux.getOptName( this ); 61 } 62 ); 63 64 if ( undefined !== redux.optName ) { 65 $.redux.disableFields(); 66 $.redux.hideFields(); 67 $.redux.disableSections(); 68 $.redux.initQtip(); 69 $.redux.tabCheck(); 70 $.redux.notices(); 71 72 if ( 'undefined' === typeof $.redux.flyoutSubmenus ) { 73 $.redux.flyoutSubmenu(); 74 } 75 } 76 } 77 ); 78 79 $.redux.flyoutSubmenu = function() { 80 81 // Close flyouts when a new menu item is activated. 82 $( '.redux-group-tab-link-li a' ).on( 83 'click', 84 function() { 85 if ( true === redux.optName.args.flyout_submenus ) { 86 $( '.redux-group-tab-link-li' ).removeClass( 'redux-section-hover' ); 87 } 88 } 89 ); 90 91 if ( true === redux.optName.args.flyout_submenus ) { 92 93 // Submenus flyout when a main menu item is hovered. 94 $( '.redux-group-tab-link-li.hasSubSections' ).each( 95 function() { 96 $( this ).on( 97 'mouseenter', 98 function() { 99 if ( ! $( this ).hasClass( 'active' ) && ! $( this ).hasClass( 'activeChild' ) ) { 100 $( this ).addClass( 'redux-section-hover' ); 101 } 102 } 103 ); 104 105 $( this ).on( 106 'mouseleave', 107 function() { 108 $( this ).removeClass( 'redux-section-hover' ); 109 } 110 ); 111 } 112 ); 113 } 114 }; 115 116 $.redux.disableSections = function() { 117 $( '.redux-group-tab' ).each( 118 function() { 119 if ( $( this ).hasClass( 'disabled' ) ) { 120 $( this ).find( 'input, select, textarea' ).attr( 'name', '' ); 121 } 122 } 123 ); 124 }; 125 126 $.redux.disableFields = function() { 127 $( 'label[for="redux_disable_field"]' ).each( 128 function() { 129 $( this ).parents( 'tr' ).find( 'fieldset:first' ).find( 'input, select, textarea' ).attr( 'name', '' ); 130 } 131 ); 132 }; 133 134 $.redux.hideFields = function() { 135 $( 'label[for="redux_hide_field"]' ).each( 136 function() { 137 var tr = $( this ).parent().parent(); 138 139 $( tr ).addClass( 'hidden' ); 140 } 141 ); 142 }; 143 144 $.redux.getOptName = function( el ) { 145 var metabox; 146 var li; 147 var optName; 148 var item = $( el ); 149 150 if ( redux.customizer ) { 151 optName = item.find( '.redux-customizer-opt-name' ).data( 'opt-name' ); 152 } else { 153 optName = $( el ).parents( '.redux-wrap-div' ).data( 'opt-name' ); 154 } 155 156 // Compatibility for metaboxes 157 if ( undefined === optName ) { 158 metabox = $( el ).parents( '.postbox' ); 159 if ( 0 === metabox.length ) { 160 metabox = $( el ).parents( '.redux-metabox' ); 161 } 162 if ( 0 !== metabox.length ) { 163 optName = metabox.attr( 'id' ).replace( 'redux-', '' ).split( '-metabox-' )[0]; 164 if ( undefined === optName ) { 165 optName = metabox.attr( 'class' ) 166 .replace( 'redux-metabox', '' ) 167 .replace( 'postbox', '' ) 168 .replace( 'redux-', '' ) 169 .replace( 'hide', '' ) 170 .replace( 'closed', '' ) 171 .trim(); 172 } 173 } else { 174 optName = $( '.redux-ajax-security' ).data( 'opt-name' ); 175 } 176 } 177 if ( undefined === optName ) { 178 optName = $( el ).find( '.redux-form-wrapper' ).data( 'opt-name' ); 179 } 180 181 // Shim, let's just get an opt_name shall we?! 182 if ( undefined === optName ) { 183 optName = redux.opt_names[0]; 184 } 185 186 if ( undefined !== optName ) { 187 redux.optName = window['redux_' + optName.replace( /\-/g, '_' )]; 188 } 189 190 return optName; 191 }; 192 193 $.redux.getSelector = function( selector, fieldType ) { 194 if ( ! selector ) { 195 selector = '.redux-container-' + fieldType + ':visible'; 196 if ( redux.customizer ) { 197 selector = $( document ).find( '.control-section-redux.open' ).find( selector ); 198 } else { 199 selector = $( document ).find( '.redux-group-tab:visible' ).find( selector ); 200 } 201 } 202 return selector; 203 }; 204 })( jQuery );