Skip to content

Commit

Permalink
Add a custom flag to prevent re-init of the alpha colorpicker. Fixes #13
Browse files Browse the repository at this point in the history


If this script is enqueued multiple times (e.g. by different WP plugins), then it will cause issues, documented in #13.
By setting and checking a flag, we can prevent multiple initiations.
  • Loading branch information
jtsternberg authored Nov 23, 2017
1 parent 8e1d1b5 commit d52b3d8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/wp-color-picker-alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* 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
Expand Down Expand Up @@ -48,6 +53,7 @@
* Overwrite wpColorPicker
*/
$.widget( 'wp.wpColorPicker', $.wp.wpColorPicker, {
_hasAlpha: true,
/**
* @summary Creates the color picker.
*
Expand Down Expand Up @@ -487,4 +493,4 @@
// Auto Call plugin is class is color-picker
jQuery( document ).ready( function( $ ) {
$( '.color-picker' ).wpColorPicker();
} );
} );

0 comments on commit d52b3d8

Please sign in to comment.