1 /**
  2  * Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
  3  *
  4  * @licstart
  5  * This file is part of WebODF.
  6  *
  7  * WebODF is free software: you can redistribute it and/or modify it
  8  * under the terms of the GNU Affero General Public License (GNU AGPL)
  9  * as published by the Free Software Foundation, either version 3 of
 10  * the License, or (at your option) any later version.
 11  *
 12  * WebODF is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15  * GNU Affero General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Affero General Public License
 18  * along with WebODF.  If not, see <http://www.gnu.org/licenses/>.
 19  * @licend
 20  *
 21  * @source: http://www.webodf.org/
 22  * @source: https://github.com/kogmbh/WebODF/
 23  */
 24 
 25 /*global gui, runtime*/
 26 
 27 /**
 28  * Clipboard wrapper to attempt some semblance of cross-browser clipboard support
 29  *
 30  * @param {!gui.MimeDataExporter} mimeDataExporter
 31  * @constructor
 32  */
 33 gui.Clipboard = function Clipboard(mimeDataExporter) {
 34     "use strict";
 35 
 36     /**
 37      * Copy the contents of the supplied range onto the clipboard (if available).
 38      * @param {!Event} e
 39      * @param {!Range} range Selection range to copy into the clipboard
 40      * @return {boolean} Returns true if the data was successfully copied to the clipboard
 41      */
 42     this.setDataFromRange = function (e, range) {
 43         var result,
 44             clipboard = e.clipboardData,
 45             /**@type{?Window}*/window = runtime.getWindow();
 46 
 47         // IE
 48         if (!clipboard && window) {
 49             clipboard = window.clipboardData;
 50         }
 51 
 52         if (clipboard) {
 53             result = true;
 54             mimeDataExporter.exportRangeToDataTransfer(/**@type{!DataTransfer}*/(clipboard), range);
 55             // By calling preventDefault on the copy event, no data is actually placed into the clipboard.
 56             // However, if we don't call it, the data we add is stripped out and thrown away :-/
 57             e.preventDefault();
 58         } else {
 59             result = false;
 60         }
 61 
 62         return result;
 63     };
 64 };
 65