nitdoc: migrate clipboard to jQuery.UI widget
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 12 Feb 2014 05:25:29 +0000 (00:25 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 20 Feb 2014 19:11:58 +0000 (14:11 -0500)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/nitdoc/js/plugins/clipboard.js

index 1d12b85..8432174 100644 (file)
 /*\r
  * Nitdoc Clipboard\r
  *\r
- * Allow user to copy signatures to clipboard\r
+ * Allow user to copy signatures to clipboard with ZeroClipboard flahs plugin\r
+ * See: https://github.com/zeroclipboard/ZeroClipboard\r
  */\r
 define([\r
        "jquery",\r
+       "jQueryUI",\r
        "ZeroClipboard"\r
-], function($, ZeroClipboard) {\r
-\r
+], function($, ui, ZeroClipboard) {\r
        //FIXME mouseover makes button disappear\r
-       var Clipboard = {\r
-               // Allow user to copy signatures to clipboard with ZeroClipboard flahs plugin\r
-               // See: https://github.com/zeroclipboard/ZeroClipboard\r
-               enable: function(copySelector) {\r
-                       $(copySelector).each(function() {\r
-                               var btn = $(document.createElement("button"))\r
-                               .addClass("nitdoc-ui-copy")\r
-                               .attr("data-clipboard-text", $(this).attr("data-untyped-signature"))\r
+       $.widget("nitdoc.clipboard", {\r
+               options: {\r
+                       btnClass: "nitdoc-ui-copy",\r
+                       btnImage: "./resources/icons/copy.png",\r
+                       dataKey: "data-untyped-signature",\r
+                       zeroConfig: {\r
+                               moviePath: "./ZeroClipboard.swf"\r
+                       }\r
+               },\r
+\r
+               _create: function() {\r
+                       this.btn = $("<button/>")\r
+                               .addClass(this.options.btnClass)\r
+                               .attr("data-clipboard-text", this.element.attr(this.options.dataKey))\r
                                .append(\r
-                                       $(document.createElement("img"))\r
-                                       .attr("src", './resources/icons/copy.png')\r
+                                       $("<img/>").attr("src", this.options.btnImage)\r
                                );\r
-                               $(this).append(btn);\r
-                       });\r
-\r
-                       var clip = new ZeroClipboard($("button.nitdoc-ui-copy"), {\r
-                               moviePath: "./ZeroClipboard.swf"\r
-                       });\r
+                       this.element.append(this.btn);\r
+                       new ZeroClipboard(this.btn, this.options.zeroConfig);\r
                }\r
-       }\r
-\r
-       Clipboard.enable(".signature");\r
+       });\r
 \r
-       return Clipboard;\r
+       $(".signature").clipboard();\r
 });\r