diff options
author | Michael Hamann <michael@content-space.de> | 2011-02-24 23:27:24 +0100 |
---|---|---|
committer | Michael Hamann <michael@content-space.de> | 2011-02-24 23:27:24 +0100 |
commit | f77fc90de1e477b721442757cd7413f91cccc044 (patch) | |
tree | 2abb734dacf39419b96b6b70c65115de57228fc3 /lib/scripts | |
parent | b8c040db1fdc0eee80963e57d95a15fd3813912d (diff) | |
parent | bd07158f0f2569ae470f980dd49d69b7f1fd2c49 (diff) | |
download | rpg-f77fc90de1e477b721442757cd7413f91cccc044.tar.gz rpg-f77fc90de1e477b721442757cd7413f91cccc044.tar.bz2 |
Merge branch 'master' into indexer_rewrite
Conflicts:
inc/fulltext.php
inc/indexer.php
lib/exe/indexer.php
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/edit.js | 111 | ||||
-rw-r--r-- | lib/scripts/locktimer.js | 99 | ||||
-rw-r--r-- | lib/scripts/script.js | 70 |
3 files changed, 165 insertions, 115 deletions
diff --git a/lib/scripts/edit.js b/lib/scripts/edit.js index 01262bcef..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); @@ -341,104 +347,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..f5ba1c60d --- /dev/null +++ b/lib/scripts/locktimer.js @@ -0,0 +1,99 @@ +/** + * 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; + if($('wiki__text').readOnly) 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(); + } +}; + diff --git a/lib/scripts/script.js b/lib/scripts/script.js index c79c9b683..2cc1246f9 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -114,6 +114,20 @@ function findPosY(object){ } //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 * * @author Andreas Gohr <andi@splitbrain.org> @@ -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; } @@ -460,19 +496,29 @@ addInitEvent(function(){ }); /** - * Add the event handler to the actiondropdown + * Autosubmit quick select forms + * + * When a <select> 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 <andi@splitbrain.org> */ 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<selects.length; i++){ + // auto submit on change + addEvent(selects[i],'change',function(e){ + this.form.submit(); + }); + // hide submit buttons + var btns = selects[i].form.getElementsByTagName('input'); + for(var j=0; j<btns.length; j++){ + if(btns[j].type == 'submit'){ + btns[j].style.display = 'none'; + } + } + } }); /** |