PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 4.7.1.1
Hustle – Email Marketing, Lead Generation, Optins, Popups v4.7.1.1
7.8.14.2 7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / js / popup-admin.js
wordpress-popup / js Last commit date
ace.js 11 years ago ace.min.js 11 years ago popup-admin.js 11 years ago popup-admin.min.js 11 years ago public.js 11 years ago public.min.js 11 years ago theme-chrome.js 11 years ago theme-chrome.min.js 11 years ago worker-css.js 11 years ago worker-css.min.js 11 years ago
popup-admin.js
576 lines
1 /*! PopUp Free - v4.7.11
2 * https://wordpress.org/plugins/wordpress-popup/
3 * Copyright (c) 2015; * Licensed GPLv2+ */
4 /*global window:false */
5 /*global document:false */
6 /*global wp:false */
7 /*global wpmUi:false */
8 /*global ace:false */
9
10 /**
11 * Admin Javascript functions for PopUp
12 */
13
14 jQuery(function init_admin() {
15
16 // ----- POPUP EDITOR --
17
18 // Disables dragging of metaboxes: Users cannot change the metabox order.
19 function disable_metabox_dragging() {
20 var boxes = jQuery( '.meta-box-sortables' ),
21 handles = jQuery( '.postbox .hndle' );
22
23 if ( ! boxes.length ) { return; }
24
25 boxes.sortable({
26 disabled: true
27 });
28 handles.css( 'cursor', 'pointer' );
29 }
30
31 // Keeps the submitdiv always visible, even when scrolling.
32 function scrolling_submitdiv() {
33 var scroll_top,
34 top_offset,
35 submitdiv = jQuery( '#submitdiv' ),
36 postbody = jQuery( '#post-body' ),
37 body = jQuery( 'body' ),
38 padding = 20;
39
40 if ( ! submitdiv.length ) { return; }
41 top_offset = submitdiv.position().top;
42
43 var small_make_sticky = function() {
44 if ( ! body.hasClass( 'sticky-submit' ) ) {
45 body.addClass( 'sticky-submit' );
46 submitdiv.css({ 'marginTop': 0 } );
47 submitdiv.find( '.sticky-actions' ).show();
48 submitdiv.find( '.non-sticky' ).hide();
49 }
50 };
51
52 var small_remove_sticky = function() {
53 if ( body.hasClass( 'sticky-submit' ) ) {
54 body.removeClass( 'sticky-submit' );
55 submitdiv.find( '.sticky-actions' ).hide();
56 submitdiv.find( '.non-sticky' ).show();
57 }
58 };
59
60 jQuery( window ).resize(function() {
61 var is_small = jQuery( window ).width() <= 850;
62
63 if ( is_small ) {
64 if ( ! body.hasClass( 'po-small' ) ) {
65 body.addClass( 'po-small' );
66 }
67 } else {
68 if ( body.hasClass( 'po-small' ) ) {
69 body.removeClass( 'po-small' );
70 small_remove_sticky();
71 }
72 }
73 }).scroll(function(){
74 if ( postbody.hasClass( 'columns-1' ) || body.hasClass( 'po-small' ) ) {
75 // 1-column view:
76 // The div stays as sticky toolbar when scrolling down.
77
78 scroll_top = jQuery( window ).scrollTop() - top_offset;
79
80 if ( scroll_top > 0 ) {
81 small_make_sticky();
82 } else {
83 small_remove_sticky();
84 }
85 } else {
86 // 2-column view:
87 // The div scrolls with the page to stay visible.
88
89 scroll_top = jQuery( window ).scrollTop() - top_offset + padding;
90
91 if ( scroll_top > 0 ) {
92 submitdiv.css({ 'marginTop': scroll_top } );
93 } else {
94 submitdiv.css({ 'marginTop': 0 } );
95 }
96 }
97 });
98
99 window.setTimeout( function() {
100 jQuery( window ).trigger( 'scroll' );
101 }, 100 );
102 }
103
104 // Change the text-fields to colorpicker fields.
105 function init_colorpicker() {
106 var inp = jQuery( '.colorpicker' );
107
108 if ( ! inp.length || 'function' !== typeof inp.wpColorPicker ) { return; }
109
110 var maybe_hide_picker = function maybe_hide_picker( ev ) {
111 var el = jQuery( ev.target ),
112 cp = el.closest( '.wp-picker-container' ),
113 me = cp.find( '.colorpicker' ),
114 do_hide = jQuery( '.colorpicker' );
115
116 if ( cp.length ) {
117 do_hide = do_hide.not( me );
118 }
119
120 do_hide.each( function() {
121 var picker = jQuery( this ),
122 wrap = picker.closest( '.wp-picker-container' );
123
124 picker.iris( 'hide' );
125
126 // As mentioned: Color picker does not like to hide properly...
127 picker.hide();
128 wrap.find( '.wp-picker-clear').addClass( 'hidden' );
129 wrap.find( '.wp-picker-open').removeClass( 'wp-picker-open' );
130 });
131 };
132
133 inp.wpColorPicker();
134
135 // Don't ask why the handler is hooked three times ;-)
136 // The Color picker is a bit bitchy when it comes to hiding it...
137 jQuery( document ).on( 'mousedown', maybe_hide_picker );
138 jQuery( document ).on( 'click', maybe_hide_picker );
139 jQuery( document ).on( 'mouseup', maybe_hide_picker );
140 }
141
142 // Add event handlers for editor UI controls (i.e. to checkboxes)
143 function init_edit_controls() {
144 var chk_colors = jQuery( '#po-custom-colors' ),
145 chk_size = jQuery( '#po-custom-size' ),
146 opt_display = jQuery( '[name=po_display]' ),
147 chk_can_hide = jQuery( '#po-can-hide' ),
148 chk_close_hides = jQuery( '#po-close-hides' );
149
150 if ( ! chk_colors.length ) { return; }
151
152 var toggle_section = function toggle_section() {
153 var group,
154 me = jQuery( this ),
155 sel = me.data( 'toggle' ),
156 sect = jQuery( sel ),
157 group_or = me.data( 'or' ),
158 group_and = me.data( 'and' ),
159 is_active = false;
160
161 if ( group_or ) {
162 group = jQuery( group_or );
163 is_active = ( group.filter( ':checked' ).length > 0);
164 } else if ( group_and ) {
165 group = jQuery( group_and );
166 is_active = ( group.length === group.filter( ':checked' ).length );
167 } else {
168 is_active = me.prop( 'checked' );
169 }
170
171 if ( is_active ) {
172 sect.removeClass( 'inactive' );
173 sect.find( 'input,select,textarea,a' )
174 .prop( 'readonly', false )
175 .removeClass( 'disabled' );
176 } else {
177 sect.addClass( 'inactive' );
178 // Do NOT set .prop('disabled', true)!
179 sect.find( 'input,select,textarea,a' )
180 .prop( 'readonly', true )
181 .addClass( 'disabled' );
182 }
183 sect.addClass( 'inactive-anim' );
184 };
185
186 var toggle_section_group = function toggle_section_group() {
187 var me = jQuery( this ),
188 name = me.attr( 'name' ),
189 group = jQuery( '[name="' + name + '"]' );
190
191 group.each(function() {
192 toggle_section.call( this );
193 });
194 };
195
196 var create_sliders = function create_sliders() {
197 jQuery( '.slider' ).each(function() {
198 var me = jQuery( this ),
199 wrap = me.closest( '.slider-wrap' ),
200 inp_base = me.data( 'input' ),
201 inp_min = wrap.find( inp_base + 'min' ),
202 inp_max = wrap.find( inp_base + 'max' ),
203 min_input = wrap.find( '.slider-min-input' ),
204 min_ignore = wrap.find( '.slider-min-ignore' ),
205 max_input = wrap.find( '.slider-max-input' ),
206 max_ignore = wrap.find( '.slider-max-ignore' ),
207 min = me.data( 'min' ),
208 max = me.data( 'max' );
209
210 if ( isNaN( min ) ) { min = 0; }
211 if ( isNaN( max ) ) { max = 9999; }
212 inp_min.prop( 'readonly', true );
213 inp_max.prop( 'readonly', true );
214
215 var update_fields = function update_fields( val1, val2 ) {
216 inp_min.val( val1 );
217 inp_max.val( val2 );
218
219 if ( val1 === min ) {
220 min_input.hide();
221 min_ignore.show();
222 } else {
223 min_input.show();
224 min_ignore.hide();
225 }
226 if ( val2 === max ) {
227 max_input.hide();
228 max_ignore.show();
229 } else {
230 max_input.show();
231 max_ignore.hide();
232 }
233 };
234
235 me.slider({
236 range: true,
237 min: min,
238 max: max,
239 values: [ inp_min.val(), inp_max.val() ],
240 slide: function( event, ui ) {
241 update_fields( ui.values[0], ui.values[1] );
242 }
243 });
244
245 update_fields( inp_min.val(), inp_max.val() );
246 });
247 };
248
249 chk_colors.click( toggle_section );
250 chk_size.click( toggle_section );
251 chk_can_hide.click( toggle_section );
252 chk_close_hides.click( toggle_section );
253 opt_display.click( toggle_section_group );
254
255 toggle_section.call( chk_colors );
256 toggle_section.call( chk_size );
257 toggle_section.call( chk_can_hide );
258 toggle_section.call( chk_close_hides );
259
260 opt_display.each(function() {
261 toggle_section.call( jQuery( this ) );
262 });
263
264 create_sliders();
265 }
266
267 // Toggle rules on/off
268 function init_rules() {
269 var all_rules = jQuery( '#meta-rules .all-rules' ),
270 active_rules = jQuery( '#meta-rules .active-rules' );
271
272 if ( ! all_rules.length ) { return; }
273
274 var toggle_checkbox = function toggle_checkbox( ev ) {
275 var me = jQuery( ev.target ),
276 chk = me.find( 'input.wpmui-toggle-checkbox' );
277
278 if ( me.closest( '.wpmui-toggle' ).length ) { return; }
279 if ( me.hasClass( 'inactive' ) ) { return false; }
280 chk.trigger( 'click' );
281 };
282
283 var toggle_rule = function toggle_rule() {
284 var me = jQuery( this ),
285 rule = me.closest( '.rule' ),
286 sel = me.data( 'form' ),
287 form = active_rules.find( sel ),
288 active = me.prop( 'checked' );
289
290 if ( active ) {
291 rule.removeClass( 'off' ).addClass( 'on' );
292 form.removeClass( 'off' ).addClass( 'on open' );
293 } else {
294 rule.removeClass( 'on' ).addClass( 'off' );
295 form.removeClass( 'on' ).addClass( 'off' );
296 }
297
298 exclude_rules( me, active );
299 };
300
301 var exclude_rules = function exclude_rules( checkbox, active ) {
302 var ind, excl1, excl2,
303 excl = checkbox.data( 'exclude' ),
304 keys = (excl ? excl.split( ',' ) : []);
305
306 // Exclude other rules.
307 for ( ind = keys.length - 1; ind >= 0; ind -= 1 ) {
308 excl1 = all_rules.find( '.rule-' + keys[ ind ] );
309 excl2 = active_rules.find( '#po-rule-' + keys[ ind ] );
310
311 if ( excl1.hasClass( 'on' ) ) {
312 // Rule is active; possibly migrated from old PopUp editor
313 // so we cannot disable the rule now...
314 continue;
315 }
316
317 excl1.prop( 'disabled', active );
318 if ( active ) {
319 excl1.addClass( 'inactive off' ).removeClass( 'on' );
320 excl2.addClass( 'off' ).removeClass( 'on' );
321 } else {
322 excl1.removeClass( 'inactive off' );
323 }
324 }
325 };
326
327 var toggle_form = function toggle_form() {
328 var me = jQuery( this ),
329 form = me.closest( '.rule' );
330
331 form.toggleClass( 'open' );
332 };
333
334 all_rules.find( 'input.wpmui-toggle-checkbox' ).click( toggle_rule );
335 all_rules.find( '.rule' ).click( toggle_checkbox );
336 active_rules.on( 'click', '.rule-title,.rule-toggle', toggle_form );
337
338 // Exclude rules.
339 all_rules.find( '.rule.on input.wpmui-toggle-checkbox' ).each(function() {
340 exclude_rules( jQuery( this ), true );
341 });
342 jQuery( '.init-loading' ).removeClass( 'wpmui-loading' );
343 }
344
345 // Hook up the "Featured image" button.
346 function init_image() {
347 // Uploading files
348 var box = jQuery( '.content-image' ),
349 btn = box.find( '.add_image' ),
350 dropzone = box.find( '.featured-img' ),
351 reset = box.find( '.reset' ),
352 inp = box.find( '.po-image' ),
353 img_preview = box.find( '.img-preview' ),
354 img_label = box.find( '.lbl-empty' ),
355 img_pos = box.find( '.img-pos' ),
356 file_frame;
357
358 // User selected an image (via drag-drop or file_frame)
359 var use_image = function use_image( url ) {
360 inp.val( url );
361 img_preview.attr( 'src', url ).show();
362 img_label.hide();
363 img_pos.show();
364 dropzone.addClass( 'has-image' );
365 };
366
367 // User selected an image (via drag-drop or file_frame)
368 var reset_image = function reset_image( url ) {
369 inp.val( '' );
370 img_preview.attr( 'src', '' ).hide();
371 img_label.show();
372 img_pos.hide();
373 dropzone.removeClass( 'has-image' );
374 };
375
376 // User clicks on the "Add image" button.
377 var select_clicked = function select_clicked( ev ) {
378 ev.preventDefault();
379
380 // If the media frame already exists, reopen it.
381 if ( file_frame ) {
382 file_frame.open();
383 return;
384 }
385
386 // Create the media frame.
387 file_frame = wp.media.frames.file_frame = wp.media({
388 title: btn.attr( 'data-title' ),
389 button: {
390 text: btn.attr( 'data-button' )
391 },
392 multiple: false // Set to true to allow multiple files to be selected
393 });
394
395 // When an image is selected, run a callback.
396 file_frame.on( 'select', function() {
397 // We set multiple to false so only get one image from the uploader
398 var attachment = file_frame.state().get('selection').first().toJSON();
399
400 // Do something with attachment.id and/or attachment.url here
401 use_image( attachment.url );
402 });
403
404 // Finally, open the modal
405 file_frame.open();
406 };
407
408 var select_pos = function select_pos( ev ) {
409 var me = jQuery( this );
410
411 img_pos.find( '.option' ).removeClass( 'selected' );
412 me.addClass( 'selected' );
413 };
414
415 btn.on( 'click', select_clicked );
416 reset.on( 'click', reset_image );
417 img_pos.on( 'click', '.option', select_pos );
418 }
419
420 // ----- POPUP LIST --
421
422 // Adds custom bulk actions to the popup list.
423 function bulk_actions() {
424 var key,
425 ba1 = jQuery( 'select[name="action"] '),
426 ba2 = jQuery( 'select[name="action2"] ');
427
428 if ( ! ba1.length || 'object' !== typeof window.po_bulk ) { return; }
429
430 for ( key in window.po_bulk ) {
431 jQuery( '<option>' )
432 .val( key )
433 .text( window.po_bulk[key] )
434 .appendTo( ba1 )
435 .clone()
436 .appendTo( ba2 );
437 }
438 }
439
440 // Makes the post-list sortable (to change popup-order)
441 function sortable_list() {
442 var table = jQuery( 'table.posts' ),
443 tbody = table.find( '#the-list' );
444
445 if ( ! tbody.length ) { return; }
446
447 var ajax_done = function ajax_done( resp, okay ) {
448 table.removeClass( 'wpmui-loading' );
449 if ( okay ) {
450 for ( var id in resp ) {
451 if ( ! resp.hasOwnProperty( id ) ) { continue; }
452 tbody.find( '#post-' + id + ' .the-pos' ).text( resp[id] );
453 }
454 }
455 };
456
457 var save_order = function save_order( event, ui ) {
458 var i,
459 rows = tbody.find('tr'),
460 order = [];
461
462 for ( i = 0; i < rows.length; i+= 1 ) {
463 order.push( jQuery( rows[i] ).attr( 'id' ) );
464 }
465
466 table.addClass( 'wpmui-loading' );
467 wpmUi.ajax( null, 'po-ajax' )
468 .data({
469 'do': 'order',
470 'order': order
471 })
472 .ondone( ajax_done )
473 .load_json();
474 };
475
476 tbody.sortable({
477 placeholder: 'ui-sortable-placeholder',
478 axis: 'y',
479 handle: '.column-po_order',
480 helper: 'clone',
481 opacity: 0.75,
482 update: save_order
483 });
484 tbody.disableSelection();
485 }
486
487 // Shows a preview of the current PopUp.
488 function init_preview() {
489 var doc = jQuery( document ),
490 body = jQuery( '#wpcontent' );
491
492 var handle_list_click = function handle_list_click( ev ) {
493 var me = jQuery( this ),
494 po_id = me.data( 'id' );
495
496 ev.preventDefault();
497 if ( undefined === window.inc_popup ) { return false; }
498
499 body.addClass( 'wpmui-loading' );
500 window.inc_popup.load( po_id );
501 return false;
502 };
503
504 var handle_editor_click = function handle_editor_click( ev ) {
505 var data,
506 me = jQuery( this ),
507 form = jQuery( '#post' ),
508 ajax = wpmUi.ajax();
509
510 ev.preventDefault();
511 if ( undefined === window.inc_popup ) { return false; }
512
513 data = ajax.extract_data( form );
514 body.addClass( 'wpmui-loading' );
515 window.inc_popup.load( 0, data );
516 return false;
517 };
518
519 var show_popup = function show_popup( ev, popup ) {
520 body.removeClass( 'wpmui-loading' );
521 popup.init();
522 };
523
524 doc.on( 'click', '.posts .po-preview', handle_list_click );
525 doc.on( 'click', '#post .preview', handle_editor_click );
526 doc.on( 'popup-initialized', show_popup );
527 }
528
529 // Initialize the CSS editor
530 function init_css_editor() {
531 jQuery('.po_css_editor').each(function(){
532 var editor = ace.edit(this.id);
533
534 jQuery(this).data('editor', editor);
535 editor.setTheme('ace/theme/chrome');
536 editor.getSession().setMode('ace/mode/css');
537 editor.getSession().setUseWrapMode(true);
538 editor.getSession().setUseWrapMode(false);
539 });
540
541 jQuery('.po_css_editor').each(function(){
542 var self = this,
543 input = jQuery( jQuery(this).data('input') );
544
545 jQuery(this).data('editor').getSession().on('change', function () {
546 input.val( jQuery(self).data('editor').getSession().getValue() );
547 });
548 });
549 }
550
551 if ( ! jQuery( 'body.post-type-inc_popup' ).length ) {
552 return;
553 }
554
555 // EDITOR
556 if ( jQuery( 'body.post-php' ).length || jQuery( 'body.post-new-php' ).length ) {
557 disable_metabox_dragging();
558 scrolling_submitdiv();
559 init_colorpicker();
560 init_edit_controls();
561 init_rules();
562 init_preview();
563 init_image();
564 init_css_editor();
565
566 wpmUi.upgrade_multiselect();
567 }
568
569 // POPUP LIST
570 else if ( jQuery( 'body.edit-php' ).length ) {
571 sortable_list();
572 bulk_actions();
573 init_preview();
574 }
575
576 });