aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/scripts/edit.js
diff options
context:
space:
mode:
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);
+}
+
+
+