文档章节

clipboard.js 复制文本

猿神出窍
 猿神出窍
发布于 2017/09/05 17:16
字数 1487
阅读 50
收藏 0
点赞 0
评论 0
/*!
 * clipboard.js v1.5.15
 * https://zenorocha.github.io/clipboard.js
 *
 * Licensed MIT © Zeno Rocha
 */
!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)
});

 

© 著作权归作者所有

共有 人打赏支持
猿神出窍
粉丝 15
博文 161
码字总数 57239
作品 0
沙坪坝
项目经理
javascript 实现跨浏览器的粘贴,复制,剪切功能(转)

这两天在做跨浏览器的粘贴、复制、剪切功能。 本以为是很简单的事,原来并不简单。 网上查了很多资料。都是跨浏览器把文本复制到剪切板的实现方案(zero clipboard.js)。没有跨浏览器粘贴的...

苏叶晚晚 ⋅ 2012/09/26 ⋅ 0

Clipboard.js v1.5.15 发布,JavaScript 复制粘贴库

Clipboard.js v1.5.15 发布了,Clipboard.js 实现了纯 JavaScript 无 Flash的浏览器内容复制到系统剪贴板的功能。可以在浏览器和 Node 环境中使用。 浏览器支持: 该库依赖于 Selection 和 ...

王练 ⋅ 2016/10/28 ⋅ 4

Clipboard.js:无需Flash的JavaScript复制粘贴库

clipboard.js 实现了纯 JavaScript (无 Flash)的浏览器内容复制到系统剪贴板的功能。

oschina ⋅ 2015/10/02 ⋅ 0

vue中怎么实现点击按钮,把一张图片复制到剪切板?

rt 有点奇葩的一个想法, 一张图片下放一个按钮,这个图片是生成的,可以获取到,点一下复制,就可以把图片复制到剪切板 在网上查了好久,找到了clipboard.js ,但是只能复制文字到剪切板 求...

hery186 ⋅ 04/11 ⋅ 0

JavaScript 内容复制--Clipboard.js

clipboard.js 实现了纯 JavaScript (无 Flash)的浏览器内容复制到系统剪贴板的功能。可以在浏览器和 Node 环境中使用。支持 Chrome 42+、Firefox 41+、IE 9+、Opera 29+ 示例代码: <scrip...

红薯 ⋅ 2015/09/30 ⋅ 11

使用clipboard.js实现复制功能

最近在工作中有一个需求,就是需要使用一个按钮实现相应内容的复制。在网上找了很多解决方案,最后对比之下选择了clipboard.js插件来进行实现。因为它不依靠flash以及其他框架,而且体积小使...

tiancai啊呆 ⋅ 2017/10/15 ⋅ 0

Clipboard.js:不用Flash实现剪贴板功能的轻量级JavaScript库

网址:http://zenorocha.github.io/clipboard.js/ <script src="<%=path%>/js/clipboard.min.js"></script> var clipboard = new Clipboard('#copybtn', { text: function() { var selected ......

w4ww ⋅ 2016/04/22 ⋅ 0

WingsJ/Clipboard

Clipboard.js A clipboard javascript code written within 50 lines, using a invisible textarea as a dummy element. 这是一段用 50 行写的剪贴板代码,用一个不可见的 textarea 作为傀儡......

WingsJ ⋅ 06/19 ⋅ 0

jQuery插件合集

plupload uploadify (H5版本收费, Flash版本MIT开源) ajaxUpload jQuery-File-Upload: https://github.com/blueimp/jQuery-File-Upload 滚动条 jquery-scrollbar: https://github.com/malih......

flydo ⋅ 2015/04/07 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

个人博客的运营模式能否学习TMALL天猫质量为上?

心情随笔|个人博客的运营模式能否学习TMALL天猫质量为上? 中国的互联网已经发展了很多年了,记得在十年前,个人博客十分流行,大量的人都在写博客,而且质量还不错,很多高质量的文章都是在...

原创小博客 ⋅ 今天 ⋅ 0

JavaScript零基础入门——(十一)JavaScript的DOM操作

JavaScript零基础入门——(十一)JavaScript的DOM操作 大家好,欢迎回到我们的JavaScript零基础入门。最近有些同学问我说,我讲的的比书上的精简不少。其实呢,我主要讲的是我在开发中经常会...

JandenMa ⋅ 今天 ⋅ 0

volatile和synchronized的区别

volatile和synchronized的区别 在讲这个之前需要先了解下JMM(Java memory Model :java内存模型):并发过程中如何处理可见性、原子性、有序性的问题--建立JMM模型 详情请看:https://baike.b...

MarinJ_Shao ⋅ 今天 ⋅ 0

深入分析Kubernetes Critical Pod(一)

Author: xidianwangtao@gmail.com 摘要:大家在部署Kubernetes集群AddOn组件的时候,经常会看到Annotation scheduler.alpha.kubernetes.io/critical-pod"="",以表示这是一个关键服务,那你知...

WaltonWang ⋅ 今天 ⋅ 0

原子性 - synchronized关键词

原子性概念 原子性提供了程序的互斥操作,同一时刻只能有一个线程能对某块代码进行操作。 原子性的实现方式 在jdk中,原子性的实现方式主要分为: synchronized:关键词,它依赖于JVM,保证了同...

dotleo ⋅ 今天 ⋅ 0

【2018.06.22学习笔记】【linux高级知识 14.4-15.3】

14.4 exportfs命令 14.5 NFS客户端问题 15.1 FTP介绍 15.2/15.3 使用vsftpd搭建ftp

lgsxp ⋅ 今天 ⋅ 0

JeeSite 4.0 功能权限管理基础(Shiro)

Shiro是Apache的一个开源框架,是一个权限管理的框架,实现用户认证、用户授权等。 只要有用户参与一般都要有权限管理,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户...

ThinkGem ⋅ 昨天 ⋅ 0

python f-string 字符串格式化

主要内容 从Python 3.6开始,f-string是格式化字符串的一种很好的新方法。与其他格式化方式相比,它们不仅更易读,更简洁,不易出错,而且速度更快! 在本文的最后,您将了解如何以及为什么今...

阿豪boy ⋅ 昨天 ⋅ 0

Python实现自动登录站点

如果我们想要实现自动登录,那么我们就需要能够驱动浏览器(比如谷歌浏览器)来实现操作,ChromeDriver 刚好能够帮助我们这一点(非谷歌浏览器的驱动有所不同)。 一、确认软件版本 首先我们...

blackfoxya ⋅ 昨天 ⋅ 0

线性回归原理和实现基本认识

一:介绍 定义:线性回归在假设特证满足线性关系,根据给定的训练数据训练一个模型,并用此模型进行预测。为了了解这个定义,我们先举个简单的例子;我们假设一个线性方程 Y=2x+1, x变量为商...

wangxuwei ⋅ 昨天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部