Added support for pasting of tags
authorAlexander Ebert <ebert@woltlab.com>
Wed, 26 Jun 2013 12:47:05 +0000 (14:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 26 Jun 2013 12:47:05 +0000 (14:47 +0200)
wcfsetup/install/files/js/WCF.js

index 6bc0e08ede3c768076be23119ca5ae4b25923c83..530f027c2f9081e259d521617a8549de8dbeb3b1 100755 (executable)
@@ -7589,7 +7589,10 @@ WCF.EditableItemList = Class.extend({
                this._form = this._itemList.parents('form').submit($.proxy(this._submit, this));
                
                if (this._allowCustomInput) {
-                       this._searchInput.keydown($.proxy(this._keyDown, this));
+                       var self = this;
+                       this._searchInput.keydown($.proxy(this._keyDown, this)).on('paste', function() {
+                               setTimeout(function() { self._onPaste(); }, 100);
+                       });
                }
        },
        
@@ -7635,6 +7638,29 @@ WCF.EditableItemList = Class.extend({
                return true;
        },
        
+       /**
+        * Handle paste event.
+        */
+       _onPaste: function() {
+               // split content by comma
+               var $value = $.trim(this._searchInput.val());
+               $value = $value.split(',');
+               
+               for (var $i = 0, $length = $value.length; $i < $length; $i++) {
+                       var $label = $.trim($value[$i]);
+                       if ($label === '') {
+                               continue;
+                       }
+                       
+                       this.addItem({
+                               objectID: 0,
+                               label: $label
+                       });
+               }
+               
+               this._searchInput.val('');
+       },
+       
        /**
         * Loads raw data and converts it into internal structure. Override this methods
         * in your derived classes.