summaryrefslogtreecommitdiff
path: root/lib/scripts/edit.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-10-15 20:44:04 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-10-15 20:44:04 +0200
commit5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63 (patch)
treec204ba3e934a2e64928d4d59395516b7c0bb881f /lib/scripts/edit.js
parent20d062ca5220daf6606e2b1bcdd73d84eebafa45 (diff)
downloadrpg-5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63.tar.gz
rpg-5e1632788b8a5f5b9eebd2acb72e1de7d9f0ac63.tar.bz2
more unobstrusive javascript
The edit form now is free of inline event handlers. There are still other places where inline javascript and even document.write is used which should be fixed as well. Currently the window.onload event is used to initialize everything which may not the best way to do so. Dean Edwards may have a solution: http://dean.edwards.name/weblog/2005/09/busted/ darcs-hash:20051015184404-7ad00-2404744d008e5ea7e1b5800c96800824b532ff47.gz
Diffstat (limited to 'lib/scripts/edit.js')
-rw-r--r--lib/scripts/edit.js106
1 files changed, 105 insertions, 1 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js
index 641124c8f..43e6843b0 100644
--- a/lib/scripts/edit.js
+++ b/lib/scripts/edit.js
@@ -21,7 +21,7 @@ function createToolButton(icon,label,key,id){
btn.title = label;
if(key){
btn.title += ' [ALT+'+key.toUpperCase()+']';
- btn.accesskey = key;
+ btn.accessKey = key;
}
// set IDs if given
@@ -127,6 +127,7 @@ function showPicker(pickerid,btn){
* @author Andreas Gohr <andi@splitbrain.org>
*/
function initToolbar(tbid,edid,tb){
+ if(!document.getElementById) return;
var toolbar = document.getElementById(tbid);
var cnt = tb.length;
for(i=0; i<cnt; i++){
@@ -306,3 +307,106 @@ function insertAtCarret(edid,value){
if (field.createTextRange) field.caretPos = document.selection.createRange().duplicate();
}
+
+/**
+ * global var used for not saved yet warning
+ */
+var textChanged = false;
+
+/**
+ * Check for changes before leaving the page
+ */
+function changeCheck(msg){
+ if(textChanged){
+ return confirm(msg);
+ }else{
+ return true;
+ }
+}
+
+/**
+ * Add changeCheck to all Links and Forms (except those with a
+ * JSnocheck class), add handlers to monitor changes
+ *
+ * Sets focus to the editbox as well
+ */
+function initChangeCheck(msg){
+ if(!document.getElementById) return;
+ // add change check for links
+ var links = document.getElementsByTagName('a');
+ for(var i=0; i < links.length; i++){
+ if(links[i].className.indexOf('JSnocheck') == -1){
+ links[i].onclick = function(){return changeCheck(msg);};
+ links[i].onkeypress = function(){return changeCheck(msg);};
+ }
+ }
+ // add change check for forms
+ var forms = document.forms;
+ for(i=0; i < forms.length; i++){
+ if(forms[i].className.indexOf('JSnocheck') == -1){
+ forms[i].onsubmit = function(){return changeCheck(msg);};
+ }
+ }
+
+ // reset change memory var on submit
+ var btn_save = document.getElementById('edbtn_save');
+ btn_save.onclick = function(){ textChanged = false; };
+ btn_save.onkeypress = function(){ textChanged = false; };
+ var btn_prev = document.getElementById('edbtn_preview');
+ btn_prev.onclick = function(){ textChanged = false; };
+ btn_prev.onkeypress = function(){ textChanged = false; };
+
+ // add change memory setter
+ var edit_text = document.getElementById('wikitext');
+ edit_text.onchange = function(){
+ textChanged = true; //global var
+ summaryCheck();
+ }
+ edit_text.onkeyup = summaryCheck;
+ var summary = document.getElementById('summary');
+ summary.onchange = summaryCheck;
+ summary.onkeyup = summaryCheck;
+
+ // set focus
+ edit_text.focus();
+}
+
+/**
+ * Checks if a summary was entered - if not the style is changed
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+function summaryCheck(){
+ var sum = document.getElementById('summary');
+ if(sum.value == ''){
+ sum.className='missing';
+ }else{
+ sum.className='edit';
+ }
+}
+
+
+/**
+ * global variable for the locktimer
+ */
+var locktimerID;
+
+/**
+ * This starts a timer to remind the user of an expiring lock
+ * Accepts the delay in seconds and a text to display.
+ */
+function init_locktimer(delay,txt){
+ txt = escapeQuotes(txt);
+ locktimerID = self.setTimeout("locktimer('"+txt+"')", delay*1000);
+}
+
+/**
+ * This stops the timer and displays a message about the expiring lock
+ */
+function locktimer(txt){
+ clearTimeout(locktimerID);
+ alert(txt);
+}
+
+
+