zero_clipboard-rails 1.0.0 → 1.3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5dab8c3e1209017ca026a6c4b5643316e6d172a
4
+ data.tar.gz: c624286a0d3d923149b0bfa804a1b52d5e8e2ee1
5
+ SHA512:
6
+ metadata.gz: e568a29d84d322cc5367a740b840c4e5f86590b8b5a9523f6698e31703c0ec35a4e572c2ac8b9108ec03fc028b0437dc55146021fdb00d90e0d8495bff9e9502
7
+ data.tar.gz: 567339635f6471fb10c9a3a283c079de5ac79dea51b730838974d25d8cb2eec33c7fd6486430379d5a76719c06e0fd523c5069dfaaecef49fbb9d1e51b256391
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v1.3.5.0 (2014-05-17)
2
+
3
+ - Upgraded to version 1.3.5 of ZeroClipboard
4
+ - Tested with Rails 4
5
+
1
6
  ## v1.0.0 (2013-02-05)
2
7
 
3
8
  - Initial public release
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Jonathan Underwood
1
+ Copyright (c) 2014 Jonathan Underwood
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ZeroClipboard for Rails
2
2
 
3
- This gem provides the ZeroClipboard Javascript/Flash library for a Rails 3.1+ application.
3
+ This gem provides the ZeroClipboard Javascript/Flash library for Rails 3.1+ and Rails 4 applications.
4
4
 
5
- ### Provides version 1.1.6 of ZeroClipboard.
5
+ ### Provides version 1.3.5 of ZeroClipboard
6
6
 
7
7
  For more information about Zero Clipboard, visit [https://github.com/jonrohan/ZeroClipboard/](https://github.com/jonrohan/ZeroClipboard/)
8
8
 
@@ -32,4 +32,4 @@ Then require it in your `application.js` manifest file:
32
32
 
33
33
  ## License
34
34
 
35
- Licensed under the MIT License.
35
+ This gem is licensed under the MIT License, copyright 2014 Jonathan Underwood. ZeroClipboard.js is also licensed under the MIT license, copyright 2014 Jon Rohan, James M. Greene.
@@ -1,6 +1,6 @@
1
1
  module ZeroClipboard
2
2
  module Rails
3
- VERSION = '1.0.0'
4
- ZERO_CLIPBOARD_VERSION = '1.1.6'
3
+ VERSION = '1.3.5.0'
4
+ ZERO_CLIPBOARD_VERSION = '1.3.5'
5
5
  end
6
6
  end
@@ -1,27 +1,98 @@
1
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.6
8
- */(function() {
2
+ * ZeroClipboard
3
+ * The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
4
+ * Copyright (c) 2014 Jon Rohan, James M. Greene
5
+ * Licensed MIT
6
+ * http://zeroclipboard.org/
7
+ * v1.3.5
8
+ */
9
+ (function(window) {
9
10
  "use strict";
11
+ var currentElement;
12
+ var flashState = {
13
+ bridge: null,
14
+ version: "0.0.0",
15
+ disabled: null,
16
+ outdated: null,
17
+ ready: null
18
+ };
19
+ var _clipData = {};
20
+ var clientIdCounter = 0;
21
+ var _clientMeta = {};
22
+ var elementIdCounter = 0;
23
+ var _elementMeta = {};
24
+ var _amdModuleId = null;
25
+ var _cjsModuleId = null;
26
+ var _swfPath = function() {
27
+ var i, jsDir, tmpJsPath, jsPath, swfPath = "ZeroClipboard.swf";
28
+ if (document.currentScript && (jsPath = document.currentScript.src)) {} else {
29
+ var scripts = document.getElementsByTagName("script");
30
+ if ("readyState" in scripts[0]) {
31
+ for (i = scripts.length; i--; ) {
32
+ if (scripts[i].readyState === "interactive" && (jsPath = scripts[i].src)) {
33
+ break;
34
+ }
35
+ }
36
+ } else if (document.readyState === "loading") {
37
+ jsPath = scripts[scripts.length - 1].src;
38
+ } else {
39
+ for (i = scripts.length; i--; ) {
40
+ tmpJsPath = scripts[i].src;
41
+ if (!tmpJsPath) {
42
+ jsDir = null;
43
+ break;
44
+ }
45
+ tmpJsPath = tmpJsPath.split("#")[0].split("?")[0];
46
+ tmpJsPath = tmpJsPath.slice(0, tmpJsPath.lastIndexOf("/") + 1);
47
+ if (jsDir == null) {
48
+ jsDir = tmpJsPath;
49
+ } else if (jsDir !== tmpJsPath) {
50
+ jsDir = null;
51
+ break;
52
+ }
53
+ }
54
+ if (jsDir !== null) {
55
+ jsPath = jsDir;
56
+ }
57
+ }
58
+ }
59
+ if (jsPath) {
60
+ jsPath = jsPath.split("#")[0].split("?")[0];
61
+ swfPath = jsPath.slice(0, jsPath.lastIndexOf("/") + 1) + swfPath;
62
+ }
63
+ return swfPath;
64
+ }();
65
+ var _camelizeCssPropName = function() {
66
+ var matcherRegex = /\-([a-z])/g, replacerFn = function(match, group) {
67
+ return group.toUpperCase();
68
+ };
69
+ return function(prop) {
70
+ return prop.replace(matcherRegex, replacerFn);
71
+ };
72
+ }();
10
73
  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]) {
74
+ var value, camelProp, tagName, possiblePointers, i, len;
75
+ if (window.getComputedStyle) {
76
+ value = window.getComputedStyle(el, null).getPropertyValue(prop);
77
+ } else {
78
+ camelProp = _camelizeCssPropName(prop);
79
+ if (el.currentStyle) {
80
+ value = el.currentStyle[camelProp];
81
+ } else {
82
+ value = el.style[camelProp];
83
+ }
84
+ }
85
+ if (prop === "cursor") {
86
+ if (!value || value === "auto") {
87
+ tagName = el.tagName.toLowerCase();
88
+ if (tagName === "a") {
17
89
  return "pointer";
18
90
  }
19
91
  }
20
92
  }
21
- return y;
93
+ return value;
22
94
  };
23
95
  var _elementMouseOver = function(event) {
24
- if (!ZeroClipboard.prototype._singleton) return;
25
96
  if (!event) {
26
97
  event = window.event;
27
98
  }
@@ -33,9 +104,12 @@
33
104
  } else if (event.srcElement) {
34
105
  target = event.srcElement;
35
106
  }
36
- ZeroClipboard.prototype._singleton.setCurrent(target);
107
+ ZeroClipboard.activate(target);
37
108
  };
38
109
  var _addEventHandler = function(element, method, func) {
110
+ if (!element || element.nodeType !== 1) {
111
+ return;
112
+ }
39
113
  if (element.addEventListener) {
40
114
  element.addEventListener(method, func, false);
41
115
  } else if (element.attachEvent) {
@@ -43,6 +117,9 @@
43
117
  }
44
118
  };
45
119
  var _removeEventHandler = function(element, method, func) {
120
+ if (!element || element.nodeType !== 1) {
121
+ return;
122
+ }
46
123
  if (element.removeEventListener) {
47
124
  element.removeEventListener(method, func, false);
48
125
  } else if (element.detachEvent) {
@@ -50,8 +127,13 @@
50
127
  }
51
128
  };
52
129
  var _addClass = function(element, value) {
53
- if (element.addClass) {
54
- element.addClass(value);
130
+ if (!element || element.nodeType !== 1) {
131
+ return element;
132
+ }
133
+ if (element.classList) {
134
+ if (!element.classList.contains(value)) {
135
+ element.classList.add(value);
136
+ }
55
137
  return element;
56
138
  }
57
139
  if (value && typeof value === "string") {
@@ -73,8 +155,13 @@
73
155
  return element;
74
156
  };
75
157
  var _removeClass = function(element, value) {
76
- if (element.removeClass) {
77
- element.removeClass(value);
158
+ if (!element || element.nodeType !== 1) {
159
+ return element;
160
+ }
161
+ if (element.classList) {
162
+ if (element.classList.contains(value)) {
163
+ element.classList.remove(value);
164
+ }
78
165
  return element;
79
166
  }
80
167
  if (value && typeof value === "string" || value === undefined) {
@@ -93,241 +180,852 @@
93
180
  }
94
181
  return element;
95
182
  };
96
- var _getDOMObjectPosition = function(obj) {
183
+ var _getZoomFactor = function() {
184
+ var rect, physicalWidth, logicalWidth, zoomFactor = 1;
185
+ if (typeof document.body.getBoundingClientRect === "function") {
186
+ rect = document.body.getBoundingClientRect();
187
+ physicalWidth = rect.right - rect.left;
188
+ logicalWidth = document.body.offsetWidth;
189
+ zoomFactor = Math.round(physicalWidth / logicalWidth * 100) / 100;
190
+ }
191
+ return zoomFactor;
192
+ };
193
+ var _getDOMObjectPosition = function(obj, defaultZIndex) {
97
194
  var info = {
98
195
  left: 0,
99
196
  top: 0,
100
- width: obj.width || obj.offsetWidth || 0,
101
- height: obj.height || obj.offsetHeight || 0,
102
- zIndex: 9999
197
+ width: 0,
198
+ height: 0,
199
+ zIndex: _getSafeZIndex(defaultZIndex) - 1
103
200
  };
104
- var zi = _getStyle(obj, "zIndex");
105
- if (zi && zi != "auto") {
106
- info.zIndex = parseInt(zi, 10);
107
- }
108
- while (obj) {
109
- var borderLeftWidth = parseInt(_getStyle(obj, "borderLeftWidth"), 10);
110
- var borderTopWidth = parseInt(_getStyle(obj, "borderTopWidth"), 10);
111
- info.left += isNaN(obj.offsetLeft) ? 0 : obj.offsetLeft;
112
- info.left += isNaN(borderLeftWidth) ? 0 : borderLeftWidth;
113
- info.top += isNaN(obj.offsetTop) ? 0 : obj.offsetTop;
114
- info.top += isNaN(borderTopWidth) ? 0 : borderTopWidth;
115
- obj = obj.offsetParent;
201
+ if (obj.getBoundingClientRect) {
202
+ var rect = obj.getBoundingClientRect();
203
+ var pageXOffset, pageYOffset, zoomFactor;
204
+ if ("pageXOffset" in window && "pageYOffset" in window) {
205
+ pageXOffset = window.pageXOffset;
206
+ pageYOffset = window.pageYOffset;
207
+ } else {
208
+ zoomFactor = _getZoomFactor();
209
+ pageXOffset = Math.round(document.documentElement.scrollLeft / zoomFactor);
210
+ pageYOffset = Math.round(document.documentElement.scrollTop / zoomFactor);
211
+ }
212
+ var leftBorderWidth = document.documentElement.clientLeft || 0;
213
+ var topBorderWidth = document.documentElement.clientTop || 0;
214
+ info.left = rect.left + pageXOffset - leftBorderWidth;
215
+ info.top = rect.top + pageYOffset - topBorderWidth;
216
+ info.width = "width" in rect ? rect.width : rect.right - rect.left;
217
+ info.height = "height" in rect ? rect.height : rect.bottom - rect.top;
116
218
  }
117
219
  return info;
118
220
  };
119
- var _noCache = function(path) {
120
- return (path.indexOf("?") >= 0 ? "&" : "?") + "nocache=" + (new Date).getTime();
221
+ var _cacheBust = function(path, options) {
222
+ var cacheBust = options == null || options && options.cacheBust === true && options.useNoCache === true;
223
+ if (cacheBust) {
224
+ return (path.indexOf("?") === -1 ? "?" : "&") + "noCache=" + new Date().getTime();
225
+ } else {
226
+ return "";
227
+ }
121
228
  };
122
229
  var _vars = function(options) {
123
- var str = [];
230
+ var i, len, domain, str = [], domains = [], trustedOriginsExpanded = [];
231
+ if (options.trustedOrigins) {
232
+ if (typeof options.trustedOrigins === "string") {
233
+ domains.push(options.trustedOrigins);
234
+ } else if (typeof options.trustedOrigins === "object" && "length" in options.trustedOrigins) {
235
+ domains = domains.concat(options.trustedOrigins);
236
+ }
237
+ }
124
238
  if (options.trustedDomains) {
125
- if (options.trustedDomains.length) {
126
- str.push("trustedDomain=" + options.trustedDomains.join(","));
127
- } else {
128
- str.push("trustedDomain=" + options.trustedDomains);
239
+ if (typeof options.trustedDomains === "string") {
240
+ domains.push(options.trustedDomains);
241
+ } else if (typeof options.trustedDomains === "object" && "length" in options.trustedDomains) {
242
+ domains = domains.concat(options.trustedDomains);
243
+ }
244
+ }
245
+ if (domains.length) {
246
+ for (i = 0, len = domains.length; i < len; i++) {
247
+ if (domains.hasOwnProperty(i) && domains[i] && typeof domains[i] === "string") {
248
+ domain = _extractDomain(domains[i]);
249
+ if (!domain) {
250
+ continue;
251
+ }
252
+ if (domain === "*") {
253
+ trustedOriginsExpanded = [ domain ];
254
+ break;
255
+ }
256
+ trustedOriginsExpanded.push.apply(trustedOriginsExpanded, [ domain, "//" + domain, window.location.protocol + "//" + domain ]);
257
+ }
129
258
  }
130
259
  }
260
+ if (trustedOriginsExpanded.length) {
261
+ str.push("trustedOrigins=" + encodeURIComponent(trustedOriginsExpanded.join(",")));
262
+ }
263
+ if (typeof options.jsModuleId === "string" && options.jsModuleId) {
264
+ str.push("jsModuleId=" + encodeURIComponent(options.jsModuleId));
265
+ }
131
266
  return str.join("&");
132
267
  };
133
- var _inArray = function(elem, array) {
134
- if (array.indexOf) {
135
- return array.indexOf(elem);
268
+ var _inArray = function(elem, array, fromIndex) {
269
+ if (typeof array.indexOf === "function") {
270
+ return array.indexOf(elem, fromIndex);
271
+ }
272
+ var i, len = array.length;
273
+ if (typeof fromIndex === "undefined") {
274
+ fromIndex = 0;
275
+ } else if (fromIndex < 0) {
276
+ fromIndex = len + fromIndex;
136
277
  }
137
- for (var i = 0, length = array.length; i < length; i++) {
138
- if (array[i] === elem) {
278
+ for (i = fromIndex; i < len; i++) {
279
+ if (array.hasOwnProperty(i) && array[i] === elem) {
139
280
  return i;
140
281
  }
141
282
  }
142
283
  return -1;
143
284
  };
144
- var _prepGlue = function(elements) {
285
+ var _prepClip = function(elements) {
145
286
  if (typeof elements === "string") throw new TypeError("ZeroClipboard doesn't accept query strings.");
146
287
  if (!elements.length) return [ elements ];
147
288
  return elements;
148
289
  };
149
- var ZeroClipboard = function(elements, options) {
150
- if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements);
151
- if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton;
152
- ZeroClipboard.prototype._singleton = this;
153
- this.options = {};
154
- for (var kd in _defaults) this.options[kd] = _defaults[kd];
155
- for (var ko in options) this.options[ko] = options[ko];
156
- this.handlers = {};
157
- if (ZeroClipboard.detectFlashSupport()) _bridge();
158
- };
159
- var currentElement, gluedElements = [];
160
- ZeroClipboard.prototype.setCurrent = function(element) {
161
- currentElement = element;
162
- this.reposition();
163
- this.setText(this.options.text || element.getAttribute("data-clipboard-text"));
164
- if (element.getAttribute("title")) {
165
- this.setTitle(element.getAttribute("title"));
290
+ var _dispatchCallback = function(func, context, args, async) {
291
+ if (async) {
292
+ window.setTimeout(function() {
293
+ func.apply(context, args);
294
+ }, 0);
295
+ } else {
296
+ func.apply(context, args);
166
297
  }
167
- this.setHandCursor(_getStyle(element, "cursor") == "pointer");
168
298
  };
169
- ZeroClipboard.prototype.setText = function(newText) {
170
- if (newText && newText !== "") {
171
- this.options.text = newText;
172
- if (this.ready()) this.flashBridge.setText(newText);
299
+ var _getSafeZIndex = function(val) {
300
+ var zIndex, tmp;
301
+ if (val) {
302
+ if (typeof val === "number" && val > 0) {
303
+ zIndex = val;
304
+ } else if (typeof val === "string" && (tmp = parseInt(val, 10)) && !isNaN(tmp) && tmp > 0) {
305
+ zIndex = tmp;
306
+ }
173
307
  }
308
+ if (!zIndex) {
309
+ if (typeof _globalConfig.zIndex === "number" && _globalConfig.zIndex > 0) {
310
+ zIndex = _globalConfig.zIndex;
311
+ } else if (typeof _globalConfig.zIndex === "string" && (tmp = parseInt(_globalConfig.zIndex, 10)) && !isNaN(tmp) && tmp > 0) {
312
+ zIndex = tmp;
313
+ }
314
+ }
315
+ return zIndex || 0;
174
316
  };
175
- ZeroClipboard.prototype.setTitle = function(newTitle) {
176
- if (newTitle && newTitle !== "") this.htmlBridge.setAttribute("title", newTitle);
317
+ var _deprecationWarning = function(deprecatedApiName, debugEnabled) {
318
+ if (deprecatedApiName && debugEnabled !== false && typeof console !== "undefined" && console && (console.warn || console.log)) {
319
+ var deprecationWarning = "`" + deprecatedApiName + "` is deprecated. See docs for more info:\n" + " https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md#deprecations";
320
+ if (console.warn) {
321
+ console.warn(deprecationWarning);
322
+ } else {
323
+ console.log(deprecationWarning);
324
+ }
325
+ }
177
326
  };
178
- ZeroClipboard.prototype.setSize = function(width, height) {
179
- if (this.ready()) this.flashBridge.setSize(width, height);
327
+ var _extend = function() {
328
+ var i, len, arg, prop, src, copy, target = arguments[0] || {};
329
+ for (i = 1, len = arguments.length; i < len; i++) {
330
+ if ((arg = arguments[i]) != null) {
331
+ for (prop in arg) {
332
+ if (arg.hasOwnProperty(prop)) {
333
+ src = target[prop];
334
+ copy = arg[prop];
335
+ if (target === copy) {
336
+ continue;
337
+ }
338
+ if (copy !== undefined) {
339
+ target[prop] = copy;
340
+ }
341
+ }
342
+ }
343
+ }
344
+ }
345
+ return target;
180
346
  };
181
- ZeroClipboard.prototype.setHandCursor = function(enabled) {
182
- if (this.ready()) this.flashBridge.setHandCursor(enabled);
347
+ var _extractDomain = function(originOrUrl) {
348
+ if (originOrUrl == null || originOrUrl === "") {
349
+ return null;
350
+ }
351
+ originOrUrl = originOrUrl.replace(/^\s+|\s+$/g, "");
352
+ if (originOrUrl === "") {
353
+ return null;
354
+ }
355
+ var protocolIndex = originOrUrl.indexOf("//");
356
+ originOrUrl = protocolIndex === -1 ? originOrUrl : originOrUrl.slice(protocolIndex + 2);
357
+ var pathIndex = originOrUrl.indexOf("/");
358
+ originOrUrl = pathIndex === -1 ? originOrUrl : protocolIndex === -1 || pathIndex === 0 ? null : originOrUrl.slice(0, pathIndex);
359
+ if (originOrUrl && originOrUrl.slice(-4).toLowerCase() === ".swf") {
360
+ return null;
361
+ }
362
+ return originOrUrl || null;
183
363
  };
184
- ZeroClipboard.version = "1.1.6";
185
- var _defaults = {
186
- moviePath: "ZeroClipboard.swf",
187
- trustedDomains: null,
188
- text: null,
189
- hoverClass: "zeroclipboard-is-hover",
190
- activeClass: "zeroclipboard-is-active"
364
+ var _determineScriptAccess = function() {
365
+ var _extractAllDomains = function(origins, resultsArray) {
366
+ var i, len, tmp;
367
+ if (origins != null && resultsArray[0] !== "*") {
368
+ if (typeof origins === "string") {
369
+ origins = [ origins ];
370
+ }
371
+ if (typeof origins === "object" && "length" in origins) {
372
+ for (i = 0, len = origins.length; i < len; i++) {
373
+ if (origins.hasOwnProperty(i)) {
374
+ tmp = _extractDomain(origins[i]);
375
+ if (tmp) {
376
+ if (tmp === "*") {
377
+ resultsArray.length = 0;
378
+ resultsArray.push("*");
379
+ break;
380
+ }
381
+ if (_inArray(tmp, resultsArray) === -1) {
382
+ resultsArray.push(tmp);
383
+ }
384
+ }
385
+ }
386
+ }
387
+ }
388
+ }
389
+ };
390
+ var _accessLevelLookup = {
391
+ always: "always",
392
+ samedomain: "sameDomain",
393
+ never: "never"
394
+ };
395
+ return function(currentDomain, configOptions) {
396
+ var asaLower, allowScriptAccess = configOptions.allowScriptAccess;
397
+ if (typeof allowScriptAccess === "string" && (asaLower = allowScriptAccess.toLowerCase()) && /^always|samedomain|never$/.test(asaLower)) {
398
+ return _accessLevelLookup[asaLower];
399
+ }
400
+ var swfDomain = _extractDomain(configOptions.moviePath);
401
+ if (swfDomain === null) {
402
+ swfDomain = currentDomain;
403
+ }
404
+ var trustedDomains = [];
405
+ _extractAllDomains(configOptions.trustedOrigins, trustedDomains);
406
+ _extractAllDomains(configOptions.trustedDomains, trustedDomains);
407
+ var len = trustedDomains.length;
408
+ if (len > 0) {
409
+ if (len === 1 && trustedDomains[0] === "*") {
410
+ return "always";
411
+ }
412
+ if (_inArray(currentDomain, trustedDomains) !== -1) {
413
+ if (len === 1 && currentDomain === swfDomain) {
414
+ return "sameDomain";
415
+ }
416
+ return "always";
417
+ }
418
+ }
419
+ return "never";
420
+ };
421
+ }();
422
+ var _objectKeys = function(obj) {
423
+ if (obj == null) {
424
+ return [];
425
+ }
426
+ if (Object.keys) {
427
+ return Object.keys(obj);
428
+ }
429
+ var keys = [];
430
+ for (var prop in obj) {
431
+ if (obj.hasOwnProperty(prop)) {
432
+ keys.push(prop);
433
+ }
434
+ }
435
+ return keys;
191
436
  };
192
- ZeroClipboard.setDefaults = function(options) {
193
- for (var ko in options) _defaults[ko] = options[ko];
437
+ var _deleteOwnProperties = function(obj) {
438
+ if (obj) {
439
+ for (var prop in obj) {
440
+ if (obj.hasOwnProperty(prop)) {
441
+ delete obj[prop];
442
+ }
443
+ }
444
+ }
445
+ return obj;
194
446
  };
195
- ZeroClipboard.destroy = function() {
196
- ZeroClipboard.prototype._singleton.unglue(gluedElements);
197
- var bridge = ZeroClipboard.prototype._singleton.htmlBridge;
198
- bridge.parentNode.removeChild(bridge);
199
- delete ZeroClipboard.prototype._singleton;
447
+ var _safeActiveElement = function() {
448
+ try {
449
+ return document.activeElement;
450
+ } catch (err) {}
451
+ return null;
200
452
  };
201
- ZeroClipboard.detectFlashSupport = function() {
453
+ var _detectFlashSupport = function() {
202
454
  var hasFlash = false;
203
- try {
204
- if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
205
- hasFlash = true;
455
+ if (typeof flashState.disabled === "boolean") {
456
+ hasFlash = flashState.disabled === false;
457
+ } else {
458
+ if (typeof ActiveXObject === "function") {
459
+ try {
460
+ if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) {
461
+ hasFlash = true;
462
+ }
463
+ } catch (error) {}
206
464
  }
207
- } catch (error) {
208
- if (navigator.mimeTypes["application/x-shockwave-flash"]) {
465
+ if (!hasFlash && navigator.mimeTypes["application/x-shockwave-flash"]) {
209
466
  hasFlash = true;
210
467
  }
211
468
  }
212
469
  return hasFlash;
213
470
  };
214
- var _bridge = function() {
215
- var client = ZeroClipboard.prototype._singleton;
216
- client.htmlBridge = document.getElementById("global-zeroclipboard-html-bridge");
217
- if (client.htmlBridge) {
218
- client.flashBridge = document["global-zeroclipboard-flash-bridge"];
471
+ function _parseFlashVersion(flashVersion) {
472
+ return flashVersion.replace(/,/g, ".").replace(/[^0-9\.]/g, "");
473
+ }
474
+ function _isFlashVersionSupported(flashVersion) {
475
+ return parseFloat(_parseFlashVersion(flashVersion)) >= 10;
476
+ }
477
+ var ZeroClipboard = function(elements, options) {
478
+ if (!(this instanceof ZeroClipboard)) {
479
+ return new ZeroClipboard(elements, options);
480
+ }
481
+ this.id = "" + clientIdCounter++;
482
+ _clientMeta[this.id] = {
483
+ instance: this,
484
+ elements: [],
485
+ handlers: {}
486
+ };
487
+ if (elements) {
488
+ this.clip(elements);
489
+ }
490
+ if (typeof options !== "undefined") {
491
+ _deprecationWarning("new ZeroClipboard(elements, options)", _globalConfig.debug);
492
+ ZeroClipboard.config(options);
493
+ }
494
+ this.options = ZeroClipboard.config();
495
+ if (typeof flashState.disabled !== "boolean") {
496
+ flashState.disabled = !_detectFlashSupport();
497
+ }
498
+ if (flashState.disabled === false && flashState.outdated !== true) {
499
+ if (flashState.bridge === null) {
500
+ flashState.outdated = false;
501
+ flashState.ready = false;
502
+ _bridge();
503
+ }
504
+ }
505
+ };
506
+ ZeroClipboard.prototype.setText = function(newText) {
507
+ if (newText && newText !== "") {
508
+ _clipData["text/plain"] = newText;
509
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setText === "function") {
510
+ flashState.bridge.setText(newText);
511
+ } else {
512
+ flashState.ready = false;
513
+ }
514
+ }
515
+ return this;
516
+ };
517
+ ZeroClipboard.prototype.setSize = function(width, height) {
518
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setSize === "function") {
519
+ flashState.bridge.setSize(width, height);
520
+ } else {
521
+ flashState.ready = false;
522
+ }
523
+ return this;
524
+ };
525
+ var _setHandCursor = function(enabled) {
526
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setHandCursor === "function") {
527
+ flashState.bridge.setHandCursor(enabled);
528
+ } else {
529
+ flashState.ready = false;
530
+ }
531
+ };
532
+ ZeroClipboard.prototype.destroy = function() {
533
+ this.unclip();
534
+ this.off();
535
+ delete _clientMeta[this.id];
536
+ };
537
+ var _getAllClients = function() {
538
+ var i, len, client, clients = [], clientIds = _objectKeys(_clientMeta);
539
+ for (i = 0, len = clientIds.length; i < len; i++) {
540
+ client = _clientMeta[clientIds[i]].instance;
541
+ if (client && client instanceof ZeroClipboard) {
542
+ clients.push(client);
543
+ }
544
+ }
545
+ return clients;
546
+ };
547
+ ZeroClipboard.version = "1.3.5";
548
+ var _globalConfig = {
549
+ swfPath: _swfPath,
550
+ trustedDomains: window.location.host ? [ window.location.host ] : [],
551
+ cacheBust: true,
552
+ forceHandCursor: false,
553
+ zIndex: 999999999,
554
+ debug: true,
555
+ title: null,
556
+ autoActivate: true
557
+ };
558
+ ZeroClipboard.config = function(options) {
559
+ if (typeof options === "object" && options !== null) {
560
+ _extend(_globalConfig, options);
561
+ }
562
+ if (typeof options === "string" && options) {
563
+ if (_globalConfig.hasOwnProperty(options)) {
564
+ return _globalConfig[options];
565
+ }
219
566
  return;
220
567
  }
221
- 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="always" /> <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>';
222
- client.htmlBridge = document.createElement("div");
223
- client.htmlBridge.id = "global-zeroclipboard-html-bridge";
224
- client.htmlBridge.setAttribute("class", "global-zeroclipboard-container");
225
- client.htmlBridge.setAttribute("data-clipboard-ready", false);
226
- client.htmlBridge.style.position = "absolute";
227
- client.htmlBridge.style.left = "-9999px";
228
- client.htmlBridge.style.top = "-9999px";
229
- client.htmlBridge.style.width = "15px";
230
- client.htmlBridge.style.height = "15px";
231
- client.htmlBridge.style.zIndex = "9999";
232
- client.htmlBridge.innerHTML = html;
233
- document.body.appendChild(client.htmlBridge);
234
- client.flashBridge = document["global-zeroclipboard-flash-bridge"];
568
+ var copy = {};
569
+ for (var prop in _globalConfig) {
570
+ if (_globalConfig.hasOwnProperty(prop)) {
571
+ if (typeof _globalConfig[prop] === "object" && _globalConfig[prop] !== null) {
572
+ if ("length" in _globalConfig[prop]) {
573
+ copy[prop] = _globalConfig[prop].slice(0);
574
+ } else {
575
+ copy[prop] = _extend({}, _globalConfig[prop]);
576
+ }
577
+ } else {
578
+ copy[prop] = _globalConfig[prop];
579
+ }
580
+ }
581
+ }
582
+ return copy;
235
583
  };
236
- ZeroClipboard.prototype.resetBridge = function() {
237
- this.htmlBridge.style.left = "-9999px";
238
- this.htmlBridge.style.top = "-9999px";
239
- this.htmlBridge.removeAttribute("title");
240
- this.htmlBridge.removeAttribute("data-clipboard-text");
241
- _removeClass(currentElement, this.options.activeClass);
242
- currentElement = null;
584
+ ZeroClipboard.destroy = function() {
585
+ ZeroClipboard.deactivate();
586
+ for (var clientId in _clientMeta) {
587
+ if (_clientMeta.hasOwnProperty(clientId) && _clientMeta[clientId]) {
588
+ var client = _clientMeta[clientId].instance;
589
+ if (client && typeof client.destroy === "function") {
590
+ client.destroy();
591
+ }
592
+ }
593
+ }
594
+ var htmlBridge = _getHtmlBridge(flashState.bridge);
595
+ if (htmlBridge && htmlBridge.parentNode) {
596
+ htmlBridge.parentNode.removeChild(htmlBridge);
597
+ flashState.ready = null;
598
+ flashState.bridge = null;
599
+ }
243
600
  };
244
- ZeroClipboard.prototype.ready = function() {
245
- var ready = this.htmlBridge.getAttribute("data-clipboard-ready");
246
- return ready === "true" || ready === true;
601
+ ZeroClipboard.activate = function(element) {
602
+ if (currentElement) {
603
+ _removeClass(currentElement, _globalConfig.hoverClass);
604
+ _removeClass(currentElement, _globalConfig.activeClass);
605
+ }
606
+ currentElement = element;
607
+ _addClass(element, _globalConfig.hoverClass);
608
+ _reposition();
609
+ var newTitle = _globalConfig.title || element.getAttribute("title");
610
+ if (newTitle) {
611
+ var htmlBridge = _getHtmlBridge(flashState.bridge);
612
+ if (htmlBridge) {
613
+ htmlBridge.setAttribute("title", newTitle);
614
+ }
615
+ }
616
+ var useHandCursor = _globalConfig.forceHandCursor === true || _getStyle(element, "cursor") === "pointer";
617
+ _setHandCursor(useHandCursor);
247
618
  };
248
- ZeroClipboard.prototype.reposition = function() {
249
- if (!currentElement) return false;
250
- var pos = _getDOMObjectPosition(currentElement);
251
- this.htmlBridge.style.top = pos.top + "px";
252
- this.htmlBridge.style.left = pos.left + "px";
253
- this.htmlBridge.style.width = pos.width + "px";
254
- this.htmlBridge.style.height = pos.height + "px";
255
- this.htmlBridge.style.zIndex = pos.zIndex + 1;
256
- this.setSize(pos.width, pos.height);
619
+ ZeroClipboard.deactivate = function() {
620
+ var htmlBridge = _getHtmlBridge(flashState.bridge);
621
+ if (htmlBridge) {
622
+ htmlBridge.style.left = "0px";
623
+ htmlBridge.style.top = "-9999px";
624
+ htmlBridge.removeAttribute("title");
625
+ }
626
+ if (currentElement) {
627
+ _removeClass(currentElement, _globalConfig.hoverClass);
628
+ _removeClass(currentElement, _globalConfig.activeClass);
629
+ currentElement = null;
630
+ }
257
631
  };
258
- ZeroClipboard.dispatch = function(eventName, args) {
259
- ZeroClipboard.prototype._singleton.receiveEvent(eventName, args);
632
+ var _bridge = function() {
633
+ var flashBridge, len;
634
+ var container = document.getElementById("global-zeroclipboard-html-bridge");
635
+ if (!container) {
636
+ var opts = ZeroClipboard.config();
637
+ opts.jsModuleId = typeof _amdModuleId === "string" && _amdModuleId || typeof _cjsModuleId === "string" && _cjsModuleId || null;
638
+ var allowScriptAccess = _determineScriptAccess(window.location.host, _globalConfig);
639
+ var flashvars = _vars(opts);
640
+ var swfUrl = _globalConfig.moviePath + _cacheBust(_globalConfig.moviePath, _globalConfig);
641
+ var html = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="' + swfUrl + '"/> <param name="allowScriptAccess" value="' + 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="' + flashvars + '"/> <embed src="' + swfUrl + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="100%" height="100%" name="global-zeroclipboard-flash-bridge" allowScriptAccess="' + allowScriptAccess + '" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashvars + '" scale="exactfit"> </embed> </object>';
642
+ container = document.createElement("div");
643
+ container.id = "global-zeroclipboard-html-bridge";
644
+ container.setAttribute("class", "global-zeroclipboard-container");
645
+ container.style.position = "absolute";
646
+ container.style.left = "0px";
647
+ container.style.top = "-9999px";
648
+ container.style.width = "15px";
649
+ container.style.height = "15px";
650
+ container.style.zIndex = "" + _getSafeZIndex(_globalConfig.zIndex);
651
+ document.body.appendChild(container);
652
+ container.innerHTML = html;
653
+ }
654
+ flashBridge = document["global-zeroclipboard-flash-bridge"];
655
+ if (flashBridge && (len = flashBridge.length)) {
656
+ flashBridge = flashBridge[len - 1];
657
+ }
658
+ flashState.bridge = flashBridge || container.children[0].lastElementChild;
659
+ };
660
+ var _getHtmlBridge = function(flashBridge) {
661
+ var isFlashElement = /^OBJECT|EMBED$/;
662
+ var htmlBridge = flashBridge && flashBridge.parentNode;
663
+ while (htmlBridge && isFlashElement.test(htmlBridge.nodeName) && htmlBridge.parentNode) {
664
+ htmlBridge = htmlBridge.parentNode;
665
+ }
666
+ return htmlBridge || null;
667
+ };
668
+ var _reposition = function() {
669
+ if (currentElement) {
670
+ var pos = _getDOMObjectPosition(currentElement, _globalConfig.zIndex);
671
+ var htmlBridge = _getHtmlBridge(flashState.bridge);
672
+ if (htmlBridge) {
673
+ htmlBridge.style.top = pos.top + "px";
674
+ htmlBridge.style.left = pos.left + "px";
675
+ htmlBridge.style.width = pos.width + "px";
676
+ htmlBridge.style.height = pos.height + "px";
677
+ htmlBridge.style.zIndex = pos.zIndex + 1;
678
+ }
679
+ if (flashState.ready === true && flashState.bridge && typeof flashState.bridge.setSize === "function") {
680
+ flashState.bridge.setSize(pos.width, pos.height);
681
+ } else {
682
+ flashState.ready = false;
683
+ }
684
+ }
685
+ return this;
260
686
  };
261
687
  ZeroClipboard.prototype.on = function(eventName, func) {
262
- var events = eventName.toString().split(/\s/g);
263
- for (var i = 0; i < events.length; i++) {
264
- eventName = events[i].toLowerCase().replace(/^on/, "");
265
- if (!this.handlers[eventName]) this.handlers[eventName] = func;
688
+ var i, len, events, added = {}, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
689
+ if (typeof eventName === "string" && eventName) {
690
+ events = eventName.toLowerCase().split(/\s+/);
691
+ } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
692
+ for (i in eventName) {
693
+ if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
694
+ this.on(i, eventName[i]);
695
+ }
696
+ }
697
+ }
698
+ if (events && events.length) {
699
+ for (i = 0, len = events.length; i < len; i++) {
700
+ eventName = events[i].replace(/^on/, "");
701
+ added[eventName] = true;
702
+ if (!handlers[eventName]) {
703
+ handlers[eventName] = [];
704
+ }
705
+ handlers[eventName].push(func);
706
+ }
707
+ if (added.noflash && flashState.disabled) {
708
+ _receiveEvent.call(this, "noflash", {});
709
+ }
710
+ if (added.wrongflash && flashState.outdated) {
711
+ _receiveEvent.call(this, "wrongflash", {
712
+ flashVersion: flashState.version
713
+ });
714
+ }
715
+ if (added.load && flashState.ready) {
716
+ _receiveEvent.call(this, "load", {
717
+ flashVersion: flashState.version
718
+ });
719
+ }
720
+ }
721
+ return this;
722
+ };
723
+ ZeroClipboard.prototype.off = function(eventName, func) {
724
+ var i, len, foundIndex, events, perEventHandlers, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
725
+ if (arguments.length === 0) {
726
+ events = _objectKeys(handlers);
727
+ } else if (typeof eventName === "string" && eventName) {
728
+ events = eventName.split(/\s+/);
729
+ } else if (typeof eventName === "object" && eventName && typeof func === "undefined") {
730
+ for (i in eventName) {
731
+ if (eventName.hasOwnProperty(i) && typeof i === "string" && i && typeof eventName[i] === "function") {
732
+ this.off(i, eventName[i]);
733
+ }
734
+ }
735
+ }
736
+ if (events && events.length) {
737
+ for (i = 0, len = events.length; i < len; i++) {
738
+ eventName = events[i].toLowerCase().replace(/^on/, "");
739
+ perEventHandlers = handlers[eventName];
740
+ if (perEventHandlers && perEventHandlers.length) {
741
+ if (func) {
742
+ foundIndex = _inArray(func, perEventHandlers);
743
+ while (foundIndex !== -1) {
744
+ perEventHandlers.splice(foundIndex, 1);
745
+ foundIndex = _inArray(func, perEventHandlers, foundIndex);
746
+ }
747
+ } else {
748
+ handlers[eventName].length = 0;
749
+ }
750
+ }
751
+ }
752
+ }
753
+ return this;
754
+ };
755
+ ZeroClipboard.prototype.handlers = function(eventName) {
756
+ var prop, copy = null, handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers;
757
+ if (handlers) {
758
+ if (typeof eventName === "string" && eventName) {
759
+ return handlers[eventName] ? handlers[eventName].slice(0) : null;
760
+ }
761
+ copy = {};
762
+ for (prop in handlers) {
763
+ if (handlers.hasOwnProperty(prop) && handlers[prop]) {
764
+ copy[prop] = handlers[prop].slice(0);
765
+ }
766
+ }
767
+ }
768
+ return copy;
769
+ };
770
+ var _dispatchClientCallbacks = function(eventName, context, args, async) {
771
+ var handlers = _clientMeta[this.id] && _clientMeta[this.id].handlers[eventName];
772
+ if (handlers && handlers.length) {
773
+ var i, len, func, originalContext = context || this;
774
+ for (i = 0, len = handlers.length; i < len; i++) {
775
+ func = handlers[i];
776
+ context = originalContext;
777
+ if (typeof func === "string" && typeof window[func] === "function") {
778
+ func = window[func];
779
+ }
780
+ if (typeof func === "object" && func && typeof func.handleEvent === "function") {
781
+ context = func;
782
+ func = func.handleEvent;
783
+ }
784
+ if (typeof func === "function") {
785
+ _dispatchCallback(func, context, args, async);
786
+ }
787
+ }
266
788
  }
267
- if (this.handlers.noflash && !ZeroClipboard.detectFlashSupport()) {
268
- this.receiveEvent("onNoFlash", null);
789
+ return this;
790
+ };
791
+ ZeroClipboard.prototype.clip = function(elements) {
792
+ elements = _prepClip(elements);
793
+ for (var i = 0; i < elements.length; i++) {
794
+ if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
795
+ if (!elements[i].zcClippingId) {
796
+ elements[i].zcClippingId = "zcClippingId_" + elementIdCounter++;
797
+ _elementMeta[elements[i].zcClippingId] = [ this.id ];
798
+ if (_globalConfig.autoActivate === true) {
799
+ _addEventHandler(elements[i], "mouseover", _elementMouseOver);
800
+ }
801
+ } else if (_inArray(this.id, _elementMeta[elements[i].zcClippingId]) === -1) {
802
+ _elementMeta[elements[i].zcClippingId].push(this.id);
803
+ }
804
+ var clippedElements = _clientMeta[this.id].elements;
805
+ if (_inArray(elements[i], clippedElements) === -1) {
806
+ clippedElements.push(elements[i]);
807
+ }
808
+ }
269
809
  }
810
+ return this;
811
+ };
812
+ ZeroClipboard.prototype.unclip = function(elements) {
813
+ var meta = _clientMeta[this.id];
814
+ if (meta) {
815
+ var clippedElements = meta.elements;
816
+ var arrayIndex;
817
+ if (typeof elements === "undefined") {
818
+ elements = clippedElements.slice(0);
819
+ } else {
820
+ elements = _prepClip(elements);
821
+ }
822
+ for (var i = elements.length; i--; ) {
823
+ if (elements.hasOwnProperty(i) && elements[i] && elements[i].nodeType === 1) {
824
+ arrayIndex = 0;
825
+ while ((arrayIndex = _inArray(elements[i], clippedElements, arrayIndex)) !== -1) {
826
+ clippedElements.splice(arrayIndex, 1);
827
+ }
828
+ var clientIds = _elementMeta[elements[i].zcClippingId];
829
+ if (clientIds) {
830
+ arrayIndex = 0;
831
+ while ((arrayIndex = _inArray(this.id, clientIds, arrayIndex)) !== -1) {
832
+ clientIds.splice(arrayIndex, 1);
833
+ }
834
+ if (clientIds.length === 0) {
835
+ if (_globalConfig.autoActivate === true) {
836
+ _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
837
+ }
838
+ delete elements[i].zcClippingId;
839
+ }
840
+ }
841
+ }
842
+ }
843
+ }
844
+ return this;
845
+ };
846
+ ZeroClipboard.prototype.elements = function() {
847
+ var meta = _clientMeta[this.id];
848
+ return meta && meta.elements ? meta.elements.slice(0) : [];
849
+ };
850
+ var _getAllClientsClippedToElement = function(element) {
851
+ var elementMetaId, clientIds, i, len, client, clients = [];
852
+ if (element && element.nodeType === 1 && (elementMetaId = element.zcClippingId) && _elementMeta.hasOwnProperty(elementMetaId)) {
853
+ clientIds = _elementMeta[elementMetaId];
854
+ if (clientIds && clientIds.length) {
855
+ for (i = 0, len = clientIds.length; i < len; i++) {
856
+ client = _clientMeta[clientIds[i]].instance;
857
+ if (client && client instanceof ZeroClipboard) {
858
+ clients.push(client);
859
+ }
860
+ }
861
+ }
862
+ }
863
+ return clients;
864
+ };
865
+ _globalConfig.hoverClass = "zeroclipboard-is-hover";
866
+ _globalConfig.activeClass = "zeroclipboard-is-active";
867
+ _globalConfig.trustedOrigins = null;
868
+ _globalConfig.allowScriptAccess = null;
869
+ _globalConfig.useNoCache = true;
870
+ _globalConfig.moviePath = "ZeroClipboard.swf";
871
+ ZeroClipboard.detectFlashSupport = function() {
872
+ _deprecationWarning("ZeroClipboard.detectFlashSupport", _globalConfig.debug);
873
+ return _detectFlashSupport();
874
+ };
875
+ ZeroClipboard.dispatch = function(eventName, args) {
876
+ if (typeof eventName === "string" && eventName) {
877
+ var cleanEventName = eventName.toLowerCase().replace(/^on/, "");
878
+ if (cleanEventName) {
879
+ var clients = currentElement && _globalConfig.autoActivate === true ? _getAllClientsClippedToElement(currentElement) : _getAllClients();
880
+ for (var i = 0, len = clients.length; i < len; i++) {
881
+ _receiveEvent.call(clients[i], cleanEventName, args);
882
+ }
883
+ }
884
+ }
885
+ };
886
+ ZeroClipboard.prototype.setHandCursor = function(enabled) {
887
+ _deprecationWarning("ZeroClipboard.prototype.setHandCursor", _globalConfig.debug);
888
+ enabled = typeof enabled === "boolean" ? enabled : !!enabled;
889
+ _setHandCursor(enabled);
890
+ _globalConfig.forceHandCursor = enabled;
891
+ return this;
892
+ };
893
+ ZeroClipboard.prototype.reposition = function() {
894
+ _deprecationWarning("ZeroClipboard.prototype.reposition", _globalConfig.debug);
895
+ return _reposition();
270
896
  };
271
- ZeroClipboard.prototype.addEventListener = ZeroClipboard.prototype.on;
272
897
  ZeroClipboard.prototype.receiveEvent = function(eventName, args) {
273
- eventName = eventName.toString().toLowerCase().replace(/^on/, "");
898
+ _deprecationWarning("ZeroClipboard.prototype.receiveEvent", _globalConfig.debug);
899
+ if (typeof eventName === "string" && eventName) {
900
+ var cleanEventName = eventName.toLowerCase().replace(/^on/, "");
901
+ if (cleanEventName) {
902
+ _receiveEvent.call(this, cleanEventName, args);
903
+ }
904
+ }
905
+ };
906
+ ZeroClipboard.prototype.setCurrent = function(element) {
907
+ _deprecationWarning("ZeroClipboard.prototype.setCurrent", _globalConfig.debug);
908
+ ZeroClipboard.activate(element);
909
+ return this;
910
+ };
911
+ ZeroClipboard.prototype.resetBridge = function() {
912
+ _deprecationWarning("ZeroClipboard.prototype.resetBridge", _globalConfig.debug);
913
+ ZeroClipboard.deactivate();
914
+ return this;
915
+ };
916
+ ZeroClipboard.prototype.setTitle = function(newTitle) {
917
+ _deprecationWarning("ZeroClipboard.prototype.setTitle", _globalConfig.debug);
918
+ newTitle = newTitle || _globalConfig.title || currentElement && currentElement.getAttribute("title");
919
+ if (newTitle) {
920
+ var htmlBridge = _getHtmlBridge(flashState.bridge);
921
+ if (htmlBridge) {
922
+ htmlBridge.setAttribute("title", newTitle);
923
+ }
924
+ }
925
+ return this;
926
+ };
927
+ ZeroClipboard.setDefaults = function(options) {
928
+ _deprecationWarning("ZeroClipboard.setDefaults", _globalConfig.debug);
929
+ ZeroClipboard.config(options);
930
+ };
931
+ ZeroClipboard.prototype.addEventListener = function(eventName, func) {
932
+ _deprecationWarning("ZeroClipboard.prototype.addEventListener", _globalConfig.debug);
933
+ return this.on(eventName, func);
934
+ };
935
+ ZeroClipboard.prototype.removeEventListener = function(eventName, func) {
936
+ _deprecationWarning("ZeroClipboard.prototype.removeEventListener", _globalConfig.debug);
937
+ return this.off(eventName, func);
938
+ };
939
+ ZeroClipboard.prototype.ready = function() {
940
+ _deprecationWarning("ZeroClipboard.prototype.ready", _globalConfig.debug);
941
+ return flashState.ready === true;
942
+ };
943
+ var _receiveEvent = function(eventName, args) {
944
+ eventName = eventName.toLowerCase().replace(/^on/, "");
945
+ var cleanVersion = args && args.flashVersion && _parseFlashVersion(args.flashVersion) || null;
274
946
  var element = currentElement;
947
+ var performCallbackAsync = true;
275
948
  switch (eventName) {
276
949
  case "load":
277
- if (args && parseFloat(args.flashVersion.replace(",", ".").replace(/[^0-9\.]/gi, "")) < 10) {
278
- this.receiveEvent("onWrongFlash", {
279
- flashVersion: args.flashVersion
280
- });
281
- return;
950
+ if (cleanVersion) {
951
+ if (!_isFlashVersionSupported(cleanVersion)) {
952
+ _receiveEvent.call(this, "onWrongFlash", {
953
+ flashVersion: cleanVersion
954
+ });
955
+ return;
956
+ }
957
+ flashState.outdated = false;
958
+ flashState.ready = true;
959
+ flashState.version = cleanVersion;
282
960
  }
283
- this.htmlBridge.setAttribute("data-clipboard-ready", true);
284
961
  break;
962
+
963
+ case "wrongflash":
964
+ if (cleanVersion && !_isFlashVersionSupported(cleanVersion)) {
965
+ flashState.outdated = true;
966
+ flashState.ready = false;
967
+ flashState.version = cleanVersion;
968
+ }
969
+ break;
970
+
285
971
  case "mouseover":
286
- _addClass(element, this.options.hoverClass);
972
+ _addClass(element, _globalConfig.hoverClass);
287
973
  break;
974
+
288
975
  case "mouseout":
289
- _removeClass(element, this.options.hoverClass);
290
- this.resetBridge();
976
+ if (_globalConfig.autoActivate === true) {
977
+ ZeroClipboard.deactivate();
978
+ }
291
979
  break;
980
+
292
981
  case "mousedown":
293
- _addClass(element, this.options.activeClass);
982
+ _addClass(element, _globalConfig.activeClass);
294
983
  break;
984
+
295
985
  case "mouseup":
296
- _removeClass(element, this.options.activeClass);
986
+ _removeClass(element, _globalConfig.activeClass);
297
987
  break;
298
- case "complete":
299
- this.options.text = null;
300
- break;
301
- }
302
- if (this.handlers[eventName]) {
303
- var func = this.handlers[eventName];
304
- if (typeof func == "function") {
305
- func.call(element, this, args);
306
- } else if (typeof func == "string") {
307
- window[func].call(element, this, args);
988
+
989
+ case "datarequested":
990
+ if (element) {
991
+ var targetId = element.getAttribute("data-clipboard-target"), targetEl = !targetId ? null : document.getElementById(targetId);
992
+ if (targetEl) {
993
+ var textContent = targetEl.value || targetEl.textContent || targetEl.innerText;
994
+ if (textContent) {
995
+ this.setText(textContent);
996
+ }
997
+ } else {
998
+ var defaultText = element.getAttribute("data-clipboard-text");
999
+ if (defaultText) {
1000
+ this.setText(defaultText);
1001
+ }
1002
+ }
308
1003
  }
309
- }
310
- };
311
- ZeroClipboard.prototype.glue = function(elements) {
312
- elements = _prepGlue(elements);
313
- for (var i = 0; i < elements.length; i++) {
314
- if (_inArray(elements[i], gluedElements) == -1) {
315
- gluedElements.push(elements[i]);
316
- _addEventHandler(elements[i], "mouseover", _elementMouseOver);
1004
+ performCallbackAsync = false;
1005
+ break;
1006
+
1007
+ case "complete":
1008
+ _deleteOwnProperties(_clipData);
1009
+ if (element && element !== _safeActiveElement() && element.focus) {
1010
+ element.focus();
317
1011
  }
1012
+ break;
318
1013
  }
1014
+ var context = element;
1015
+ var eventArgs = [ this, args ];
1016
+ return _dispatchClientCallbacks.call(this, eventName, context, eventArgs, performCallbackAsync);
319
1017
  };
320
- ZeroClipboard.prototype.unglue = function(elements) {
321
- elements = _prepGlue(elements);
322
- for (var i = 0; i < elements.length; i++) {
323
- _removeEventHandler(elements[i], "mouseover", _elementMouseOver);
324
- var arrayIndex = _inArray(elements[i], gluedElements);
325
- if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
326
- }
327
- };
328
- if (typeof module !== "undefined") {
1018
+ if (typeof define === "function" && define.amd) {
1019
+ define([ "require", "exports", "module" ], function(require, exports, module) {
1020
+ _amdModuleId = module && module.id || null;
1021
+ return ZeroClipboard;
1022
+ });
1023
+ } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports && typeof window.require === "function") {
1024
+ _cjsModuleId = module.id || null;
329
1025
  module.exports = ZeroClipboard;
330
1026
  } else {
331
1027
  window.ZeroClipboard = ZeroClipboard;
332
1028
  }
333
- })();
1029
+ })(function() {
1030
+ return this;
1031
+ }());