clipboard-rails 0.1.0 → 1.3.1

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: 2b5b8c9df3fb9d44672d0cb6d668935fd62661e5
4
- data.tar.gz: bff948a4cce224ba0f08d204e2a4cfcf834807b7
3
+ metadata.gz: e750ae5d862a0990d32e9d10b6014749d816a17e
4
+ data.tar.gz: 8a9824e759b9c8a658334450789fb2d74a55a4f6
5
5
  SHA512:
6
- metadata.gz: 04509fd13acd6364ea0e1a6d2b30f0c077a9b6dd1708f060a106949ca8783c87dcdbd636ecf229cbd5b5bafca727ecab689dfaa0a77f7cf2248887e3a996f6b9
7
- data.tar.gz: 7e53bc6def15e2d391c9a5b0f0e167ebfb59e398a3629e08b6684082fcd081c25fdeae53f7dad8fd857cf81ac202e15fa39bd88c3317cc0fce881633e863b36d
6
+ metadata.gz: 0609d812260b58a92e8cc9138b6cb31e0af41a88c51fc84120c16fb6da74f1306da62622f9a301d8520341afa5d8b4414e798101e3b4d789b99866e1fbb03045
7
+ data.tar.gz: f2f413e1615ea0d6da06307813825ebf5e1e765ae535fc2e72ad7bc163f2348aa911b535f746a80575cd1ca878a69006953efb7dab441b1254cfc2732fd078fb
data/.travis.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
3
+ - 2.2.2
4
4
  before_install: gem install bundler -v 1.10.6
@@ -2,6 +2,6 @@ require "clipboard/rails/version"
2
2
 
3
3
  module Clipboard
4
4
  module Rails
5
- # Your code goes here...
5
+ class Engine < ::Rails::Engine; end
6
6
  end
7
7
  end
@@ -1,5 +1,5 @@
1
1
  module Clipboard
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
File without changes
@@ -0,0 +1,578 @@
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+ /**
3
+ * Module dependencies.
4
+ */
5
+
6
+ var closest = require('closest')
7
+ , event = require('component-event');
8
+
9
+ /**
10
+ * Delegate event `type` to `selector`
11
+ * and invoke `fn(e)`. A callback function
12
+ * is returned which may be passed to `.unbind()`.
13
+ *
14
+ * @param {Element} el
15
+ * @param {String} selector
16
+ * @param {String} type
17
+ * @param {Function} fn
18
+ * @param {Boolean} capture
19
+ * @return {Function}
20
+ * @api public
21
+ */
22
+
23
+ // Some events don't bubble, so we want to bind to the capture phase instead
24
+ // when delegating.
25
+ var forceCaptureEvents = ['focus', 'blur'];
26
+
27
+ exports.bind = function(el, selector, type, fn, capture){
28
+ if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
29
+
30
+ return event.bind(el, type, function(e){
31
+ var target = e.target || e.srcElement;
32
+ e.delegateTarget = closest(target, selector, true, el);
33
+ if (e.delegateTarget) fn.call(el, e);
34
+ }, capture);
35
+ };
36
+
37
+ /**
38
+ * Unbind event `type`'s callback `fn`.
39
+ *
40
+ * @param {Element} el
41
+ * @param {String} type
42
+ * @param {Function} fn
43
+ * @param {Boolean} capture
44
+ * @api public
45
+ */
46
+
47
+ exports.unbind = function(el, type, fn, capture){
48
+ if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
49
+
50
+ event.unbind(el, type, fn, capture);
51
+ };
52
+
53
+ },{"closest":2,"component-event":4}],2:[function(require,module,exports){
54
+ var matches = require('matches-selector')
55
+
56
+ module.exports = function (element, selector, checkYoSelf) {
57
+ var parent = checkYoSelf ? element : element.parentNode
58
+
59
+ while (parent && parent !== document) {
60
+ if (matches(parent, selector)) return parent;
61
+ parent = parent.parentNode
62
+ }
63
+ }
64
+
65
+ },{"matches-selector":3}],3:[function(require,module,exports){
66
+
67
+ /**
68
+ * Element prototype.
69
+ */
70
+
71
+ var proto = Element.prototype;
72
+
73
+ /**
74
+ * Vendor function.
75
+ */
76
+
77
+ var vendor = proto.matchesSelector
78
+ || proto.webkitMatchesSelector
79
+ || proto.mozMatchesSelector
80
+ || proto.msMatchesSelector
81
+ || proto.oMatchesSelector;
82
+
83
+ /**
84
+ * Expose `match()`.
85
+ */
86
+
87
+ module.exports = match;
88
+
89
+ /**
90
+ * Match `el` to `selector`.
91
+ *
92
+ * @param {Element} el
93
+ * @param {String} selector
94
+ * @return {Boolean}
95
+ * @api public
96
+ */
97
+
98
+ function match(el, selector) {
99
+ if (vendor) return vendor.call(el, selector);
100
+ var nodes = el.parentNode.querySelectorAll(selector);
101
+ for (var i = 0; i < nodes.length; ++i) {
102
+ if (nodes[i] == el) return true;
103
+ }
104
+ return false;
105
+ }
106
+ },{}],4:[function(require,module,exports){
107
+ var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
108
+ unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
109
+ prefix = bind !== 'addEventListener' ? 'on' : '';
110
+
111
+ /**
112
+ * Bind `el` event `type` to `fn`.
113
+ *
114
+ * @param {Element} el
115
+ * @param {String} type
116
+ * @param {Function} fn
117
+ * @param {Boolean} capture
118
+ * @return {Function}
119
+ * @api public
120
+ */
121
+
122
+ exports.bind = function(el, type, fn, capture){
123
+ el[bind](prefix + type, fn, capture || false);
124
+ return fn;
125
+ };
126
+
127
+ /**
128
+ * Unbind `el` event `type`'s callback `fn`.
129
+ *
130
+ * @param {Element} el
131
+ * @param {String} type
132
+ * @param {Function} fn
133
+ * @param {Boolean} capture
134
+ * @return {Function}
135
+ * @api public
136
+ */
137
+
138
+ exports.unbind = function(el, type, fn, capture){
139
+ el[unbind](prefix + type, fn, capture || false);
140
+ return fn;
141
+ };
142
+ },{}],5:[function(require,module,exports){
143
+ function E () {
144
+ // Keep this empty so it's easier to inherit from
145
+ // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
146
+ }
147
+
148
+ E.prototype = {
149
+ on: function (name, callback, ctx) {
150
+ var e = this.e || (this.e = {});
151
+
152
+ (e[name] || (e[name] = [])).push({
153
+ fn: callback,
154
+ ctx: ctx
155
+ });
156
+
157
+ return this;
158
+ },
159
+
160
+ once: function (name, callback, ctx) {
161
+ var self = this;
162
+ var fn = function () {
163
+ self.off(name, fn);
164
+ callback.apply(ctx, arguments);
165
+ };
166
+
167
+ return this.on(name, fn, ctx);
168
+ },
169
+
170
+ emit: function (name) {
171
+ var data = [].slice.call(arguments, 1);
172
+ var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
173
+ var i = 0;
174
+ var len = evtArr.length;
175
+
176
+ for (i; i < len; i++) {
177
+ evtArr[i].fn.apply(evtArr[i].ctx, data);
178
+ }
179
+
180
+ return this;
181
+ },
182
+
183
+ off: function (name, callback) {
184
+ var e = this.e || (this.e = {});
185
+ var evts = e[name];
186
+ var liveEvents = [];
187
+
188
+ if (evts && callback) {
189
+ for (var i = 0, len = evts.length; i < len; i++) {
190
+ if (evts[i].fn !== callback) liveEvents.push(evts[i]);
191
+ }
192
+ }
193
+
194
+ // Remove event from queue to prevent memory leak
195
+ // Suggested by https://github.com/lazd
196
+ // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
197
+
198
+ (liveEvents.length)
199
+ ? e[name] = liveEvents
200
+ : delete e[name];
201
+
202
+ return this;
203
+ }
204
+ };
205
+
206
+ module.exports = E;
207
+
208
+ },{}],6:[function(require,module,exports){
209
+ /**
210
+ * Inner class which performs selection from either `text` or `target`
211
+ * properties and then executes copy or cut operations.
212
+ */
213
+ 'use strict';
214
+
215
+ exports.__esModule = true;
216
+
217
+ var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
218
+
219
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
220
+
221
+ var ClipboardAction = (function () {
222
+ /**
223
+ * @param {Object} options
224
+ */
225
+
226
+ function ClipboardAction(options) {
227
+ _classCallCheck(this, ClipboardAction);
228
+
229
+ this.resolveOptions(options);
230
+ this.initSelection();
231
+ }
232
+
233
+ /**
234
+ * Defines base properties passed from constructor.
235
+ * @param {Object} options
236
+ */
237
+
238
+ ClipboardAction.prototype.resolveOptions = function resolveOptions() {
239
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
240
+
241
+ this.action = options.action;
242
+ this.emitter = options.emitter;
243
+ this.target = options.target;
244
+ this.text = options.text;
245
+ this.trigger = options.trigger;
246
+
247
+ this.selectedText = '';
248
+ };
249
+
250
+ /**
251
+ * Decides which selection strategy is going to be applied based
252
+ * on the existence of `text` and `target` properties.
253
+ */
254
+
255
+ ClipboardAction.prototype.initSelection = function initSelection() {
256
+ if (this.text && this.target) {
257
+ throw new Error('Multiple attributes declared, use either "target" or "text"');
258
+ } else if (this.text) {
259
+ this.selectFake();
260
+ } else if (this.target) {
261
+ this.selectTarget();
262
+ } else {
263
+ throw new Error('Missing required attributes, use either "target" or "text"');
264
+ }
265
+ };
266
+
267
+ /**
268
+ * Creates a fake input element, sets its value from `text` property,
269
+ * and makes a selection on it.
270
+ */
271
+
272
+ ClipboardAction.prototype.selectFake = function selectFake() {
273
+ var _this = this;
274
+
275
+ this.removeFake();
276
+
277
+ this.fakeHandler = document.body.addEventListener('click', function () {
278
+ return _this.removeFake();
279
+ });
280
+
281
+ this.fakeElem = document.createElement('input');
282
+ this.fakeElem.style.position = 'absolute';
283
+ this.fakeElem.style.left = '-9999px';
284
+ this.fakeElem.setAttribute('readonly', '');
285
+ this.fakeElem.value = this.text;
286
+ this.selectedText = this.text;
287
+
288
+ document.body.appendChild(this.fakeElem);
289
+
290
+ this.fakeElem.select();
291
+ this.copyText();
292
+ };
293
+
294
+ /**
295
+ * Only removes the fake element after another click event, that way
296
+ * an user can hit `Ctrl+C` to copy because selection still exists.
297
+ */
298
+
299
+ ClipboardAction.prototype.removeFake = function removeFake() {
300
+ if (this.fakeHandler) {
301
+ document.body.removeEventListener('click');
302
+ this.fakeHandler = null;
303
+ }
304
+
305
+ if (this.fakeElem) {
306
+ document.body.removeChild(this.fakeElem);
307
+ this.fakeElem = null;
308
+ }
309
+ };
310
+
311
+ /**
312
+ * Selects the content from element passed on `target` property.
313
+ */
314
+
315
+ ClipboardAction.prototype.selectTarget = function selectTarget() {
316
+ if (this.target.nodeName === 'INPUT' || this.target.nodeName === 'TEXTAREA') {
317
+ this.target.select();
318
+ this.selectedText = this.target.value;
319
+ } else {
320
+ var range = document.createRange();
321
+ var selection = window.getSelection();
322
+
323
+ range.selectNodeContents(this.target);
324
+ selection.addRange(range);
325
+ this.selectedText = selection.toString();
326
+ }
327
+
328
+ this.copyText();
329
+ };
330
+
331
+ /**
332
+ * Executes the copy operation based on the current selection.
333
+ */
334
+
335
+ ClipboardAction.prototype.copyText = function copyText() {
336
+ var succeeded = undefined;
337
+
338
+ try {
339
+ succeeded = document.execCommand(this.action);
340
+ } catch (err) {
341
+ succeeded = false;
342
+ }
343
+
344
+ this.handleResult(succeeded);
345
+ };
346
+
347
+ /**
348
+ * Fires an event based on the copy operation result.
349
+ * @param {Boolean} succeeded
350
+ */
351
+
352
+ ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
353
+ if (succeeded) {
354
+ this.emitter.emit('success', {
355
+ action: this.action,
356
+ text: this.selectedText,
357
+ trigger: this.trigger,
358
+ clearSelection: this.clearSelection.bind(this)
359
+ });
360
+ } else {
361
+ this.emitter.emit('error', {
362
+ action: this.action,
363
+ trigger: this.trigger,
364
+ clearSelection: this.clearSelection.bind(this)
365
+ });
366
+ }
367
+ };
368
+
369
+ /**
370
+ * Removes current selection and focus from `target` element.
371
+ */
372
+
373
+ ClipboardAction.prototype.clearSelection = function clearSelection() {
374
+ if (this.target) {
375
+ this.target.blur();
376
+ }
377
+
378
+ window.getSelection().removeAllRanges();
379
+ };
380
+
381
+ /**
382
+ * Sets the `action` to be performed which can be either 'copy' or 'cut'.
383
+ * @param {String} action
384
+ */
385
+
386
+ _createClass(ClipboardAction, [{
387
+ key: 'action',
388
+ set: function set() {
389
+ var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
390
+
391
+ this._action = action;
392
+
393
+ if (this._action !== 'copy' && this._action !== 'cut') {
394
+ throw new Error('Invalid "action" value, use either "copy" or "cut"');
395
+ }
396
+ },
397
+
398
+ /**
399
+ * Gets the `action` property.
400
+ * @return {String}
401
+ */
402
+ get: function get() {
403
+ return this._action;
404
+ }
405
+
406
+ /**
407
+ * Sets the `target` property using an element
408
+ * that will be have its content copied.
409
+ * @param {Element} target
410
+ */
411
+ }, {
412
+ key: 'target',
413
+ set: function set(target) {
414
+ if (target !== undefined) {
415
+ if (target && typeof target === 'object' && target.nodeType === 1) {
416
+ this._target = target;
417
+ } else {
418
+ throw new Error('Invalid "target" value, use a valid Element');
419
+ }
420
+ }
421
+ },
422
+
423
+ /**
424
+ * Gets the `target` property.
425
+ * @return {String|HTMLElement}
426
+ */
427
+ get: function get() {
428
+ return this._target;
429
+ }
430
+ }]);
431
+
432
+ return ClipboardAction;
433
+ })();
434
+
435
+ exports['default'] = ClipboardAction;
436
+ module.exports = exports['default'];
437
+
438
+ },{}],7:[function(require,module,exports){
439
+ 'use strict';
440
+
441
+ exports.__esModule = true;
442
+
443
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
444
+
445
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
446
+
447
+ function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
448
+
449
+ var _clipboardAction = require('./clipboard-action');
450
+
451
+ var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
452
+
453
+ var _delegateEvents = require('delegate-events');
454
+
455
+ var _delegateEvents2 = _interopRequireDefault(_delegateEvents);
456
+
457
+ var _tinyEmitter = require('tiny-emitter');
458
+
459
+ var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
460
+
461
+ var prefix = 'data-clipboard-';
462
+
463
+ /**
464
+ * Base class which takes a selector, delegates a click event to it,
465
+ * and instantiates a new `ClipboardAction` on each click.
466
+ */
467
+
468
+ var Clipboard = (function (_Emitter) {
469
+ _inherits(Clipboard, _Emitter);
470
+
471
+ /**
472
+ * @param {String} selector
473
+ * @param {Object} options
474
+ */
475
+
476
+ function Clipboard(selector, options) {
477
+ _classCallCheck(this, Clipboard);
478
+
479
+ _Emitter.call(this);
480
+
481
+ this.resolveOptions(options);
482
+ this.delegateClick(selector);
483
+ }
484
+
485
+ /**
486
+ * Defines if attributes would be resolved using internal setter functions
487
+ * or custom functions that were passed in the constructor.
488
+ * @param {Object} options
489
+ */
490
+
491
+ Clipboard.prototype.resolveOptions = function resolveOptions() {
492
+ var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
493
+
494
+ this.action = typeof options.action === 'function' ? options.action : this.setAction;
495
+ this.target = typeof options.target === 'function' ? options.target : this.setTarget;
496
+ this.text = typeof options.text === 'function' ? options.text : this.setText;
497
+ };
498
+
499
+ /**
500
+ * Delegates a click event on the passed selector.
501
+ * @param {String} selector
502
+ */
503
+
504
+ Clipboard.prototype.delegateClick = function delegateClick(selector) {
505
+ var _this = this;
506
+
507
+ _delegateEvents2['default'].bind(document.body, selector, 'click', function (e) {
508
+ return _this.initialize(e);
509
+ });
510
+ };
511
+
512
+ /**
513
+ * Defines a new `ClipboardAction` on each click event.
514
+ * @param {Event} e
515
+ */
516
+
517
+ Clipboard.prototype.initialize = function initialize(e) {
518
+ if (this.clipboardAction) {
519
+ this.clipboardAction = null;
520
+ }
521
+
522
+ this.clipboardAction = new _clipboardAction2['default']({
523
+ action: this.action(e.delegateTarget),
524
+ target: this.target(e.delegateTarget),
525
+ text: this.text(e.delegateTarget),
526
+ trigger: e.delegateTarget,
527
+ emitter: this
528
+ });
529
+ };
530
+
531
+ /**
532
+ * Sets the `action` lookup function.
533
+ * @param {Element} trigger
534
+ */
535
+
536
+ Clipboard.prototype.setAction = function setAction(trigger) {
537
+ if (!trigger.hasAttribute(prefix + 'action')) {
538
+ return;
539
+ }
540
+
541
+ return trigger.getAttribute(prefix + 'action');
542
+ };
543
+
544
+ /**
545
+ * Sets the `target` lookup function.
546
+ * @param {Element} trigger
547
+ */
548
+
549
+ Clipboard.prototype.setTarget = function setTarget(trigger) {
550
+ if (!trigger.hasAttribute(prefix + 'target')) {
551
+ return;
552
+ }
553
+
554
+ var target = trigger.getAttribute(prefix + 'target');
555
+ return document.querySelector(target);
556
+ };
557
+
558
+ /**
559
+ * Sets the `text` lookup function.
560
+ * @param {Element} trigger
561
+ */
562
+
563
+ Clipboard.prototype.setText = function setText(trigger) {
564
+ if (!trigger.hasAttribute(prefix + 'text')) {
565
+ return;
566
+ }
567
+
568
+ return trigger.getAttribute(prefix + 'text');
569
+ };
570
+
571
+ return Clipboard;
572
+ })(_tinyEmitter2['default']);
573
+
574
+ exports['default'] = Clipboard;
575
+ module.exports = exports['default'];
576
+
577
+ },{"./clipboard-action":6,"delegate-events":1,"tiny-emitter":5}]},{},[7])(7)
578
+ });
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammed Sadiq
@@ -57,6 +57,9 @@ files:
57
57
  - clipboard-rails.gemspec
58
58
  - lib/clipboard/rails.rb
59
59
  - lib/clipboard/rails/version.rb
60
+ - vendor/assets/javascripts/.keep
61
+ - vendor/assets/javascripts/clipboard.js
62
+ - vendor/assets/stylesheets/.keep
60
63
  homepage: https://github.com/sadiqmmm/clipboard-rails
61
64
  licenses:
62
65
  - MIT