/** * * ----------------------------------------------------------- * * ShapedPlugin Framework * A Lightweight and easy-to-use WordPress Options Framework * * Copyright 2017 www.shapedplugin.com * * ----------------------------------------------------------- * */ ;(function ( $, window, document, undefined ) { 'use strict'; $.SPFRAMEWORK = $.SPFRAMEWORK || {}; // caching selector var $sp_body = $('body'); // caching variables var sp_is_rtl = $sp_body.hasClass('rtl'); // ====================================================== // SPFRAMEWORK TAB NAVIGATION // ------------------------------------------------------ $.fn.SPFRAMEWORK_TAB_NAVIGATION = function() { return this.each(function() { var $this = $(this), $nav = $this.find('.sp-nav'), $reset = $this.find('.sp-reset'), $expand = $this.find('.sp-expand-all'); $nav.find('ul:first a').on('click', function (e) { e.preventDefault(); var $el = $(this), $next = $el.next(), $target = $el.data('section'); if( $next.is('ul') ) { $next.slideToggle( 'fast' ); $el.closest('li').toggleClass('sp-tab-active'); } else { $('#sp-tab-'+$target).fadeIn('fast').siblings().hide(); $nav.find('a').removeClass('sp-section-active'); $el.addClass('sp-section-active'); $reset.val($target); } }); $expand.on('click', function (e) { e.preventDefault(); $this.find('.sp-body').toggleClass('sp-show-all'); $(this).find('.fa').toggleClass('fa-eye-slash' ).toggleClass('fa-eye'); }); }); }; // ====================================================== // ====================================================== // SPFRAMEWORK CHOSEN // ------------------------------------------------------ $.fn.SPFRAMEWORK_CHOSEN = function() { return this.each(function() { $(this).chosen({allow_single_deselect: true, disable_search_threshold: 15, width: 150 + 25 +'px'}); }); }; // ====================================================== // ====================================================== // SPFRAMEWORK RESET CONFIRM // ------------------------------------------------------ $.fn.SPFRAMEWORK_CONFIRM = function() { return this.each( function() { $(this).on('click', function( e ) { if ( !confirm('Are you sure?') ) { e.preventDefault(); } }); }); }; // ====================================================== // ====================================================== // SPFRAMEWORK SAVE OPTIONS // ------------------------------------------------------ $.fn.SPFRAMEWORK_SAVE = function() { return this.each( function() { var $this = $(this), $text = $this.data('save'), $value = $this.val(), $ajax = $('#sp-save-ajax'); $(document).on('keydown', function(event) { if (event.ctrlKey || event.metaKey) { if( String.fromCharCode(event.which).toLowerCase() === 's' ) { event.preventDefault(); $this.trigger('click'); } } }); $this.on('click', function ( e ) { if( $ajax.length ) { if( typeof tinyMCE === 'object' ) { tinyMCE.triggerSave(); } $this.prop('disabled', true).attr('value', $text); var serializedOptions = $('#sp_framework_form').serialize(); $.post( 'options.php', serializedOptions ).error( function() { alert('Error, Please try again.'); }).success( function() { $this.prop('disabled', false).attr('value', $value); $ajax.hide().fadeIn().delay(250).fadeOut(); }); e.preventDefault(); } else { $this.addClass('disabled').attr('value', $text); } }); }); }; // ====================================================== // ====================================================== // SPFRAMEWORK UI DIALOG OVERLAY HELPER // ------------------------------------------------------ if( typeof $.widget !== 'undefined' && typeof $.ui !== 'undefined' && typeof $.ui.dialog !== 'undefined' ) { $.widget( 'ui.dialog', $.ui.dialog, { _createOverlay: function() { this._super(); if ( !this.options.modal ) { return; } this._on(this.overlay, {click: 'close'}); } } ); } // ====================================================== // SPFRAMEWORK COLORPICKER // ------------------------------------------------------ if( typeof Color === 'function' ) { // adding alpha support for Automattic Color.js toString function. Color.fn.toString = function () { // check for alpha if ( this._alpha < 1 ) { return this.toCSS('rgba', this._alpha).replace(/\s+/g, ''); } var hex = parseInt( this._color, 10 ).toString( 16 ); if ( this.error ) { return ''; } // maybe left pad it if ( hex.length < 6 ) { for (var i = 6 - hex.length - 1; i >= 0; i--) { hex = '0' + hex; } } return '#' + hex; }; } $.SPFRAMEWORK.PARSE_COLOR_VALUE = function( val ) { var value = val.replace(/\s+/g, ''), alpha = ( value.indexOf('rgba') !== -1 ) ? parseFloat( value.replace(/^.*,(.+)\)/, '$1') * 100 ) : 100, rgba = ( alpha < 100 ) ? true : false; return { value: value, alpha: alpha, rgba: rgba }; }; $.fn.SPFRAMEWORK_COLORPICKER = function() { return this.each(function() { var $this = $(this); // check for rgba enabled/disable if( $this.data('rgba') !== false ) { // parse value var picker = $.SPFRAMEWORK.PARSE_COLOR_VALUE( $this.val() ); // wpColorPicker core $this.wpColorPicker({ // wpColorPicker: clear clear: function() { $this.trigger('keyup'); }, // wpColorPicker: change change: function( event, ui ) { var ui_color_value = ui.color.toString(); // update checkerboard background color $this.closest('.wp-picker-container').find('.sp-alpha-slider-offset').css('background-color', ui_color_value); $this.val(ui_color_value).trigger('change'); }, // wpColorPicker: create create: function() { // set variables for alpha slider var a8cIris = $this.data('a8cIris'), $container = $this.closest('.wp-picker-container'), // appending alpha wrapper $alpha_wrap = $('