1function DecryptDialog(textArea) { 2 this.visible = true; 3 this.textArea = textArea; 4 this.sack = new sack(DOKU_BASE + "lib/exe/ajax.php"); 5 6 // read cached password 7 if ((JSINFO['crypto_cache_password'] == 1) && (JSINFO['crypto_password'] != undefined)) { 8 this.password = ' value="' + JSINFO['crypto_password'] + '"'; 9 } else { 10 this.password = ""; 11 } 12 13 // create HTML Structure 14 this.div = document.createElement('div'); 15 this.div.id = 'decrypt_dialog'; 16 this.div.className = 'picker cryptodialog'; 17 this.div.style.top = (findPosY(textArea)+20)+'px'; 18 this.div.style.left = (findPosX(textArea)+80)+'px'; 19 20 this.textArea.form.parentNode.appendChild(this.div); 21 this.div.innerHTML = 22 '<div id="decrypt_dialog_header" class="cryptoheader">'+ 23 ' <img src="' + DOKU_BASE + 'lib/images/close.png" width="16" height="16" align="right" alt="" id="decrypt_dialog_close" />' + 24 LANG.plugins.crypto['decrypt_dialog_title'] + 25 '</div>' + 26 '<div>' + 27 ' <table>' + 28 ' <tr>' + 29 ' <th>' + LANG.plugins.crypto['input_secret'] + ':</th>' + 30 ' <td><input type="password" class="edit" id="decrypt_dialog_password"' + this.password + '/></td>' + 31 ' </tr>' + 32 ' <tr>' + 33 ' <td colspan="2"><button id="decrypt_dialog_button_decrypt" class="toolbutton">' + LANG.plugins.crypto['decrypt_button'] + '</button></td>' + 34 ' </tr>' + 35 ' </table>' + 36 '</div>'; 37 38 // attach event handlers 39 drag.attach(this.div, $('decrypt_dialog_header')); 40 41 var dialog = this; 42 43 $('decrypt_dialog_password').focus(); 44 $('decrypt_dialog_password').onkeypress = function(event) { 45 if (event.keyCode==9) { 46 $('decrypt_dialog_button_decrypt').focus(); 47 return false; 48 } 49 50 if (event.keyCode==13) { 51 $('decrypt_dialog_button_decrypt').onclick(); 52 } 53 54 return true; 55 }; 56 57 $('decrypt_dialog_button_decrypt').onkeypress = function(event) { 58 if (event.keyCode==9) { 59 $('decrypt_dialog_password').focus(); 60 return false; 61 } 62 63 return true; 64 }; 65 66 // register destructor 67 $('decrypt_dialog_close').onclick = function() { 68 dialog.textArea.focus(); 69 dialog.textArea.form.parentNode.removeChild(dialog.div); 70 dialog.visible = false; 71 dialog.div = null; 72 dialog.textArea = null; 73 }; 74 75 $('decrypt_dialog_button_decrypt').onclick = function() { 76 var selection = getSelection(dialog.textArea); 77 var text = selection.getText(); 78 dialog.sack.setVar("call", "crypto_decrypt"); 79 dialog.sack.setVar("secret", escape($('decrypt_dialog_password').value)); 80 dialog.sack.setVar("data", getSelection(dialog.textArea).getText()); 81 dialog.sack.onCompletion = function() { 82 if (dialog.sack.response) { 83 pasteText(selection, unescape(dialog.sack.response)); 84 $('decrypt_dialog_close').onclick(); 85 } else { 86 alert(LANG.plugins.crypto['decrypt_wrong_secret']); 87 } 88 }; 89 90 // cache the password 91 if (JSINFO['crypto_cache_password'] == 1) { 92 JSINFO['crypto_password'] = $('decrypt_dialog_password').value; 93 } else { 94 JSINFO['crypto_password'] = ""; 95 } 96 97 dialog.sack.runAJAX(); 98 }; 99}; 100 101