clipboard-toastr-rails 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ffb0f8d8f3febe84b7e7dd48f94b60f87466546
4
- data.tar.gz: 1bb640f72c92893e5bdc56ddbeb25ae86aba470b
3
+ metadata.gz: a95c86654413ab317f0ce0a136b20f693a1d7639
4
+ data.tar.gz: 694a39fd4f04dfabc7ee79d64a6688dcb3adb5a7
5
5
  SHA512:
6
- metadata.gz: 52bfe7cd7e788ccc851fff7e235363218073b0995dbcc649c0df2c9ff106049f132b21e0a637123470e84d9d9fdde1824c1f3d93eea64a35dca56bd7a0bd9084
7
- data.tar.gz: 7b01493a2e9ba28126ddb209fdb8821c8156a69b26d467355add9691297debb12def008f388a1f6e544a26680034108a445651aa4393f5a1f0531bab132c5a7c
6
+ metadata.gz: 673b1ff23d1f38a08e0f178fa05304429f2870a23a2cf011684a011be0b119805f96880e197d898f9d59d12c06c65d3a875b3f7ace4e5a0f34ab5c2430812af4
7
+ data.tar.gz: 5b6ad9ae282477ee765b4e5b284f3c20991bb854712b30ba585b0e644201434d4d388bb1ff99a40c6907bf28efea878b07d77ea72cefdc302184f550695fdca5
data/README.md CHANGED
@@ -68,8 +68,23 @@ $(document).ready(function(){
68
68
  ....
69
69
  }
70
70
 
71
- $(".copy-target").click ->
71
+ $(".copy-target").click(function() {
72
72
  toastr.info "Copy Success Alert"
73
+ });
74
+
75
+ target_clip = new Clipboard('.copy-target1')
76
+
77
+ toastr.options = {
78
+ "positionClass": "toast-top-center",
79
+ ....
80
+ ....
81
+ }
82
+
83
+ $(".copy-target1").click(function() {
84
+ toastr.info "Copy Success Alert"
85
+ });
86
+
87
+
73
88
 
74
89
 
75
90
  });
@@ -86,6 +101,13 @@ $(document).ready(function(){
86
101
  ...
87
102
  ...
88
103
 
104
+ <input id="copy-content" value="This is Copy Content"/>
105
+
106
+ <span class="copy-target1" data-clipboard-target="#copy-content">Copy This Content</span>
107
+
108
+ ...
109
+ ...
110
+
89
111
  <span class="copy-target" data-clipboard-text="COPY CONTENT">Copy Link</span>
90
112
 
91
113
  ...
@@ -102,12 +124,14 @@ $(document).ready(function(){
102
124
  ## Full documentation
103
125
 
104
126
  The Documentation is at
127
+
105
128
  [Clipboard.js Document](https://clipboardjs.com/)
129
+
106
130
  [Toastr Document](http://codeseven.github.io/toastr/)
107
131
 
108
132
  ## Change Log
109
133
 
110
- Current Version 1.0.0
134
+ Current Version 1.2.0
111
135
 
112
136
  This link listing [Change Log](https://github.com/ggomagundan/clipboard-toastr-rails/blob/master/CHANGE_LOG.md)
113
137
 
@@ -1,5 +1,5 @@
1
1
  module ClipboardToastr
2
2
  module Rails
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -1,7 +1,778 @@
1
1
  /*!
2
- * clipboard.js v1.5.15
2
+ * clipboard.js v1.6.0
3
3
  * https://zenorocha.github.io/clipboard.js
4
4
  *
5
5
  * Licensed MIT © Zeno Rocha
6
6
  */
7
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Clipboard=e()}}(function(){var e,t,n;return function e(t,n,i){function o(a,c){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!c&&l)return l(a,!0);if(r)return r(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var u=n[a]={exports:{}};t[a][0].call(u.exports,function(e){var n=t[a][1][e];return o(n?n:e)},u,u.exports,e,t,n,i)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a<i.length;a++)o(i[a]);return o}({1:[function(e,t,n){function i(e,t){for(;e&&e!==document;){if(e.matches(t))return e;e=e.parentNode}}if(Element&&!Element.prototype.matches){var o=Element.prototype;o.matches=o.matchesSelector||o.mozMatchesSelector||o.msMatchesSelector||o.oMatchesSelector||o.webkitMatchesSelector}t.exports=i},{}],2:[function(e,t,n){function i(e,t,n,i,r){var a=o.apply(this,arguments);return e.addEventListener(n,a,r),{destroy:function(){e.removeEventListener(n,a,r)}}}function o(e,t,n,i){return function(n){n.delegateTarget=r(n.target,t),n.delegateTarget&&i.call(e,n)}}var r=e("./closest");t.exports=i},{"./closest":1}],3:[function(e,t,n){n.node=function(e){return void 0!==e&&e instanceof HTMLElement&&1===e.nodeType},n.nodeList=function(e){var t=Object.prototype.toString.call(e);return void 0!==e&&("[object NodeList]"===t||"[object HTMLCollection]"===t)&&"length"in e&&(0===e.length||n.node(e[0]))},n.string=function(e){return"string"==typeof e||e instanceof String},n.fn=function(e){var t=Object.prototype.toString.call(e);return"[object Function]"===t}},{}],4:[function(e,t,n){function i(e,t,n){if(!e&&!t&&!n)throw new Error("Missing required arguments");if(!c.string(t))throw new TypeError("Second argument must be a String");if(!c.fn(n))throw new TypeError("Third argument must be a Function");if(c.node(e))return o(e,t,n);if(c.nodeList(e))return r(e,t,n);if(c.string(e))return a(e,t,n);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function o(e,t,n){return e.addEventListener(t,n),{destroy:function(){e.removeEventListener(t,n)}}}function r(e,t,n){return Array.prototype.forEach.call(e,function(e){e.addEventListener(t,n)}),{destroy:function(){Array.prototype.forEach.call(e,function(e){e.removeEventListener(t,n)})}}}function a(e,t,n){return l(document.body,e,t,n)}var c=e("./is"),l=e("delegate");t.exports=i},{"./is":3,delegate:2}],5:[function(e,t,n){function i(e){var t;if("SELECT"===e.nodeName)e.focus(),t=e.value;else if("INPUT"===e.nodeName||"TEXTAREA"===e.nodeName)e.focus(),e.setSelectionRange(0,e.value.length),t=e.value;else{e.hasAttribute("contenteditable")&&e.focus();var n=window.getSelection(),i=document.createRange();i.selectNodeContents(e),n.removeAllRanges(),n.addRange(i),t=n.toString()}return t}t.exports=i},{}],6:[function(e,t,n){function i(){}i.prototype={on:function(e,t,n){var i=this.e||(this.e={});return(i[e]||(i[e]=[])).push({fn:t,ctx:n}),this},once:function(e,t,n){function i(){o.off(e,i),t.apply(n,arguments)}var o=this;return i._=t,this.on(e,i,n)},emit:function(e){var t=[].slice.call(arguments,1),n=((this.e||(this.e={}))[e]||[]).slice(),i=0,o=n.length;for(i;i<o;i++)n[i].fn.apply(n[i].ctx,t);return this},off:function(e,t){var n=this.e||(this.e={}),i=n[e],o=[];if(i&&t)for(var r=0,a=i.length;r<a;r++)i[r].fn!==t&&i[r].fn._!==t&&o.push(i[r]);return o.length?n[e]=o:delete n[e],this}},t.exports=i},{}],7:[function(t,n,i){!function(o,r){if("function"==typeof e&&e.amd)e(["module","select"],r);else if("undefined"!=typeof i)r(n,t("select"));else{var a={exports:{}};r(a,o.select),o.clipboardAction=a.exports}}(this,function(e,t){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=n(t),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),c=function(){function e(t){i(this,e),this.resolveOptions(t),this.initSelection()}return a(e,[{key:"resolveOptions",value:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function e(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function e(){var t=this,n="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=document.body.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[n?"right":"left"]="-9999px";var i=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.addEventListener("focus",window.scrollTo(0,i)),this.fakeElem.style.top=i+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,document.body.appendChild(this.fakeElem),this.selectedText=(0,o.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function e(){this.fakeHandler&&(document.body.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function e(){this.selectedText=(0,o.default)(this.target),this.copyText()}},{key:"copyText",value:function e(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function e(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function e(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function e(){this.removeFake()}},{key:"action",set:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function e(){return this._action}},{key:"target",set:function e(t){if(void 0!==t){if(!t||"object"!==("undefined"==typeof t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function e(){return this._target}}]),e}();e.exports=c})},{select:5}],8:[function(t,n,i){!function(o,r){if("function"==typeof e&&e.amd)e(["module","./clipboard-action","tiny-emitter","good-listener"],r);else if("undefined"!=typeof i)r(n,t("./clipboard-action"),t("tiny-emitter"),t("good-listener"));else{var a={exports:{}};r(a,o.clipboardAction,o.tinyEmitter,o.goodListener),o.clipboard=a.exports}}(this,function(e,t,n,i){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function l(e,t){var n="data-clipboard-"+e;if(t.hasAttribute(n))return t.getAttribute(n)}var s=o(t),u=o(n),f=o(i),d=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),h=function(e){function t(e,n){r(this,t);var i=a(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.resolveOptions(n),i.listenClick(e),i}return c(t,e),d(t,[{key:"resolveOptions",value:function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText}},{key:"listenClick",value:function e(t){var n=this;this.listener=(0,f.default)(t,"click",function(e){return n.onClick(e)})}},{key:"onClick",value:function e(t){var n=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new s.default({action:this.action(n),target:this.target(n),text:this.text(n),trigger:n,emitter:this})}},{key:"defaultAction",value:function e(t){return l("action",t)}},{key:"defaultTarget",value:function e(t){var n=l("target",t);if(n)return document.querySelector(n)}},{key:"defaultText",value:function e(t){return l("text",t)}},{key:"destroy",value:function e(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}]),t}(u.default);e.exports=h})},{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)});
7
+ (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){
8
+ var DOCUMENT_NODE_TYPE = 9;
9
+
10
+ /**
11
+ * A polyfill for Element.matches()
12
+ */
13
+ if (Element && !Element.prototype.matches) {
14
+ var proto = Element.prototype;
15
+
16
+ proto.matches = proto.matchesSelector ||
17
+ proto.mozMatchesSelector ||
18
+ proto.msMatchesSelector ||
19
+ proto.oMatchesSelector ||
20
+ proto.webkitMatchesSelector;
21
+ }
22
+
23
+ /**
24
+ * Finds the closest parent that matches a selector.
25
+ *
26
+ * @param {Element} element
27
+ * @param {String} selector
28
+ * @return {Function}
29
+ */
30
+ function closest (element, selector) {
31
+ while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
32
+ if (element.matches(selector)) return element;
33
+ element = element.parentNode;
34
+ }
35
+ }
36
+
37
+ module.exports = closest;
38
+
39
+ },{}],2:[function(require,module,exports){
40
+ var closest = require('./closest');
41
+
42
+ /**
43
+ * Delegates event to a selector.
44
+ *
45
+ * @param {Element} element
46
+ * @param {String} selector
47
+ * @param {String} type
48
+ * @param {Function} callback
49
+ * @param {Boolean} useCapture
50
+ * @return {Object}
51
+ */
52
+ function delegate(element, selector, type, callback, useCapture) {
53
+ var listenerFn = listener.apply(this, arguments);
54
+
55
+ element.addEventListener(type, listenerFn, useCapture);
56
+
57
+ return {
58
+ destroy: function() {
59
+ element.removeEventListener(type, listenerFn, useCapture);
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Finds closest match and invokes callback.
66
+ *
67
+ * @param {Element} element
68
+ * @param {String} selector
69
+ * @param {String} type
70
+ * @param {Function} callback
71
+ * @return {Function}
72
+ */
73
+ function listener(element, selector, type, callback) {
74
+ return function(e) {
75
+ e.delegateTarget = closest(e.target, selector);
76
+
77
+ if (e.delegateTarget) {
78
+ callback.call(element, e);
79
+ }
80
+ }
81
+ }
82
+
83
+ module.exports = delegate;
84
+
85
+ },{"./closest":1}],3:[function(require,module,exports){
86
+ /**
87
+ * Check if argument is a HTML element.
88
+ *
89
+ * @param {Object} value
90
+ * @return {Boolean}
91
+ */
92
+ exports.node = function(value) {
93
+ return value !== undefined
94
+ && value instanceof HTMLElement
95
+ && value.nodeType === 1;
96
+ };
97
+
98
+ /**
99
+ * Check if argument is a list of HTML elements.
100
+ *
101
+ * @param {Object} value
102
+ * @return {Boolean}
103
+ */
104
+ exports.nodeList = function(value) {
105
+ var type = Object.prototype.toString.call(value);
106
+
107
+ return value !== undefined
108
+ && (type === '[object NodeList]' || type === '[object HTMLCollection]')
109
+ && ('length' in value)
110
+ && (value.length === 0 || exports.node(value[0]));
111
+ };
112
+
113
+ /**
114
+ * Check if argument is a string.
115
+ *
116
+ * @param {Object} value
117
+ * @return {Boolean}
118
+ */
119
+ exports.string = function(value) {
120
+ return typeof value === 'string'
121
+ || value instanceof String;
122
+ };
123
+
124
+ /**
125
+ * Check if argument is a function.
126
+ *
127
+ * @param {Object} value
128
+ * @return {Boolean}
129
+ */
130
+ exports.fn = function(value) {
131
+ var type = Object.prototype.toString.call(value);
132
+
133
+ return type === '[object Function]';
134
+ };
135
+
136
+ },{}],4:[function(require,module,exports){
137
+ var is = require('./is');
138
+ var delegate = require('delegate');
139
+
140
+ /**
141
+ * Validates all params and calls the right
142
+ * listener function based on its target type.
143
+ *
144
+ * @param {String|HTMLElement|HTMLCollection|NodeList} target
145
+ * @param {String} type
146
+ * @param {Function} callback
147
+ * @return {Object}
148
+ */
149
+ function listen(target, type, callback) {
150
+ if (!target && !type && !callback) {
151
+ throw new Error('Missing required arguments');
152
+ }
153
+
154
+ if (!is.string(type)) {
155
+ throw new TypeError('Second argument must be a String');
156
+ }
157
+
158
+ if (!is.fn(callback)) {
159
+ throw new TypeError('Third argument must be a Function');
160
+ }
161
+
162
+ if (is.node(target)) {
163
+ return listenNode(target, type, callback);
164
+ }
165
+ else if (is.nodeList(target)) {
166
+ return listenNodeList(target, type, callback);
167
+ }
168
+ else if (is.string(target)) {
169
+ return listenSelector(target, type, callback);
170
+ }
171
+ else {
172
+ throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Adds an event listener to a HTML element
178
+ * and returns a remove listener function.
179
+ *
180
+ * @param {HTMLElement} node
181
+ * @param {String} type
182
+ * @param {Function} callback
183
+ * @return {Object}
184
+ */
185
+ function listenNode(node, type, callback) {
186
+ node.addEventListener(type, callback);
187
+
188
+ return {
189
+ destroy: function() {
190
+ node.removeEventListener(type, callback);
191
+ }
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Add an event listener to a list of HTML elements
197
+ * and returns a remove listener function.
198
+ *
199
+ * @param {NodeList|HTMLCollection} nodeList
200
+ * @param {String} type
201
+ * @param {Function} callback
202
+ * @return {Object}
203
+ */
204
+ function listenNodeList(nodeList, type, callback) {
205
+ Array.prototype.forEach.call(nodeList, function(node) {
206
+ node.addEventListener(type, callback);
207
+ });
208
+
209
+ return {
210
+ destroy: function() {
211
+ Array.prototype.forEach.call(nodeList, function(node) {
212
+ node.removeEventListener(type, callback);
213
+ });
214
+ }
215
+ }
216
+ }
217
+
218
+ /**
219
+ * Add an event listener to a selector
220
+ * and returns a remove listener function.
221
+ *
222
+ * @param {String} selector
223
+ * @param {String} type
224
+ * @param {Function} callback
225
+ * @return {Object}
226
+ */
227
+ function listenSelector(selector, type, callback) {
228
+ return delegate(document.body, selector, type, callback);
229
+ }
230
+
231
+ module.exports = listen;
232
+
233
+ },{"./is":3,"delegate":2}],5:[function(require,module,exports){
234
+ function select(element) {
235
+ var selectedText;
236
+
237
+ if (element.nodeName === 'SELECT') {
238
+ element.focus();
239
+
240
+ selectedText = element.value;
241
+ }
242
+ else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
243
+ var isReadOnly = element.hasAttribute('readonly');
244
+
245
+ if (!isReadOnly) {
246
+ element.setAttribute('readonly', '');
247
+ }
248
+
249
+ element.select();
250
+ element.setSelectionRange(0, element.value.length);
251
+
252
+ if (!isReadOnly) {
253
+ element.removeAttribute('readonly');
254
+ }
255
+
256
+ selectedText = element.value;
257
+ }
258
+ else {
259
+ if (element.hasAttribute('contenteditable')) {
260
+ element.focus();
261
+ }
262
+
263
+ var selection = window.getSelection();
264
+ var range = document.createRange();
265
+
266
+ range.selectNodeContents(element);
267
+ selection.removeAllRanges();
268
+ selection.addRange(range);
269
+
270
+ selectedText = selection.toString();
271
+ }
272
+
273
+ return selectedText;
274
+ }
275
+
276
+ module.exports = select;
277
+
278
+ },{}],6:[function(require,module,exports){
279
+ function E () {
280
+ // Keep this empty so it's easier to inherit from
281
+ // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
282
+ }
283
+
284
+ E.prototype = {
285
+ on: function (name, callback, ctx) {
286
+ var e = this.e || (this.e = {});
287
+
288
+ (e[name] || (e[name] = [])).push({
289
+ fn: callback,
290
+ ctx: ctx
291
+ });
292
+
293
+ return this;
294
+ },
295
+
296
+ once: function (name, callback, ctx) {
297
+ var self = this;
298
+ function listener () {
299
+ self.off(name, listener);
300
+ callback.apply(ctx, arguments);
301
+ };
302
+
303
+ listener._ = callback
304
+ return this.on(name, listener, ctx);
305
+ },
306
+
307
+ emit: function (name) {
308
+ var data = [].slice.call(arguments, 1);
309
+ var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
310
+ var i = 0;
311
+ var len = evtArr.length;
312
+
313
+ for (i; i < len; i++) {
314
+ evtArr[i].fn.apply(evtArr[i].ctx, data);
315
+ }
316
+
317
+ return this;
318
+ },
319
+
320
+ off: function (name, callback) {
321
+ var e = this.e || (this.e = {});
322
+ var evts = e[name];
323
+ var liveEvents = [];
324
+
325
+ if (evts && callback) {
326
+ for (var i = 0, len = evts.length; i < len; i++) {
327
+ if (evts[i].fn !== callback && evts[i].fn._ !== callback)
328
+ liveEvents.push(evts[i]);
329
+ }
330
+ }
331
+
332
+ // Remove event from queue to prevent memory leak
333
+ // Suggested by https://github.com/lazd
334
+ // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
335
+
336
+ (liveEvents.length)
337
+ ? e[name] = liveEvents
338
+ : delete e[name];
339
+
340
+ return this;
341
+ }
342
+ };
343
+
344
+ module.exports = E;
345
+
346
+ },{}],7:[function(require,module,exports){
347
+ (function (global, factory) {
348
+ if (typeof define === "function" && define.amd) {
349
+ define(['module', 'select'], factory);
350
+ } else if (typeof exports !== "undefined") {
351
+ factory(module, require('select'));
352
+ } else {
353
+ var mod = {
354
+ exports: {}
355
+ };
356
+ factory(mod, global.select);
357
+ global.clipboardAction = mod.exports;
358
+ }
359
+ })(this, function (module, _select) {
360
+ 'use strict';
361
+
362
+ var _select2 = _interopRequireDefault(_select);
363
+
364
+ function _interopRequireDefault(obj) {
365
+ return obj && obj.__esModule ? obj : {
366
+ default: obj
367
+ };
368
+ }
369
+
370
+ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
371
+ return typeof obj;
372
+ } : function (obj) {
373
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
374
+ };
375
+
376
+ function _classCallCheck(instance, Constructor) {
377
+ if (!(instance instanceof Constructor)) {
378
+ throw new TypeError("Cannot call a class as a function");
379
+ }
380
+ }
381
+
382
+ var _createClass = function () {
383
+ function defineProperties(target, props) {
384
+ for (var i = 0; i < props.length; i++) {
385
+ var descriptor = props[i];
386
+ descriptor.enumerable = descriptor.enumerable || false;
387
+ descriptor.configurable = true;
388
+ if ("value" in descriptor) descriptor.writable = true;
389
+ Object.defineProperty(target, descriptor.key, descriptor);
390
+ }
391
+ }
392
+
393
+ return function (Constructor, protoProps, staticProps) {
394
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
395
+ if (staticProps) defineProperties(Constructor, staticProps);
396
+ return Constructor;
397
+ };
398
+ }();
399
+
400
+ var ClipboardAction = function () {
401
+ /**
402
+ * @param {Object} options
403
+ */
404
+ function ClipboardAction(options) {
405
+ _classCallCheck(this, ClipboardAction);
406
+
407
+ this.resolveOptions(options);
408
+ this.initSelection();
409
+ }
410
+
411
+ /**
412
+ * Defines base properties passed from constructor.
413
+ * @param {Object} options
414
+ */
415
+
416
+
417
+ _createClass(ClipboardAction, [{
418
+ key: 'resolveOptions',
419
+ value: function resolveOptions() {
420
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
421
+
422
+ this.action = options.action;
423
+ this.emitter = options.emitter;
424
+ this.target = options.target;
425
+ this.text = options.text;
426
+ this.trigger = options.trigger;
427
+
428
+ this.selectedText = '';
429
+ }
430
+ }, {
431
+ key: 'initSelection',
432
+ value: function initSelection() {
433
+ if (this.text) {
434
+ this.selectFake();
435
+ } else if (this.target) {
436
+ this.selectTarget();
437
+ }
438
+ }
439
+ }, {
440
+ key: 'selectFake',
441
+ value: function selectFake() {
442
+ var _this = this;
443
+
444
+ var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
445
+
446
+ this.removeFake();
447
+
448
+ this.fakeHandlerCallback = function () {
449
+ return _this.removeFake();
450
+ };
451
+ this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true;
452
+
453
+ this.fakeElem = document.createElement('textarea');
454
+ // Prevent zooming on iOS
455
+ this.fakeElem.style.fontSize = '12pt';
456
+ // Reset box model
457
+ this.fakeElem.style.border = '0';
458
+ this.fakeElem.style.padding = '0';
459
+ this.fakeElem.style.margin = '0';
460
+ // Move element out of screen horizontally
461
+ this.fakeElem.style.position = 'absolute';
462
+ this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
463
+ // Move element to the same position vertically
464
+ var yPosition = window.pageYOffset || document.documentElement.scrollTop;
465
+ this.fakeElem.style.top = yPosition + 'px';
466
+
467
+ this.fakeElem.setAttribute('readonly', '');
468
+ this.fakeElem.value = this.text;
469
+
470
+ document.body.appendChild(this.fakeElem);
471
+
472
+ this.selectedText = (0, _select2.default)(this.fakeElem);
473
+ this.copyText();
474
+ }
475
+ }, {
476
+ key: 'removeFake',
477
+ value: function removeFake() {
478
+ if (this.fakeHandler) {
479
+ document.body.removeEventListener('click', this.fakeHandlerCallback);
480
+ this.fakeHandler = null;
481
+ this.fakeHandlerCallback = null;
482
+ }
483
+
484
+ if (this.fakeElem) {
485
+ document.body.removeChild(this.fakeElem);
486
+ this.fakeElem = null;
487
+ }
488
+ }
489
+ }, {
490
+ key: 'selectTarget',
491
+ value: function selectTarget() {
492
+ this.selectedText = (0, _select2.default)(this.target);
493
+ this.copyText();
494
+ }
495
+ }, {
496
+ key: 'copyText',
497
+ value: function copyText() {
498
+ var succeeded = void 0;
499
+
500
+ try {
501
+ succeeded = document.execCommand(this.action);
502
+ } catch (err) {
503
+ succeeded = false;
504
+ }
505
+
506
+ this.handleResult(succeeded);
507
+ }
508
+ }, {
509
+ key: 'handleResult',
510
+ value: function handleResult(succeeded) {
511
+ this.emitter.emit(succeeded ? 'success' : 'error', {
512
+ action: this.action,
513
+ text: this.selectedText,
514
+ trigger: this.trigger,
515
+ clearSelection: this.clearSelection.bind(this)
516
+ });
517
+ }
518
+ }, {
519
+ key: 'clearSelection',
520
+ value: function clearSelection() {
521
+ if (this.target) {
522
+ this.target.blur();
523
+ }
524
+
525
+ window.getSelection().removeAllRanges();
526
+ }
527
+ }, {
528
+ key: 'destroy',
529
+ value: function destroy() {
530
+ this.removeFake();
531
+ }
532
+ }, {
533
+ key: 'action',
534
+ set: function set() {
535
+ var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
536
+
537
+ this._action = action;
538
+
539
+ if (this._action !== 'copy' && this._action !== 'cut') {
540
+ throw new Error('Invalid "action" value, use either "copy" or "cut"');
541
+ }
542
+ },
543
+ get: function get() {
544
+ return this._action;
545
+ }
546
+ }, {
547
+ key: 'target',
548
+ set: function set(target) {
549
+ if (target !== undefined) {
550
+ if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
551
+ if (this.action === 'copy' && target.hasAttribute('disabled')) {
552
+ throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
553
+ }
554
+
555
+ if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
556
+ throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
557
+ }
558
+
559
+ this._target = target;
560
+ } else {
561
+ throw new Error('Invalid "target" value, use a valid Element');
562
+ }
563
+ }
564
+ },
565
+ get: function get() {
566
+ return this._target;
567
+ }
568
+ }]);
569
+
570
+ return ClipboardAction;
571
+ }();
572
+
573
+ module.exports = ClipboardAction;
574
+ });
575
+
576
+ },{"select":5}],8:[function(require,module,exports){
577
+ (function (global, factory) {
578
+ if (typeof define === "function" && define.amd) {
579
+ define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
580
+ } else if (typeof exports !== "undefined") {
581
+ factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
582
+ } else {
583
+ var mod = {
584
+ exports: {}
585
+ };
586
+ factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
587
+ global.clipboard = mod.exports;
588
+ }
589
+ })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
590
+ 'use strict';
591
+
592
+ var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
593
+
594
+ var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
595
+
596
+ var _goodListener2 = _interopRequireDefault(_goodListener);
597
+
598
+ function _interopRequireDefault(obj) {
599
+ return obj && obj.__esModule ? obj : {
600
+ default: obj
601
+ };
602
+ }
603
+
604
+ function _classCallCheck(instance, Constructor) {
605
+ if (!(instance instanceof Constructor)) {
606
+ throw new TypeError("Cannot call a class as a function");
607
+ }
608
+ }
609
+
610
+ var _createClass = function () {
611
+ function defineProperties(target, props) {
612
+ for (var i = 0; i < props.length; i++) {
613
+ var descriptor = props[i];
614
+ descriptor.enumerable = descriptor.enumerable || false;
615
+ descriptor.configurable = true;
616
+ if ("value" in descriptor) descriptor.writable = true;
617
+ Object.defineProperty(target, descriptor.key, descriptor);
618
+ }
619
+ }
620
+
621
+ return function (Constructor, protoProps, staticProps) {
622
+ if (protoProps) defineProperties(Constructor.prototype, protoProps);
623
+ if (staticProps) defineProperties(Constructor, staticProps);
624
+ return Constructor;
625
+ };
626
+ }();
627
+
628
+ function _possibleConstructorReturn(self, call) {
629
+ if (!self) {
630
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
631
+ }
632
+
633
+ return call && (typeof call === "object" || typeof call === "function") ? call : self;
634
+ }
635
+
636
+ function _inherits(subClass, superClass) {
637
+ if (typeof superClass !== "function" && superClass !== null) {
638
+ throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
639
+ }
640
+
641
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
642
+ constructor: {
643
+ value: subClass,
644
+ enumerable: false,
645
+ writable: true,
646
+ configurable: true
647
+ }
648
+ });
649
+ if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
650
+ }
651
+
652
+ var Clipboard = function (_Emitter) {
653
+ _inherits(Clipboard, _Emitter);
654
+
655
+ /**
656
+ * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
657
+ * @param {Object} options
658
+ */
659
+ function Clipboard(trigger, options) {
660
+ _classCallCheck(this, Clipboard);
661
+
662
+ var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
663
+
664
+ _this.resolveOptions(options);
665
+ _this.listenClick(trigger);
666
+ return _this;
667
+ }
668
+
669
+ /**
670
+ * Defines if attributes would be resolved using internal setter functions
671
+ * or custom functions that were passed in the constructor.
672
+ * @param {Object} options
673
+ */
674
+
675
+
676
+ _createClass(Clipboard, [{
677
+ key: 'resolveOptions',
678
+ value: function resolveOptions() {
679
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
680
+
681
+ this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
682
+ this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
683
+ this.text = typeof options.text === 'function' ? options.text : this.defaultText;
684
+ }
685
+ }, {
686
+ key: 'listenClick',
687
+ value: function listenClick(trigger) {
688
+ var _this2 = this;
689
+
690
+ this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
691
+ return _this2.onClick(e);
692
+ });
693
+ }
694
+ }, {
695
+ key: 'onClick',
696
+ value: function onClick(e) {
697
+ var trigger = e.delegateTarget || e.currentTarget;
698
+
699
+ if (this.clipboardAction) {
700
+ this.clipboardAction = null;
701
+ }
702
+
703
+ this.clipboardAction = new _clipboardAction2.default({
704
+ action: this.action(trigger),
705
+ target: this.target(trigger),
706
+ text: this.text(trigger),
707
+ trigger: trigger,
708
+ emitter: this
709
+ });
710
+ }
711
+ }, {
712
+ key: 'defaultAction',
713
+ value: function defaultAction(trigger) {
714
+ return getAttributeValue('action', trigger);
715
+ }
716
+ }, {
717
+ key: 'defaultTarget',
718
+ value: function defaultTarget(trigger) {
719
+ var selector = getAttributeValue('target', trigger);
720
+
721
+ if (selector) {
722
+ return document.querySelector(selector);
723
+ }
724
+ }
725
+ }, {
726
+ key: 'defaultText',
727
+ value: function defaultText(trigger) {
728
+ return getAttributeValue('text', trigger);
729
+ }
730
+ }, {
731
+ key: 'destroy',
732
+ value: function destroy() {
733
+ this.listener.destroy();
734
+
735
+ if (this.clipboardAction) {
736
+ this.clipboardAction.destroy();
737
+ this.clipboardAction = null;
738
+ }
739
+ }
740
+ }], [{
741
+ key: 'isSupported',
742
+ value: function isSupported() {
743
+ var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
744
+
745
+ var actions = typeof action === 'string' ? [action] : action;
746
+ var support = !!document.queryCommandSupported;
747
+
748
+ actions.forEach(function (action) {
749
+ support = support && !!document.queryCommandSupported(action);
750
+ });
751
+
752
+ return support;
753
+ }
754
+ }]);
755
+
756
+ return Clipboard;
757
+ }(_tinyEmitter2.default);
758
+
759
+ /**
760
+ * Helper function to retrieve attribute value.
761
+ * @param {String} suffix
762
+ * @param {Element} element
763
+ */
764
+ function getAttributeValue(suffix, element) {
765
+ var attribute = 'data-clipboard-' + suffix;
766
+
767
+ if (!element.hasAttribute(attribute)) {
768
+ return;
769
+ }
770
+
771
+ return element.getAttribute(attribute);
772
+ }
773
+
774
+ module.exports = Clipboard;
775
+ });
776
+
777
+ },{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)
778
+ });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipboard-toastr-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Park
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-22 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: clipboard.js and toastr.js to rails Gem
14
14
  email: ggogun@gmail.com
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.5.1
53
+ rubygems_version: 2.6.8
54
54
  signing_key:
55
55
  specification_version: 3
56
56
  summary: Clipboard and Toast Gem!