attachLink.js (2113B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2014 Center for History and New Media 5 George Mason University, Fairfax, Virginia, USA 6 http://zotero.org 7 8 This file is part of Zotero. 9 10 Zotero is free software: you can redistribute it and/or modify 11 it under the terms of the GNU Affero General Public License as published by 12 the Free Software Foundation, either version 3 of the License, or 13 (at your option) any later version. 14 15 Zotero is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU Affero General Public License for more details. 19 20 You should have received a copy of the GNU Affero General Public License 21 along with Zotero. If not, see <http://www.gnu.org/licenses/>. 22 23 ***** END LICENSE BLOCK ***** 24 */ 25 26 var Zotero_AttachLink = new function() { 27 function getAttachFileLabel() { 28 return window.opener.document 29 .getElementById('zotero-tb-attachment-add-file-link') 30 .label; 31 }; 32 33 this.submit = function() { 34 var link = document.getElementById('zotero-attach-uri-input').value; 35 var message = document.getElementById('zotero-attach-uri-message'); 36 var cleanURI = Zotero.Attachments.cleanAttachmentURI(link, true); 37 38 if (!cleanURI) { 39 message.textContent = Zotero.getString('pane.items.attach.link.uri.unrecognized'); 40 window.sizeToContent(); 41 document.getElementById('zotero-attach-uri-input').select(); 42 return false; 43 } 44 // Don't allow "file:" links, because using "Attach link to file" is the right way 45 else if (cleanURI.toLowerCase().indexOf('file:') == 0) { 46 message.textContent = Zotero.getString('pane.items.attach.link.uri.file', 47 [getAttachFileLabel()]); 48 window.sizeToContent(); 49 document.getElementById('zotero-attach-uri-input').select(); 50 return false; 51 } 52 else { 53 window.arguments[0].out = { 54 link: cleanURI, 55 title: document.getElementById('zotero-attach-uri-title').value 56 }; 57 return true; 58 } 59 }; 60 }