/* New UI Class */ ;(function($) { $.fn.outerHTML = function() { return $('
').append(this.eq(0).clone()).html(); }; panelUi = { id: '#spyropress-panel', messages: { agreeReset: 'Are you sure you want to reset back to the defaults?', agreeRemove: 'Are you sure you want to remove this?', agreeImport: 'Are you sure you want to restore the settings?', agreeDummy: 'Are you sure you want to install the dummy data?' }, resources: { buttonRemoveMedia: 'Remove Media' }, fontList: false, sliders: {}, // Start the Engine! init: function() { // Panel Functions this.init_select_wrapper(); this.init_tabs(); this.init_datepicker(); this.init_radio_image(); this.init_toggle_checkboxes(); this.init_upload(); this.init_upload_remove(); this.init_google_fonts(); this.init_toggles(); this.init_section_reset(); // Ajax Events this.ajax_widget_fix(); this.save_settings(); this.reset_settings(); this.import_settings(); this.skin_generator(); // Repeater this.repeater.init(); // Gallery Uploader this.gallery.init(); }, // Select to Chosen init_select_wrapper: function() { // if widget page if ( typeof pagenow !== 'undefined' && 'widgets' == pagenow) { // normal select $('.chosen', '#widgets-right').chosen({ allow_single_deselect: true }); // ajax select $('.chosen-ajax', '#widgets-right').each(function(i, obj) { var $this = $(obj), type = $this.data('type'), wp_type = $this.data('wp_type'); $this.ajaxChosen({ type: 'GET', url: ajaxurl, dataType: 'json', data: { action: 'spyropress_search_taxonomy', type: type, wp_type: wp_type } }, function(data) { var results = []; $.each(data, function(i, val) { results.push({ value: val.value, text: val.text }); }); return results; }, { allow_single_deselect: true }); }); } // if other than widget page else { // normal select $('.chosen').chosen({ allow_single_deselect: true }); // ajax select $('.chosen-ajax').each(function(i, obj) { var $this = $(obj), type = $this.data('type'), wp_type = $this.data('wp_type'); $this.ajaxChosen({ type: 'GET', url: ajaxurl, dataType: 'json', data: { action: 'spyropress_search_taxonomy', type: type, wp_type: wp_type } }, function(data) { var results = []; $.each(data, function(i, val) { results.push({ value: val.value, text: val.text }); }); return results; }, { allow_single_deselect: true }); }); } // Enable Changer var select_changer = $( '.enable_changer select, .enable_changer input:radio, #page_template, #post-formats-select .post-format'); select_changer.each(function() { var $this = $(this), id = $this.is(':radio') ? $this.attr('name') : $this.attr('id'); $( '.' + id ).hide(); }); select_changer.change(function() { var $this = $(this), id = $this.is(':radio') ? $this.attr('name') : $this.attr('id'), val = $this.val(); if( $this.is(':radio') ) { val = $('input[name=' + id + ']:radio:checked').val(); } val = val.replace( '.', '-' ); // hide $('.' + id).hide(); // show if (val) $('.' + id + '.' + val).show(); }).trigger('change'); }, init_tabs: function() { // Option Panel Main Tabs $('.panel-nav').idTabs(function(id, list, set) { var $this = $('a', set), span = $('span', $this); $this.removeClass('selected'); span.removeClass('module-icon-white'); $this.filter('a[href="' + id + '"]').addClass('selected').find('span').addClass('module-icon-white'); for (i in list) $(list[i]).hide(); $(id).fadeIn(); return false; }); // Meta Box Tabs $('.panel-tabs').idTabs(function(id, list, set) { $('li', set).removeClass('open'); $('a', set).filter('a[href="' + id + '"]', set).parent().addClass('open'); for (i in list) $(list[i]).hide(); $(id).fadeIn(); return false; }); }, init_datepicker: function() { $('.field', '.section-datepicker').datepicker(); }, init_radio_image: function() { $('.radio-img', '.section-radio-img').live('click', function() { var $this = $(this); $this.parents('.section-radio-img').find('.radio-img').removeClass('selected'); $this.addClass('selected'); }); }, init_toggle_checkboxes: function() { $('label.checkbox', '.section-radiolist').click(function(){ var $this = $(this), $parent = $this.parent(); $parent.find('.checkbox').removeClass('selected'); $this.addClass('selected'); }); }, // http://mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/ // https://github.com/thomasgriffin/New-Media-Image-Uploader // http://stackoverflow.com/questions/13847714/wordpress-3-5-custom-media-upload-for-your-theme-options init_upload: function() { $('body').on( 'click', '.upload_button', function( e ) { e.preventDefault(); var $this = $(this), $field = $this.prev('input'), field_id = $field.attr('id'), clone = wp.media.editor.send.attachment; wp.media.editor.send.attachment = function(props, attachment) { if( 'video' != attachment.type ) { var img = ( 'x-icon' == attachment.subtype) ? attachment.url : attachment.sizes[props.size].url; btnContent = ''; btnContent += '
'; btnContent += '' + panelUi.resources.buttonRemoveMedia + ''; $field.val(img); $field.parent('div').append('