notes.js (1956B)
1 /* 2 ***** BEGIN LICENSE BLOCK ***** 3 4 Copyright © 2009 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 27 Zotero.Notes = new function() { 28 this.noteToTitle = noteToTitle; 29 30 this.__defineGetter__("MAX_TITLE_LENGTH", function() { return 120; }); 31 this.__defineGetter__("defaultNote", function () { return '<div class="zotero-note znv1"></div>'; }); 32 this.__defineGetter__("notePrefix", function () { return '<div class="zotero-note znv1">'; }); 33 this.__defineGetter__("noteSuffix", function () { return '</div>'; }); 34 35 /** 36 * Return first line (or first MAX_LENGTH characters) of note content 37 **/ 38 function noteToTitle(text) { 39 var origText = text; 40 text = text.trim(); 41 text = Zotero.Utilities.unescapeHTML(text); 42 43 // If first line is just an opening HTML tag, remove it 44 // 45 // Example: 46 // 47 // <blockquote> 48 // <p>Foo</p> 49 // </blockquote> 50 if (/^<[^>\n]+[^\/]>\n/.test(origText)) { 51 text = text.trim(); 52 } 53 54 var max = this.MAX_TITLE_LENGTH; 55 56 var t = text.substring(0, max); 57 var ln = t.indexOf("\n"); 58 if (ln>-1 && ln<max) { 59 t = t.substring(0, ln); 60 } 61 return t; 62 } 63 } 64