1 /** 2 * Copyright (C) 2012-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 ops, odf, core, runtime */ 26 27 /** 28 * @constructor 29 * @implements ops.Operation 30 */ 31 ops.OpRemoveHyperlink = function OpRemoveHyperlink() { 32 "use strict"; 33 34 var memberid, timestamp, position, length, 35 domUtils = core.DomUtils, 36 odfUtils = odf.OdfUtils; 37 38 /** 39 * @param {!ops.OpRemoveHyperlink.InitSpec} data 40 */ 41 this.init = function (data) { 42 memberid = data.memberid; 43 timestamp = data.timestamp; 44 position = data.position; 45 length = data.length; 46 }; 47 48 this.isEdit = true; 49 this.group = undefined; 50 51 /** 52 * @param {!ops.Document} document 53 */ 54 this.execute = function (document) { 55 var odtDocument = /**@type{ops.OdtDocument}*/(document), 56 range = odtDocument.convertCursorToDomRange(position, length), 57 links = odfUtils.getHyperlinkElements(range), 58 node; 59 60 runtime.assert(links.length === 1, "The given range should only contain a single link."); 61 node = domUtils.mergeIntoParent(/**@type{!Node}*/(links[0])); 62 range.detach(); 63 64 odtDocument.fixCursorPositions(); 65 odtDocument.getOdfCanvas().refreshSize(); 66 odtDocument.getOdfCanvas().rerenderAnnotations(); 67 odtDocument.emit(ops.OdtDocument.signalParagraphChanged, { 68 paragraphElement: odfUtils.getParagraphElement(node), 69 memberId: memberid, 70 timeStamp: timestamp 71 }); 72 return true; 73 }; 74 75 /** 76 * @return {!ops.OpRemoveHyperlink.Spec} 77 */ 78 this.spec = function () { 79 return { 80 optype: "RemoveHyperlink", 81 memberid: memberid, 82 timestamp: timestamp, 83 position: position, 84 length: length 85 }; 86 }; 87 }; 88 /**@typedef{{ 89 optype:string, 90 memberid:string, 91 timestamp:number, 92 position:number, 93 length:number 94 }}*/ 95 ops.OpRemoveHyperlink.Spec; 96 /**@typedef{{ 97 memberid:string, 98 timestamp:(number|undefined), 99 position:number, 100 length:number 101 }}*/ 102 ops.OpRemoveHyperlink.InitSpec; 103