From ceea734a6e745087356b0119fc7a4acac821c5aa Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 31 Jan 2011 13:49:10 +0100 Subject: Made the auto submit script more versatile When a tag has the class "quickselect", this script will + * automatically submit its parent form when the select value changes. + * It also hides the submit button of the form. * * @author Andreas Gohr */ addInitEvent(function(){ - var selector = $('action__selector'); - if(!selector) return; - - addEvent(selector,'change',function(e){ - this.form.submit(); - }); - - $('action__selectorbtn').style.display = 'none'; + var selects = getElementsByClass('quickselect',document,'select'); + for(var i=0; i Date: Sun, 6 Feb 2011 10:03:34 +0100 Subject: moved locktimer class to its own file I also adjusted the coding style to match our other JS classes --- lib/scripts/edit.js | 101 ----------------------------------------------- lib/scripts/locktimer.js | 98 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 101 deletions(-) create mode 100644 lib/scripts/locktimer.js (limited to 'lib/scripts') diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index 01262bcef..3276c9e06 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -341,104 +341,3 @@ function summaryCheck(){ } } - -/** - * Class managing the timer to display a warning on a expiring lock - */ -function locktimer_class(){ - this.sack = null; - this.timeout = 0; - this.timerID = null; - this.lasttime = null; - this.msg = ''; - this.pageid = ''; -}; -var locktimer = new locktimer_class(); - locktimer.init = function(timeout,msg,draft){ - // init values - locktimer.timeout = timeout*1000; - locktimer.msg = msg; - locktimer.draft = draft; - locktimer.lasttime = new Date(); - - if(!$('dw__editform')) return; - locktimer.pageid = $('dw__editform').elements.id.value; - if(!locktimer.pageid) return; - - // init ajax component - locktimer.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php'); - locktimer.sack.AjaxFailedAlert = ''; - locktimer.sack.encodeURIString = false; - locktimer.sack.onCompletion = locktimer.refreshed; - - // register refresh event - addEvent($('dw__editform'),'keypress',function(){locktimer.refresh();}); - // start timer - locktimer.reset(); - }; - - /** - * (Re)start the warning timer - */ - locktimer.reset = function(){ - locktimer.clear(); - locktimer.timerID = window.setTimeout("locktimer.warning()", locktimer.timeout); - }; - - /** - * Display the warning about the expiring lock - */ - locktimer.warning = function(){ - locktimer.clear(); - alert(locktimer.msg); - }; - - /** - * Remove the current warning timer - */ - locktimer.clear = function(){ - if(locktimer.timerID !== null){ - window.clearTimeout(locktimer.timerID); - locktimer.timerID = null; - } - }; - - /** - * Refresh the lock via AJAX - * - * Called on keypresses in the edit area - */ - locktimer.refresh = function(){ - var now = new Date(); - // refresh every minute only - if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ //FIXME decide on time - var params = 'call=lock&id='+encodeURIComponent(locktimer.pageid); - var dwform = $('dw__editform'); - if(locktimer.draft && dwform.elements.wikitext){ - params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value); - params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value); - params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value); - if(dwform.elements.date){ - params += '&date='+encodeURIComponent(dwform.elements.date.value); - } - } - locktimer.sack.runAJAX(params); - locktimer.lasttime = now; - } - }; - - - /** - * Callback. Resets the warning timer - */ - locktimer.refreshed = function(){ - var data = this.response; - var error = data.charAt(0); - data = data.substring(1); - - $('draft__status').innerHTML=data; - if(error != '1') return; // locking failed - locktimer.reset(); - }; -// end of locktimer class functions - diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js new file mode 100644 index 000000000..1cd9d29db --- /dev/null +++ b/lib/scripts/locktimer.js @@ -0,0 +1,98 @@ +/** + * Class managing the timer to display a warning on a expiring lock + */ +var locktimer = { + sack: null, + timeout: 0, + timerID: null, + lasttime: null, + msg: '', + pageid: '', + + init: function(timeout,msg,draft){ + // init values + locktimer.timeout = timeout*1000; + locktimer.msg = msg; + locktimer.draft = draft; + locktimer.lasttime = new Date(); + + if(!$('dw__editform')) return; + locktimer.pageid = $('dw__editform').elements.id.value; + if(!locktimer.pageid) return; + + // init ajax component + locktimer.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php'); + locktimer.sack.AjaxFailedAlert = ''; + locktimer.sack.encodeURIString = false; + locktimer.sack.onCompletion = locktimer.refreshed; + + // register refresh event + addEvent($('dw__editform'),'keypress',function(){locktimer.refresh();}); + // start timer + locktimer.reset(); + }, + + /** + * (Re)start the warning timer + */ + reset: function(){ + locktimer.clear(); + locktimer.timerID = window.setTimeout("locktimer.warning()", locktimer.timeout); + }, + + /** + * Display the warning about the expiring lock + */ + warning: function(){ + locktimer.clear(); + alert(locktimer.msg); + }, + + /** + * Remove the current warning timer + */ + clear: function(){ + if(locktimer.timerID !== null){ + window.clearTimeout(locktimer.timerID); + locktimer.timerID = null; + } + }, + + /** + * Refresh the lock via AJAX + * + * Called on keypresses in the edit area + */ + refresh: function(){ + var now = new Date(); + // refresh every minute only + if(now.getTime() - locktimer.lasttime.getTime() > 30*1000){ + var params = 'call=lock&id='+encodeURIComponent(locktimer.pageid); + var dwform = $('dw__editform'); + if(locktimer.draft && dwform.elements.wikitext){ + params += '&prefix='+encodeURIComponent(dwform.elements.prefix.value); + params += '&wikitext='+encodeURIComponent(dwform.elements.wikitext.value); + params += '&suffix='+encodeURIComponent(dwform.elements.suffix.value); + if(dwform.elements.date){ + params += '&date='+encodeURIComponent(dwform.elements.date.value); + } + } + locktimer.sack.runAJAX(params); + locktimer.lasttime = now; + } + }, + + /** + * Callback. Resets the warning timer + */ + refreshed: function(){ + var data = this.response; + var error = data.charAt(0); + data = data.substring(1); + + $('draft__status').innerHTML=data; + if(error != '1') return; // locking failed + locktimer.reset(); + }, +}; + -- cgit v1.2.3 From dba09ad209b14cfb149a1a14c9aa1370537d69d1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 10:11:30 +0100 Subject: don't show lock timer in readonly mode FS#2146 --- lib/scripts/locktimer.js | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/scripts') diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js index 1cd9d29db..51d533056 100644 --- a/lib/scripts/locktimer.js +++ b/lib/scripts/locktimer.js @@ -19,6 +19,7 @@ var locktimer = { if(!$('dw__editform')) return; locktimer.pageid = $('dw__editform').elements.id.value; if(!locktimer.pageid) return; + if($('wiki__text').readOnly) return; // init ajax component locktimer.sack = new sack(DOKU_BASE + 'lib/exe/ajax.php'); -- cgit v1.2.3 From bf14d727a44e746ad142636acbb19f59fb075b13 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 10:42:28 +0100 Subject: keep drafts on preview FS#2116 --- lib/scripts/edit.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/scripts') diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index 3276c9e06..45c1fb111 100644 --- a/lib/scripts/edit.js +++ b/lib/scripts/edit.js @@ -268,6 +268,7 @@ var textChanged = false; */ function deleteDraft() { if (is_opera) return; + if (window.keepDraft) return; // remove a possibly saved draft using ajax var dwform = $('dw__editform'); @@ -318,8 +319,13 @@ addInitEvent(function (){ window.onunload = deleteDraft; // reset change memory var on submit - addEvent($('edbtn__save'), 'click', function(){ textChanged = false; }); - addEvent($('edbtn__preview'), 'click', function(){ textChanged = false; }); + addEvent($('edbtn__save'), 'click', function(){ + textChanged = false; + }); + addEvent($('edbtn__preview'), 'click', function(){ + textChanged = false; + window.keepDraft = true; // needed to keep draft on page unload + }); var summary = $('edit__summary'); addEvent(summary, 'change', summaryCheck); -- cgit v1.2.3 From 999913b8ccbcd63a3bc3d3350c8eb9a17bcdf305 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 20:38:08 +0100 Subject: no final comma in class members or IE craps out --- lib/scripts/locktimer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/scripts') diff --git a/lib/scripts/locktimer.js b/lib/scripts/locktimer.js index 51d533056..f5ba1c60d 100644 --- a/lib/scripts/locktimer.js +++ b/lib/scripts/locktimer.js @@ -94,6 +94,6 @@ var locktimer = { $('draft__status').innerHTML=data; if(error != '1') return; // locking failed locktimer.reset(); - }, + } }; -- cgit v1.2.3 From 4c5a5d3dd4fcc2636b2861f06d52a2ac32ad5544 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sun, 6 Feb 2011 20:41:58 +0100 Subject: JS: Add style helper and fix footnotes in non-static containers --- lib/scripts/script.js | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'lib/scripts') diff --git a/lib/scripts/script.js b/lib/scripts/script.js index b9b324f96..2cc1246f9 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -113,6 +113,20 @@ function findPosY(object){ return curtop; } //end findPosY function +/** + * Get the computed style of a node. + * + * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/ + * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js + */ +function gcs(node){ + if(node.currentStyle){ + return node.currentStyle; + }else{ + return node.ownerDocument.defaultView.getComputedStyle(node, null); + } +} + /** * Escape special chars in JavaScript * @@ -260,10 +274,32 @@ function insitu_popup(target, popup_id) { getElementsByClass('dokuwiki', document.body, 'div')[0].appendChild(fndiv); } + var non_static_parent = fndiv.parentNode; + while (non_static_parent != document && gcs(non_static_parent)['position'] == 'static') { + non_static_parent = non_static_parent.parentNode; + } + + var fixed_target_parent = target; + while (fixed_target_parent != document && gcs(fixed_target_parent)['position'] != 'fixed') { + fixed_target_parent = fixed_target_parent.parentNode; + } + // position the div and make it visible - fndiv.style.position = 'absolute'; - fndiv.style.left = findPosX(target)+'px'; - fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5) + 'px'; + if (fixed_target_parent != document) { + // the target has position fixed, that means the footnote needs to be fixed, too + fndiv.style.position = 'fixed'; + } else { + fndiv.style.position = 'absolute'; + } + + if (fixed_target_parent != document || non_static_parent == document) { + fndiv.style.left = findPosX(target)+'px'; + fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5) + 'px'; + } else { + fndiv.style.left = (findPosX(target) - findPosX(non_static_parent)) +'px'; + fndiv.style.top = (findPosY(target)+target.offsetHeight * 1.5 - findPosY(non_static_parent)) + 'px'; + } + fndiv.style.display = ''; return fndiv; } -- cgit v1.2.3