From 9e948519edd9d7682891612b492baf40292797d5 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 11 Jun 2013 17:09:22 +0200 Subject: [PATCH] Allow pasting of values like '#888888' --- wcfsetup/install/files/js/WCF.ColorPicker.js | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.ColorPicker.js b/wcfsetup/install/files/js/WCF.ColorPicker.js index 4ddf1c7c87..e22db23801 100644 --- a/wcfsetup/install/files/js/WCF.ColorPicker.js +++ b/wcfsetup/install/files/js/WCF.ColorPicker.js @@ -1,3 +1,10 @@ +/** + * Color picker for WCF + * + * @author Alexander Ebert + * @copyright 2001-2013 WoltLab GmbH + * @license GNU Lesser General Public License + */ WCF.ColorPicker = Class.extend({ /** * hue bar element @@ -246,6 +253,25 @@ WCF.ColorPicker = Class.extend({ // submit button var $submitForm = $('
').appendTo(this._dialog); $('').appendTo($submitForm).click($.proxy(this._submit, this)); + + // allow pasting of colors like '#888888' + var self = this; + this._hex.on('paste', function() { + self._hex.attr('maxlength', '7'); + + setTimeout(function() { + var $value = self._hex.val(); + if ($value.substring(0, 1) == '#') { + $value = $value.substr(1); + } + + if ($value.length > 6) { + $value = $value.substring(0, 6); + } + + self._hex.attr('maxlength', '6').val($value); + }, 50); + }); }, /** -- 2.20.1