Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- e.exports = function() {
- if ("undefined" == typeof document || !document.addEventListener) return null;
- var r, o, i, a = {};
- return a.copy = function() {
- var e = !1,
- t = null,
- n = !1;
- function r() {
- e = !1, t = null, n && window.getSelection().removeAllRanges(), n = !1
- }
- return document.addEventListener("copy", function(n) {
- if (e) {
- for (var r in t) n.clipboardData.setData(r, t[r]);
- n.preventDefault()
- }
- }),
- function(o) {
- return new Promise(function(i, a) {
- e = !0, "string" == typeof o ? t = {
- "text/plain": o
- } : o instanceof Node ? t = {
- "text/html": (new XMLSerializer).serializeToString(o)
- } : o instanceof Object ? t = o : a("Invalid data type. Must be string, DOM node, or an object mapping MIME types to strings."),
- function e(t) {
- try {
- if (document.execCommand("copy")) r(), i();
- else {
- if (t) throw r(), new Error("Unable to copy. Perhaps it's not available in your browser?");
- ! function() {
- var e = document.getSelection();
- if (!document.queryCommandEnabled("copy") && e.isCollapsed) {
- var t = document.createRange();
- t.selectNodeContents(document.body), e.removeAllRanges(), e.addRange(t), n = !0
- }
- }(), e(!0)
- }
- } catch (e) {
- r(), a(e)
- }
- }(!1)
- })
- }
- }(), a.paste = (i = !1, document.addEventListener("paste", function(e) {
- if (i) {
- i = !1, e.preventDefault();
- var t = r;
- r = null, t(e.clipboardData.getData(o))
- }
- }), function(e) {
- return new Promise(function(t, n) {
- i = !0, r = t, o = e || "text/plain";
- try {
- document.execCommand("paste") || (i = !1, n(new Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")))
- } catch (e) {
- i = !1, n(new Error(e))
- }
- })
- }), "undefined" == typeof ClipboardEvent && void 0 !== window.clipboardData && void 0 !== window.clipboardData.setData && (
- /*! promise-polyfill 2.0.1 */
- function(r) {
- function o(e, t) {
- return function() {
- e.apply(t, arguments)
- }
- }
- function i(e) {
- if ("object" != n(this)) throw new TypeError("Promises must be constructed via new");
- if ("function" != typeof e) throw new TypeError("not a function");
- this._state = null, this._value = null, this._deferreds = [], f(e, o(l, this), o(u, this))
- }
- function a(e) {
- var t = this;
- return null === this._state ? void this._deferreds.push(e) : void p(function() {
- var n = t._state ? e.onFulfilled : e.onRejected;
- if (null !== n) {
- var r;
- try {
- r = n(t._value)
- } catch (t) {
- return void e.reject(t)
- }
- e.resolve(r)
- } else(t._state ? e.resolve : e.reject)(t._value)
- })
- }
- function l(e) {
- try {
- if (e === this) throw new TypeError("A promise cannot be resolved with itself.");
- if (e && ("object" == n(e) || "function" == typeof e)) {
- var t = e.then;
- if ("function" == typeof t) return void f(o(t, e), o(l, this), o(u, this))
- }
- this._state = !0, this._value = e, c.call(this)
- } catch (e) {
- u.call(this, e)
- }
- }
- function u(e) {
- this._state = !1, this._value = e, c.call(this)
- }
- function c() {
- for (var e = 0, t = this._deferreds.length; t > e; e++) a.call(this, this._deferreds[e]);
- this._deferreds = null
- }
- function s(e, t, n, r) {
- this.onFulfilled = "function" == typeof e ? e : null, this.onRejected = "function" == typeof t ? t : null, this.resolve = n, this.reject = r
- }
- function f(e, t, n) {
- var r = !1;
- try {
- e(function(e) {
- r || (r = !0, t(e))
- }, function(e) {
- r || (r = !0, n(e))
- })
- } catch (e) {
- if (r) return;
- r = !0, n(e)
- }
- }
- var p = i.immediateFn || "function" == typeof t && t || function(e) {
- setTimeout(e, 1)
- },
- d = Array.isArray || function(e) {
- return "[object Array]" === Object.prototype.toString.call(e)
- };
- i.prototype.catch = function(e) {
- return this.then(null, e)
- }, i.prototype.then = function(e, t) {
- var n = this;
- return new i(function(r, o) {
- a.call(n, new s(e, t, r, o))
- })
- }, i.all = function() {
- var e = Array.prototype.slice.call(1 === arguments.length && d(arguments[0]) ? arguments[0] : arguments);
- return new i(function(t, r) {
- function o(a, l) {
- try {
- if (l && ("object" == n(l) || "function" == typeof l)) {
- var u = l.then;
- if ("function" == typeof u) return void u.call(l, function(e) {
- o(a, e)
- }, r)
- }
- e[a] = l, 0 == --i && t(e)
- } catch (e) {
- r(e)
- }
- }
- if (0 === e.length) return t([]);
- for (var i = e.length, a = 0; a < e.length; a++) o(a, e[a])
- })
- }, i.resolve = function(e) {
- return e && "object" == n(e) && e.constructor === i ? e : new i(function(t) {
- t(e)
- })
- }, i.reject = function(e) {
- return new i(function(t, n) {
- n(e)
- })
- }, i.race = function(e) {
- return new i(function(t, n) {
- for (var r = 0, o = e.length; o > r; r++) e[r].then(t, n)
- })
- }, e.exports ? e.exports = i : r.Promise || (r.Promise = i)
- }(this), a.copy = function(e) {
- return new Promise(function(t, n) {
- if ("string" != typeof e && !("text/plain" in e)) throw new Error("You must provide a text/plain type.");
- var r = "string" == typeof e ? e : e["text/plain"];
- window.clipboardData.setData("Text", r) ? t() : n(new Error("Copying was rejected."))
- })
- }, a.paste = function() {
- return new Promise(function(e, t) {
- var n = window.clipboardData.getData("Text");
- n ? e(n) : t(new Error("Pasting was rejected."))
- })
- }), a
- }()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement