This commit is contained in:
2024-05-20 15:37:46 +03:00
commit 00b7dbd0b7
10404 changed files with 3285853 additions and 0 deletions

View File

@ -0,0 +1,211 @@
/**
* Used for character counters
*/
window.CMB2 = window.CMB2 || {};
window.CMB2.charcounter = window.CMB2.charcounter || {};
( function(window, document, $, cmb, counter ) {
'use strict';
if ( ! wp.utils || ! wp.utils.WordCounter ) {
return cmb.log( 'Cannot find wp.utils!' );
}
// Private variables
counter.counters = {};
var counters = counter.counters;
var wpCounter = new wp.utils.WordCounter();
/**
* Update a field's character counter
*
* @since 2.7.0
*
* @param {string} field_id
*
* @return {int}
*/
counter.updateCounter = function( field_id ) {
// No counter?
if ( ! counters.hasOwnProperty( field_id ) ) {
return null;
}
var instance = counters[ field_id ];
var wysiwyg = instance.editor && ! instance.editor.isHidden();
// Are we dealing with WYSIWYG visual editor, or textarea / WYSIWYG textarea?
var text = wysiwyg ? instance.editor.getContent( { format: 'raw' } ) : cmb.$id( field_id ).val().trim();
var count = wpCounter.count( text, instance.type );
var exceeded = instance.max && count > instance.max;
// Number remaining when max is defined
var val = instance.max ? instance.max - count : count;
// Over maximum?
instance.$el.parents( '.cmb2-char-counter-wrap' )[ exceeded ? 'addClass' : 'removeClass' ]( 'cmb2-max-exceeded' );
// Update counter, and update counter input width.
instance.$el.val( val ).outerWidth( ( ( 8 * String( val ).length ) + 15 ) + 'px' );
return count;
};
counter.instantiate = function( $el ) {
var data = $el.data();
// Add counter details if not already done
if ( ! ( data.fieldId in counters ) ) {
var instance = {
$el : $el,
max : data.max,
type : 'words' === data.counterType ? 'words' : 'characters_including_spaces',
editor : false,
};
counters[ data.fieldId ] = instance;
// Initialise counter
counter.updateCounter( data.fieldId );
}
};
/**
* Initializes all character counters. Hooked to cmb_init.
*
* @since 2.7.0
*
* @param {bool} init First init?
*
* @return {void}
*/
counter.initAll = function() {
// Gather counters and initialise
$( '.cmb2-char-counter' ).each( function() {
counter.instantiate( $( this ) );
});
};
/**
* Initializes WYSIWYG editors. Hooked to tinymce-editor-init
*
* @since 2.7.0
*
* @param {object} evt
* @param {object} editor
*
* @return {void}
*/
counter.initWysiwyg = function( evt, editor ) {
// Check if it's one of our WYSIWYGs
// Should have already been registered in counters via hidden textarea
if ( editor.id in counters ) {
// Add editor to counter
counters[ editor.id ].editor = editor;
// Add nodechange event
editor.on( 'nodechange keyup', counter.countWysiwyg );
}
};
/**
* Initializes after a new repeatable row has been added. Hooked to cmb2_add_row
*
* @since 2.7.0
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $row A jQuery dom element object for the group row.
*
* @return {void}
*/
counter.addRow = function( evt, $row ) {
// Character counters in row?
$row.find( '.cmb2-char-counter' ).each( function() {
// Update attributes
var $this = $( this );
var id = $this.attr( 'id' );
var field_id = id.replace( /^char-counter-/, '' );
$this.attr( 'data-field-id', field_id ).data( 'field-id', field_id );
counter.instantiate( $this );
});
};
/**
* Clean the counters array.
* Removes counters after a repeatable row has been removed. Hooked to cmb2_remove_row.
*
* @since 2.7.0
*
* @return {void}
*/
counter.cleanCounters = function() {
var field_id, remove = [];
// Got through counters
for ( field_id in counters ) {
// Check for element, gather for removal
if ( ! document.getElementById( field_id ) ) {
remove.push( field_id );
}
}
// Anything to remove?
if ( remove.length ) {
_.each( remove, function( field_id ) {
delete counters[ field_id ];
});
}
};
/**
* Counts the value of wysiwyg on the keyup event.
*
* @since 2.7.0
*
* @param {object} evt
*
* @return {void}
*/
counter.countWysiwyg = _.throttle( function( evt ) {
// Init event
if ( evt.hasOwnProperty( 'element' ) ) {
return counter.updateCounter( $( evt.element ).data( 'id' ) );
}
// Nodechange event
if ( evt.hasOwnProperty( 'currentTarget' ) ) {
return counter.updateCounter( $( evt.currentTarget ).data( 'id' ) );
}
} );
/**
* Counts the value of textarea on the keyup event.
*
* @since 2.7.0
*
* @param {object} evt
*
* @return {void}
*/
counter.countTextarea = _.throttle( function(evt) {
counter.updateCounter( evt.currentTarget.id );
}, 400 );
// Hook in our event callbacks.
$( document )
.on( 'cmb_init', counter.initAll )
.on( 'tinymce-editor-init', counter.initWysiwyg )
.on( 'cmb2_add_row', counter.addRow )
.on( 'cmb2_remove_row', counter.cleanCounters )
.on( 'input keyup', '.cmb2-count-chars', counter.countTextarea );
} )( window, document, jQuery, window.CMB2, window.CMB2.charcounter );

View File

@ -0,0 +1,345 @@
/**
* Used for WYSIWYG logic
*/
window.CMB2 = window.CMB2 || {};
window.CMB2.wysiwyg = window.CMB2.wysiwyg || {};
( function(window, document, $, cmb, wysiwyg, undefined ) {
'use strict';
// Private variables
var toBeDestroyed = [];
var toBeInitialized = [];
var all = wysiwyg.all = {};
// Private functions
/**
* Initializes any editors that weren't initialized because they didn't exist yet.
*
* @since 2.2.3
*
* @return {void}
*/
function delayedInit() {
// Don't initialize until they've all been destroyed.
if ( 0 === toBeDestroyed.length ) {
toBeInitialized.forEach( function ( toInit ) {
toBeInitialized.splice( toBeInitialized.indexOf( toInit ), 1 );
wysiwyg.init.apply( wysiwyg, toInit );
} );
} else {
window.setTimeout( delayedInit, 100 );
}
}
/**
* Destroys any editors that weren't destroyed because they didn't exist yet.
*
* @since 2.2.3
*
* @return {void}
*/
function delayedDestroy() {
toBeDestroyed.forEach( function( id ) {
toBeDestroyed.splice( toBeDestroyed.indexOf( id ), 1 );
wysiwyg.destroy( id );
} );
}
/**
* Gets the option data for a group (and initializes that data if it doesn't exist).
*
* @since 2.2.3
*
* @param {object} data The group/field data.
*
* @return {object} Options data object for a group.
*/
function getGroupData( data ) {
var groupid = data.groupid;
var fieldid = data.fieldid;
if ( ! all[ groupid ] || ! all[ groupid ][ fieldid ] ) {
all[ groupid ] = all[ groupid ] || {};
all[ groupid ][ fieldid ] = {
template : wp.template( 'cmb2-wysiwyg-' + groupid + '-' + fieldid ),
defaults : {
// Get the data from the template-wysiwyg initiation.
mce : $.extend( {}, tinyMCEPreInit.mceInit[ 'cmb2_i_' + groupid + fieldid ] ),
qt : $.extend( {}, tinyMCEPreInit.qtInit[ 'cmb2_i_' + groupid + fieldid ] )
}
};
// This is the template-wysiwyg data, and we do not want that to be initiated.
delete tinyMCEPreInit.mceInit[ 'cmb2_i_' + groupid + fieldid ];
delete tinyMCEPreInit.qtInit[ 'cmb2_i_' + groupid + fieldid ];
}
return all[ groupid ][ fieldid ];
}
/**
* Initiates the tinyMCEPreInit options for a wysiwyg editor instance.
*
* @since 2.2.3
*
* @param {object} options Options data object for the wysiwyg editor instance.
*
* @return {void}
*/
function initOptions( options ) {
var nameRegex = new RegExp( 'cmb2_n_' + options.groupid + options.fieldid, 'g' );
var idRegex = new RegExp( 'cmb2_i_' + options.groupid + options.fieldid, 'g' );
var prop, newSettings, newQTS;
// If no settings for this field. Clone from placeholder.
if ( 'undefined' === typeof( tinyMCEPreInit.mceInit[ options.id ] ) ) {
newSettings = $.extend( {}, options.defaults.mce );
for ( prop in newSettings ) {
if ( 'string' === typeof( newSettings[ prop ] ) ) {
newSettings[ prop ] = newSettings[ prop ]
.replace( idRegex, options.id )
.replace( nameRegex, options.name );
}
}
tinyMCEPreInit.mceInit[ options.id ] = newSettings;
}
// If no Quicktag settings for this field. Clone from placeholder.
if ( 'undefined' === typeof( tinyMCEPreInit.qtInit[ options.id ] ) ) {
newQTS = $.extend( {}, options.defaults.qt );
for ( prop in newQTS ) {
if ( 'string' === typeof( newQTS[ prop ] ) ) {
newQTS[ prop ] = newQTS[ prop ]
.replace( idRegex, options.id )
.replace( nameRegex, options.name );
}
}
tinyMCEPreInit.qtInit[ options.id ] = newQTS;
}
}
/**
* Initializes all group wysiwyg editors. Hooked to cmb_init.
*
* @since 2.2.3
*
* @return {void}
*/
wysiwyg.initAll = function() {
var $this,data,initiated;
$( '.cmb2-wysiwyg-placeholder' ).each( function() {
$this = $( this );
data = $this.data();
if ( data.groupid ) {
data.id = $this.attr( 'id' );
data.name = $this.attr( 'name' );
data.value = $this.val();
wysiwyg.init( $this, data, false );
initiated = true;
}
} );
if ( true === initiated ) {
if ( 'undefined' !== typeof window.QTags ) {
window.QTags._buttonsInit();
}
// Hook in our event callbacks.
$( document )
.on( 'cmb2_add_row', wysiwyg.addRow )
.on( 'cmb2_remove_group_row_start', wysiwyg.destroyRowEditors )
.on( 'cmb2_shift_rows_start', wysiwyg.shiftStart )
.on( 'cmb2_shift_rows_complete', wysiwyg.shiftComplete );
}
};
/**
* Initiates wysiwyg editors in a new group row. Hooked to cmb2_add_row.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $row A jQuery dom element object for the group row.
*
* @return {void}
*/
wysiwyg.addRow = function( evt, $row ) {
wysiwyg.initRow( $row, evt );
};
/**
* Destroys wysiwyg editors in a group row when that row is removed. Hooked to cmb2_remove_group_row_start.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
*
* @return {void}
*/
wysiwyg.destroyRowEditors = function( evt, $btn ) {
wysiwyg.destroy( $btn.parents( '.cmb-repeatable-grouping' ).find( '.wp-editor-area' ).attr( 'id' ) );
};
/**
* When a row-shift starts, we need to destroy the wysiwyg editors for the group-rows being shuffled.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
* @param {object} $from A jQuery dom element object for the row being shifted from.
* @param {object} $to A jQuery dom element object for the row being shifted to.
*
* @return {void}
*/
wysiwyg.shiftStart = function( evt, $btn, $from, $to ) {
$from.add( $to ).find( '.wp-editor-wrap textarea' ).each( function() {
wysiwyg.destroy( $( this ).attr( 'id' ) );
} );
};
/**
* When a row-shift completes, we need to re-init the wysiwyg editors for the group-rows being shuffled.
*
* @since 2.2.3
*
* @param {object} evt A jQuery-normalized event object.
* @param {object} $btn A jQuery dom element object for the remove-row button.
* @param {object} $from A jQuery dom element object for the row being shifted from.
* @param {object} $to A jQuery dom element object for the row being shifted to.
*
* @return {void}
*/
wysiwyg.shiftComplete = function( evt, $btn, $from, $to ) {
$from.add( $to ).each( function() {
wysiwyg.initRow( $( this ), evt );
} );
};
/**
* Initializes editors for a new CMB row.
*
* @since 2.2.3
*
* @param {object} $row A jQuery dom element object for the group row.
* @param {object} evt A jQuery-normalized event object.
*
* @return {void}
*/
wysiwyg.initRow = function( $row, evt ) {
var $toReplace, data, defVal;
$row.find( '.cmb2-wysiwyg-inner-wrap' ).each( function() {
$toReplace = $( this );
data = $toReplace.data();
defVal = cmb.getFieldArg( data.hash, 'default', '' );
defVal = 'undefined' !== typeof defVal && false !== defVal ? defVal : '';
data.iterator = $row.data( 'iterator' );
data.fieldid = data.id;
data.id = data.groupid + '_' + data.iterator + '_' + data.fieldid;
data.name = data.groupid + '[' + data.iterator + '][' + data.fieldid + ']';
data.value = 'cmb2_add_row' !== evt.type && $toReplace.find( '.wp-editor-area' ).length ? $toReplace.find( '.wp-editor-area' ).val() : defVal;
// The destroys might not have happened yet. Don't init until they have.
if ( 0 === toBeDestroyed.length ) {
wysiwyg.init( $toReplace, data );
} else {
toBeInitialized.push( [$toReplace, data] );
window.setTimeout( delayedInit, 100 );
}
} );
};
/**
* Initiates a wysiwyg editor instance and replaces the passed dom element w/ the editor html.
*
* @since 2.2.3
*
* @param {object} $toReplace A jQuery dom element which will be replaced with the wysiwyg editor.
* @param {object} data Data used to initate the editor.
* @param {bool} buttonsInit Whether to run QTags._buttonsInit()
*
* @return {void}
*/
wysiwyg.init = function( $toReplace, data, buttonsInit ) {
if ( ! data.groupid ) {
return false;
}
var mceActive = cmb.canTinyMCE();
var qtActive = 'function' === typeof window.quicktags;
$.extend( data, getGroupData( data ) );
initOptions( data );
$toReplace.replaceWith( data.template( data ) );
if ( mceActive ) {
window.tinyMCE.init( tinyMCEPreInit.mceInit[ data.id ] );
}
if ( qtActive ) {
window.quicktags( tinyMCEPreInit.qtInit[ data.id ] );
}
if ( mceActive ) {
$( document.getElementById( data.id ) ).parents( '.wp-editor-wrap' ).removeClass( 'html-active' ).addClass( 'tmce-active' );
}
if ( false !== buttonsInit && 'undefined' !== typeof window.QTags ) {
window.QTags._buttonsInit();
}
};
/**
* Destroys a wysiwyg editor instance.
*
* @since 2.2.3
*
* @param {string} id Editor id.
*
* @return {void}
*/
wysiwyg.destroy = function( id ) {
if ( ! cmb.canTinyMCE() ) {
// Nothing to see here.
return;
}
// The editor might not be initialized yet. But we need to destroy it once it is.
var editor = tinyMCE.get( id );
if ( editor !== null && typeof( editor ) !== 'undefined' ) {
editor.destroy();
if ( 'undefined' === typeof( tinyMCEPreInit.mceInit[ id ] ) ) {
delete tinyMCEPreInit.mceInit[ id ];
}
if ( 'undefined' === typeof( tinyMCEPreInit.qtInit[ id ] ) ) {
delete tinyMCEPreInit.qtInit[ id ];
}
} else if ( -1 === toBeDestroyed.indexOf( id ) ) {
toBeDestroyed.push( id );
window.setTimeout( delayedDestroy, 100 );
}
};
// Hook in our event callbacks.
$( document ).on( 'cmb_init', wysiwyg.initAll );
} )( window, document, jQuery, window.CMB2, window.CMB2.wysiwyg );

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
<?php
// Silence is golden

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,496 @@
/**!
* wp-color-picker-alpha
*
* Overwrite Automattic Iris for enabled Alpha Channel in wpColorPicker
* Only run in input and is defined data alpha in true
*
* Version: 2.1.3
* https://github.com/kallookoo/wp-color-picker-alpha
* Licensed under the GPLv2 license.
*/
( function( $ ) {
// Prevent double-init.
if ( $.wp.wpColorPicker.prototype._hasAlpha ) {
return;
}
// Variable for some backgrounds ( grid )
var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAAHnlligAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHJJREFUeNpi+P///4EDBxiAGMgCCCAGFB5AADGCRBgYDh48CCRZIJS9vT2QBAggFBkmBiSAogxFBiCAoHogAKIKAlBUYTELAiAmEtABEECk20G6BOmuIl0CIMBQ/IEMkO0myiSSraaaBhZcbkUOs0HuBwDplz5uFJ3Z4gAAAABJRU5ErkJggg==',
// html stuff for wpColorPicker copy of the original color-picker.js
_after = '<div class="wp-picker-holder" />',
_wrap = '<div class="wp-picker-container" />',
_button = '<input type="button" class="button button-small" />',
// Prevent CSS issues in < WordPress 4.9
_deprecated = ( wpColorPickerL10n.current !== undefined );
// Declare some global variables when is deprecated or not
if ( _deprecated ) {
var _before = '<a tabindex="0" class="wp-color-result" />';
} else {
var _before = '<button type="button" class="button wp-color-result" aria-expanded="false"><span class="wp-color-result-text"></span></button>',
_wrappingLabel = '<label></label>',
_wrappingLabelText = '<span class="screen-reader-text"></span>';
}
/**
* Overwrite Color
* for enable support rbga
*/
Color.fn.toString = function() {
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 '';
if ( hex.length < 6 )
hex = ( '00000' + hex ).substr( -6 );
return '#' + hex;
};
/**
* Overwrite wpColorPicker
*/
$.widget( 'wp.wpColorPicker', $.wp.wpColorPicker, {
_hasAlpha: true,
/**
* @summary Creates the color picker.
*
* Creates the color picker, sets default values, css classes and wraps it all in HTML.
*
* @since 3.5.0
*
* @access private
*
* @returns {void}
*/
_create: function() {
// Return early if Iris support is missing.
if ( ! $.support.iris ) {
return;
}
var self = this,
el = self.element;
// Override default options with options bound to the element.
$.extend( self.options, el.data() );
// Create a color picker which only allows adjustments to the hue.
if ( self.options.type === 'hue' ) {
return self._createHueOnly();
}
// Bind the close event.
self.close = $.proxy( self.close, self );
self.initialValue = el.val();
// Add a CSS class to the input field.
el.addClass( 'wp-color-picker' );
if ( _deprecated ) {
el.hide().wrap( _wrap );
self.wrap = el.parent();
self.toggler = $( _before )
.insertBefore( el )
.css( { backgroundColor : self.initialValue } )
.attr( 'title', wpColorPickerL10n.pick )
.attr( 'data-current', wpColorPickerL10n.current );
self.pickerContainer = $( _after ).insertAfter( el );
self.button = $( _button ).addClass('hidden');
} else {
/*
* Check if there's already a wrapping label, e.g. in the Customizer.
* If there's no label, add a default one to match the Customizer template.
*/
if ( ! el.parent( 'label' ).length ) {
// Wrap the input field in the default label.
el.wrap( _wrappingLabel );
// Insert the default label text.
self.wrappingLabelText = $( _wrappingLabelText )
.insertBefore( el )
.text( wpColorPickerL10n.defaultLabel );
}
/*
* At this point, either it's the standalone version or the Customizer
* one, we have a wrapping label to use as hook in the DOM, let's store it.
*/
self.wrappingLabel = el.parent();
// Wrap the label in the main wrapper.
self.wrappingLabel.wrap( _wrap );
// Store a reference to the main wrapper.
self.wrap = self.wrappingLabel.parent();
// Set up the toggle button and insert it before the wrapping label.
self.toggler = $( _before )
.insertBefore( self.wrappingLabel )
.css( { backgroundColor: self.initialValue } );
// Set the toggle button span element text.
self.toggler.find( '.wp-color-result-text' ).text( wpColorPickerL10n.pick );
// Set up the Iris container and insert it after the wrapping label.
self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel );
// Store a reference to the Clear/Default button.
self.button = $( _button );
}
// Set up the Clear/Default button.
if ( self.options.defaultColor ) {
self.button.addClass( 'wp-picker-default' ).val( wpColorPickerL10n.defaultString );
if ( ! _deprecated ) {
self.button.attr( 'aria-label', wpColorPickerL10n.defaultAriaLabel );
}
} else {
self.button.addClass( 'wp-picker-clear' ).val( wpColorPickerL10n.clear );
if ( ! _deprecated ) {
self.button.attr( 'aria-label', wpColorPickerL10n.clearAriaLabel );
}
}
if ( _deprecated ) {
el.wrap( '<span class="wp-picker-input-wrap" />' ).after( self.button );
} else {
// Wrap the wrapping label in its wrapper and append the Clear/Default button.
self.wrappingLabel
.wrap( '<span class="wp-picker-input-wrap hidden" />' )
.after( self.button );
/*
* The input wrapper now contains the label+input+Clear/Default button.
* Store a reference to the input wrapper: we'll use this to toggle
* the controls visibility.
*/
self.inputWrapper = el.closest( '.wp-picker-input-wrap' );
}
el.iris( {
target: self.pickerContainer,
hide: self.options.hide,
width: self.options.width,
mode: self.options.mode,
palettes: self.options.palettes,
/**
* @summary Handles the onChange event if one has been defined in the options.
*
* Handles the onChange event if one has been defined in the options and additionally
* sets the background color for the toggler element.
*
* @since 3.5.0
*
* @param {Event} event The event that's being called.
* @param {HTMLElement} ui The HTMLElement containing the color picker.
*
* @returns {void}
*/
change: function( event, ui ) {
if ( self.options.alpha ) {
self.toggler.css( { 'background-image' : 'url(' + image + ')' } );
if ( _deprecated ) {
self.toggler.html( '<span class="color-alpha" />' );
} else {
self.toggler.css( {
'position' : 'relative'
} );
if ( self.toggler.find('span.color-alpha').length == 0 ) {
self.toggler.append('<span class="color-alpha" />');
}
}
self.toggler.find( 'span.color-alpha' ).css( {
'width' : '30px',
'position' : 'absolute',
'top' : 0,
'bottom' : 0,
'left' : 0,
'border-top-left-radius' : '2px',
'border-bottom-left-radius' : '2px',
'background' : ui.color.toString()
} );
} else {
self.toggler.css( { backgroundColor : ui.color.toString() } );
}
if ( $.isFunction( self.options.change ) ) {
self.options.change.call( this, event, ui );
}
}
} );
el.val( self.initialValue );
self._addListeners();
// Force the color picker to always be closed on initial load.
if ( ! self.options.hide ) {
self.toggler.click();
}
},
/**
* @summary Binds event listeners to the color picker.
*
* @since 3.5.0
*
* @access private
*
* @returns {void}
*/
_addListeners: function() {
var self = this;
/**
* @summary Prevent any clicks inside this widget from leaking to the top and closing it.
*
* @since 3.5.0
*
* @param {Event} event The event that's being called.
*
* @returs {void}
*/
self.wrap.on( 'click.wpcolorpicker', function( event ) {
event.stopPropagation();
});
/**
* @summary Open or close the color picker depending on the class.
*
* @since 3.5
*/
self.toggler.click( function(){
if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
self.close();
} else {
self.open();
}
});
/**
* @summary Checks if value is empty when changing the color in the color picker.
*
* Checks if value is empty when changing the color in the color picker.
* If so, the background color is cleared.
*
* @since 3.5.0
*
* @param {Event} event The event that's being called.
*
* @returns {void}
*/
self.element.on( 'change', function( event ) {
// Empty or Error = clear
if ( $( this ).val() === '' || self.element.hasClass( 'iris-error' ) ) {
if ( self.options.alpha ) {
if ( _deprecated ) {
self.toggler.removeAttr( 'style' );
}
self.toggler.find( 'span.color-alpha' ).css( 'backgroundColor', '' );
} else {
self.toggler.css( 'backgroundColor', '' );
}
// fire clear callback if we have one
if ( $.isFunction( self.options.clear ) )
self.options.clear.call( this, event );
}
} );
/**
* @summary Enables the user to clear or revert the color in the color picker.
*
* Enables the user to either clear the color in the color picker or revert back to the default color.
*
* @since 3.5.0
*
* @param {Event} event The event that's being called.
*
* @returns {void}
*/
self.button.on( 'click', function( event ) {
if ( $( this ).hasClass( 'wp-picker-clear' ) ) {
self.element.val( '' );
if ( self.options.alpha ) {
if ( _deprecated ) {
self.toggler.removeAttr( 'style' );
}
self.toggler.find( 'span.color-alpha' ).css( 'backgroundColor', '' );
} else {
self.toggler.css( 'backgroundColor', '' );
}
if ( $.isFunction( self.options.clear ) )
self.options.clear.call( this, event );
} else if ( $( this ).hasClass( 'wp-picker-default' ) ) {
self.element.val( self.options.defaultColor ).change();
}
});
},
});
/**
* Overwrite iris
*/
$.widget( 'a8c.iris', $.a8c.iris, {
_create: function() {
this._super();
// Global option for check is mode rbga is enabled
this.options.alpha = this.element.data( 'alpha' ) || false;
// Is not input disabled
if ( ! this.element.is( ':input' ) )
this.options.alpha = false;
if ( typeof this.options.alpha !== 'undefined' && this.options.alpha ) {
var self = this,
el = self.element,
_html = '<div class="iris-strip iris-slider iris-alpha-slider"><div class="iris-slider-offset iris-slider-offset-alpha"></div></div>',
aContainer = $( _html ).appendTo( self.picker.find( '.iris-picker-inner' ) ),
aSlider = aContainer.find( '.iris-slider-offset-alpha' ),
controls = {
aContainer : aContainer,
aSlider : aSlider
};
if ( typeof el.data( 'custom-width' ) !== 'undefined' ) {
self.options.customWidth = parseInt( el.data( 'custom-width' ) ) || 0;
} else {
self.options.customWidth = 100;
}
// Set default width for input reset
self.options.defaultWidth = el.width();
// Update width for input
if ( self._color._alpha < 1 || self._color.toString().indexOf('rgb') != -1 )
el.width( parseInt( self.options.defaultWidth + self.options.customWidth ) );
// Push new controls
$.each( controls, function( k, v ) {
self.controls[k] = v;
} );
// Change size strip and add margin for sliders
self.controls.square.css( { 'margin-right': '0' } );
var emptyWidth = ( self.picker.width() - self.controls.square.width() - 20 ),
stripsMargin = ( emptyWidth / 6 ),
stripsWidth = ( ( emptyWidth / 2 ) - stripsMargin );
$.each( [ 'aContainer', 'strip' ], function( k, v ) {
self.controls[v].width( stripsWidth ).css( { 'margin-left' : stripsMargin + 'px' } );
} );
// Add new slider
self._initControls();
// For updated widget
self._change();
}
},
_initControls: function() {
this._super();
if ( this.options.alpha ) {
var self = this,
controls = self.controls;
controls.aSlider.slider({
orientation : 'vertical',
min : 0,
max : 100,
step : 1,
value : parseInt( self._color._alpha * 100 ),
slide : function( event, ui ) {
// Update alpha value
self._color._alpha = parseFloat( ui.value / 100 );
self._change.apply( self, arguments );
}
});
}
},
_change: function() {
this._super();
var self = this,
el = self.element;
if ( this.options.alpha ) {
var controls = self.controls,
alpha = parseInt( self._color._alpha * 100 ),
color = self._color.toRgb(),
gradient = [
'rgb(' + color.r + ',' + color.g + ',' + color.b + ') 0%',
'rgba(' + color.r + ',' + color.g + ',' + color.b + ', 0) 100%'
],
defaultWidth = self.options.defaultWidth,
customWidth = self.options.customWidth,
target = self.picker.closest( '.wp-picker-container' ).find( '.wp-color-result' );
// Generate background slider alpha, only for CSS3 old browser fuck!! :)
controls.aContainer.css( { 'background' : 'linear-gradient(to bottom, ' + gradient.join( ', ' ) + '), url(' + image + ')' } );
if ( target.hasClass( 'wp-picker-open' ) ) {
// Update alpha value
controls.aSlider.slider( 'value', alpha );
/**
* Disabled change opacity in default slider Saturation ( only is alpha enabled )
* and change input width for view all value
*/
if ( self._color._alpha < 1 ) {
controls.strip.attr( 'style', controls.strip.attr( 'style' ).replace( /rgba\(([0-9]+,)(\s+)?([0-9]+,)(\s+)?([0-9]+)(,(\s+)?[0-9\.]+)\)/g, 'rgb($1$3$5)' ) );
el.width( parseInt( defaultWidth + customWidth ) );
} else {
el.width( defaultWidth );
}
}
}
var reset = el.data( 'reset-alpha' ) || false;
if ( reset ) {
self.picker.find( '.iris-palette-container' ).on( 'click.palette', '.iris-palette', function() {
self._color._alpha = 1;
self.active = 'external';
self._change();
} );
}
},
_addInputListeners: function( input ) {
var self = this,
debounceTimeout = 100,
callback = function( event ) {
var color = new Color( input.val() ),
val = input.val();
input.removeClass( 'iris-error' );
// we gave a bad color
if ( color.error ) {
// don't error on an empty input
if ( val !== '' )
input.addClass( 'iris-error' );
} else {
if ( color.toString() !== self._color.toString() ) {
// let's not do this on keyup for hex shortcodes
if ( ! ( event.type === 'keyup' && val.match( /^[0-9a-fA-F]{3}$/ ) ) )
self._setOption( 'color', color.toString() );
}
}
};
input.on( 'change', callback ).on( 'keyup', self._debounce( callback, debounceTimeout ) );
// If we initialized hidden, show on first focus. The rest is up to you.
if ( self.options.hide ) {
input.on( 'focus', function() {
self.show();
} );
}
}
} );
}( jQuery ) );
// Auto Call plugin is class is color-picker
jQuery( document ).ready( function( $ ) {
$( '.color-picker' ).wpColorPicker();
} );

File diff suppressed because one or more lines are too long