1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2014, 2015, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Clipboard access. Current implementation is built on clipboard.js 26 * 27 * @class 28 * @constructor 29 */ 30 AjxClipboard = function() { 31 32 }; 33 34 /** 35 * Returns true if clipboard access is supported. 36 * @returns {Boolean} true if clipboard access is supported 37 */ 38 AjxClipboard.isSupported = function() { 39 // clipboard.js works on all browsers except IE8 and Safari 40 return !AjxEnv.isIE8 && !(AjxEnv.isSafari && !AjxEnv.isChrome); 41 }; 42 43 /** 44 * Initialize clipboard action 45 * 46 * @param {DwtControl} op widget that initiates copy (eg button or menu item) 47 * @param {Object} listeners hash of events 48 */ 49 AjxClipboard.prototype.init = function(op, listeners) { 50 if (listeners.onComplete) { 51 this._completionListener = listeners.onComplete.bind(null, this); 52 } 53 if (op && listeners.onMouseDown) { 54 op.addSelectionListener(listeners.onMouseDown.bind(null, this)); 55 } 56 }; 57 58 AjxClipboard.prototype.setText = function(text) { 59 if (window.clipboard) { 60 clipboard.copy(text).then(this._completionListener, this._onError); 61 } 62 }; 63 64 AjxClipboard.prototype._onError = function(error) { 65 appCtxt.setStatusMsg(error && error.message, ZmStatusView.LEVEL_WARNING); 66 }; 67