123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- UE.plugin.register('copy', function () {
- var me = this;
- function initZeroClipboard() {
- ZeroClipboard.config({
- debug: false,
- swfPath: me.options.UEDITOR_HOME_URL + 'third-party/zeroclipboard/ZeroClipboard.swf'
- });
- var client = me.zeroclipboard = new ZeroClipboard();
- // 复制内容
- client.on('copy', function (e) {
- var client = e.client,
- rng = me.selection.getRange(),
- div = document.createElement('div');
- div.appendChild(rng.cloneContents());
- client.setText(div.innerText || div.textContent);
- client.setHtml(div.innerHTML);
- rng.select();
- });
- // hover事件传递到target
- client.on('mouseover mouseout', function (e) {
- var target = e.target;
- if (target) {
- if (e.type == 'mouseover') {
- domUtils.addClass(target, 'edui-state-hover');
- } else if (e.type == 'mouseout') {
- domUtils.removeClasses(target, 'edui-state-hover');
- }
- }
- });
- // flash加载不成功
- client.on('wrongflash noflash', function () {
- ZeroClipboard.destroy();
- });
- // 触发事件
- me.fireEvent('zeroclipboardready', client);
- }
- return {
- bindEvents: {
- 'ready': function () {
- if (!browser.ie) {
- if (window.ZeroClipboard) {
- initZeroClipboard();
- } else {
- utils.loadFile(document, {
- src: me.options.UEDITOR_HOME_URL + "third-party/zeroclipboard/ZeroClipboard.js",
- tag: "script",
- type: "text/javascript",
- defer: "defer"
- }, function () {
- initZeroClipboard();
- });
- }
- }
- }
- },
- commands: {
- 'copy': {
- execCommand: function (cmd) {
- if (!me.document.execCommand('copy')) {
- alert(me.getLang('copymsg'));
- }
- }
- }
- }
- }
- });
|