captcha.js (2073B)
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 var Zotero_Captcha = new function() { 27 this._io; 28 29 this.onLoad = function() { 30 this._io = window.arguments[0]; 31 var description = document.getElementById('zotero-captcha-description'), 32 errorMsg = document.getElementById('zotero-captcha-error'); 33 34 if(this._io.dataIn.title) { 35 document.title = this._io.dataIn.title; 36 } 37 38 if(this._io.dataIn.description) { 39 description.textContent = this._io.dataIn.description; 40 description.hidden = false; 41 } else { 42 description.hidden = true; 43 } 44 45 if(this._io.dataIn.error) { 46 errorMsg.textContent = this._io.dataIn.error; 47 errorMsg.hidden = false; 48 } else { 49 errorMsg.hidden = true; 50 } 51 52 document.getElementById('zotero-captcha-image').src = this._io.dataIn.imgUrl; 53 document.getElementById('zotero-captcha-input').focus(); 54 } 55 56 this.imageOnLoad = function() { 57 window.sizeToContent(); 58 } 59 60 this.resolve = function() { 61 var result = document.getElementById('zotero-captcha-input'); 62 if(!result.value) return; 63 64 this._io.dataOut = { 65 captcha: result.value 66 }; 67 window.close(); 68 } 69 70 this.cancel = function() { 71 window.close(); 72 } 73 }