init-events.js (6730B)
1 /* global redux, redux_change, jQuery, pagenow, ajaxurl */ 2 3 (function( $ ) { 4 'use strict'; 5 6 $.redux = $.redux || {}; 7 8 $.redux.initEvents = function( el ) { 9 var stickyHeight; 10 var search = window.location.search; 11 var curPage = pagenow; 12 var dialog; 13 var messageDialog; 14 15 if ( 'string' === typeof search && 'string' === typeof curPage && true === redux.optName.args.dev_mode ) { 16 search = search.replace( '?page=', '' ); 17 curPage = curPage.replace( 'toplevel_page_', '' ); 18 19 if ( search === curPage ) { 20 document.addEventListener( 21 'keydown', 22 function( event ) { 23 if ( event.ctrlKey && event.shiftKey && 'H' === event.key ) { 24 dialog.dialog( 'open' ); 25 } 26 } 27 ); 28 29 messageDialog = $( '#redux-dialog-message' ).dialog( 30 { 31 classes: { 32 'ui-dialog': 'redux-message-dialog', 33 'ui-dialog-buttonpane': 'redux-message-dialog-buttonpane', 34 'ui-dialog-title': 'redux-message-dialog-title', 35 'ui-dialog-content': 'redux-message-dialog-content' 36 }, 37 modal: true, 38 autoOpen: false, 39 resizable: false, 40 height: 'auto', 41 width: 400, 42 buttons: { 43 Ok: function() { 44 $( this ).dialog( 'close' ); 45 } 46 } 47 } 48 ); 49 50 dialog = $( '#redux-dialog-confirm' ).dialog( 51 { 52 modal: true, 53 classes: { 54 'ui-dialog': 'redux-support-dialog' 55 }, 56 autoOpen: false, 57 resizable: false, 58 height: 'auto', 59 width: 400, 60 buttons: { 61 Submit: function() { 62 var buttonPane = $( '.redux-message-dialog-buttonpane' ); 63 var dialogTitle = $( '.redux-message-dialog-title' ); 64 var content = $( '.redux-message-dialog-content .redux-message-p' ); 65 66 $.ajax( 67 { type: 'post', 68 dataType: 'json', 69 url: ajaxurl, 70 data: { 71 action: 'redux_submit_support_data', 72 nonce: $( '#redux-dialog-confirm' ).data( 'nonce' ) 73 }, 74 beforeSend: function() { 75 buttonPane.css( { 'display': 'none' } ); 76 $( '#redux-dialog-message .spinner' ).css( { 'visibility': 'visible' } ); 77 78 messageDialog.dialog( 'open' ); 79 }, 80 error: function( response ) { 81 buttonPane.css( { 'display': 'block' } ); 82 dialogTitle.text( 'Error' ); 83 84 console.log( response ); 85 }, 86 success: function( response ) { 87 buttonPane.css( { 'display': 'block' } ); 88 89 if ( response.status && 'success' === response.status ) { 90 dialogTitle.text( 'Information Sent' ); 91 content.html( 'Your support data has been transmitted. The reference number for this transmission is: <strong>' + response.data + '</strong>' ); 92 } else { 93 dialogTitle.text( 'Error' ); 94 content.text( response.data ); 95 } 96 } 97 } 98 ); 99 100 $( this ).dialog( 'close' ); 101 }, 102 Cancel: function() { 103 $( this ).dialog( 'close' ); 104 } 105 } 106 } 107 ); 108 } 109 } 110 111 el.find( '.redux-presets-bar' ).on( 112 'click', 113 function() { 114 window.onbeforeunload = null; 115 } 116 ); 117 118 // Customizer save hook. 119 el.find( '#customize-save-button-wrapper #save' ).on( 120 'click', 121 function() { 122 123 } 124 ); 125 126 el.find( '#toplevel_page_' + redux.optName.args.slug + ' .wp-submenu a, #wp-admin-bar-' + redux.optName.args.slug + ' a.ab-item' ).on( 127 'click', 128 function( e ) { 129 var url; 130 131 if ( ( el.find( '#toplevel_page_' + redux.optName.args.slug ).hasClass( 'wp-menu-open' ) || 132 $( this ).hasClass( 'ab-item' ) ) && 133 ! $( this ).parents( 'ul.ab-submenu:first' ).hasClass( 'ab-sub-secondary' ) && 134 $( this ).attr( 'href' ).toLowerCase().indexOf( redux.optName.args.slug + '&tab=' ) >= 0 ) { 135 136 url = $( this ).attr( 'href' ).split( '&tab=' ); 137 138 e.preventDefault(); 139 140 el.find( '#' + url[1] + '_section_group_li_a' ).trigger( 'click' ); 141 142 $( this ).parents( 'ul:first' ).find( '.current' ).removeClass( 'current' ); 143 $( this ).addClass( 'current' ); 144 $( this ).parent().addClass( 'current' ); 145 146 return false; 147 } 148 } 149 ); 150 151 // Save button clicked. 152 el.find( '.redux-action_bar input, #redux-import-action input' ).on( 153 'click', 154 function( e ) { 155 if ( $( this ).attr( 'name' ) === redux.optName.args.opt_name + '[defaults]' ) { 156 157 // Defaults button clicked. 158 if ( ! confirm( redux.optName.args.reset_confirm ) ) { 159 return false; 160 } 161 } else if ( $( this ).attr( 'name' ) === redux.optName.args.opt_name + '[defaults-section]' ) { 162 163 // Default section clicked. 164 if ( ! confirm( redux.optName.args.reset_section_confirm ) ) { 165 return false; 166 } 167 } else if ( 'import' === $( this ).attr( 'name' ) ) { 168 if ( ! confirm( redux.optName.args.import_section_confirm ) ) { 169 return false; 170 } 171 } 172 173 window.onbeforeunload = null; 174 175 if ( true === redux.optName.args.ajax_save ) { 176 $.redux.ajax_save( $( this ) ); 177 e.preventDefault(); 178 } else { 179 location.reload( true ); 180 } 181 } 182 ); 183 184 $( '.expand_options' ).on( 185 'click', 186 function( e ) { 187 var tab; 188 189 var container = el; 190 191 e.preventDefault(); 192 193 if ( $( container ).hasClass( 'fully-expanded' ) ) { 194 $( container ).removeClass( 'fully-expanded' ); 195 196 tab = $.cookie( 'redux_current_tab_' + redux.optName.args.opt_name ); 197 198 el.find( '#' + tab + '_section_group' ).fadeIn( 199 200, 200 function() { 201 if ( 0 !== el.find( '#redux-footer' ).length ) { 202 $.redux.stickyInfo(); // Race condition fix. 203 } 204 205 $.redux.initFields(); 206 } 207 ); 208 } 209 210 $.redux.expandOptions( $( this ).parents( '.redux-container:first' ) ); 211 212 return false; 213 } 214 ); 215 216 if ( el.find( '.saved_notice' ).is( ':visible' ) ) { 217 el.find( '.saved_notice' ).slideDown(); 218 } 219 220 $( document.body ).on( 221 'change', 222 '.redux-field input, .redux-field textarea, .redux-field select', 223 function() { 224 if ( $( '.redux-container-typography select' ).hasClass( 'ignore-change' ) ) { 225 return; 226 } 227 if ( ! $( this ).hasClass( 'noUpdate' ) && ! $( this ).hasClass( 'no-update' ) ) { 228 redux_change( $( this ) ); 229 } 230 } 231 ); 232 233 stickyHeight = el.find( '#redux-footer' ).height(); 234 235 el.find( '#redux-sticky-padder' ).css( 236 { height: stickyHeight } 237 ); 238 239 el.find( '#redux-footer-sticky' ).removeClass( 'hide' ); 240 241 if ( 0 !== el.find( '#redux-footer' ).length ) { 242 $( window ).on( 243 'scroll', 244 function() { 245 $.redux.stickyInfo(); 246 } 247 ); 248 249 $( window ).on( 250 'resize', 251 function() { 252 $.redux.stickyInfo(); 253 } 254 ); 255 } 256 257 el.find( '.saved_notice' ).delay( 4000 ).slideUp(); 258 }; 259 })( jQuery );