TEXT   114
wpml color picker
Guest on 7th May 2022 04:02:10 PM


  1. /**
  2.  * Created by Created by OnTheGo Systems.
  3.  */
  4.  
  5. var WPML_Core = WPML_Core || {};
  6.  
  7. WPML_Core.ColorPicker = function () {
  8.         var self = this;
  9.  
  10.         self.init = function () {
  11.                 jQuery(document).ready(function () {
  12.                         var colorPickers = jQuery('.wp-picker-container .wpml-colorpicker');
  13.  
  14.                         if (colorPickers.length) {
  15.                                 jQuery(colorPickers).on('focus', function () {
  16.                                         jQuery(this).data('old-value', jQuery(this).val());
  17.                                 });
  18.  
  19.                                 jQuery(colorPickers).on('blur', function () {
  20.                                         var oldValue = '';
  21.                                         if (jQuery(this).data('old-value')) {
  22.                                                 oldValue = jQuery(this).data('old-value');
  23.                                         }
  24.                                         if (jQuery(this).hasClass('iris-error') || !self.isValidColor(jQuery(this).val())) {
  25.                                                 jQuery(this).val(oldValue);
  26.                                         }
  27.                                 });
  28.                         }
  29.  
  30.                 });
  31.         };
  32.  
  33.         self.isValidColor = function (input) {
  34.                 return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(input);
  35.         };
  36.  
  37.         self.init();
  38. };
  39.  
  40. WPML_Core.ColorPicker = new WPML_Core.ColorPicker();

Raw Paste

Login or Register to edit or fork this paste. It's free.