PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.1.4
StreamCast – bring live radio to your site with a sleek player v2.1.4
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / admin / codestar-framework / assets / js / main.js

main.js in StreamCast – bring live radio to your site with a sleek player 2.1.4, at admin/codestar-framework/assets/js/main.js

3,381 lines 94.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 *
3 * -----------------------------------------------------------
4 *
5 * Codestar Framework
6 * A Simple and Lightweight WordPress Option Framework
7 *
8 * -----------------------------------------------------------
9 *
10 */
11 ;(function( $, window, document, undefined ) {
12 'use strict';
13
14 //
15 // Constants
16 //
17 var CSF = CSF || {};
18
19 CSF.funcs = {};
20
21 CSF.vars = {
22 onloaded: false,
23 $body: $('body'),
24 $window: $(window),
25 $document: $(document),
26 $form_warning: null,
27 is_confirm: false,
28 form_modified: false,
29 code_themes: [],
30 is_rtl: $('body').hasClass('rtl'),
31 };
32
33 //
34 // Helper Functions
35 //
36 CSF.helper = {
37
38 //
39 // Generate UID
40 //
41 uid: function( prefix ) {
42 return ( prefix || '' ) + Math.random().toString(36).substr(2, 9);
43 },
44
45 // Quote regular expression characters
46 //
47 preg_quote: function( str ) {
48 return (str+'').replace(/(\[|\])/g, "\\$1");
49 },
50
51 //
52 // Reneme input names
53 //
54 name_nested_replace: function( $selector, field_id ) {
55
56 var checks = [];
57 var regex = new RegExp(CSF.helper.preg_quote(field_id +'[\\d+]'), 'g');
58
59 $selector.find(':radio').each(function() {
60 if ( this.checked || this.orginal_checked ) {
61 this.orginal_checked = true;
62 }
63 });
64
65 $selector.each( function( index ) {
66 $(this).find(':input').each(function() {
67 this.name = this.name.replace(regex, field_id +'['+ index +']');
68 if ( this.orginal_checked ) {
69 this.checked = true;
70 }
71 });
72 });
73
74 },
75
76 //
77 // Debounce
78 //
79 debounce: function( callback, threshold, immediate ) {
80 var timeout;
81 return function() {
82 var context = this, args = arguments;
83 var later = function() {
84 timeout = null;
85 if ( !immediate ) {
86 callback.apply(context, args);
87 }
88 };
89 var callNow = ( immediate && !timeout );
90 clearTimeout( timeout );
91 timeout = setTimeout( later, threshold );
92 if ( callNow ) {
93 callback.apply(context, args);
94 }
95 };
96 },
97
98 };
99
100 //
101 // Custom clone for textarea and select clone() bug
102 //
103 $.fn.csf_clone = function() {
104
105 var base = $.fn.clone.apply(this, arguments),
106 clone = this.find('select').add(this.filter('select')),
107 cloned = base.find('select').add(base.filter('select'));
108
109 for( var i = 0; i < clone.length; ++i ) {
110 for( var j = 0; j < clone[i].options.length; ++j ) {
111
112 if ( clone[i].options[j].selected === true ) {
113 cloned[i].options[j].selected = true;
114 }
115
116 }
117 }
118
119 this.find(':radio').each( function() {
120 this.orginal_checked = this.checked;
121 });
122
123 return base;
124
125 };
126
127 //
128 // Expand All Options
129 //
130 $.fn.csf_expand_all = function() {
131 return this.each( function() {
132 $(this).on('click', function( e ) {
133
134 e.preventDefault();
135 $('.csf-wrapper').toggleClass('csf-show-all');
136 $('.csf-section').csf_reload_script();
137 $(this).find('.fa').toggleClass('fa-indent').toggleClass('fa-outdent');
138
139 });
140 });
141 };
142
143 //
144 // Options Navigation
145 //
146 $.fn.csf_nav_options = function() {
147 return this.each( function() {
148
149 var $nav = $(this),
150 $links = $nav.find('a'),
151 $last;
152
153 $(window).on('hashchange csf.hashchange', function() {
154
155 var hash = window.location.hash.replace('#tab=', '');
156 var slug = hash ? hash : $links.first().attr('href').replace('#tab=', '');
157 var $link = $('[data-tab-id="'+slug+'"]');
158
159 if ( $link.length ) {
160
161 $link.closest('.csf-tab-item').addClass('csf-tab-expanded').siblings().removeClass('csf-tab-expanded');
162
163 if( $link.next().is('ul') ) {
164
165 $link = $link.next().find('li').first().find('a');
166 slug = $link.data('tab-id');
167
168 }
169
170 $links.removeClass('csf-active');
171 $link.addClass('csf-active');
172
173 if ( $last ) {
174 $last.addClass('hidden');
175 }
176
177 var $section = $('[data-section-id="'+slug+'"]');
178
179 $section.removeClass('hidden');
180 $section.csf_reload_script();
181
182 $('.csf-section-id').val( $section.index()+1 );
183
184 $last = $section;
185
186 }
187
188 }).trigger('csf.hashchange');
189
190 });
191 };
192
193 //
194 // Metabox Tabs
195 //
196 $.fn.csf_nav_metabox = function() {
197 return this.each( function() {
198
199 var $nav = $(this),
200 $links = $nav.find('a'),
201 $sections = $nav.parent().find('.csf-section'),
202 $last;
203
204 $links.each( function( index ) {
205
206 $(this).on('click', function( e ) {
207
208 e.preventDefault();
209
210 var $link = $(this);
211
212 $links.removeClass('csf-active');
213 $link.addClass('csf-active');
214
215 if ( $last !== undefined ) {
216 $last.addClass('hidden');
217 }
218
219 var $section = $sections.eq(index);
220
221 $section.removeClass('hidden');
222 $section.csf_reload_script();
223
224 $last = $section;
225
226 });
227
228 });
229
230 $links.first().trigger('click');
231
232 });
233 };
234
235 //
236 // Metabox Page Templates Listener
237 //
238 $.fn.csf_page_templates = function() {
239 if ( this.length ) {
240
241 $(document).on('change', '.editor-page-attributes__template select, #page_template', function() {
242
243 var maybe_value = $(this).val() || 'default';
244
245 $('.csf-page-templates').removeClass('csf-metabox-show').addClass('csf-metabox-hide');
246 $('.csf-page-'+maybe_value.toLowerCase().replace(/[^a-zA-Z0-9]+/g,'-')).removeClass('csf-metabox-hide').addClass('csf-metabox-show');
247
248 });
249
250 }
251 };
252
253 //
254 // Metabox Post Formats Listener
255 //
256 $.fn.csf_post_formats = function() {
257 if ( this.length ) {
258
259 $(document).on('change', '.editor-post-format select, #formatdiv input[name="post_format"]', function() {
260
261 var maybe_value = $(this).val() || 'default';
262
263 // Fallback for classic editor version
264 maybe_value = ( maybe_value === '0' ) ? 'default' : maybe_value;
265
266 $('.csf-post-formats').removeClass('csf-metabox-show').addClass('csf-metabox-hide');
267 $('.csf-post-format-'+maybe_value).removeClass('csf-metabox-hide').addClass('csf-metabox-show');
268
269 });
270
271 }
272 };
273
274 //
275 // Search
276 //
277 $.fn.csf_search = function() {
278 return this.each( function() {
279
280 var $this = $(this),
281 $input = $this.find('input');
282
283 $input.on('change keyup', function() {
284
285 var value = $(this).val(),
286 $wrapper = $('.csf-wrapper'),
287 $section = $wrapper.find('.csf-section'),
288 $fields = $section.find('> .csf-field:not(.csf-depend-on)'),
289 $titles = $fields.find('> .csf-title, .csf-search-tags');
290
291 if ( value.length > 3 ) {
292
293 $fields.addClass('csf-metabox-hide');
294 $wrapper.addClass('csf-search-all');
295
296 $titles.each( function() {
297
298 var $title = $(this);
299
300 if ( $title.text().match( new RegExp('.*?' + value + '.*?', 'i') ) ) {
301
302 var $field = $title.closest('.csf-field');
303
304 $field.removeClass('csf-metabox-hide');
305 $field.parent().csf_reload_script();
306
307 }
308
309 });
310
311 } else {
312
313 $fields.removeClass('csf-metabox-hide');
314 $wrapper.removeClass('csf-search-all');
315
316 }
317
318 });
319
320 });
321 };
322
323 //
324 // Sticky Header
325 //
326 $.fn.csf_sticky = function() {
327 return this.each( function() {
328
329 var $this = $(this),
330 $window = $(window),
331 $inner = $this.find('.csf-header-inner'),
332 padding = parseInt( $inner.css('padding-left') ) + parseInt( $inner.css('padding-right') ),
333 offset = 32,
334 scrollTop = 0,
335 lastTop = 0,
336 ticking = false,
337 stickyUpdate = function() {
338
339 var offsetTop = $this.offset().top,
340 stickyTop = Math.max(offset, offsetTop - scrollTop ),
341 winWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
342
343 if ( stickyTop <= offset && winWidth > 782 ) {
344 $inner.css({width: $this.outerWidth()-padding});
345 $this.css({height: $this.outerHeight()}).addClass( 'csf-sticky' );
346 } else {
347 $inner.removeAttr('style');
348 $this.removeAttr('style').removeClass( 'csf-sticky' );
349 }
350
351 },
352 requestTick = function() {
353
354 if ( !ticking ) {
355 requestAnimationFrame( function() {
356 stickyUpdate();
357 ticking = false;
358 });
359 }
360
361 ticking = true;
362
363 },
364 onSticky = function() {
365
366 scrollTop = $window.scrollTop();
367 requestTick();
368
369 };
370
371 $window.on( 'scroll resize', onSticky);
372
373 onSticky();
374
375 });
376 };
377
378 //
379 // Dependency System
380 //
381 $.fn.csf_dependency = function() {
382 return this.each( function() {
383
384 var $this = $(this),
385 $fields = $this.children('[data-controller]');
386
387 if( $fields.length ) {
388
389 var normal_ruleset = $.csf_deps.createRuleset(),
390 global_ruleset = $.csf_deps.createRuleset(),
391 normal_depends = [],
392 global_depends = [];
393
394 $fields.each( function() {
395
396 var $field = $(this),
397 controllers = $field.data('controller').split('|'),
398 conditions = $field.data('condition').split('|'),
399 values = $field.data('value').toString().split('|'),
400 is_global = $field.data('depend-global') ? true : false,
401 ruleset = ( is_global ) ? global_ruleset : normal_ruleset;
402
403 $.each(controllers, function( index, depend_id ) {
404
405 var value = values[index] || '',
406 condition = conditions[index] || conditions[0];
407
408 ruleset = ruleset.createRule('[data-depend-id="'+ depend_id +'"]', condition, value);
409
410 ruleset.include($field);
411
412 if ( is_global ) {
413 global_depends.push(depend_id);
414 } else {
415 normal_depends.push(depend_id);
416 }
417
418 });
419
420 });
421
422 if ( normal_depends.length ) {
423 $.csf_deps.enable($this, normal_ruleset, normal_depends);
424 }
425
426 if ( global_depends.length ) {
427 $.csf_deps.enable(CSF.vars.$body, global_ruleset, global_depends);
428 }
429
430 }
431
432 });
433 };
434
435 //
436 // Field: accordion
437 //
438 $.fn.csf_field_accordion = function() {
439 return this.each( function() {
440
441 var $titles = $(this).find('.csf-accordion-title');
442
443 $titles.on('click', function() {
444
445 var $title = $(this),
446 $icon = $title.find('.csf-accordion-icon'),
447 $content = $title.next();
448
449 if ( $icon.hasClass('fa-angle-right') ) {
450 $icon.removeClass('fa-angle-right').addClass('fa-angle-down');
451 } else {
452 $icon.removeClass('fa-angle-down').addClass('fa-angle-right');
453 }
454
455 if ( !$content.data( 'opened' ) ) {
456
457 $content.csf_reload_script();
458 $content.data( 'opened', true );
459
460 }
461
462 $content.toggleClass('csf-accordion-open');
463
464 });
465
466 });
467 };
468
469 //
470 // Field: backup
471 //
472 $.fn.csf_field_backup = function() {
473 return this.each( function() {
474
475 if ( window.wp.customize === undefined ) { return; }
476
477 var base = this,
478 $this = $(this),
479 $body = $('body'),
480 $import = $this.find('.csf-import'),
481 $reset = $this.find('.csf-reset');
482
483 base.notificationOverlay = function() {
484
485 if ( wp.customize.notifications && wp.customize.OverlayNotification ) {
486
487 // clear if there is any saved data.
488 if ( !wp.customize.state('saved').get() ) {
489 wp.customize.state('changesetStatus').set('trash');
490 wp.customize.each( function( setting ) { setting._dirty = false; });
491 wp.customize.state('saved').set(true);
492 }
493
494 // then show a notification overlay
495 wp.customize.notifications.add( new wp.customize.OverlayNotification('csf_field_backup_notification', {
496 type: 'default',
497 message: '&nbsp;',
498 loading: true
499 }));
500
501 }
502
503 };
504
505 $reset.on('click', function( e ) {
506
507 e.preventDefault();
508
509 if ( CSF.vars.is_confirm ) {
510
511 base.notificationOverlay();
512
513 window.wp.ajax.post('csf-reset', {
514 unique: $reset.data('unique'),
515 nonce: $reset.data('nonce')
516 })
517 .done( function( response ) {
518 window.location.reload(true);
519 })
520 .fail( function( response ) {
521 alert( response.error );
522 wp.customize.notifications.remove('csf_field_backup_notification');
523 });
524
525 }
526
527 });
528
529 $import.on('click', function( e ) {
530
531 e.preventDefault();
532
533 if ( CSF.vars.is_confirm ) {
534
535 base.notificationOverlay();
536
537 window.wp.ajax.post( 'csf-import', {
538 unique: $import.data('unique'),
539 nonce: $import.data('nonce'),
540 data: $this.find('.csf-import-data').val()
541 }).done( function( response ) {
542 window.location.reload(true);
543 }).fail( function( response ) {
544 alert( response.error );
545 wp.customize.notifications.remove('csf_field_backup_notification');
546 });
547
548 }
549
550 });
551
552 });
553 };
554
555 //
556 // Field: background
557 //
558 $.fn.csf_field_background = function() {
559 return this.each( function() {
560 $(this).find('.csf--background-image').csf_reload_script();
561 });
562 };
563
564 //
565 // Field: code_editor
566 //
567 $.fn.csf_field_code_editor = function() {
568 return this.each( function() {
569
570 if ( typeof CodeMirror !== 'function' ) { return; }
571
572 var $this = $(this),
573 $textarea = $this.find('textarea'),
574 $inited = $this.find('.CodeMirror'),
575 data_editor = $textarea.data('editor');
576
577 if ( $inited.length ) {
578 $inited.remove();
579 }
580
581 var interval = setInterval(function () {
582 if ( $this.is(':visible') ) {
583
584 var code_editor = CodeMirror.fromTextArea( $textarea[0], data_editor );
585
586 // load code-mirror theme css.
587 if ( data_editor.theme !== 'default' && CSF.vars.code_themes.indexOf(data_editor.theme) === -1 ) {
588
589 var $cssLink = $('<link>');
590
591 $('#csf-codemirror-css').after( $cssLink );
592
593 $cssLink.attr({
594 rel: 'stylesheet',
595 id: 'csf-codemirror-'+ data_editor.theme +'-css',
596 href: data_editor.cdnURL +'/theme/'+ data_editor.theme +'.min.css',
597 type: 'text/css',
598 media: 'all'
599 });
600
601 CSF.vars.code_themes.push(data_editor.theme);
602
603 }
604
605 CodeMirror.modeURL = data_editor.cdnURL +'/mode/%N/%N.min.js';
606 CodeMirror.autoLoadMode(code_editor, data_editor.mode);
607
608 code_editor.on( 'change', function( editor, event ) {
609 $textarea.val( code_editor.getValue() ).trigger('change');
610 });
611
612 clearInterval(interval);
613
614 }
615 });
616
617 });
618 };
619
620 //
621 // Field: date
622 //
623 $.fn.csf_field_date = function() {
624 return this.each( function() {
625
626 var $this = $(this),
627 $inputs = $this.find('input'),
628 settings = $this.find('.csf-date-settings').data('settings'),
629 wrapper = '<div class="csf-datepicker-wrapper"></div>',
630 $datepicker;
631
632 var defaults = {
633 showAnim: '',
634 beforeShow: function(input, inst) {
635 $(inst.dpDiv).addClass('csf-datepicker-wrapper');
636 },
637 onClose: function( input, inst ) {
638 $(inst.dpDiv).removeClass('csf-datepicker-wrapper');
639 },
640 };
641
642 settings = $.extend({}, settings, defaults);
643
644 if ( $inputs.length === 2 ) {
645
646 settings = $.extend({}, settings, {
647 onSelect: function( selectedDate ) {
648
649 var $this = $(this),
650 $from = $inputs.first(),
651 option = ( $inputs.first().attr('id') === $(this).attr('id') ) ? 'minDate' : 'maxDate',
652 date = $.datepicker.parseDate( settings.dateFormat, selectedDate );
653
654 $inputs.not(this).datepicker('option', option, date );
655
656 }
657 });
658
659 }
660
661 $inputs.each( function() {
662
663 var $input = $(this);
664
665 if ( $input.hasClass('hasDatepicker') ) {
666 $input.removeAttr('id').removeClass('hasDatepicker');
667 }
668
669 $input.datepicker(settings);
670
671 });
672
673 });
674 };
675
676 //
677 // Field: fieldset
678 //
679 $.fn.csf_field_fieldset = function() {
680 return this.each( function() {
681 $(this).find('.csf-fieldset-content').csf_reload_script();
682 });
683 };
684
685 //
686 // Field: gallery
687 //
688 $.fn.csf_field_gallery = function() {
689 return this.each( function() {
690
691 var $this = $(this),
692 $edit = $this.find('.csf-edit-gallery'),
693 $clear = $this.find('.csf-clear-gallery'),
694 $list = $this.find('ul'),
695 $input = $this.find('input'),
696 $img = $this.find('img'),
697 wp_media_frame;
698
699 $this.on('click', '.csf-button, .csf-edit-gallery', function( e ) {
700
701 var $el = $(this),
702 ids = $input.val(),
703 what = ( $el.hasClass('csf-edit-gallery') ) ? 'edit' : 'add',
704 state = ( what === 'add' && !ids.length ) ? 'gallery' : 'gallery-edit';
705
706 e.preventDefault();
707
708 if ( typeof window.wp === 'undefined' || ! window.wp.media || ! window.wp.media.gallery ) { return; }
709
710 // Open media with state
711 if ( state === 'gallery' ) {
712
713 wp_media_frame = window.wp.media({
714 library: {
715 type: 'image'
716 },
717 frame: 'post',
718 state: 'gallery',
719 multiple: true
720 });
721
722 wp_media_frame.open();
723
724 } else {
725
726 wp_media_frame = window.wp.media.gallery.edit( '[gallery ids="'+ ids +'"]' );
727
728 if ( what === 'add' ) {
729 wp_media_frame.setState('gallery-library');
730 }
731
732 }
733
734 // Media Update
735 wp_media_frame.on( 'update', function( selection ) {
736
737 $list.empty();
738
739 var selectedIds = selection.models.map( function( attachment ) {
740
741 var item = attachment.toJSON();
742 var thumb = ( item.sizes && item.sizes.thumbnail && item.sizes.thumbnail.url ) ? item.sizes.thumbnail.url : item.url;
743
744 $list.append('<li><img src="'+ thumb +'"></li>');
745
746 return item.id;
747
748 });
749
750 $input.val( selectedIds.join( ',' ) ).trigger('change');
751 $clear.removeClass('hidden');
752 $edit.removeClass('hidden');
753
754 });
755
756 });
757
758 $clear.on('click', function( e ) {
759 e.preventDefault();
760 $list.empty();
761 $input.val('').trigger('change');
762 $clear.addClass('hidden');
763 $edit.addClass('hidden');
764 });
765
766 });
767
768 };
769
770 //
771 // Field: group
772 //
773 $.fn.csf_field_group = function() {
774 return this.each( function() {
775
776 var $this = $(this),
777 $fieldset = $this.children('.csf-fieldset'),
778 $group = $fieldset.length ? $fieldset : $this,
779 $wrapper = $group.children('.csf-cloneable-wrapper'),
780 $hidden = $group.children('.csf-cloneable-hidden'),
781 $max = $group.children('.csf-cloneable-max'),
782 $min = $group.children('.csf-cloneable-min'),
783 field_id = $wrapper.data('field-id'),
784 is_number = Boolean( Number( $wrapper.data('title-number') ) ),
785 max = parseInt( $wrapper.data('max') ),
786 min = parseInt( $wrapper.data('min') );
787
788 // clear accordion arrows if multi-instance
789 if ( $wrapper.hasClass('ui-accordion') ) {
790 $wrapper.find('.ui-accordion-header-icon').remove();
791 }
792
793 var update_title_numbers = function( $selector ) {
794 $selector.find('.csf-cloneable-title-number').each( function( index ) {
795 $(this).html( ( $(this).closest('.csf-cloneable-item').index()+1 ) + '.' );
796 });
797 };
798
799 $wrapper.accordion({
800 header: '> .csf-cloneable-item > .csf-cloneable-title',
801 collapsible : true,
802 active: false,
803 animate: false,
804 heightStyle: 'content',
805 icons: {
806 'header': 'csf-cloneable-header-icon fas fa-angle-right',
807 'activeHeader': 'csf-cloneable-header-icon fas fa-angle-down'
808 },
809 activate: function( event, ui ) {
810
811 var $panel = ui.newPanel;
812 var $header = ui.newHeader;
813
814 if ( $panel.length && !$panel.data( 'opened' ) ) {
815
816 var $fields = $panel.children();
817 var $first = $fields.first().find(':input').first();
818 var $title = $header.find('.csf-cloneable-value');
819
820 $first.on('change keyup', function( event ) {
821 $title.text($first.val());
822 });
823
824 $panel.csf_reload_script();
825 $panel.data( 'opened', true );
826 $panel.data( 'retry', false );
827
828 } else if ( $panel.data( 'retry' ) ) {
829
830 $panel.csf_reload_script_retry();
831 $panel.data( 'retry', false );
832
833 }
834
835 }
836 });
837
838 $wrapper.sortable({
839 axis: 'y',
840 handle: '.csf-cloneable-title,.csf-cloneable-sort',
841 helper: 'original',
842 cursor: 'move',
843 placeholder: 'widget-placeholder',
844 start: function( event, ui ) {
845
846 $wrapper.accordion({ active:false });
847 $wrapper.sortable('refreshPositions');
848 ui.item.children('.csf-cloneable-content').data('retry', true);
849
850 },
851 update: function( event, ui ) {
852
853 CSF.helper.name_nested_replace( $wrapper.children('.csf-cloneable-item'), field_id );
854 $wrapper.csf_customizer_refresh();
855
856 if ( is_number ) {
857 update_title_numbers($wrapper);
858 }
859
860 },
861 });
862
863 $group.children('.csf-cloneable-add').on('click', function( e ) {
864
865 e.preventDefault();
866
867 var count = $wrapper.children('.csf-cloneable-item').length;
868
869 $min.hide();
870
871 if ( max && (count+1) > max ) {
872 $max.show();
873 return;
874 }
875
876 var $cloned_item = $hidden.csf_clone(true);
877
878 $cloned_item.removeClass('csf-cloneable-hidden');
879
880 $cloned_item.find(':input[name!="_pseudo"]').each( function() {
881 this.name = this.name.replace( '___', '' ).replace( field_id +'[0]', field_id +'['+ count +']' );
882 });
883
884 $wrapper.append($cloned_item);
885 $wrapper.accordion('refresh');
886 $wrapper.accordion({active: count});
887 $wrapper.csf_customizer_refresh();
888 $wrapper.csf_customizer_listen({closest: true});
889
890 if ( is_number ) {
891 update_title_numbers($wrapper);
892 }
893
894 });
895
896 var event_clone = function( e ) {
897
898 e.preventDefault();
899
900 var count = $wrapper.children('.csf-cloneable-item').length;
901
902 $min.hide();
903
904 if ( max && (count+1) > max ) {
905 $max.show();
906 return;
907 }
908
909 var $this = $(this),
910 $parent = $this.parent().parent(),
911 $cloned_helper = $parent.children('.csf-cloneable-helper').csf_clone(true),
912 $cloned_title = $parent.children('.csf-cloneable-title').csf_clone(),
913 $cloned_content = $parent.children('.csf-cloneable-content').csf_clone(),
914 $cloned_item = $('<div class="csf-cloneable-item" />');
915
916 $cloned_item.append($cloned_helper);
917 $cloned_item.append($cloned_title);
918 $cloned_item.append($cloned_content);
919
920 $wrapper.children().eq($parent.index()).after($cloned_item);
921
922 CSF.helper.name_nested_replace( $wrapper.children('.csf-cloneable-item'), field_id );
923
924 $wrapper.accordion('refresh');
925 $wrapper.csf_customizer_refresh();
926 $wrapper.csf_customizer_listen({closest: true});
927
928 if ( is_number ) {
929 update_title_numbers($wrapper);
930 }
931
932 };
933
934 $wrapper.children('.csf-cloneable-item').children('.csf-cloneable-helper').on('click', '.csf-cloneable-clone', event_clone);
935 $group.children('.csf-cloneable-hidden').children('.csf-cloneable-helper').on('click', '.csf-cloneable-clone', event_clone);
936
937 var event_remove = function( e ) {
938
939 e.preventDefault();
940
941 var count = $wrapper.children('.csf-cloneable-item').length;
942
943 $max.hide();
944 $min.hide();
945
946 if ( min && (count-1) < min ) {
947 $min.show();
948 return;
949 }
950
951 $(this).closest('.csf-cloneable-item').remove();
952
953 CSF.helper.name_nested_replace( $wrapper.children('.csf-cloneable-item'), field_id );
954
955 $wrapper.csf_customizer_refresh();
956
957 if ( is_number ) {
958 update_title_numbers($wrapper);
959 }
960
961 };
962
963 $wrapper.children('.csf-cloneable-item').children('.csf-cloneable-helper').on('click', '.csf-cloneable-remove', event_remove);
964 $group.children('.csf-cloneable-hidden').children('.csf-cloneable-helper').on('click', '.csf-cloneable-remove', event_remove);
965
966 });
967 };
968
969 //
970 // Field: icon
971 //
972 $.fn.csf_field_icon = function() {
973 return this.each( function() {
974
975 var $this = $(this);
976
977 $this.on('click', '.csf-icon-add', function( e ) {
978
979 e.preventDefault();
980
981 var $button = $(this);
982 var $modal = $('#csf-modal-icon');
983
984 $modal.removeClass('hidden');
985
986 CSF.vars.$icon_target = $this;
987
988 if ( !CSF.vars.icon_modal_loaded ) {
989
990 $modal.find('.csf-modal-loading').show();
991
992 window.wp.ajax.post( 'csf-get-icons', {
993 nonce: $button.data('nonce')
994 }).done( function( response ) {
995
996 $modal.find('.csf-modal-loading').hide();
997
998 CSF.vars.icon_modal_loaded = true;
999
1000 var $load = $modal.find('.csf-modal-load').html( response.content );
1001
1002 $load.on('click', 'i', function( e ) {
1003
1004 e.preventDefault();
1005
1006 var icon = $(this).attr('title');
1007
1008 CSF.vars.$icon_target.find('.csf-icon-preview i').removeAttr('class').addClass(icon);
1009 CSF.vars.$icon_target.find('.csf-icon-preview').removeClass('hidden');
1010 CSF.vars.$icon_target.find('.csf-icon-remove').removeClass('hidden');
1011 CSF.vars.$icon_target.find('input').val(icon).trigger('change');
1012
1013 $modal.addClass('hidden');
1014
1015 });
1016
1017 $modal.on('change keyup', '.csf-icon-search', function() {
1018
1019 var value = $(this).val(),
1020 $icons = $load.find('i');
1021
1022 $icons.each( function() {
1023
1024 var $elem = $(this);
1025
1026 if ( $elem.attr('title').search( new RegExp( value, 'i' ) ) < 0 ) {
1027 $elem.hide();
1028 } else {
1029 $elem.show();
1030 }
1031
1032 });
1033
1034 });
1035
1036 $modal.on('click', '.csf-modal-close, .csf-modal-overlay', function() {
1037 $modal.addClass('hidden');
1038 });
1039
1040 }).fail( function( response ) {
1041 $modal.find('.csf-modal-loading').hide();
1042 $modal.find('.csf-modal-load').html( response.error );
1043 $modal.on('click', function() {
1044 $modal.addClass('hidden');
1045 });
1046 });
1047 }
1048
1049 });
1050
1051 $this.on('click', '.csf-icon-remove', function( e ) {
1052 e.preventDefault();
1053 $this.find('.csf-icon-preview').addClass('hidden');
1054 $this.find('input').val('').trigger('change');
1055 $(this).addClass('hidden');
1056 });
1057
1058 });
1059 };
1060
1061 //
1062 // Field: map
1063 //
1064 $.fn.csf_field_map = function() {
1065 return this.each( function() {
1066
1067 if ( typeof L === 'undefined' ) { return; }
1068
1069 var $this = $(this),
1070 $map = $this.find('.csf--map-osm'),
1071 $search_input = $this.find('.csf--map-search input'),
1072 $latitude = $this.find('.csf--latitude'),
1073 $longitude = $this.find('.csf--longitude'),
1074 $zoom = $this.find('.csf--zoom'),
1075 map_data = $map.data( 'map' );
1076
1077 var mapInit = L.map( $map.get(0), map_data);
1078
1079 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
1080 attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
1081 }).addTo(mapInit);
1082
1083 var mapMarker = L.marker(map_data.center,{draggable: true}).addTo(mapInit);
1084
1085 var update_latlng = function( data ) {
1086 $latitude.val( data.lat );
1087 $longitude.val( data.lng );
1088 $zoom.val( mapInit.getZoom() );
1089 };
1090
1091 mapInit.on( 'click', function ( data ) {
1092 mapMarker.setLatLng( data.latlng );
1093 update_latlng( data.latlng );
1094 });
1095
1096 mapInit.on( 'zoom', function () {
1097 update_latlng( mapMarker.getLatLng() );
1098 });
1099
1100 mapMarker.on( 'drag', function () {
1101 update_latlng( mapMarker.getLatLng() );
1102 });
1103
1104 if ( ! $search_input.length ) {
1105 $search_input = $( '[data-depend-id="'+ $this.find('.csf--address-field').data( 'address-field' ) +'"]' );
1106 }
1107
1108 var cache = {};
1109
1110 $search_input.autocomplete({
1111 source: function ( request, response ) {
1112
1113 var term = request.term;
1114
1115 if ( term in cache ) {
1116 response( cache[term] );
1117 return;
1118 }
1119
1120 $.get( 'https://nominatim.openstreetmap.org/search', {
1121 format: 'json',
1122 q: term,
1123 }, function( results ) {
1124
1125 var data;
1126
1127 if ( results.length ) {
1128 data = results.map( function( item ) {
1129 return {
1130 value: item.display_name,
1131 label: item.display_name,
1132 lat: item.lat,
1133 lon: item.lon
1134 };
1135 }, 'json');
1136 } else {
1137 data = [{
1138 value: 'no-data',
1139 label: 'No Results.'
1140 }];
1141 }
1142
1143 cache[term] = data;
1144 response(data);
1145
1146 });
1147
1148 },
1149 select: function ( event, ui ) {
1150
1151 if ( ui.item.value === 'no-data' ) { return false; }
1152
1153 var latLng = L.latLng( ui.item.lat, ui.item.lon );
1154
1155 mapInit.panTo( latLng );
1156 mapMarker.setLatLng( latLng );
1157 update_latlng( latLng );
1158
1159 },
1160 create: function (event, ui) {
1161 $(this).autocomplete('widget').addClass('csf-map-ui-autocomplate');
1162 }
1163 });
1164
1165 var input_update_latlng = function() {
1166
1167 var latLng = L.latLng( $latitude.val(), $longitude.val() );
1168
1169 mapInit.panTo( latLng );
1170 mapMarker.setLatLng( latLng );
1171
1172 };
1173
1174 $latitude.on('change', input_update_latlng );
1175 $longitude.on('change', input_update_latlng );
1176
1177 });
1178 };
1179
1180 //
1181 // Field: link
1182 //
1183 $.fn.csf_field_link = function() {
1184 return this.each( function() {
1185
1186 var $this = $(this),
1187 $link = $this.find('.csf--link'),
1188 $add = $this.find('.csf--add'),
1189 $edit = $this.find('.csf--edit'),
1190 $remove = $this.find('.csf--remove'),
1191 $result = $this.find('.csf--result'),
1192 uniqid = CSF.helper.uid('csf-wplink-textarea-');
1193
1194 $add.on('click', function( e ) {
1195
1196 e.preventDefault();
1197
1198 window.wpLink.open(uniqid);
1199
1200 });
1201
1202 $edit.on('click', function( e ) {
1203
1204 e.preventDefault();
1205
1206 $add.trigger('click');
1207
1208 $('#wp-link-url').val($this.find('.csf--url').val());
1209 $('#wp-link-text').val($this.find('.csf--text').val());
1210 $('#wp-link-target').prop('checked', ($this.find('.csf--target').val() === '_blank'));
1211
1212 });
1213
1214 $remove.on('click', function( e ) {
1215
1216 e.preventDefault();
1217
1218 $this.find('.csf--url').val('').trigger('change');
1219 $this.find('.csf--text').val('');
1220 $this.find('.csf--target').val('');
1221
1222 $add.removeClass('hidden');
1223 $edit.addClass('hidden');
1224 $remove.addClass('hidden');
1225 $result.parent().addClass('hidden');
1226
1227 });
1228
1229 $link.attr('id', uniqid).on('change', function() {
1230
1231 var atts = window.wpLink.getAttrs(),
1232 href = atts.href,
1233 text = $('#wp-link-text').val(),
1234 target = ( atts.target ) ? atts.target : '';
1235
1236 $this.find('.csf--url').val(href).trigger('change');
1237 $this.find('.csf--text').val(text);
1238 $this.find('.csf--target').val(target);
1239
1240 $result.html('{url:"'+href+'", text:"'+text+'", target:"'+target+'"}');
1241
1242 $add.addClass('hidden');
1243 $edit.removeClass('hidden');
1244 $remove.removeClass('hidden');
1245 $result.parent().removeClass('hidden');
1246
1247 });
1248
1249 });
1250
1251 };
1252
1253 //
1254 // Field: media
1255 //
1256 $.fn.csf_field_media = function() {
1257 return this.each( function() {
1258
1259 var $this = $(this),
1260 $upload_button = $this.find('.csf--button'),
1261 $remove_button = $this.find('.csf--remove'),
1262 $library = $upload_button.data('library') && $upload_button.data('library').split(',') || '',
1263 $auto_attributes = ( $this.hasClass('csf-assign-field-background') ) ? $this.closest('.csf-field-background').find('.csf--auto-attributes') : false,
1264 wp_media_frame;
1265
1266 $upload_button.on('click', function( e ) {
1267
1268 e.preventDefault();
1269
1270 if ( typeof window.wp === 'undefined' || ! window.wp.media || ! window.wp.media.gallery ) {
1271 return;
1272 }
1273
1274 if ( wp_media_frame ) {
1275 wp_media_frame.open();
1276 return;
1277 }
1278
1279 wp_media_frame = window.wp.media({
1280 library: {
1281 type: $library
1282 }
1283 });
1284
1285 wp_media_frame.on( 'select', function() {
1286
1287 var thumbnail;
1288 var attributes = wp_media_frame.state().get('selection').first().attributes;
1289 var preview_size = $upload_button.data('preview-size') || 'thumbnail';
1290
1291 if ( $library.length && $library.indexOf(attributes.subtype) === -1 && $library.indexOf(attributes.type) === -1 ) {
1292 return;
1293 }
1294
1295 $this.find('.csf--id').val( attributes.id );
1296 $this.find('.csf--width').val( attributes.width );
1297 $this.find('.csf--height').val( attributes.height );
1298 $this.find('.csf--alt').val( attributes.alt );
1299 $this.find('.csf--title').val( attributes.title );
1300 $this.find('.csf--description').val( attributes.description );
1301
1302 if ( typeof attributes.sizes !== 'undefined' && typeof attributes.sizes.thumbnail !== 'undefined' && preview_size === 'thumbnail' ) {
1303 thumbnail = attributes.sizes.thumbnail.url;
1304 } else if ( typeof attributes.sizes !== 'undefined' && typeof attributes.sizes.full !== 'undefined' ) {
1305 thumbnail = attributes.sizes.full.url;
1306 } else if ( attributes.url.split('.').pop().toLowerCase() === 'svg' ) {
1307 thumbnail = attributes.url;
1308 } else {
1309 thumbnail = attributes.icon;
1310 }
1311
1312 if ( $auto_attributes ) {
1313 $auto_attributes.removeClass('csf--attributes-hidden');
1314 }
1315
1316 $remove_button.removeClass('hidden');
1317
1318 $this.find('.csf--preview').removeClass('hidden');
1319 $this.find('.csf--src').attr('src', thumbnail);
1320 $this.find('.csf--thumbnail').val( thumbnail );
1321 $this.find('.csf--url').val( attributes.url ).trigger('change');
1322
1323 });
1324
1325 wp_media_frame.open();
1326
1327 });
1328
1329 $remove_button.on('click', function( e ) {
1330
1331 e.preventDefault();
1332
1333 if ( $auto_attributes ) {
1334 $auto_attributes.addClass('csf--attributes-hidden');
1335 }
1336
1337 $remove_button.addClass('hidden');
1338 $this.find('input').val('');
1339 $this.find('.csf--preview').addClass('hidden');
1340 $this.find('.csf--url').trigger('change');
1341
1342 });
1343
1344 });
1345
1346 };
1347
1348 //
1349 // Field: repeater
1350 //
1351 $.fn.csf_field_repeater = function() {
1352 return this.each( function() {
1353
1354 var $this = $(this),
1355 $fieldset = $this.children('.csf-fieldset'),
1356 $repeater = $fieldset.length ? $fieldset : $this,
1357 $wrapper = $repeater.children('.csf-repeater-wrapper'),
1358 $hidden = $repeater.children('.csf-repeater-hidden'),
1359 $max = $repeater.children('.csf-repeater-max'),
1360 $min = $repeater.children('.csf-repeater-min'),
1361 field_id = $wrapper.data('field-id'),
1362 max = parseInt( $wrapper.data('max') ),
1363 min = parseInt( $wrapper.data('min') );
1364
1365 $wrapper.children('.csf-repeater-item').children('.csf-repeater-content').csf_reload_script();
1366
1367 $wrapper.sortable({
1368 axis: 'y',
1369 handle: '.csf-repeater-sort',
1370 helper: 'original',
1371 cursor: 'move',
1372 placeholder: 'widget-placeholder',
1373 update: function( event, ui ) {
1374
1375 CSF.helper.name_nested_replace( $wrapper.children('.csf-repeater-item'), field_id );
1376 $wrapper.csf_customizer_refresh();
1377 ui.item.csf_reload_script_retry();
1378
1379 }
1380 });
1381
1382 $repeater.children('.csf-repeater-add').on('click', function( e ) {
1383
1384 e.preventDefault();
1385
1386 var count = $wrapper.children('.csf-repeater-item').length;
1387
1388 $min.hide();
1389
1390 if ( max && (count+1) > max ) {
1391 $max.show();
1392 return;
1393 }
1394
1395 var $cloned_item = $hidden.csf_clone(true);
1396
1397 $cloned_item.removeClass('csf-repeater-hidden');
1398
1399 $cloned_item.find(':input[name!="_pseudo"]').each( function() {
1400 this.name = this.name.replace( '___', '' ).replace( field_id +'[0]', field_id +'['+ count +']' );
1401 });
1402
1403 $wrapper.append($cloned_item);
1404 $cloned_item.children('.csf-repeater-content').csf_reload_script();
1405 $wrapper.csf_customizer_refresh();
1406 $wrapper.csf_customizer_listen({closest: true});
1407
1408 });
1409
1410 var event_clone = function( e ) {
1411
1412 e.preventDefault();
1413
1414 var count = $wrapper.children('.csf-repeater-item').length;
1415
1416 $min.hide();
1417
1418 if ( max && (count+1) > max ) {
1419 $max.show();
1420 return;
1421 }
1422
1423 var $this = $(this),
1424 $parent = $this.parent().parent().parent(),
1425 $cloned_content = $parent.children('.csf-repeater-content').csf_clone(),
1426 $cloned_helper = $parent.children('.csf-repeater-helper').csf_clone(true),
1427 $cloned_item = $('<div class="csf-repeater-item" />');
1428
1429 $cloned_item.append($cloned_content);
1430 $cloned_item.append($cloned_helper);
1431
1432 $wrapper.children().eq($parent.index()).after($cloned_item);
1433
1434 $cloned_item.children('.csf-repeater-content').csf_reload_script();
1435
1436 CSF.helper.name_nested_replace( $wrapper.children('.csf-repeater-item'), field_id );
1437
1438 $wrapper.csf_customizer_refresh();
1439 $wrapper.csf_customizer_listen({closest: true});
1440
1441 };
1442
1443 $wrapper.children('.csf-repeater-item').children('.csf-repeater-helper').on('click', '.csf-repeater-clone', event_clone);
1444 $repeater.children('.csf-repeater-hidden').children('.csf-repeater-helper').on('click', '.csf-repeater-clone', event_clone);
1445
1446 var event_remove = function( e ) {
1447
1448 e.preventDefault();
1449
1450 var count = $wrapper.children('.csf-repeater-item').length;
1451
1452 $max.hide();
1453 $min.hide();
1454
1455 if ( min && (count-1) < min ) {
1456 $min.show();
1457 return;
1458 }
1459
1460 $(this).closest('.csf-repeater-item').remove();
1461
1462 CSF.helper.name_nested_replace( $wrapper.children('.csf-repeater-item'), field_id );
1463
1464 $wrapper.csf_customizer_refresh();
1465
1466 };
1467
1468 $wrapper.children('.csf-repeater-item').children('.csf-repeater-helper').on('click', '.csf-repeater-remove', event_remove);
1469 $repeater.children('.csf-repeater-hidden').children('.csf-repeater-helper').on('click', '.csf-repeater-remove', event_remove);
1470
1471 });
1472 };
1473
1474 //
1475 // Field: slider
1476 //
1477 $.fn.csf_field_slider = function() {
1478 return this.each( function() {
1479
1480 var $this = $(this),
1481 $input = $this.find('input'),
1482 $slider = $this.find('.csf-slider-ui'),
1483 data = $input.data(),
1484 value = $input.val() || 0;
1485
1486 if ( $slider.hasClass('ui-slider') ) {
1487 $slider.empty();
1488 }
1489
1490 $slider.slider({
1491 range: 'min',
1492 value: value,
1493 min: data.min || 0,
1494 max: data.max || 100,
1495 step: data.step || 1,
1496 slide: function( e, o ) {
1497 $input.val( o.value ).trigger('change');
1498 }
1499 });
1500
1501 $input.on('keyup', function() {
1502 $slider.slider('value', $input.val());
1503 });
1504
1505 });
1506 };
1507
1508 //
1509 // Field: sortable
1510 //
1511 $.fn.csf_field_sortable = function() {
1512 return this.each( function() {
1513
1514 var $sortable = $(this).find('.csf-sortable');
1515
1516 $sortable.sortable({
1517 axis: 'y',
1518 helper: 'original',
1519 cursor: 'move',
1520 placeholder: 'widget-placeholder',
1521 update: function( event, ui ) {
1522 $sortable.csf_customizer_refresh();
1523 }
1524 });
1525
1526 $sortable.find('.csf-sortable-content').csf_reload_script();
1527
1528 });
1529 };
1530
1531 //
1532 // Field: sorter
1533 //
1534 $.fn.csf_field_sorter = function() {
1535 return this.each( function() {
1536
1537 var $this = $(this),
1538 $enabled = $this.find('.csf-enabled'),
1539 $has_disabled = $this.find('.csf-disabled'),
1540 $disabled = ( $has_disabled.length ) ? $has_disabled : false;
1541
1542 $enabled.sortable({
1543 connectWith: $disabled,
1544 placeholder: 'ui-sortable-placeholder',
1545 update: function( event, ui ) {
1546
1547 var $el = ui.item.find('input');
1548
1549 if ( ui.item.parent().hasClass('csf-enabled') ) {
1550 $el.attr('name', $el.attr('name').replace('disabled', 'enabled'));
1551 } else {
1552 $el.attr('name', $el.attr('name').replace('enabled', 'disabled'));
1553 }
1554
1555 $this.csf_customizer_refresh();
1556
1557 }
1558 });
1559
1560 if ( $disabled ) {
1561
1562 $disabled.sortable({
1563 connectWith: $enabled,
1564 placeholder: 'ui-sortable-placeholder',
1565 update: function( event, ui ) {
1566 $this.csf_customizer_refresh();
1567 }
1568 });
1569
1570 }
1571
1572 });
1573 };
1574
1575 //
1576 // Field: spinner
1577 //
1578 $.fn.csf_field_spinner = function() {
1579 return this.each( function() {
1580
1581 var $this = $(this),
1582 $input = $this.find('input'),
1583 $inited = $this.find('.ui-button'),
1584 data = $input.data();
1585
1586 if ( $inited.length ) {
1587 $inited.remove();
1588 }
1589
1590 $input.spinner({
1591 min: data.min || 0,
1592 max: data.max || 100,
1593 step: data.step || 1,
1594 create: function( event, ui ) {
1595 if ( data.unit ) {
1596 $input.after('<span class="ui-button csf--unit">'+ data.unit +'</span>');
1597 }
1598 },
1599 spin: function (event, ui ) {
1600 $input.val(ui.value).trigger('change');
1601 }
1602 });
1603
1604 });
1605 };
1606
1607 //
1608 // Field: switcher
1609 //
1610 $.fn.csf_field_switcher = function() {
1611 return this.each( function() {
1612
1613 var $switcher = $(this).find('.csf--switcher');
1614
1615 $switcher.on('click', function() {
1616
1617 var value = 0;
1618 var $input = $switcher.find('input');
1619
1620 if ( $switcher.hasClass('csf--active') ) {
1621 $switcher.removeClass('csf--active');
1622 } else {
1623 value = 1;
1624 $switcher.addClass('csf--active');
1625 }
1626
1627 $input.val(value).trigger('change');
1628
1629 });
1630
1631 });
1632 };
1633
1634 //
1635 // Field: tabbed
1636 //
1637 $.fn.csf_field_tabbed = function() {
1638 return this.each( function() {
1639
1640 var $this = $(this),
1641 $links = $this.find('.csf-tabbed-nav a'),
1642 $contents = $this.find('.csf-tabbed-content');
1643
1644 $contents.eq(0).csf_reload_script();
1645
1646 $links.on( 'click', function( e ) {
1647
1648 e.preventDefault();
1649
1650 var $link = $(this),
1651 index = $link.index(),
1652 $content = $contents.eq(index);
1653
1654 $link.addClass('csf-tabbed-active').siblings().removeClass('csf-tabbed-active');
1655 $content.csf_reload_script();
1656 $content.removeClass('hidden').siblings().addClass('hidden');
1657
1658 });
1659
1660 });
1661 };
1662
1663 //
1664 // Field: typography
1665 //
1666 $.fn.csf_field_typography = function() {
1667 return this.each(function () {
1668
1669 var base = this;
1670 var $this = $(this);
1671 var loaded_fonts = [];
1672 var webfonts = csf_typography_json.webfonts;
1673 var googlestyles = csf_typography_json.googlestyles;
1674 var defaultstyles = csf_typography_json.defaultstyles;
1675
1676 //
1677 //
1678 // Sanitize google font subset
1679 base.sanitize_subset = function( subset ) {
1680 subset = subset.replace('-ext', ' Extended');
1681 subset = subset.charAt(0).toUpperCase() + subset.slice(1);
1682 return subset;
1683 };
1684
1685 //
1686 //
1687 // Sanitize google font styles (weight and style)
1688 base.sanitize_style = function( style ) {
1689 return googlestyles[style] ? googlestyles[style] : style;
1690 };
1691
1692 //
1693 //
1694 // Load google font
1695 base.load_google_font = function( font_family, weight, style ) {
1696
1697 if ( font_family && typeof WebFont === 'object' ) {
1698
1699 weight = weight ? weight.replace('normal', '') : '';
1700 style = style ? style.replace('normal', '') : '';
1701
1702 if ( weight || style ) {
1703 font_family = font_family +':'+ weight + style;
1704 }
1705
1706 if ( loaded_fonts.indexOf( font_family ) === -1 ) {
1707 WebFont.load({ google: { families: [font_family] } });
1708 }
1709
1710 loaded_fonts.push( font_family );
1711
1712 }
1713
1714 };
1715
1716 //
1717 //
1718 // Append select options
1719 base.append_select_options = function( $select, options, condition, type, is_multi ) {
1720
1721 $select.find('option').not(':first').remove();
1722
1723 var opts = '';
1724
1725 $.each( options, function( key, value ) {
1726
1727 var selected;
1728 var name = value;
1729
1730 // is_multi
1731 if ( is_multi ) {
1732 selected = ( condition && condition.indexOf(value) !== -1 ) ? ' selected' : '';
1733 } else {
1734 selected = ( condition && condition === value ) ? ' selected' : '';
1735 }
1736
1737 if ( type === 'subset' ) {
1738 name = base.sanitize_subset( value );
1739 } else if ( type === 'style' ){
1740 name = base.sanitize_style( value );
1741 }
1742
1743 opts += '<option value="'+ value +'"'+ selected +'>'+ name +'</option>';
1744
1745 });
1746
1747 $select.append(opts).trigger('csf.change').trigger('chosen:updated');
1748
1749 };
1750
1751 base.init = function () {
1752
1753 //
1754 //
1755 // Constants
1756 var selected_styles = [];
1757 var $typography = $this.find('.csf--typography');
1758 var $type = $this.find('.csf--type');
1759 var $styles = $this.find('.csf--block-font-style');
1760 var unit = $typography.data('unit');
1761 var line_height_unit = $typography.data('line-height-unit');
1762 var exclude_fonts = $typography.data('exclude') ? $typography.data('exclude').split(',') : [];
1763
1764 //
1765 //
1766 // Chosen init
1767 if ( $this.find('.csf--chosen').length ) {
1768
1769 var $chosen_selects = $this.find('select');
1770
1771 $chosen_selects.each( function() {
1772
1773 var $chosen_select = $(this),
1774 $chosen_inited = $chosen_select.parent().find('.chosen-container');
1775
1776 if ( $chosen_inited.length ) {
1777 $chosen_inited.remove();
1778 }
1779
1780 $chosen_select.chosen({
1781 allow_single_deselect: true,
1782 disable_search_threshold: 15,
1783 width: '100%'
1784 });
1785
1786 });
1787
1788 }
1789
1790 //
1791 //
1792 // Font family select
1793 var $font_family_select = $this.find('.csf--font-family');
1794 var first_font_family = $font_family_select.val();
1795
1796 // Clear default font family select options
1797 $font_family_select.find('option').not(':first-child').remove();
1798
1799 var opts = '';
1800
1801 $.each(webfonts, function( type, group ) {
1802
1803 // Check for exclude fonts
1804 if ( exclude_fonts && exclude_fonts.indexOf(type) !== -1 ) { return; }
1805
1806 opts += '<optgroup label="' + group.label + '">';
1807
1808 $.each(group.fonts, function( key, value ) {
1809
1810 // use key if value is object
1811 value = ( typeof value === 'object' ) ? key : value;
1812 var selected = ( value === first_font_family ) ? ' selected' : '';
1813 opts += '<option value="'+ value +'" data-type="'+ type +'"'+ selected +'>'+ value +'</option>';
1814
1815 });
1816
1817 opts += '</optgroup>';
1818
1819 });
1820
1821 // Append google font select options
1822 $font_family_select.append(opts).trigger('chosen:updated');
1823
1824 //
1825 //
1826 // Font style select
1827 var $font_style_block = $this.find('.csf--block-font-style');
1828
1829 if ( $font_style_block.length ) {
1830
1831 var $font_style_select = $this.find('.csf--font-style-select');
1832 var first_style_value = $font_style_select.val() ? $font_style_select.val().replace(/normal/g, '' ) : '';
1833
1834 //
1835 // Font Style on on change listener
1836 $font_style_select.on('change csf.change', function( event ) {
1837
1838 var style_value = $font_style_select.val();
1839
1840 // set a default value
1841 if ( !style_value && selected_styles && selected_styles.indexOf('normal') === -1 ) {
1842 style_value = selected_styles[0];
1843 }
1844
1845 // set font weight, for eg. replacing 800italic to 800
1846 var font_normal = ( style_value && style_value !== 'italic' && style_value === 'normal' ) ? 'normal' : '';
1847 var font_weight = ( style_value && style_value !== 'italic' && style_value !== 'normal' ) ? style_value.replace('italic', '') : font_normal;
1848 var font_style = ( style_value && style_value.substr(-6) === 'italic' ) ? 'italic' : '';
1849
1850 $this.find('.csf--font-weight').val( font_weight );
1851 $this.find('.csf--font-style').val( font_style );
1852
1853 });
1854
1855 //
1856 //
1857 // Extra font style select
1858 var $extra_font_style_block = $this.find('.csf--block-extra-styles');
1859
1860 if ( $extra_font_style_block.length ) {
1861 var $extra_font_style_select = $this.find('.csf--extra-styles');
1862 var first_extra_style_value = $extra_font_style_select.val();
1863 }
1864
1865 }
1866
1867 //
1868 //
1869 // Subsets select
1870 var $subset_block = $this.find('.csf--block-subset');
1871 if ( $subset_block.length ) {
1872 var $subset_select = $this.find('.csf--subset');
1873 var first_subset_select_value = $subset_select.val();
1874 var subset_multi_select = $subset_select.data('multiple') || false;
1875 }
1876
1877 //
1878 //
1879 // Backup font family
1880 var $backup_font_family_block = $this.find('.csf--block-backup-font-family');
1881
1882 //
1883 //
1884 // Font Family on Change Listener
1885 $font_family_select.on('change csf.change', function( event ) {
1886
1887 // Hide subsets on change
1888 if ( $subset_block.length ) {
1889 $subset_block.addClass('hidden');
1890 }
1891
1892 // Hide extra font style on change
1893 if ( $extra_font_style_block.length ) {
1894 $extra_font_style_block.addClass('hidden');
1895 }
1896
1897 // Hide backup font family on change
1898 if ( $backup_font_family_block.length ) {
1899 $backup_font_family_block.addClass('hidden');
1900 }
1901
1902 var $selected = $font_family_select.find(':selected');
1903 var value = $selected.val();
1904 var type = $selected.data('type');
1905
1906 if ( type && value ) {
1907
1908 // Show backup fonts if font type google or custom
1909 if ( ( type === 'google' || type === 'custom' ) && $backup_font_family_block.length ) {
1910 $backup_font_family_block.removeClass('hidden');
1911 }
1912
1913 // Appending font style select options
1914 if ( $font_style_block.length ) {
1915
1916 // set styles for multi and normal style selectors
1917 var styles = defaultstyles;
1918
1919 // Custom or gogle font styles
1920 if ( type === 'google' && webfonts[type].fonts[value][0] ) {
1921 styles = webfonts[type].fonts[value][0];
1922 } else if ( type === 'custom' && webfonts[type].fonts[value] ) {
1923 styles = webfonts[type].fonts[value];
1924 }
1925
1926 selected_styles = styles;
1927
1928 // Set selected style value for avoid load errors
1929 var set_auto_style = ( styles.indexOf('normal') !== -1 ) ? 'normal' : styles[0];
1930 var set_style_value = ( first_style_value && styles.indexOf(first_style_value) !== -1 ) ? first_style_value : set_auto_style;
1931
1932 // Append style select options
1933 base.append_select_options( $font_style_select, styles, set_style_value, 'style' );
1934
1935 // Clear first value
1936 first_style_value = false;
1937
1938 // Show style select after appended
1939 $font_style_block.removeClass('hidden');
1940
1941 // Appending extra font style select options
1942 if ( type === 'google' && $extra_font_style_block.length && styles.length > 1 ) {
1943
1944 // Append extra-style select options
1945 base.append_select_options( $extra_font_style_select, styles, first_extra_style_value, 'style', true );
1946
1947 // Clear first value
1948 first_extra_style_value = false;
1949
1950 // Show style select after appended
1951 $extra_font_style_block.removeClass('hidden');
1952
1953 }
1954
1955 }
1956
1957 // Appending google fonts subsets select options
1958 if ( type === 'google' && $subset_block.length && webfonts[type].fonts[value][1] ) {
1959
1960 var subsets = webfonts[type].fonts[value][1];
1961 var set_auto_subset = ( subsets.length < 2 && subsets[0] !== 'latin' ) ? subsets[0] : '';
1962 var set_subset_value = ( first_subset_select_value && subsets.indexOf(first_subset_select_value) !== -1 ) ? first_subset_select_value : set_auto_subset;
1963
1964 // check for multiple subset select
1965 set_subset_value = ( subset_multi_select && first_subset_select_value ) ? first_subset_select_value : set_subset_value;
1966
1967 base.append_select_options( $subset_select, subsets, set_subset_value, 'subset', subset_multi_select );
1968
1969 first_subset_select_value = false;
1970
1971 $subset_block.removeClass('hidden');
1972
1973 }
1974
1975 } else {
1976
1977 // Clear Styles
1978 $styles.find(':input').val('');
1979
1980 // Clear subsets options if type and value empty
1981 if ( $subset_block.length ) {
1982 $subset_select.find('option').not(':first-child').remove();
1983 $subset_select.trigger('chosen:updated');
1984 }
1985
1986 // Clear font styles options if type and value empty
1987 if ( $font_style_block.length ) {
1988 $font_style_select.find('option').not(':first-child').remove();
1989 $font_style_select.trigger('chosen:updated');
1990 }
1991
1992 }
1993
1994 // Update font type input value
1995 $type.val(type);
1996
1997 }).trigger('csf.change');
1998
1999 //
2000 //
2001 // Preview
2002 var $preview_block = $this.find('.csf--block-preview');
2003
2004 if ( $preview_block.length ) {
2005
2006 var $preview = $this.find('.csf--preview');
2007
2008 // Set preview styles on change
2009 $this.on('change', CSF.helper.debounce( function( event ) {
2010
2011 $preview_block.removeClass('hidden');
2012
2013 var font_family = $font_family_select.val(),
2014 font_weight = $this.find('.csf--font-weight').val(),
2015 font_style = $this.find('.csf--font-style').val(),
2016 font_size = $this.find('.csf--font-size').val(),
2017 font_variant = $this.find('.csf--font-variant').val(),
2018 line_height = $this.find('.csf--line-height').val(),
2019 text_align = $this.find('.csf--text-align').val(),
2020 text_transform = $this.find('.csf--text-transform').val(),
2021 text_decoration = $this.find('.csf--text-decoration').val(),
2022 text_color = $this.find('.csf--color').val(),
2023 word_spacing = $this.find('.csf--word-spacing').val(),
2024 letter_spacing = $this.find('.csf--letter-spacing').val(),
2025 custom_style = $this.find('.csf--custom-style').val(),
2026 type = $this.find('.csf--type').val();
2027
2028 if ( type === 'google' ) {
2029 base.load_google_font(font_family, font_weight, font_style);
2030 }
2031
2032 var properties = {};
2033
2034 if ( font_family ) { properties.fontFamily = font_family; }
2035 if ( font_weight ) { properties.fontWeight = font_weight; }
2036 if ( font_style ) { properties.fontStyle = font_style; }
2037 if ( font_variant ) { properties.fontVariant = font_variant; }
2038 if ( font_size ) { properties.fontSize = font_size + unit; }
2039 if ( line_height ) { properties.lineHeight = line_height + line_height_unit; }
2040 if ( letter_spacing ) { properties.letterSpacing = letter_spacing + unit; }
2041 if ( word_spacing ) { properties.wordSpacing = word_spacing + unit; }
2042 if ( text_align ) { properties.textAlign = text_align; }
2043 if ( text_transform ) { properties.textTransform = text_transform; }
2044 if ( text_decoration ) { properties.textDecoration = text_decoration; }
2045 if ( text_color ) { properties.color = text_color; }
2046
2047 $preview.removeAttr('style');
2048
2049 // Customs style attribute
2050 if ( custom_style ) { $preview.attr('style', custom_style); }
2051
2052 $preview.css(properties);
2053
2054 }, 100 ) );
2055
2056 // Preview black and white backgrounds trigger
2057 $preview_block.on('click', function() {
2058
2059 $preview.toggleClass('csf--black-background');
2060
2061 var $toggle = $preview_block.find('.csf--toggle');
2062
2063 if ( $toggle.hasClass('fa-toggle-off') ) {
2064 $toggle.removeClass('fa-toggle-off').addClass('fa-toggle-on');
2065 } else {
2066 $toggle.removeClass('fa-toggle-on').addClass('fa-toggle-off');
2067 }
2068
2069 });
2070
2071 if ( !$preview_block.hasClass('hidden') ) {
2072 $this.trigger('change');
2073 }
2074
2075 }
2076
2077 };
2078
2079 base.init();
2080
2081 });
2082 };
2083
2084 //
2085 // Field: upload
2086 //
2087 $.fn.csf_field_upload = function() {
2088 return this.each( function() {
2089
2090 var $this = $(this),
2091 $input = $this.find('input'),
2092 $upload_button = $this.find('.csf--button'),
2093 $remove_button = $this.find('.csf--remove'),
2094 $library = $upload_button.data('library') && $upload_button.data('library').split(',') || '',
2095 wp_media_frame;
2096
2097 $input.on('change', function( e ) {
2098 if ( $input.val() ) {
2099 $remove_button.removeClass('hidden');
2100 } else {
2101 $remove_button.addClass('hidden');
2102 }
2103 });
2104
2105 $upload_button.on('click', function( e ) {
2106
2107 e.preventDefault();
2108
2109 if ( typeof window.wp === 'undefined' || ! window.wp.media || ! window.wp.media.gallery ) {
2110 return;
2111 }
2112
2113 if ( wp_media_frame ) {
2114 wp_media_frame.open();
2115 return;
2116 }
2117
2118 wp_media_frame = window.wp.media({
2119 library: {
2120 type: $library
2121 },
2122 });
2123
2124 wp_media_frame.on( 'select', function() {
2125
2126 var attributes = wp_media_frame.state().get('selection').first().attributes;
2127
2128 if ( $library.length && $library.indexOf(attributes.subtype) === -1 && $library.indexOf(attributes.type) === -1 ) {
2129 return;
2130 }
2131
2132 $input.val(attributes.url).trigger('change');
2133
2134 });
2135
2136 wp_media_frame.open();
2137
2138 });
2139
2140 $remove_button.on('click', function( e ) {
2141 e.preventDefault();
2142 $input.val('').trigger('change');
2143 });
2144
2145 });
2146
2147 };
2148
2149 //
2150 // Field: wp_editor
2151 //
2152 $.fn.csf_field_wp_editor = function() {
2153 return this.each( function() {
2154
2155 if ( typeof window.wp.editor === 'undefined' || typeof window.tinyMCEPreInit === 'undefined' || typeof window.tinyMCEPreInit.mceInit.csf_wp_editor === 'undefined' ) {
2156 return;
2157 }
2158
2159 var $this = $(this),
2160 $editor = $this.find('.csf-wp-editor'),
2161 $textarea = $this.find('textarea');
2162
2163 // If there is wp-editor remove it for avoid dupliated wp-editor conflicts.
2164 var $has_wp_editor = $this.find('.wp-editor-wrap').length || $this.find('.mce-container').length;
2165
2166 if ( $has_wp_editor ) {
2167 $editor.empty();
2168 $editor.append($textarea);
2169 $textarea.css('display', '');
2170 }
2171
2172 // Generate a unique id
2173 var uid = CSF.helper.uid('csf-editor-');
2174
2175 $textarea.attr('id', uid);
2176
2177 // Get default editor settings
2178 var default_editor_settings = {
2179 tinymce: window.tinyMCEPreInit.mceInit.csf_wp_editor,
2180 quicktags: window.tinyMCEPreInit.qtInit.csf_wp_editor
2181 };
2182
2183 // Get default editor settings
2184 var field_editor_settings = $editor.data('editor-settings');
2185
2186 // Callback for old wp editor
2187 var wpEditor = wp.oldEditor ? wp.oldEditor : wp.editor;
2188
2189 if ( wpEditor && wpEditor.hasOwnProperty('autop') ) {
2190 wp.editor.autop = wpEditor.autop;
2191 wp.editor.removep = wpEditor.removep;
2192 wp.editor.initialize = wpEditor.initialize;
2193 }
2194
2195 // Add on change event handle
2196 var editor_on_change = function( editor ) {
2197 editor.on('change keyup', function() {
2198 var value = ( field_editor_settings.wpautop ) ? editor.getContent() : wp.editor.removep(editor.getContent());
2199 $textarea.val(value).trigger('change');
2200 });
2201 };
2202
2203 // Extend editor selector and on change event handler
2204 default_editor_settings.tinymce = $.extend( {}, default_editor_settings.tinymce, { selector: '#'+ uid, setup: editor_on_change } );
2205
2206 // Override editor tinymce settings
2207 if ( field_editor_settings.tinymce === false ) {
2208 default_editor_settings.tinymce = false;
2209 $editor.addClass('csf-no-tinymce');
2210 }
2211
2212 // Override editor quicktags settings
2213 if ( field_editor_settings.quicktags === false ) {
2214 default_editor_settings.quicktags = false;
2215 $editor.addClass('csf-no-quicktags');
2216 }
2217
2218 // Wait until :visible
2219 var interval = setInterval(function () {
2220 if ( $this.is(':visible') ) {
2221 window.wp.editor.initialize(uid, default_editor_settings);
2222 clearInterval(interval);
2223 }
2224 });
2225
2226 // Add Media buttons
2227 if ( field_editor_settings.media_buttons && window.csf_media_buttons ) {
2228
2229 var $editor_buttons = $editor.find('.wp-media-buttons');
2230
2231 if ( $editor_buttons.length ) {
2232
2233 $editor_buttons.find('.csf-shortcode-button').data('editor-id', uid);
2234
2235 } else {
2236
2237 var $media_buttons = $(window.csf_media_buttons);
2238
2239 $media_buttons.find('.csf-shortcode-button').data('editor-id', uid);
2240
2241 $editor.prepend( $media_buttons );
2242
2243 }
2244
2245 }
2246
2247 });
2248
2249 };
2250
2251 //
2252 // Confirm
2253 //
2254 $.fn.csf_confirm = function() {
2255 return this.each( function() {
2256 $(this).on('click', function( e ) {
2257
2258 var confirm_text = $(this).data('confirm') || window.csf_vars.i18n.confirm;
2259 var confirm_answer = confirm( confirm_text );
2260
2261 if ( confirm_answer ) {
2262 CSF.vars.is_confirm = true;
2263 CSF.vars.form_modified = false;
2264 } else {
2265 e.preventDefault();
2266 return false;
2267 }
2268
2269 });
2270 });
2271 };
2272
2273 $.fn.serializeObject = function() {
2274
2275 var obj = {};
2276
2277 $.each( this.serializeArray(), function(i,o){
2278 var n = o.name,
2279 v = o.value;
2280
2281 obj[n] = obj[n] === undefined ? v
2282 : $.isArray( obj[n] ) ? obj[n].concat( v )
2283 : [ obj[n], v ];
2284 });
2285
2286 return obj;
2287
2288 };
2289
2290 //
2291 // Options Save
2292 //
2293 $.fn.csf_save = function() {
2294 return this.each( function() {
2295
2296 var $this = $(this),
2297 $buttons = $('.csf-save'),
2298 $panel = $('.csf-options'),
2299 flooding = false,
2300 timeout;
2301
2302 $this.on('click', function( e ) {
2303
2304 if ( !flooding ) {
2305
2306 var $text = $this.data('save'),
2307 $value = $this.val();
2308
2309 $buttons.attr('value', $text);
2310
2311 if ( $this.hasClass('csf-save-ajax') ) {
2312
2313 e.preventDefault();
2314
2315 $panel.addClass('csf-saving');
2316 $buttons.prop('disabled', true);
2317
2318 window.wp.ajax.post( 'csf_'+ $panel.data('unique') +'_ajax_save', {
2319 data: $('#csf-form').serializeJSONCSF()
2320 })
2321 .done( function( response ) {
2322
2323 // clear errors
2324 $('.csf-error').remove();
2325
2326 if ( Object.keys( response.errors ).length ) {
2327
2328 var error_icon = '<i class="csf-label-error csf-error">!</i>';
2329
2330 $.each(response.errors, function( key, error_message ) {
2331
2332 var $field = $('[data-depend-id="'+ key +'"]'),
2333 $link = $('a[href="#tab='+ $field.closest('.csf-section').data('section-id') +'"]' ),
2334 $tab = $link.closest('.csf-tab-item');
2335
2336 $field.closest('.csf-fieldset').append( '<p class="csf-error csf-error-text">'+ error_message +'</p>' );
2337
2338 if ( !$link.find('.csf-error').length ) {
2339 $link.append( error_icon );
2340 }
2341
2342 if ( !$tab.find('.csf-arrow .csf-error').length ) {
2343 $tab.find('.csf-arrow').append( error_icon );
2344 }
2345
2346 });
2347
2348 }
2349
2350 $panel.removeClass('csf-saving');
2351 $buttons.prop('disabled', false).attr('value', $value);
2352 flooding = false;
2353
2354 CSF.vars.form_modified = false;
2355 CSF.vars.$form_warning.hide();
2356
2357 clearTimeout(timeout);
2358
2359 var $result_success = $('.csf-form-success');
2360 $result_success.empty().append(response.notice).fadeIn('fast', function() {
2361 timeout = setTimeout( function() {
2362 $result_success.fadeOut('fast');
2363 }, 1000);
2364 });
2365
2366 })
2367 .fail( function( response ) {
2368 alert( response.error );
2369 });
2370
2371 } else {
2372
2373 CSF.vars.form_modified = false;
2374
2375 }
2376
2377 }
2378
2379 flooding = true;
2380
2381 });
2382
2383 });
2384 };
2385
2386 //
2387 // Option Framework
2388 //
2389 $.fn.csf_options = function() {
2390 return this.each( function() {
2391
2392 var $this = $(this),
2393 $content = $this.find('.csf-content'),
2394 $form_success = $this.find('.csf-form-success'),
2395 $form_warning = $this.find('.csf-form-warning'),
2396 $save_button = $this.find('.csf-header .csf-save');
2397
2398 CSF.vars.$form_warning = $form_warning;
2399
2400 // Shows a message white leaving theme options without saving
2401 if ( $form_warning.length ) {
2402
2403 window.onbeforeunload = function() {
2404 return ( CSF.vars.form_modified ) ? true : undefined;
2405 };
2406
2407 $content.on('change keypress', ':input', function() {
2408 if ( !CSF.vars.form_modified ) {
2409 $form_success.hide();
2410 $form_warning.fadeIn('fast');
2411 CSF.vars.form_modified = true;
2412 }
2413 });
2414
2415 }
2416
2417 if ( $form_success.hasClass('csf-form-show') ) {
2418 setTimeout( function() {
2419 $form_success.fadeOut('fast');
2420 }, 1000);
2421 }
2422
2423 $(document).keydown(function (event) {
2424 if ( ( event.ctrlKey || event.metaKey ) && event.which === 83 ) {
2425 $save_button.trigger('click');
2426 event.preventDefault();
2427 return false;
2428 }
2429 });
2430
2431 });
2432 };
2433
2434 //
2435 // Taxonomy Framework
2436 //
2437 $.fn.csf_taxonomy = function() {
2438 return this.each( function() {
2439
2440 var $this = $(this),
2441 $form = $this.parents('form');
2442
2443 if ( $form.attr('id') === 'addtag' ) {
2444
2445 var $submit = $form.find('#submit'),
2446 $cloned = $this.find('.csf-field').csf_clone();
2447
2448 $submit.on( 'click', function() {
2449
2450 if ( !$form.find('.form-required').hasClass('form-invalid') ) {
2451
2452 $this.data('inited', false);
2453
2454 $this.empty();
2455
2456 $this.html( $cloned );
2457
2458 $cloned = $cloned.csf_clone();
2459
2460 $this.csf_reload_script();
2461
2462 }
2463
2464 });
2465
2466 }
2467
2468 });
2469 };
2470
2471 //
2472 // Shortcode Framework
2473 //
2474 $.fn.csf_shortcode = function() {
2475
2476 var base = this;
2477
2478 base.shortcode_parse = function( serialize, key ) {
2479
2480 var shortcode = '';
2481
2482 $.each(serialize, function( shortcode_key, shortcode_values ) {
2483
2484 key = ( key ) ? key : shortcode_key;
2485
2486 shortcode += '[' + key;
2487
2488 $.each(shortcode_values, function( shortcode_tag, shortcode_value ) {
2489
2490 if ( shortcode_tag === 'content' ) {
2491
2492 shortcode += ']';
2493 shortcode += shortcode_value;
2494 shortcode += '[/'+ key +'';
2495
2496 } else {
2497
2498 shortcode += base.shortcode_tags( shortcode_tag, shortcode_value );
2499
2500 }
2501
2502 });
2503
2504 shortcode += ']';
2505
2506 });
2507
2508 return shortcode;
2509
2510 };
2511
2512 base.shortcode_tags = function( shortcode_tag, shortcode_value ) {
2513
2514 var shortcode = '';
2515
2516 if ( shortcode_value !== '' ) {
2517
2518 if ( typeof shortcode_value === 'object' && !$.isArray( shortcode_value ) ) {
2519
2520 $.each(shortcode_value, function( sub_shortcode_tag, sub_shortcode_value ) {
2521
2522 // sanitize spesific key/value
2523 switch( sub_shortcode_tag ) {
2524
2525 case 'background-image':
2526 sub_shortcode_value = ( sub_shortcode_value.url ) ? sub_shortcode_value.url : '';
2527 break;
2528
2529 }
2530
2531 if ( sub_shortcode_value !== '' ) {
2532 shortcode += ' ' + sub_shortcode_tag.replace('-', '_') + '="' + sub_shortcode_value.toString() + '"';
2533 }
2534
2535 });
2536
2537 } else {
2538
2539 shortcode += ' ' + shortcode_tag.replace('-', '_') + '="' + shortcode_value.toString() + '"';
2540
2541 }
2542
2543 }
2544
2545 return shortcode;
2546
2547 };
2548
2549 base.insertAtChars = function( _this, currentValue ) {
2550
2551 var obj = ( typeof _this[0].name !== 'undefined' ) ? _this[0] : _this;
2552
2553 if ( obj.value.length && typeof obj.selectionStart !== 'undefined' ) {
2554 obj.focus();
2555 return obj.value.substring( 0, obj.selectionStart ) + currentValue + obj.value.substring( obj.selectionEnd, obj.value.length );
2556 } else {
2557 obj.focus();
2558 return currentValue;
2559 }
2560
2561 };
2562
2563 base.send_to_editor = function( html, editor_id ) {
2564
2565 var tinymce_editor;
2566
2567 if ( typeof tinymce !== 'undefined' ) {
2568 tinymce_editor = tinymce.get( editor_id );
2569 }
2570
2571 if ( tinymce_editor && !tinymce_editor.isHidden() ) {
2572 tinymce_editor.execCommand( 'mceInsertContent', false, html );
2573 } else {
2574 var $editor = $('#'+editor_id);
2575 $editor.val( base.insertAtChars( $editor, html ) ).trigger('change');
2576 }
2577
2578 };
2579
2580 return this.each( function() {
2581
2582 var $modal = $(this),
2583 $load = $modal.find('.csf-modal-load'),
2584 $content = $modal.find('.csf-modal-content'),
2585 $insert = $modal.find('.csf-modal-insert'),
2586 $loading = $modal.find('.csf-modal-loading'),
2587 $select = $modal.find('select'),
2588 modal_id = $modal.data('modal-id'),
2589 nonce = $modal.data('nonce'),
2590 editor_id,
2591 target_id,
2592 gutenberg_id,
2593 sc_key,
2594 sc_name,
2595 sc_view,
2596 sc_group,
2597 $cloned,
2598 $button;
2599
2600 $(document).on('click', '.csf-shortcode-button[data-modal-id="'+ modal_id +'"]', function( e ) {
2601
2602 e.preventDefault();
2603
2604 $button = $(this);
2605 editor_id = $button.data('editor-id') || false;
2606 target_id = $button.data('target-id') || false;
2607 gutenberg_id = $button.data('gutenberg-id') || false;
2608
2609 $modal.removeClass('hidden');
2610
2611 // single usage trigger first shortcode
2612 if ( $modal.hasClass('csf-shortcode-single') && sc_name === undefined ) {
2613 $select.trigger('change');
2614 }
2615
2616 });
2617
2618 $select.on( 'change', function() {
2619
2620 var $option = $(this);
2621 var $selected = $option.find(':selected');
2622
2623 sc_key = $option.val();
2624 sc_name = $selected.data('shortcode');
2625 sc_view = $selected.data('view') || 'normal';
2626 sc_group = $selected.data('group') || sc_name;
2627
2628 $load.empty();
2629
2630 if ( sc_key ) {
2631
2632 $loading.show();
2633
2634 window.wp.ajax.post( 'csf-get-shortcode-'+ modal_id, {
2635 shortcode_key: sc_key,
2636 nonce: nonce
2637 })
2638 .done( function( response ) {
2639
2640 $loading.hide();
2641
2642 var $appended = $(response.content).appendTo($load);
2643
2644 $insert.parent().removeClass('hidden');
2645
2646 $cloned = $appended.find('.csf--repeat-shortcode').csf_clone();
2647
2648 $appended.csf_reload_script();
2649 $appended.find('.csf-fields').csf_reload_script();
2650
2651 });
2652
2653 } else {
2654
2655 $insert.parent().addClass('hidden');
2656
2657 }
2658
2659 });
2660
2661 $insert.on('click', function( e ) {
2662
2663 e.preventDefault();
2664
2665 if ( $insert.prop('disabled') || $insert.attr('disabled') ) { return; }
2666
2667 var shortcode = '';
2668 var serialize = $modal.find('.csf-field:not(.csf-depend-on)').find(':input:not(.ignore)').serializeObjectCSF();
2669
2670 switch ( sc_view ) {
2671
2672 case 'contents':
2673 var contentsObj = ( sc_name ) ? serialize[sc_name] : serialize;
2674 $.each(contentsObj, function( sc_key, sc_value ) {
2675 var sc_tag = ( sc_name ) ? sc_name : sc_key;
2676 shortcode += '['+ sc_tag +']'+ sc_value +'[/'+ sc_tag +']';
2677 });
2678 break;
2679
2680 case 'group':
2681
2682 shortcode += '[' + sc_name;
2683 $.each(serialize[sc_name], function( sc_key, sc_value ) {
2684 shortcode += base.shortcode_tags( sc_key, sc_value );
2685 });
2686 shortcode += ']';
2687 shortcode += base.shortcode_parse( serialize[sc_group], sc_group );
2688 shortcode += '[/' + sc_name + ']';
2689
2690 break;
2691
2692 case 'repeater':
2693 shortcode += base.shortcode_parse( serialize[sc_group], sc_group );
2694 break;
2695
2696 default:
2697 shortcode += base.shortcode_parse( serialize );
2698 break;
2699
2700 }
2701
2702 shortcode = ( shortcode === '' ) ? '['+ sc_name +']' : shortcode;
2703
2704 if ( gutenberg_id ) {
2705
2706 var content = window.csf_gutenberg_props.attributes.hasOwnProperty('shortcode') ? window.csf_gutenberg_props.attributes.shortcode : '';
2707 window.csf_gutenberg_props.setAttributes({shortcode: content + shortcode});
2708
2709 } else if ( editor_id ) {
2710
2711 base.send_to_editor( shortcode, editor_id );
2712
2713 } else {
2714
2715 var $textarea = (target_id) ? $(target_id) : $button.parent().find('textarea');
2716 $textarea.val( base.insertAtChars( $textarea, shortcode ) ).trigger('change');
2717
2718 }
2719
2720 $modal.addClass('hidden');
2721
2722 });
2723
2724 $modal.on('click', '.csf--repeat-button', function( e ) {
2725
2726 e.preventDefault();
2727
2728 var $repeatable = $modal.find('.csf--repeatable');
2729 var $new_clone = $cloned.csf_clone();
2730 var $remove_btn = $new_clone.find('.csf-repeat-remove');
2731
2732 var $appended = $new_clone.appendTo( $repeatable );
2733
2734 $new_clone.find('.csf-fields').csf_reload_script();
2735
2736 CSF.helper.name_nested_replace( $modal.find('.csf--repeat-shortcode'), sc_group );
2737
2738 $remove_btn.on('click', function() {
2739
2740 $new_clone.remove();
2741
2742 CSF.helper.name_nested_replace( $modal.find('.csf--repeat-shortcode'), sc_group );
2743
2744 });
2745
2746 });
2747
2748 $modal.on('click', '.csf-modal-close, .csf-modal-overlay', function() {
2749 $modal.addClass('hidden');
2750 });
2751
2752 });
2753 };
2754
2755 //
2756 // WP Color Picker
2757 //
2758 if ( typeof Color === 'function' ) {
2759
2760 Color.prototype.toString = function() {
2761
2762 if ( this._alpha < 1 ) {
2763 return this.toCSS('rgba', this._alpha).replace(/\s+/g, '');
2764 }
2765
2766 var hex = parseInt( this._color, 10 ).toString( 16 );
2767
2768 if ( this.error ) { return ''; }
2769
2770 if ( hex.length < 6 ) {
2771 for (var i = 6 - hex.length - 1; i >= 0; i--) {
2772 hex = '0' + hex;
2773 }
2774 }
2775
2776 return '#' + hex;
2777
2778 };
2779
2780 }
2781
2782 CSF.funcs.parse_color = function( color ) {
2783
2784 var value = color.replace(/\s+/g, ''),
2785 trans = ( value.indexOf('rgba') !== -1 ) ? parseFloat( value.replace(/^.*,(.+)\)/, '$1') * 100 ) : 100,
2786 rgba = ( trans < 100 ) ? true : false;
2787
2788 return { value: value, transparent: trans, rgba: rgba };
2789
2790 };
2791
2792 $.fn.csf_color = function() {
2793 return this.each( function() {
2794
2795 var $input = $(this),
2796 picker_color = CSF.funcs.parse_color( $input.val() ),
2797 palette_color = window.csf_vars.color_palette.length ? window.csf_vars.color_palette : true,
2798 $container;
2799
2800 // Destroy and Reinit
2801 if ( $input.hasClass('wp-color-picker') ) {
2802 $input.closest('.wp-picker-container').after($input).remove();
2803 }
2804
2805 $input.wpColorPicker({
2806 palettes: palette_color,
2807 change: function( event, ui ) {
2808
2809 var ui_color_value = ui.color.toString();
2810
2811 $container.removeClass('csf--transparent-active');
2812 $container.find('.csf--transparent-offset').css('background-color', ui_color_value);
2813 $input.val(ui_color_value).trigger('change');
2814
2815 },
2816 create: function() {
2817
2818 $container = $input.closest('.wp-picker-container');
2819
2820 var a8cIris = $input.data('a8cIris'),
2821 $transparent_wrap = $('<div class="csf--transparent-wrap">' +
2822 '<div class="csf--transparent-slider"></div>' +
2823 '<div class="csf--transparent-offset"></div>' +
2824 '<div class="csf--transparent-text"></div>' +
2825 '<div class="csf--transparent-button">transparent <i class="fas fa-toggle-off"></i></div>' +
2826 '</div>').appendTo( $container.find('.wp-picker-holder') ),
2827 $transparent_slider = $transparent_wrap.find('.csf--transparent-slider'),
2828 $transparent_text = $transparent_wrap.find('.csf--transparent-text'),
2829 $transparent_offset = $transparent_wrap.find('.csf--transparent-offset'),
2830 $transparent_button = $transparent_wrap.find('.csf--transparent-button');
2831
2832 if ( $input.val() === 'transparent' ) {
2833 $container.addClass('csf--transparent-active');
2834 }
2835
2836 $transparent_button.on('click', function() {
2837 if ( $input.val() !== 'transparent' ) {
2838 $input.val('transparent').trigger('change').removeClass('iris-error');
2839 $container.addClass('csf--transparent-active');
2840 } else {
2841 $input.val( a8cIris._color.toString() ).trigger('change');
2842 $container.removeClass('csf--transparent-active');
2843 }
2844 });
2845
2846 $transparent_slider.slider({
2847 value: picker_color.transparent,
2848 step: 1,
2849 min: 0,
2850 max: 100,
2851 slide: function( event, ui ) {
2852
2853 var slide_value = parseFloat( ui.value / 100 );
2854 a8cIris._color._alpha = slide_value;
2855 $input.wpColorPicker( 'color', a8cIris._color.toString() );
2856 $transparent_text.text( ( slide_value === 1 || slide_value === 0 ? '' : slide_value ) );
2857
2858 },
2859 create: function() {
2860
2861 var slide_value = parseFloat( picker_color.transparent / 100 ),
2862 text_value = slide_value < 1 ? slide_value : '';
2863
2864 $transparent_text.text(text_value);
2865 $transparent_offset.css('background-color', picker_color.value);
2866
2867 $container.on('click', '.wp-picker-clear', function() {
2868
2869 a8cIris._color._alpha = 1;
2870 $transparent_text.text('');
2871 $transparent_slider.slider('option', 'value', 100);
2872 $container.removeClass('csf--transparent-active');
2873 $input.trigger('change');
2874
2875 });
2876
2877 $container.on('click', '.wp-picker-default', function() {
2878
2879 var default_color = CSF.funcs.parse_color( $input.data('default-color') ),
2880 default_value = parseFloat( default_color.transparent / 100 ),
2881 default_text = default_value < 1 ? default_value : '';
2882
2883 a8cIris._color._alpha = default_value;
2884 $transparent_text.text(default_text);
2885 $transparent_slider.slider('option', 'value', default_color.transparent);
2886
2887 if ( default_color.value === 'transparent' ) {
2888 $input.removeClass('iris-error');
2889 $container.addClass('csf--transparent-active');
2890 }
2891
2892 });
2893
2894 }
2895 });
2896 }
2897 });
2898
2899 });
2900 };
2901
2902 //
2903 // ChosenJS
2904 //
2905 $.fn.csf_chosen = function() {
2906 return this.each( function() {
2907
2908 var $this = $(this),
2909 $inited = $this.parent().find('.chosen-container'),
2910 is_sortable = $this.hasClass('csf-chosen-sortable') || false,
2911 is_ajax = $this.hasClass('csf-chosen-ajax') || false,
2912 is_multiple = $this.attr('multiple') || false,
2913 set_width = is_multiple ? '100%' : 'auto',
2914 set_options = $.extend({
2915 allow_single_deselect: true,
2916 disable_search_threshold: 10,
2917 width: set_width,
2918 no_results_text: window.csf_vars.i18n.no_results_text,
2919 }, $this.data('chosen-settings'));
2920
2921 if ( $inited.length ) {
2922 $inited.remove();
2923 }
2924
2925 // Chosen ajax
2926 if ( is_ajax ) {
2927
2928 var set_ajax_options = $.extend({
2929 data: {
2930 type: 'post',
2931 nonce: '',
2932 },
2933 allow_single_deselect: true,
2934 disable_search_threshold: -1,
2935 width: '100%',
2936 min_length: 3,
2937 type_delay: 500,
2938 typing_text: window.csf_vars.i18n.typing_text,
2939 searching_text: window.csf_vars.i18n.searching_text,
2940 no_results_text: window.csf_vars.i18n.no_results_text,
2941 }, $this.data('chosen-settings'));
2942
2943 $this.CSFAjaxChosen(set_ajax_options);
2944
2945 } else {
2946
2947 $this.chosen(set_options);
2948
2949 }
2950
2951 // Chosen keep options order
2952 if ( is_multiple ) {
2953
2954 var $hidden_select = $this.parent().find('.csf-hide-select');
2955 var $hidden_value = $hidden_select.val() || [];
2956
2957 $this.on('change', function(obj, result) {
2958
2959 if ( result && result.selected ) {
2960 $hidden_select.append( '<option value="'+ result.selected +'" selected="selected">'+ result.selected +'</option>' );
2961 } else if ( result && result.deselected ) {
2962 $hidden_select.find('option[value="'+ result.deselected +'"]').remove();
2963 }
2964
2965 // Force customize refresh
2966 if ( window.wp.customize !== undefined && $hidden_select.children().length === 0 && $hidden_select.data('customize-setting-link') ) {
2967 window.wp.customize.control( $hidden_select.data('customize-setting-link') ).setting.set('');
2968 }
2969
2970 $hidden_select.trigger('change');
2971
2972 });
2973
2974 // Chosen order abstract
2975 $this.CSFChosenOrder($hidden_value, true);
2976
2977 }
2978
2979 // Chosen sortable
2980 if ( is_sortable ) {
2981
2982 var $chosen_container = $this.parent().find('.chosen-container');
2983 var $chosen_choices = $chosen_container.find('.chosen-choices');
2984
2985 $chosen_choices.bind('mousedown', function( event ) {
2986 if ( $(event.target).is('span') ) {
2987 event.stopPropagation();
2988 }
2989 });
2990
2991 $chosen_choices.sortable({
2992 items: 'li:not(.search-field)',
2993 helper: 'orginal',
2994 cursor: 'move',
2995 placeholder: 'search-choice-placeholder',
2996 start: function(e,ui) {
2997 ui.placeholder.width( ui.item.innerWidth() );
2998 ui.placeholder.height( ui.item.innerHeight() );
2999 },
3000 update: function( e, ui ) {
3001
3002 var select_options = '';
3003 var chosen_object = $this.data('chosen');
3004 var $prev_select = $this.parent().find('.csf-hide-select');
3005
3006 $chosen_choices.find('.search-choice-close').each( function() {
3007 var option_array_index = $(this).data('option-array-index');
3008 $.each(chosen_object.results_data, function(index, data) {
3009 if ( data.array_index === option_array_index ){
3010 select_options += '<option value="'+ data.value +'" selected>'+ data.value +'</option>';
3011 }
3012 });
3013 });
3014
3015 $prev_select.children().remove();
3016 $prev_select.append(select_options);
3017 $prev_select.trigger('change');
3018
3019 }
3020 });
3021
3022 }
3023
3024 });
3025 };
3026
3027 //
3028 // Helper Checkbox Checker
3029 //
3030 $.fn.csf_checkbox = function() {
3031 return this.each( function() {
3032
3033 var $this = $(this),
3034 $input = $this.find('.csf--input'),
3035 $checkbox = $this.find('.csf--checkbox');
3036
3037 $checkbox.on('click', function() {
3038 $input.val( Number( $checkbox.prop('checked') ) ).trigger('change');
3039 });
3040
3041 });
3042 };
3043
3044 //
3045 // Siblings
3046 //
3047 $.fn.csf_siblings = function() {
3048 return this.each( function() {
3049
3050 var $this = $(this),
3051 $siblings = $this.find('.csf--sibling'),
3052 multiple = $this.data('multiple') || false;
3053
3054 $siblings.on('click', function() {
3055
3056 var $sibling = $(this);
3057
3058 if ( multiple ) {
3059
3060 if ( $sibling.hasClass('csf--active') ) {
3061 $sibling.removeClass('csf--active');
3062 $sibling.find('input').prop('checked', false).trigger('change');
3063 } else {
3064 $sibling.addClass('csf--active');
3065 $sibling.find('input').prop('checked', true).trigger('change');
3066 }
3067
3068 } else {
3069
3070 $this.find('input').prop('checked', false);
3071 $sibling.find('input').prop('checked', true).trigger('change');
3072 $sibling.addClass('csf--active').siblings().removeClass('csf--active');
3073
3074 }
3075
3076 });
3077
3078 });
3079 };
3080
3081 //
3082 // Help Tooltip
3083 //
3084 $.fn.csf_help = function() {
3085 return this.each( function() {
3086
3087 var $this = $(this),
3088 $tooltip,
3089 offset_left;
3090
3091 $this.on({
3092 mouseenter: function() {
3093
3094 $tooltip = $( '<div class="csf-tooltip"></div>' ).html( $this.find('.csf-help-text').html() ).appendTo('body');
3095 offset_left = ( CSF.vars.is_rtl ) ? ( $this.offset().left + 24 ) : ( $this.offset().left - $tooltip.outerWidth() );
3096
3097 $tooltip.css({
3098 top: $this.offset().top - ( ( $tooltip.outerHeight() / 2 ) - 14 ),
3099 left: offset_left,
3100 });
3101
3102 },
3103 mouseleave: function() {
3104
3105 if ( $tooltip !== undefined ) {
3106 $tooltip.remove();
3107 }
3108
3109 }
3110
3111 });
3112
3113 });
3114 };
3115
3116 //
3117 // Customize Refresh
3118 //
3119 $.fn.csf_customizer_refresh = function() {
3120 return this.each( function() {
3121
3122 var $this = $(this),
3123 $complex = $this.closest('.csf-customize-complex');
3124
3125 if ( $complex.length ) {
3126
3127 var unique_id = $complex.data('unique-id');
3128
3129 if ( unique_id === undefined ) {
3130 return;
3131 }
3132
3133 var $input = $complex.find(':input'),
3134 option_id = $complex.data('option-id'),
3135 obj = $input.serializeObjectCSF(),
3136 data = ( ! $.isEmptyObject(obj) && obj[unique_id] && obj[unique_id][option_id] ) ? obj[unique_id][option_id] : '',
3137 control = window.wp.customize.control(unique_id +'['+ option_id +']');
3138
3139 // clear the value to force refresh.
3140 control.setting._value = null;
3141
3142 control.setting.set( data );
3143
3144 } else {
3145
3146 $this.find(':input').first().trigger('change');
3147
3148 }
3149
3150 $(document).trigger('csf-customizer-refresh', $this);
3151
3152 });
3153 };
3154
3155 //
3156 // Customize Listen Form Elements
3157 //
3158 $.fn.csf_customizer_listen = function( options ) {
3159
3160 var settings = $.extend({
3161 closest: false,
3162 }, options );
3163
3164 return this.each( function() {
3165
3166 if ( window.wp.customize === undefined ) { return; }
3167
3168 var $this = ( settings.closest ) ? $(this).closest('.csf-customize-complex') : $(this),
3169 $input = $this.find(':input'),
3170 unique_id = $this.data('unique-id'),
3171 option_id = $this.data('option-id');
3172
3173 if ( unique_id === undefined ) {
3174 return;
3175 }
3176
3177 $input.on('change keyup', function() {
3178
3179 var obj = $this.find(':input').serializeObjectCSF();
3180 var val = ( !$.isEmptyObject(obj) && obj[unique_id] && obj[unique_id][option_id] ) ? obj[unique_id][option_id] : '';
3181
3182 window.wp.customize.control( unique_id +'['+ option_id +']' ).setting.set( val );
3183
3184 });
3185
3186 });
3187 };
3188
3189 //
3190 // Customizer Listener for Reload JS
3191 //
3192 $(document).on('expanded', '.control-section', function() {
3193
3194 var $this = $(this);
3195
3196 if ( $this.hasClass('open') && !$this.data('inited') ) {
3197
3198 var $fields = $this.find('.csf-customize-field');
3199 var $complex = $this.find('.csf-customize-complex');
3200
3201 if ( $fields.length ) {
3202 $this.csf_dependency();
3203 $fields.csf_reload_script({dependency: false});
3204 $complex.csf_customizer_listen();
3205 }
3206
3207 $this.data('inited', true);
3208
3209 }
3210
3211 });
3212
3213 //
3214 // Window on resize
3215 //
3216 CSF.vars.$window.on('resize csf.resize', CSF.helper.debounce( function( event ) {
3217
3218 var window_width = navigator.userAgent.indexOf('AppleWebKit/') > -1 ? CSF.vars.$window.width() : window.innerWidth;
3219
3220 if ( window_width <= 782 && !CSF.vars.onloaded ) {
3221 $('.csf-section').csf_reload_script();
3222 CSF.vars.onloaded = true;
3223 }
3224
3225 }, 200)).trigger('csf.resize');
3226
3227 //
3228 // Widgets Framework
3229 //
3230 $.fn.csf_widgets = function() {
3231 if ( this.length ) {
3232
3233 $(document).on('widget-added widget-updated', function( event, $widget ) {
3234 $widget.find('.csf-fields').csf_reload_script();
3235 });
3236
3237 $('.widgets-sortables, .control-section-sidebar').on('sortstop', function( event, ui ) {
3238 ui.item.find('.csf-fields').csf_reload_script_retry();
3239 });
3240
3241 $(document).on('click', '.widget-top', function( event ) {
3242 $(this).parent().find('.csf-fields').csf_reload_script();
3243 });
3244
3245 }
3246 };
3247
3248 //
3249 // Nav Menu Options Framework
3250 //
3251 $.fn.csf_nav_menu = function() {
3252 return this.each( function() {
3253
3254 var $navmenu = $(this);
3255
3256 $navmenu.on('click', 'a.item-edit', function() {
3257 $(this).closest('li.menu-item').find('.csf-fields').csf_reload_script();
3258 });
3259
3260 $navmenu.on('sortstop', function( event, ui ) {
3261 ui.item.find('.csf-fields').csf_reload_script_retry();
3262 });
3263
3264 });
3265 };
3266
3267 //
3268 // Retry Plugins
3269 //
3270 $.fn.csf_reload_script_retry = function() {
3271 return this.each( function() {
3272
3273 var $this = $(this);
3274
3275 if ( $this.data('inited') ) {
3276 $this.children('.csf-field-wp_editor').csf_field_wp_editor();
3277 }
3278
3279 });
3280 };
3281
3282 //
3283 // Reload Plugins
3284 //
3285 $.fn.csf_reload_script = function( options ) {
3286
3287 var settings = $.extend({
3288 dependency: true,
3289 }, options );
3290
3291 return this.each( function() {
3292
3293 var $this = $(this);
3294
3295 // Avoid for conflicts
3296 if ( !$this.data('inited') ) {
3297
3298 // Field plugins
3299 $this.children('.csf-field-accordion').csf_field_accordion();
3300 $this.children('.csf-field-backup').csf_field_backup();
3301 $this.children('.csf-field-background').csf_field_background();
3302 $this.children('.csf-field-code_editor').csf_field_code_editor();
3303 $this.children('.csf-field-date').csf_field_date();
3304 $this.children('.csf-field-fieldset').csf_field_fieldset();
3305 $this.children('.csf-field-gallery').csf_field_gallery();
3306 $this.children('.csf-field-group').csf_field_group();
3307 $this.children('.csf-field-icon').csf_field_icon();
3308 $this.children('.csf-field-link').csf_field_link();
3309 $this.children('.csf-field-media').csf_field_media();
3310 $this.children('.csf-field-map').csf_field_map();
3311 $this.children('.csf-field-repeater').csf_field_repeater();
3312 $this.children('.csf-field-slider').csf_field_slider();
3313 $this.children('.csf-field-sortable').csf_field_sortable();
3314 $this.children('.csf-field-sorter').csf_field_sorter();
3315 $this.children('.csf-field-spinner').csf_field_spinner();
3316 $this.children('.csf-field-switcher').csf_field_switcher();
3317 $this.children('.csf-field-tabbed').csf_field_tabbed();
3318 $this.children('.csf-field-typography').csf_field_typography();
3319 $this.children('.csf-field-upload').csf_field_upload();
3320 $this.children('.csf-field-wp_editor').csf_field_wp_editor();
3321
3322 // Field colors
3323 $this.children('.csf-field-border').find('.csf-color').csf_color();
3324 $this.children('.csf-field-background').find('.csf-color').csf_color();
3325 $this.children('.csf-field-color').find('.csf-color').csf_color();
3326 $this.children('.csf-field-color_group').find('.csf-color').csf_color();
3327 $this.children('.csf-field-link_color').find('.csf-color').csf_color();
3328 $this.children('.csf-field-typography').find('.csf-color').csf_color();
3329
3330 // Field chosenjs
3331 $this.children('.csf-field-select').find('.csf-chosen').csf_chosen();
3332
3333 // Field Checkbox
3334 $this.children('.csf-field-checkbox').find('.csf-checkbox').csf_checkbox();
3335
3336 // Field Siblings
3337 $this.children('.csf-field-button_set').find('.csf-siblings').csf_siblings();
3338 $this.children('.csf-field-image_select').find('.csf-siblings').csf_siblings();
3339 $this.children('.csf-field-palette').find('.csf-siblings').csf_siblings();
3340
3341 // Help Tooptip
3342 $this.children('.csf-field').find('.csf-help').csf_help();
3343
3344 if ( settings.dependency ) {
3345 $this.csf_dependency();
3346 }
3347
3348 $this.data('inited', true);
3349
3350 $(document).trigger('csf-reload-script', $this);
3351
3352 }
3353
3354 });
3355 };
3356
3357 //
3358 // Document ready and run scripts
3359 //
3360 $(document).ready( function() {
3361
3362 $('.csf-save').csf_save();
3363 $('.csf-options').csf_options();
3364 $('.csf-sticky-header').csf_sticky();
3365 $('.csf-nav-options').csf_nav_options();
3366 $('.csf-nav-metabox').csf_nav_metabox();
3367 $('.csf-taxonomy').csf_taxonomy();
3368 $('.csf-page-templates').csf_page_templates();
3369 $('.csf-post-formats').csf_post_formats();
3370 $('.csf-shortcode').csf_shortcode();
3371 $('.csf-search').csf_search();
3372 $('.csf-confirm').csf_confirm();
3373 $('.csf-expand-all').csf_expand_all();
3374 $('.csf-onload').csf_reload_script();
3375 $('.widget').csf_widgets();
3376 $('#menu-to-edit').csf_nav_menu();
3377
3378 });
3379
3380 })( jQuery, window, document );
3381