zeroclipboard-rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzJiMzUyODU5OTUxMDVjNzI5N2MyNTUyOWJiZTI5ZGUzMDdkYzRkYg==
5
+ data.tar.gz: !binary |-
6
+ MTBkNmMxN2NkZGRkMmQ1MWVlOWFlZjkyM2M3NmI0Nzg4Njk4YTZmMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YjEwNDhlM2E0ZWJiY2E5YTgzNDk3NzRmZmIyOTM5ODUzNDYzOGUyZTE5MmZh
10
+ OTk1ZTFlZGY2ZmQ4YjM4MTQwNWYxOTRkNTQ5OTQ3NDgzM2ZiNmFkYTU3MjE4
11
+ ZDhhNzc2YzAzZTlmZjBjYWZjNDA2YTljNTU5YmRjNjI3Njg4YzA=
12
+ data.tar.gz: !binary |-
13
+ MGE5NjBmYmYxOWZkMTQzMjEzOWJhM2RiYmJlNjJlNjI0MDcwZTg3OWVhNDRj
14
+ ZTE5Njc0ZTA0Y2NhMTY0M2U5ZmVjMmYxZmMzOGYyNDUyZjRhMjJhMmMyNmZk
15
+ NjdiMDMzZmY4OTJlMzVlMTFmMmYwOWZkYTc4NDNjYTUyYWI3OGQ=
data/README.md CHANGED
@@ -1,121 +1,94 @@
1
1
  # Zeroclipboard::Rails
2
2
 
3
- Adds the Zeroclipboard libary to your Rails 3.x app.
4
- If you would like to use JQuery try the zClip libary instead.
3
+ Add the [ZeroClipboard](https://github.com/jonrohan/ZeroClipboard) libary to your Rails app
5
4
 
6
- ## Installation
5
+ ## Setup
7
6
 
8
- Add this line to your application's Gemfile:
7
+ Add this line to your application's `Gemfile`:
9
8
 
10
- gem 'zeroclipboard-rails'
9
+ ```ruby
10
+ gem 'zeroclipboard-rails'
11
+ ```
11
12
 
12
- And then execute:
13
+ Then execute:
13
14
 
14
- $ bundle
15
+ ```bash
16
+ $ bundle
17
+ ```
15
18
 
16
- Add this line to your application.js file:
19
+ Add this line to your `app/assets/javascripts/application.js` file:
17
20
 
18
- //= require zero-clipboard
21
+ ```javascript
22
+ //= require zeroclipboard
23
+ ```
19
24
 
20
25
  ## Usage
21
26
 
22
- ### Clients
23
-
24
- Now you are ready to create one or more Clients. A client is a single instance of the clipboard library on the page, linked to a particular button or other DOM element. You probably only need a single instance, but if you have multiple copy-to-clipboard buttons on your page, potentially containing different text, you can activate an instance for each. Here is how to create a client instance:
25
-
26
- var clip = new ZeroClipboard.Client();
27
-
28
- Next, you can set some options.
29
-
30
- ### Setting Options
31
-
32
- Once you have your client instance, you can set some options. These include setting the initial text to be copied, amongst other things. The following subsections describe all the available options you can set.
33
-
34
- ### Text To Copy
35
-
36
- This function allows you to set the text to be copied to the clipboard, once the user clicks on the control. You can call this function at any time; when the page first loads, or later in an onMouseOver or onMouseDown handler. Example:
37
-
38
- clip.setText( "Copy me!" );
39
-
40
- ### Hand Cursor
41
-
42
- This setting controls whether the "hand" or "arrow" cursor is shown when the mouse hovers over the Flash movie. Here is an example:
43
-
44
- clip.setHandCursor( true );
45
-
46
- The only values accepted are true (show "hand" cursor), or false (show "arrow" cursor). The default is true. You can set this option at any time.
47
-
48
- ### Gluing
49
-
50
- Gluing refers to the process of "linking" the Flash movie to a DOM element on the page. Meaning, the library will automatically generate a movie that is the exact size of the DOM element, and float it just above the element. Since the Flash movie is completely transparent, the user sees nothing out of the ordinary.
51
-
52
- The Flash movie receives the click event and copies the current text (last set with setText()) to the clipboard (a requirement of Flash Player 10 is that a user click event inside the movie must initiate the thread that interacts with the clipboard). Also, mouse actions like hovering and mouse-down generate events that you can capture (see Event Handlers below) and set CSS classes on your DOM element too (see CSS Effects below).
53
-
54
- Here is how to glue your clip library instance to a DOM element:
55
-
56
- clip.glue( 'd_clip_button' );
57
-
58
- You can pass in a DOM element ID (as shown above), or a reference to the actual DOM element object itself. The rest all happens automatically -- the movie is created, all your options set, and it is floated above the element, awaiting clicks from the user.
59
-
60
- The glue system is an optional implementation. If you would prefer to handle your own implementation of the Flash movie, see Custom Implementation below.
61
-
62
- ### Recommended Implementation
63
-
64
- It is highly recommended you create a "container" DIV element around your button, set its CSS "position" to "relative", and place your button just inside. Then, pass two arguments to glue(), your button DOM element or ID, and the container DOM element or ID. This way Zero Clipboard can position the floating Flash movie relative to the container DIV (not the page body), resulting in much more exact positioning. Example (HTML):
65
-
66
- <div id="d_clip_container" style="position:relative">
67
- <div id="d_clip_button">Copy to Clipboard</div>
68
- </div>
69
-
70
- And the code:
71
-
72
- clip.glue( 'd_clip_button', 'd_clip_container' );
73
-
74
- Note that gluing to a container element does not work with the reposition() method (see next section).
75
-
76
-
77
- For all usage options please visit the [zeroclipboard doc page](http://code.google.com/p/zeroclipboard/wiki/Instructions)
78
-
79
- ## Browser Support
80
-
81
- The Zero Clipboard Library has been tested on the following browsers / platforms:
82
-
83
- <table>
84
- <tr>
85
- <td> <strong>Browser</strong></td>
86
- <td> <strong>Windows XP SP3</strong></td>
87
- <td> <strong>Windows Vista</strong></td>
88
- <td> <strong>Mac OS X Leopard</strong></td>
89
- </tr>
90
- <tr>
91
- <td> Internet Exploder </td>
92
- <td> 7.0 </td>
93
- <td> 7.0 </td>
94
- <td> - </td>
95
- </tr> <tr>
96
- <td> Firefox </td>
97
- <td> 3.0 </td>
98
- <td> 3.0 </td>
99
- <td> 3.0 </td>
100
- </tr> <tr>
101
- <td> Safari </td>
102
- <td> - </td>
103
- <td> - </td>
104
- <td> 3.0 </td>
105
- </tr> <tr>
106
- <td> Google Chrome </td>
107
- <td> 1.0 </td>
108
- <td> 1.0 </td>
109
- <td> - </td>
110
- </tr>
111
- </table>
112
-
113
- Adobe Flash Flash Player versions 9 and 10 are supported.
114
-
115
- ### Credits
116
-
117
- Thanks to Joseph Huckaby and all the [contributers](http://code.google.com/u/100866768200529838600/)!
118
-
27
+ For usage information, browser support see the [ZeroClipboard documentation](https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md). The 'Setup' section can be skipped as this is covered by the Rails-specific instructions provided above.
28
+
29
+ ## Example (HTML, ERB)
30
+
31
+ Place the following in a plain HTML or ERB view file:
32
+
33
+ ```html
34
+ <div class='demo-area'>
35
+ <button class='my_clip_button' data-clipboard-target='fe_text' data-clipboard-text='Default clipboard text from attribute' id='d_clip_button' title='Click me to copy to clipboard.'>
36
+ <b>Copy To Clipboard...</b>
37
+ </button>
38
+ <h4>
39
+ <label for='fe_text'>Change Copy Text Here</label>
40
+ </h4>
41
+ <textarea cols='50' id='fe_text' rows='3'>Copy me!</textarea>
42
+ <h4>
43
+ <label for='testarea'>Paste Text Here</label>
44
+ </h4>
45
+ <textarea cols='50' id='testarea' rows='3'></textarea>
46
+ <p>
47
+ <button id='clear-test'>Clear Test Area</button>
48
+ </p>
49
+ </div>
50
+ <script>
51
+ $(document).ready(function() {
52
+ var clip = new ZeroClipboard($("#d_clip_button"))
53
+ });
54
+
55
+ $("#clear-test").on("click", function(){
56
+ $("#fe_text").val("Copy me!");
57
+ $("#testarea").val("");
58
+ });
59
+ </script>
60
+ ```
61
+
62
+ ## Example (HAML)
63
+
64
+ Place the following in a [Haml](http://haml.info/) view file:
65
+
66
+ ```haml
67
+ .demo-area
68
+ %button#d_clip_button.my_clip_button{"data-clipboard-target" => "fe_text", "data-clipboard-text" => "Default clipboard text from attribute", :title => "Click me to copy to clipboard."}
69
+ %b Copy To Clipboard...
70
+ %h4
71
+ %label{:for => "fe_text"} Change Copy Text Here
72
+ %textarea#fe_text{:cols => "50", :rows => "3"} Copy me!
73
+ %h4
74
+ %label{:for => "testarea"} Paste Text Here
75
+ %textarea#testarea{:cols => "50", :rows => "3"}
76
+ %p
77
+ %button#clear-test Clear Test Area
78
+ :javascript
79
+ $(document).ready(function() {
80
+ var clip = new ZeroClipboard($("#d_clip_button"))
81
+ });
82
+
83
+ $("#clear-test").on("click", function(){
84
+ $("#fe_text").val("Copy me!");
85
+ $("#testarea").val("");
86
+ });
87
+ ```
88
+
89
+ ## Credits
90
+
91
+ Credits entirely to the team behind [ZeroClipboard](https://github.com/jonrohan/ZeroClipboard)
119
92
 
120
93
  ## Contributing
121
94
 
@@ -1,5 +1,5 @@
1
1
  module Zeroclipboard
2
2
  module Rails
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
Binary file
@@ -0,0 +1,2 @@
1
+ //= require "./zeroclipboard/ZeroClipboard"
2
+ //= require "./zeroclipboard/asset-path"
@@ -0,0 +1,383 @@
1
+ /*!
2
+ * zeroclipboard
3
+ * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.
4
+ * Copyright 2012 Jon Rohan, James M. Greene, .
5
+ * Released under the MIT license
6
+ * http://jonrohan.github.com/ZeroClipboard/
7
+ * v1.1.7
8
+ */(function() {
9
+ "use strict";
10
+ var _getStyle = function(el, prop) {
11
+ var y = el.style[prop];
12
+ if (el.currentStyle) y = el.currentStyle[prop]; else if (window.getComputedStyle) y = document.defaultView.getComputedStyle(el, null).getPropertyValue(prop);
13
+ if (y == "auto" && prop == "cursor") {
14
+ var possiblePointers = [ "a" ];
15
+ for (var i = 0; i < possiblePointers.length; i++) {
16
+ if (el.tagName.toLowerCase() == possiblePointers[i]) {
17
+ return "pointer";
18
+ }
19
+ }
20
+ }
21
+ return y;
22
+ };
23
+ var _getZoom = function(obj) {
24
+ var zoom = 1;
25
+ if(RegExp(' AppleWebKit/').test(navigator.userAgent)){
26
+ while(obj)
27
+ {
28
+ zoom = zoom * _getStyle(obj,'zoom');
29
+ obj = obj.offsetParent;
30
+ }
31
+ }
32
+ return zoom;
33
+ };
34
+ var _elementMouseOver = function(event) {
35
+ if (!ZeroClipboard.prototype._singleton) return;
36
+ if (!event) {
37
+ event = window.event;
38
+ }
39
+ var target;
40
+ if (this !== window) {
41
+ target = this;
42
+ } else if (event.target) {
43
+ target = event.target;
44
+ } else if (event.srcElement) {
45
+ target = event.srcElement;
46
+ }
47
+ ZeroClipboard.prototype._singleton.setCurrent(target);
48
+ };
49
+ var _addEventHandler = function(element, method, func) {
50
+ if (element.addEventListener) {
51
+ element.addEventListener(method, func, false);
52
+ } else if (element.attachEvent) {
53
+ element.attachEvent("on" + method, func);
54
+ }
55
+ };
56
+ var _removeEventHandler = function(element, method, func) {
57
+ if (element.removeEventListener) {
58
+ element.removeEventListener(method, func, false);
59
+ } else if (element.detachEvent) {
60
+ element.detachEvent("on" + method, func);
61
+ }
62
+ };
63
+ var _addClass = function(element, value) {
64
+ if (element.addClass) {
65
+ element.addClass(value);
66
+ return element;
67
+ }
68
+ if (value && typeof value === "string") {
69
+ var classNames = (value || "").split(/\s+/);
70
+ if (element.nodeType === 1) {
71
+ if (!element.className) {
72
+ element.className = value;
73
+ } else {
74
+ var className = " " + element.className + " ", setClass = element.className;
75
+ for (var c = 0, cl = classNames.length; c < cl; c++) {
76
+ if (className.indexOf(" " + classNames[c] + " ") < 0) {
77
+ setClass += " " + classNames[c];
78
+ }
79
+ }
80
+ element.className = setClass.replace(/^\s+|\s+$/g, "");
81
+ }
82
+ }
83
+ }
84
+ return element;
85
+ };
86
+ var _removeClass = function(element, value) {
87
+ if (element.removeClass) {
88
+ element.removeClass(value);
89
+ return element;
90
+ }
91
+ if (value && typeof value === "string" || value === undefined) {
92
+ var classNames = (value || "").split(/\s+/);
93
+ if (element.nodeType === 1 && element.className) {
94
+ if (value) {
95
+ var className = (" " + element.className + " ").replace(/[\n\t]/g, " ");
96
+ for (var c = 0, cl = classNames.length; c < cl; c++) {
97
+ className = className.replace(" " + classNames[c] + " ", " ");
98
+ }
99
+ element.className = className.replace(/^\s+|\s+$/g, "");
100
+ } else {
101
+ element.className = "";
102
+ }
103
+ }
104
+ }
105
+ return element;
106
+ };
107
+ var _getDOMObjectPosition = function(obj) {
108
+ var info = {
109
+ left: 0,
110
+ top: 0,
111
+ width: obj.width || obj.offsetWidth || 0,
112
+ height: obj.height || obj.offsetHeight || 0,
113
+ zIndex: 9999
114
+ };
115
+ var zi = _getStyle(obj, "zIndex");
116
+ if (zi && zi != "auto") {
117
+ info.zIndex = parseInt(zi, 10);
118
+ }
119
+ if (typeof obj.getBoundingClientRect !== "undefined") {
120
+ var rect = obj.getBoundingClientRect();
121
+ var pageXOffset = window.pageXOffset || document.documentElement.scrollLeft || 0;
122
+ var pageYOffset = window.pageYOffset || document.documentElement.scrollTop || 0;
123
+ var leftBorderWidth = document.documentElement.clientLeft || 0;
124
+ var topBorderWidth = document.documentElement.clientTop || 0;
125
+ var zoom = _getZoom(obj);
126
+ info.width = rect.width * zoom;
127
+ info.height = rect.height * zoom;
128
+ info.left = (rect.left + pageXOffset - leftBorderWidth) * zoom;
129
+ info.top = (rect.top + pageYOffset - topBorderWidth) * zoom;
130
+ return info;
131
+ }
132
+ while (obj) {
133
+ var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
134
+ var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
135
+ info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
136
+ info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
137
+ info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
138
+ info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
139
+ obj = obj.offsetParent;
140
+ }
141
+ return info;
142
+ };
143
+ var _noCache = function(path) {
144
+ return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime();
145
+ };
146
+ var _vars = function(options) {
147
+ var str = [];
148
+ if (options.trustedDomains) {
149
+ if (typeof options.trustedDomains === "string") {
150
+ str.push("trustedDomain=" + options.trustedDomains);
151
+ } else {
152
+ str.push("trustedDomain=" + options.trustedDomains.join(","));
153
+ }
154
+ }
155
+ return str.join("&");
156
+ };
157
+ var _inArray = function(elem, array) {
158
+ if (array.indexOf) {
159
+ return array.indexOf(elem);
160
+ }
161
+ for (var i = 0, length = array.length; i < length; i++) {
162
+ if (array[i] === elem) {
163
+ return i;
164
+ }
165
+ }
166
+ return -1;
167
+ };
168
+ var _prepGlue = function(elements) {
169
+ if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings.");
170
+ if (!elements.length) return [ elements ];
171
+ return elements;
172
+ };
173
+ var ZeroClipboard = function(elements, options) {
174
+ if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements);
175
+ if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton;
176
+ ZeroClipboard.prototype._singleton = this;
177
+ this.options = {};
178
+ for (var kd in _defaults) this.options[kd] = _defaults[kd];
179
+ for (var ko in options) this.options[ko] = options[ko];
180
+ this.handlers = {};
181
+ if (ZeroClipboard.detectFlashSupport()) _bridge();
182
+ };
183
+ var currentElement, gluedElements = [];
184
+ ZeroClipboard.prototype.setCurrent = function(element) {
185
+ currentElement = element;
186
+ this.reposition();
187
+ if (element.getAttribute("title")) {
188
+ this.setTitle(element.getAttribute("title"));
189
+ }
190
+ this.setHandCursor(_getStyle(element, "cursor") == "pointer");
191
+ };
192
+ ZeroClipboard.prototype.setText = function(newText) {
193
+ if (newText && newText !== "") {
194
+ this.options.text = newText;
195
+ if (this.ready()) this.flashBridge.setText(newText);
196
+ }
197
+ };
198
+ ZeroClipboard.prototype.setTitle = function(newTitle) {
199
+ if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle);
200
+ };
201
+ ZeroClipboard.prototype.setSize = function(width, height) {
202
+ if (this.ready()) this.flashBridge.setSize(width, height);
203
+ };
204
+ ZeroClipboard.prototype.setHandCursor = function(enabled) {
205
+ if (this.ready()) this.flashBridge.setHandCursor(enabled);
206
+ };
207
+ ZeroClipboard.version = "1.1.7";
208
+ var _defaults = {
209
+ moviePath: "ZeroClipboard.swf",
210
+ trustedDomains: null,
211
+ text: null,
212
+ hoverClass: "zeroclipboard-is-hover",
213
+ activeClass: "zeroclipboard-is-active",
214
+ allowScriptAccess: "sameDomain"
215
+ };
216
+ ZeroClipboard.setDefaults = function(options) {
217
+ for (var ko in options) _defaults[ko] = options[ko];
218
+ };
219
+ ZeroClipboard.destroy = function() {
220
+ ZeroClipboard.prototype._singleton.unglue(gluedElements);
221
+ var bridge = ZeroClipboard.prototype._singleton.htmlBridge;
222
+ bridge.parentNode.removeChild(bridge);
223
+ delete ZeroClipboard.prototype._singleton;
224
+ };
225
+ ZeroClipboard.detectFlashSupport = function() {
226
+ var hasFlash = false;
227
+ try {
228
+ if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
229
+ hasFlash = true;
230
+ }
231
+ } catch (error) {
232
+ if (navigator.mimeTypes["application/x-shockwave-flash"]) {
233
+ hasFlash = true;
234
+ }
235
+ }
236
+ return hasFlash;
237
+ };
238
+ var _bridge = function() {
239
+ var client = ZeroClipboard.prototype._singleton;
240
+ var container = document.getElementById("global-zeroclipboard-html-bridge");
241
+ if (!container) {
242
+ var html = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="' + client.options.moviePath + _noCache(client.options.moviePath) + '"/> <param name="allowScriptAccess" value="' + client.options.allowScriptAccess + '"/> <param name="scale" value="exactfit"/> <param name="loop" value="false"/> <param name="menu" value="false"/> <param name="quality" value="best" /> <param name="bgcolor" value="#ffffff"/> <param name="wmode" value="transparent"/> <param name="flashvars" value="' + _vars(client.options) + '"/> <embed src="' + client.options.moviePath + _noCache(client.options.moviePath) + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="100%" height="100%" name="global-zeroclipboard-flash-bridge" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + _vars(client.options) + '" scale="exactfit"> </embed> </object>';
243
+ container = document.createElement("div");
244
+ container.id = "global-zeroclipboard-html-bridge";
245
+ container.setAttribute("class", "global-zeroclipboard-container");
246
+ container.setAttribute("data-clipboard-ready", false);
247
+ container.style.position = "absolute";
248
+ container.style.left = "-9999px";
249
+ container.style.top = "-9999px";
250
+ container.style.width = "15px";
251
+ container.style.height = "15px";
252
+ container.style.zIndex = "9999";
253
+ container.innerHTML = html;
254
+ document.body.appendChild(container);
255
+ }
256
+ client.htmlBridge = container;
257
+ client.flashBridge = document["global-zeroclipboard-flash-bridge"] || container.children[0].lastElementChild;
258
+ };
259
+ ZeroClipboard.prototype.resetBridge = function() {
260
+ this.htmlBridge.style.left = "-9999px";
261
+ this.htmlBridge.style.top = "-9999px";
262
+ this.htmlBridge.removeAttribute("title");
263
+ this.htmlBridge.removeAttribute("data-clipboard-text");
264
+ _removeClass(currentElement, this.options.activeClass);
265
+ currentElement = null;
266
+ this.options.text = null;
267
+ };
268
+ ZeroClipboard.prototype.ready = function() {
269
+ var ready = this.htmlBridge.getAttribute("data-clipboard-ready");
270
+ return ready === "true" || ready === true;
271
+ };
272
+ ZeroClipboard.prototype.reposition = function() {
273
+ if (!currentElement) return false;
274
+ var pos = _getDOMObjectPosition(currentElement);
275
+ this.htmlBridge.style.top = pos.top + "px";
276
+ this.htmlBridge.style.left = pos.left + "px";
277
+ this.htmlBridge.style.width = pos.width + "px";
278
+ this.htmlBridge.style.height = pos.height + "px";
279
+ this.htmlBridge.style.zIndex = pos.zIndex + 1;
280
+ this.setSize(pos.width, pos.height);
281
+ };
282
+ ZeroClipboard.dispatch = function(eventName, args) {
283
+ ZeroClipboard.prototype._singleton.receiveEvent(eventName, args);
284
+ };
285
+ ZeroClipboard.prototype.on = function(eventName, func) {
286
+ var events = eventName.toString().split(/\s/g);
287
+ for (var i = 0; i < events.length; i++) {
288
+ eventName = events[i].toLowerCase().replace(/^on/, "");
289
+ if (!this.handlers[eventName]) this.handlers[eventName] = func;
290
+ }
291
+ if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) {
292
+ this.receiveEvent("onNoFlash", null);
293
+ }
294
+ };
295
+ ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on;
296
+ ZeroClipboard.prototype.off = function(eventName, func) {
297
+ var events = eventName.toString().split(/\s/g);
298
+ for (var i = 0; i < events.length; i++) {
299
+ eventName = events[i].toLowerCase().replace(/^on/, "");
300
+ for (var event in this.handlers) {
301
+ if (event === eventName && this.handlers[event] === func) {
302
+ delete this.handlers[event];
303
+ }
304
+ }
305
+ }
306
+ };
307
+ ZeroClipboard.prototype.removeEventListener = ZeroClipboard.prototype.off;
308
+ ZeroClipboard.prototype.receiveEvent = function(eventName, args) {
309
+ eventName = eventName.toString().toLowerCase().replace(/^on/, "");
310
+ var element = currentElement;
311
+ switch (eventName) {
312
+ case "load":
313
+ if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) {
314
+ this.receiveEvent("onWrongFlash", {
315
+ flashVersion: args.flashVersion
316
+ });
317
+ return;
318
+ }
319
+ this.htmlBridge.setAttribute("data-clipboard-ready", true);
320
+ break;
321
+ case "mouseover":
322
+ _addClass(element, this.options.hoverClass);
323
+ break;
324
+ case "mouseout":
325
+ _removeClass(element, this.options.hoverClass);
326
+ this.resetBridge();
327
+ break;
328
+ case "mousedown":
329
+ _addClass(element, this.options.activeClass);
330
+ break;
331
+ case "mouseup":
332
+ _removeClass(element, this.options.activeClass);
333
+ break;
334
+ case "datarequested":
335
+ var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
336
+ if (targetEl) {
337
+ var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
338
+ if (textContent) this.setText(textContent);
339
+ } else {
340
+ var defaultText = element.getAttribute("data-clipboard-text");
341
+ if (defaultText) this.setText(defaultText);
342
+ }
343
+ break;
344
+ case "complete":
345
+ this.options.text = null;
346
+ break;
347
+ }
348
+ if (this.handlers[eventName]) {
349
+ var func = this.handlers[eventName];
350
+ if (typeof func == "function") {
351
+ func.call(element, this, args);
352
+ } else if (typeof func == "string") {
353
+ window[func].call(element, this, args);
354
+ }
355
+ }
356
+ };
357
+ ZeroClipboard.prototype.glue = function(elements) {
358
+ elements = _prepGlue(elements);
359
+ for (var i = 0; i < elements.length; i++) {
360
+ if (_inArray(elements[i], gluedElements) == -1) {
361
+ gluedElements.push(elements[i]);
362
+ _addEventHandler(elements[i], "mouseover", _elementMouseOver);
363
+ }
364
+ }
365
+ };
366
+ ZeroClipboard.prototype.unglue = function(elements) {
367
+ elements = _prepGlue(elements);
368
+ for (var i = 0; i < elements.length; i++) {
369
+ _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
370
+ var arrayIndex = _inArray(elements[i], gluedElements);
371
+ if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
372
+ }
373
+ };
374
+ if (typeof module !== "undefined") {
375
+ module.exports = ZeroClipboard;
376
+ } else if (typeof define === "function" && define.amd) {
377
+ define(function() {
378
+ return ZeroClipboard;
379
+ });
380
+ } else {
381
+ window.ZeroClipboard = ZeroClipboard;
382
+ }
383
+ })();
@@ -0,0 +1 @@
1
+ ZeroClipboard.setDefaults( { moviePath: '<%= asset_path 'ZeroClipboard.swf' %>' } );
metadata CHANGED
@@ -1,33 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeroclipboard-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Henrik Wenz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: railties
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ! '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.1'
30
- description: Adds the Javascript ZeroClipboard libary to Rails 3.x
27
+ description: Adds the Javascript ZeroClipboard libary to Rails
31
28
  email:
32
29
  - handtrix@gmail.com
33
30
  executables: []
@@ -37,34 +34,32 @@ files:
37
34
  - lib/zeroclipboard-rails/version.rb
38
35
  - lib/zeroclipboard-rails.rb
39
36
  - vendor/assets/images/ZeroClipboard.swf
40
- - vendor/assets/images/ZeroClipboard10.swf
41
- - vendor/assets/javascripts/zero-clipboard/asset-path.js.erb
42
- - vendor/assets/javascripts/zero-clipboard/zero-clipboard.js
43
- - vendor/assets/javascripts/zero-clipboard.js
37
+ - vendor/assets/javascripts/zeroclipboard/asset-path.js.erb
38
+ - vendor/assets/javascripts/zeroclipboard/ZeroClipboard.js
39
+ - vendor/assets/javascripts/zeroclipboard.js
44
40
  - LICENSE
45
41
  - README.md
46
42
  homepage: https://github.com/HaNdTriX/zeroclipboard-rails
47
43
  licenses: []
44
+ metadata: {}
48
45
  post_install_message:
49
46
  rdoc_options: []
50
47
  require_paths:
51
48
  - lib
52
49
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
50
  requirements:
55
51
  - - ! '>='
56
52
  - !ruby/object:Gem::Version
57
53
  version: '0'
58
54
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
55
  requirements:
61
56
  - - ! '>='
62
57
  - !ruby/object:Gem::Version
63
58
  version: '0'
64
59
  requirements: []
65
60
  rubyforge_project:
66
- rubygems_version: 1.8.24
61
+ rubygems_version: 2.0.3
67
62
  signing_key:
68
- specification_version: 3
69
- summary: Adds the Javascript ZeroClipboard libary to Rails 3.x
63
+ specification_version: 4
64
+ summary: Adds the Javascript ZeroClipboard libary to Rails
70
65
  test_files: []
@@ -1,2 +0,0 @@
1
- //= require "./zero-clipboard/zero-clipboard"
2
- //= require "./zero-clipboard/asset-path"
@@ -1 +0,0 @@
1
- ZeroClipboard.setMoviePath( '<%= asset_path 'ZeroClipboard10.swf' %>' );
@@ -1,337 +0,0 @@
1
- // Simple Set Clipboard System
2
- // Author: Joseph Huckaby
3
-
4
- window.ZeroClipboard = {
5
-
6
- version: "1.0.8",
7
- clients: {}, // registered upload clients on page, indexed by id
8
- moviePath: 'ZeroClipboard.swf', // URL to movie
9
- nextId: 1, // ID of next movie
10
-
11
- $: function(thingy) {
12
- // simple DOM lookup utility function
13
- if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
14
- if (!thingy.addClass) {
15
- // extend element with a few useful methods
16
- thingy.hide = function() { this.style.display = 'none'; };
17
- thingy.show = function() { this.style.display = ''; };
18
- thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
19
- thingy.removeClass = function(name) {
20
- var classes = this.className.split(/\s+/);
21
- var idx = -1;
22
- for (var k = 0; k < classes.length; k++) {
23
- if (classes[k] == name) { idx = k; k = classes.length; }
24
- }
25
- if (idx > -1) {
26
- classes.splice( idx, 1 );
27
- this.className = classes.join(' ');
28
- }
29
- return this;
30
- };
31
- thingy.hasClass = function(name) {
32
- return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
33
- };
34
- }
35
- return thingy;
36
- },
37
-
38
- setMoviePath: function(path) {
39
- // set path to ZeroClipboard.swf
40
- this.moviePath = path;
41
- },
42
-
43
- // use this method in JSNI calls to obtain a new Client instance
44
- newClient: function() {
45
- return new ZeroClipboard.Client();
46
- },
47
-
48
- dispatch: function(id, eventName, args) {
49
- // receive event from flash movie, send to client
50
- var client = this.clients[id];
51
- if (client) {
52
- client.receiveEvent(eventName, args);
53
- }
54
- },
55
-
56
- register: function(id, client) {
57
- // register new client to receive events
58
- this.clients[id] = client;
59
- },
60
-
61
- getDOMObjectPosition: function(obj, stopObj) {
62
- // get absolute coordinates for dom element
63
- var info = {
64
- left: 0,
65
- top: 0,
66
- width: obj.width ? obj.width : obj.offsetWidth,
67
- height: obj.height ? obj.height : obj.offsetHeight
68
- };
69
-
70
- while (obj && (obj != stopObj)) {
71
- info.left += obj.offsetLeft;
72
- info.left += obj.style.borderLeftWidth ? parseInt(obj.style.borderLeftWidth) : 0;
73
- info.top += obj.offsetTop;
74
- info.top += obj.style.borderTopWidth ? parseInt(obj.style.borderTopWidth) : 0;
75
- obj = obj.offsetParent;
76
- }
77
-
78
- return info;
79
- },
80
-
81
- Client: function(elem) {
82
- // constructor for new simple upload client
83
- this.handlers = {};
84
-
85
- // unique ID
86
- this.id = ZeroClipboard.nextId++;
87
- this.movieId = 'ZeroClipboardMovie_' + this.id;
88
-
89
- // register client with singleton to receive flash events
90
- ZeroClipboard.register(this.id, this);
91
-
92
- // create movie
93
- if (elem) this.glue(elem);
94
- }
95
- };
96
-
97
- ZeroClipboard.Client.prototype = {
98
-
99
- id: 0, // unique ID for us
100
- title: "", // tooltip for the flash element
101
- ready: false, // whether movie is ready to receive events or not
102
- movie: null, // reference to movie object
103
- clipText: '', // text to copy to clipboard
104
- handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
105
- cssEffects: true, // enable CSS mouse effects on dom container
106
- handlers: null, // user event handlers
107
- zIndex: 99, // default zIndex of the movie object
108
-
109
- glue: function(elem, appendElem, stylesToAdd) {
110
- // glue to DOM element
111
- // elem can be ID or actual DOM element object
112
- this.domElement = ZeroClipboard.$(elem);
113
-
114
- // float just above object, or default zIndex if dom element isn't set
115
- if (this.domElement.style.zIndex) {
116
- this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
117
- }
118
-
119
- // check if the element has a title
120
- if (this.domElement.getAttribute("title") != null) {
121
- this.title = this.domElement.getAttribute("title");
122
- }
123
-
124
- if (typeof(appendElem) == 'string') {
125
- appendElem = ZeroClipboard.$(appendElem);
126
- }
127
- else if (typeof(appendElem) == 'undefined') {
128
- appendElem = document.getElementsByTagName('body')[0];
129
- }
130
-
131
- // find X/Y position of domElement
132
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
133
-
134
- // create floating DIV above element
135
- this.div = document.createElement('div');
136
- var style = this.div.style;
137
- style.position = 'absolute';
138
- style.left = '' + box.left + 'px';
139
- style.top = '' + box.top + 'px';
140
- style.width = '' + box.width + 'px';
141
- style.height = '' + box.height + 'px';
142
- style.zIndex = this.zIndex;
143
-
144
- if (typeof(stylesToAdd) == 'object') {
145
- for (var addedStyle in stylesToAdd) {
146
- style[addedStyle] = stylesToAdd[addedStyle];
147
- }
148
- }
149
-
150
- // style.backgroundColor = '#f00'; // debug
151
-
152
- appendElem.appendChild(this.div);
153
-
154
- this.div.innerHTML = this.getHTML( box.width, box.height );
155
- },
156
-
157
- getHTML: function(width, height) {
158
- // return HTML for movie
159
- var html = '';
160
- var flashvars = 'id=' + this.id +
161
- '&width=' + width +
162
- '&height=' + height,
163
- title = this.title ? ' title="' + this.title + '"' : '';
164
-
165
- if (navigator.userAgent.match(/MSIE/)) {
166
- // IE gets an OBJECT tag
167
- var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
168
- html += '<object' + title + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
169
- }
170
- else {
171
- // all other browsers get an EMBED tag
172
- html += '<embed' + title + ' id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
173
- }
174
- return html;
175
- },
176
-
177
- hide: function() {
178
- // temporarily hide floater offscreen
179
- if (this.div) {
180
- this.div.style.left = '-2000px';
181
- }
182
- },
183
-
184
- show: function() {
185
- // show ourselves after a call to hide()
186
- this.reposition();
187
- },
188
-
189
- destroy: function() {
190
- // destroy control and floater
191
- if (this.domElement && this.div) {
192
- this.hide();
193
- this.div.innerHTML = '';
194
-
195
- var body = document.getElementsByTagName('body')[0];
196
- try { body.removeChild( this.div ); } catch(e) {}
197
-
198
- this.domElement = null;
199
- this.div = null;
200
- }
201
- },
202
-
203
- reposition: function(elem) {
204
- // reposition our floating div, optionally to new container
205
- // warning: container CANNOT change size, only position
206
- if (elem) {
207
- this.domElement = ZeroClipboard.$(elem);
208
- if (!this.domElement) this.hide();
209
- }
210
-
211
- if (this.domElement && this.div) {
212
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
213
- var style = this.div.style;
214
- style.left = '' + box.left + 'px';
215
- style.top = '' + box.top + 'px';
216
- }
217
- },
218
-
219
- setText: function(newText) {
220
- // set text to be copied to clipboard
221
- this.clipText = newText;
222
- if (this.ready) this.movie.setText(newText);
223
- },
224
-
225
- setTitle: function(newTitle) {
226
- // set title of flash element
227
- this.title = newTitle;
228
- if (this.ready) this.movie.setTitle(newTitle);
229
- },
230
-
231
- addEventListener: function(eventName, func) {
232
- // add user event listener for event
233
- // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
234
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
235
- if (!this.handlers[eventName]) this.handlers[eventName] = [];
236
- this.handlers[eventName].push(func);
237
- },
238
-
239
- setHandCursor: function(enabled) {
240
- // enable hand cursor (true), or default arrow cursor (false)
241
- this.handCursorEnabled = enabled;
242
- if (this.ready) this.movie.setHandCursor(enabled);
243
- },
244
-
245
- setCSSEffects: function(enabled) {
246
- // enable or disable CSS effects on DOM container
247
- this.cssEffects = !!enabled;
248
- },
249
-
250
- receiveEvent: function(eventName, args) {
251
- // receive event from flash
252
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
253
-
254
- // special behavior for certain events
255
- switch (eventName) {
256
- case 'load':
257
- // movie claims it is ready, but in IE this isn't always the case...
258
- // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
259
- this.movie = document.getElementById(this.movieId);
260
- if (!this.movie) {
261
- var self = this;
262
- setTimeout( function() { self.receiveEvent('load', null); }, 1 );
263
- return;
264
- }
265
-
266
- // firefox on pc needs a "kick" in order to set these in certain cases
267
- if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
268
- var self = this;
269
- setTimeout( function() { self.receiveEvent('load', null); }, 100 );
270
- this.ready = true;
271
- return;
272
- }
273
-
274
- this.ready = true;
275
- this.movie.setText( this.clipText );
276
- this.movie.setTitle( this.title );
277
- this.movie.setHandCursor( this.handCursorEnabled );
278
- break;
279
-
280
- case 'mouseover':
281
- if (this.domElement && this.cssEffects) {
282
- this.domElement.addClass('hover');
283
- if (this.recoverActive) this.domElement.addClass('active');
284
- }
285
- break;
286
-
287
- case 'mouseout':
288
- if (this.domElement && this.cssEffects) {
289
- this.recoverActive = false;
290
- if (this.domElement.hasClass('active')) {
291
- this.domElement.removeClass('active');
292
- this.recoverActive = true;
293
- }
294
- this.domElement.removeClass('hover');
295
- }
296
- break;
297
-
298
- case 'mousedown':
299
- if (this.domElement && this.cssEffects) {
300
- this.domElement.addClass('active');
301
- }
302
- break;
303
-
304
- case 'mouseup':
305
- if (this.domElement && this.cssEffects) {
306
- this.domElement.removeClass('active');
307
- this.recoverActive = false;
308
- }
309
- break;
310
- } // switch eventName
311
-
312
- if (this.handlers[eventName]) {
313
- for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
314
- var func = this.handlers[eventName][idx];
315
-
316
- if (typeof(func) == 'function') {
317
- // actual function reference
318
- func(this, args);
319
- }
320
- else if ((typeof(func) == 'object') && (func.length == 2)) {
321
- // PHP style object + method, i.e. [myObject, 'myMethod']
322
- func[0][ func[1] ](this, args);
323
- }
324
- else if (typeof(func) == 'string') {
325
- // name of function
326
- window[func](this, args);
327
- }
328
- } // foreach event handler defined
329
- } // user defined handler for event
330
- }
331
-
332
- };
333
-
334
- if (typeof module !== "undefined") {
335
- module.exports = ZeroClipboard;
336
- }
337
-