Allow pasting of values like '#888888'
authorAlexander Ebert <ebert@woltlab.com>
Tue, 11 Jun 2013 15:09:22 +0000 (17:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 11 Jun 2013 15:09:22 +0000 (17:09 +0200)
wcfsetup/install/files/js/WCF.ColorPicker.js

index 4ddf1c7c873eb52765e79317c08f0f71236636b1..e22db238014a0a6bf1d5162a253ef65e8af98b9f 100644 (file)
@@ -1,3 +1,10 @@
+/**
+ * Color picker for WCF
+ * 
+ * @author     Alexander Ebert
+ * @copyright  2001-2013 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
 WCF.ColorPicker = Class.extend({
        /**
         * hue bar element
@@ -246,6 +253,25 @@ WCF.ColorPicker = Class.extend({
                // submit button
                var $submitForm = $('<div class="formSubmit" />').appendTo(this._dialog);
                $('<button class="buttonPrimary">' + WCF.Language.get('wcf.global.button.save') + '</button>').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);
+               });
        },
        
        /**