clipboard-rails 1.4.3 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97e668f905893a41535a1700422c2ad31ff95f94
4
- data.tar.gz: 83a9ce237ce1e2e3282ed1b925621cac7438e6b8
3
+ metadata.gz: e052ee82b3c3ec5e3bf9486a07bdfdc3403f83ab
4
+ data.tar.gz: 8a4bc12307def0cc86b8dafd60ff667f46f747a1
5
5
  SHA512:
6
- metadata.gz: bce2e2d5c8a1fa3eb90f1676ca5b882d007b62a6e516577f5849c3a9ea0e7b97b0bf3eca5c0cf7a34e4c2f479f1b3e0bf673a28014feaffa4c9b3e029e42fef4
7
- data.tar.gz: f4858986c9f3607728fa078d7838216de4974f4055e513d44c49e8bad4d99e953ca2ff1802abe6d06bf34af9e79fdaea4bad163474142e3712e9c93b5538da07
6
+ metadata.gz: 8b8cd6da6c1f0a2b821f8e63baea39bb304288253003df3fdcbcb4d920238244ecf65d6c60fe0317530b3cfd2c7f9512224cf8bf6a156d588d04db4fad1ae7b5
7
+ data.tar.gz: 03354f091925d645d66633bf3db879facea9b5bf7c9b62e2846b6fd0b8695936e3ff8b72dc1adb9b38c1ed942683e59efe3e56e14572fb8bb1591823019c28fa
@@ -1,5 +1,5 @@
1
1
  module Clipboard
2
2
  module Rails
3
- VERSION = "1.4.3"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * clipboard.js v1.4.3
2
+ * clipboard.js v1.5.0
3
3
  * https://zenorocha.github.io/clipboard.js
4
4
  *
5
5
  * Licensed MIT © Zeno Rocha
@@ -61,61 +61,226 @@ function match(el, selector) {
61
61
  var closest = require('closest');
62
62
 
63
63
  /**
64
- * Delegate event `type` to `selector`
65
- * and invoke `fn(e)`. A callback function
66
- * is returned which may be passed to `.unbind()`.
64
+ * Delegates event to a selector.
67
65
  *
68
- * @param {Element} el
66
+ * @param {Element} element
69
67
  * @param {String} selector
70
68
  * @param {String} type
71
- * @param {Function} fn
72
- * @param {Boolean} capture
69
+ * @param {Function} callback
70
+ * @return {Object}
71
+ */
72
+ function delegate(element, selector, type, callback) {
73
+ var listenerFn = listener.apply(this, arguments);
74
+
75
+ element.addEventListener(type, listenerFn);
76
+
77
+ return {
78
+ destroy: function() {
79
+ element.removeEventListener(type, listenerFn);
80
+ }
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Finds closest match and invokes callback.
86
+ *
87
+ * @param {Element} element
88
+ * @param {String} selector
89
+ * @param {String} type
90
+ * @param {Function} callback
73
91
  * @return {Function}
74
92
  */
93
+ function listener(element, selector, type, callback) {
94
+ return function(e) {
95
+ var delegateTarget = closest(e.target, selector, true);
75
96
 
76
- exports.bind = function(el, selector, type, fn, capture){
77
- return el.addEventListener(type, function(e){
78
- var target = e.target || e.srcElement;
79
- e.delegateTarget = closest(target, selector, true, el);
80
- if (e.delegateTarget) fn.call(el, e);
81
- }, capture);
97
+ if (delegateTarget) {
98
+ Object.defineProperty(e, 'target', {
99
+ value: delegateTarget
100
+ });
101
+
102
+ callback.call(element, e);
103
+ }
104
+ }
105
+ }
106
+
107
+ module.exports = delegate;
108
+
109
+ },{"closest":1}],4:[function(require,module,exports){
110
+ /**
111
+ * Check if argument is a HTML element.
112
+ *
113
+ * @param {Object} value
114
+ * @return {Boolean}
115
+ */
116
+ exports.node = function(value) {
117
+ return value !== undefined
118
+ && value instanceof HTMLElement
119
+ && value.nodeType === 1;
82
120
  };
83
121
 
84
122
  /**
85
- * Unbind event `type`'s callback `fn`.
123
+ * Check if argument is a list of HTML elements.
86
124
  *
87
- * @param {Element} el
88
- * @param {String} type
89
- * @param {Function} fn
90
- * @param {Boolean} capture
125
+ * @param {Object} value
126
+ * @return {Boolean}
91
127
  */
128
+ exports.nodeList = function(value) {
129
+ var type = Object.prototype.toString.call(value);
92
130
 
93
- exports.unbind = function(el, type, fn, capture){
94
- el.removeEventListener(type, fn, capture);
131
+ return value !== undefined
132
+ && (type === '[object NodeList]' || type === '[object HTMLCollection]')
133
+ && ('length' in value)
134
+ && (value.length === 0 || exports.node(value[0]));
95
135
  };
96
136
 
97
- },{"closest":1}],4:[function(require,module,exports){
137
+ /**
138
+ * Check if argument is a string.
139
+ *
140
+ * @param {Object} value
141
+ * @return {Boolean}
142
+ */
143
+ exports.string = function(value) {
144
+ return typeof value === 'string'
145
+ || value instanceof String;
146
+ };
147
+
148
+ /**
149
+ * Check if argument is a function.
150
+ *
151
+ * @param {Object} value
152
+ * @return {Boolean}
153
+ */
154
+ exports.function = function(value) {
155
+ var type = Object.prototype.toString.call(value);
156
+
157
+ return type === '[object Function]';
158
+ };
159
+
160
+ },{}],5:[function(require,module,exports){
161
+ var is = require('./is');
162
+ var delegate = require('delegate');
163
+
164
+ /**
165
+ * Validates all params and calls the right
166
+ * listener function based on its target type.
167
+ *
168
+ * @param {String|HTMLElement|HTMLCollection|NodeList} target
169
+ * @param {String} type
170
+ * @param {Function} callback
171
+ * @return {Object}
172
+ */
173
+ function listen(target, type, callback) {
174
+ if (!target && !type && !callback) {
175
+ throw new Error('Missing required arguments');
176
+ }
177
+
178
+ if (!is.string(type)) {
179
+ throw new TypeError('Second argument must be a String');
180
+ }
181
+
182
+ if (!is.function(callback)) {
183
+ throw new TypeError('Third argument must be a Function');
184
+ }
185
+
186
+ if (is.node(target)) {
187
+ return listenNode(target, type, callback);
188
+ }
189
+ else if (is.nodeList(target)) {
190
+ return listenNodeList(target, type, callback);
191
+ }
192
+ else if (is.string(target)) {
193
+ return listenSelector(target, type, callback);
194
+ }
195
+ else {
196
+ throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Adds an event listener to a HTML element
202
+ * and returns a remove listener function.
203
+ *
204
+ * @param {HTMLElement} node
205
+ * @param {String} type
206
+ * @param {Function} callback
207
+ * @return {Object}
208
+ */
209
+ function listenNode(node, type, callback) {
210
+ node.addEventListener(type, callback);
211
+
212
+ return {
213
+ destroy: function() {
214
+ node.removeEventListener(type, callback);
215
+ }
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Add an event listener to a list of HTML elements
221
+ * and returns a remove listener function.
222
+ *
223
+ * @param {NodeList|HTMLCollection} nodeList
224
+ * @param {String} type
225
+ * @param {Function} callback
226
+ * @return {Object}
227
+ */
228
+ function listenNodeList(nodeList, type, callback) {
229
+ Array.prototype.forEach.call(nodeList, function(node) {
230
+ node.addEventListener(type, callback);
231
+ });
232
+
233
+ return {
234
+ destroy: function() {
235
+ Array.prototype.forEach.call(nodeList, function(node) {
236
+ node.removeEventListener(type, callback);
237
+ });
238
+ }
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Add an event listener to a selector
244
+ * and returns a remove listener function.
245
+ *
246
+ * @param {String} selector
247
+ * @param {String} type
248
+ * @param {Function} callback
249
+ * @return {Object}
250
+ */
251
+ function listenSelector(selector, type, callback) {
252
+ return delegate(document.body, selector, type, callback);
253
+ }
254
+
255
+ module.exports = listen;
256
+
257
+ },{"./is":4,"delegate":3}],6:[function(require,module,exports){
98
258
  function select(element) {
99
- var selection = window.getSelection();
259
+ var selectedText;
100
260
 
101
261
  if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
102
262
  element.selectionStart = 0;
103
263
  element.selectionEnd = element.value.length;
264
+
265
+ selectedText = element.value;
104
266
  }
105
267
  else {
268
+ var selection = window.getSelection();
106
269
  var range = document.createRange();
107
270
 
108
271
  range.selectNodeContents(element);
109
272
  selection.removeAllRanges();
110
273
  selection.addRange(range);
274
+
275
+ selectedText = selection.toString();
111
276
  }
112
277
 
113
- return selection.toString();
278
+ return selectedText;
114
279
  }
115
280
 
116
281
  module.exports = select;
117
282
 
118
- },{}],5:[function(require,module,exports){
283
+ },{}],7:[function(require,module,exports){
119
284
  function E () {
120
285
  // Keep this empty so it's easier to inherit from
121
286
  // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
@@ -183,7 +348,7 @@ E.prototype = {
183
348
 
184
349
  module.exports = E;
185
350
 
186
- },{}],6:[function(require,module,exports){
351
+ },{}],8:[function(require,module,exports){
187
352
  'use strict';
188
353
 
189
354
  exports.__esModule = true;
@@ -417,7 +582,7 @@ var ClipboardAction = (function () {
417
582
  exports['default'] = ClipboardAction;
418
583
  module.exports = exports['default'];
419
584
 
420
- },{"select":4}],7:[function(require,module,exports){
585
+ },{"select":6}],9:[function(require,module,exports){
421
586
  'use strict';
422
587
 
423
588
  exports.__esModule = true;
@@ -432,16 +597,16 @@ var _clipboardAction = require('./clipboard-action');
432
597
 
433
598
  var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
434
599
 
435
- var _delegate = require('delegate');
436
-
437
- var _delegate2 = _interopRequireDefault(_delegate);
438
-
439
600
  var _tinyEmitter = require('tiny-emitter');
440
601
 
441
602
  var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
442
603
 
604
+ var _goodListener = require('good-listener');
605
+
606
+ var _goodListener2 = _interopRequireDefault(_goodListener);
607
+
443
608
  /**
444
- * Base class which takes a selector, delegates a click event to it,
609
+ * Base class which takes one or more elements, adds event listeners to them,
445
610
  * and instantiates a new `ClipboardAction` on each click.
446
611
  */
447
612
 
@@ -449,17 +614,17 @@ var Clipboard = (function (_Emitter) {
449
614
  _inherits(Clipboard, _Emitter);
450
615
 
451
616
  /**
452
- * @param {String} selector
617
+ * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
453
618
  * @param {Object} options
454
619
  */
455
620
 
456
- function Clipboard(selector, options) {
621
+ function Clipboard(trigger, options) {
457
622
  _classCallCheck(this, Clipboard);
458
623
 
459
624
  _Emitter.call(this);
460
625
 
461
626
  this.resolveOptions(options);
462
- this.delegateClick(selector);
627
+ this.listenClick(trigger);
463
628
  }
464
629
 
465
630
  /**
@@ -483,27 +648,18 @@ var Clipboard = (function (_Emitter) {
483
648
  };
484
649
 
485
650
  /**
486
- * Delegates a click event on the passed selector.
487
- * @param {String} selector
651
+ * Adds a click event listener to the passed trigger.
652
+ * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
488
653
  */
489
654
 
490
- Clipboard.prototype.delegateClick = function delegateClick(selector) {
655
+ Clipboard.prototype.listenClick = function listenClick(trigger) {
491
656
  var _this = this;
492
657
 
493
- this.binding = _delegate2['default'].bind(document.body, selector, 'click', function (e) {
658
+ this.listener = _goodListener2['default'](trigger, 'click', function (e) {
494
659
  return _this.onClick(e);
495
660
  });
496
661
  };
497
662
 
498
- /**
499
- * Undelegates a click event on body.
500
- * @param {String} selector
501
- */
502
-
503
- Clipboard.prototype.undelegateClick = function undelegateClick() {
504
- _delegate2['default'].unbind(document.body, 'click', this.binding);
505
- };
506
-
507
663
  /**
508
664
  * Defines a new `ClipboardAction` on each click event.
509
665
  * @param {Event} e
@@ -515,10 +671,10 @@ var Clipboard = (function (_Emitter) {
515
671
  }
516
672
 
517
673
  this.clipboardAction = new _clipboardAction2['default']({
518
- action: this.action(e.delegateTarget),
519
- target: this.target(e.delegateTarget),
520
- text: this.text(e.delegateTarget),
521
- trigger: e.delegateTarget,
674
+ action: this.action(e.target),
675
+ target: this.target(e.target),
676
+ text: this.text(e.target),
677
+ trigger: e.target,
522
678
  emitter: this
523
679
  });
524
680
  };
@@ -559,7 +715,7 @@ var Clipboard = (function (_Emitter) {
559
715
  */
560
716
 
561
717
  Clipboard.prototype.destroy = function destroy() {
562
- this.undelegateClick();
718
+ this.listener.destroy();
563
719
 
564
720
  if (this.clipboardAction) {
565
721
  this.clipboardAction.destroy();
@@ -583,5 +739,5 @@ function getAttributeValue(suffix, element) {
583
739
  exports['default'] = Clipboard;
584
740
  module.exports = exports['default'];
585
741
 
586
- },{"./clipboard-action":6,"delegate":3,"tiny-emitter":5}]},{},[7])(7)
742
+ },{"./clipboard-action":8,"good-listener":5,"tiny-emitter":7}]},{},[9])(9)
587
743
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammed Sadiq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-24 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler