function ToggleEncryptionDialog(button, tag) { this.button = button; this.tag = tag; this.encrypted = null; this.decrypted = null; this.sack = new sack(DOKU_BASE + "lib/exe/ajax.php"); // read cached password if ((JSINFO['crypto_cache_password'] == 1) && (JSINFO['crypto_password'] != undefined)) { this.password = ' value="' + JSINFO['crypto_password'] + '"'; } else { this.password = ""; } // create HTML Structure this.div = document.createElement('div'); this.div.id = 'toggle_encryption_dialog'; this.div.className = 'picker cryptodialog'; this.div.style.top = (findPosY(this.button.parentNode)+20)+'px'; this.div.style.left = (findPosX(this.button.parentNode)+80)+'px'; this.button.parentNode.appendChild(this.div); this.div.innerHTML = '
'+ ' ' + this.tag.attributes["hint"].nodeValue + '
' + '
' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
' + LANG.plugins.crypto['input_secret'] + ':
' + '
'; // attach event handlers drag.attach(this.div, $('toggle_encryption_dialog_header')); var dialog = this; this.toggle = function() { if (dialog.tag.className == "encrypted") { dialog.button.innerHTML = ''; dialog.tag.className = "decrypted"; if (dialog.tag.attributes["inline"].nodeValue == "true") { dialog.tag.innerHTML = dialog.decrypted; } else { dialog.tag.innerHTML = '
' + dialog.decrypted + '
'; } } else { dialog.button.innerHTML = ''; dialog.tag.className = "encrypted"; dialog.tag.innerHTML = dialog.encrypted; } dialog.button.onclick = function() { dialog.toggle(); }; }; $('toggle_encryption_dialog_password').focus(); $('toggle_encryption_dialog_password').onkeypress = function(event) { if (event.keyCode==9) { $('toggle_encryption_dialog_button').focus(); return false; } if (event.keyCode==13) { $('toggle_encryption_dialog_button').onclick(); } return true; }; $('toggle_encryption_dialog_button').onkeypress = function(event) { if (event.keyCode==9) { $('toggle_encryption_dialog_password').focus(); return false; } return true; }; // register destructor $('toggle_encryption_dialog_close').onclick = function() { dialog.button.parentNode.removeChild(dialog.div); dialog.div = null; }; $('toggle_encryption_dialog_button').onclick = function() { dialog.sack.setVar("call", "crypto_decrypt"); dialog.sack.setVar("secret", escape($('toggle_encryption_dialog_password').value)); dialog.sack.setVar("data", dialog.tag.textContent); dialog.sack.onCompletion = function() { if (dialog.sack.response) { $('toggle_encryption_dialog_close').onclick(); dialog.encrypted = dialog.tag.textContent; dialog.decrypted = unescape(dialog.sack.response); dialog.toggle(); } else { alert(LANG.plugins.crypto['decrypt_wrong_secret']); } }; // cache the password if (JSINFO['crypto_cache_password'] == 1) { JSINFO['crypto_password'] = $('toggle_encryption_dialog_password').value; } else { JSINFO['crypto_password'] = ""; } dialog.sack.runAJAX(); }; };