diff --git a/lib/exe/js.php b/lib/exe/js.php index e4c5c2ab8916f02fea8c763c1580b2aa8c8d6f11..0d4a08ebdbdfa46e6bc2355c0344e5738e6dafad 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -60,6 +60,7 @@ function js_out(){ DOKU_INC.'lib/scripts/subscriptions.js', # disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js', DOKU_TPLINC.'script.js', + DOKU_INC.'lib/scripts/behaviour.js', ); // add possible plugin scripts and userscript @@ -121,8 +122,6 @@ function js_out(){ if($conf['locktime'] != 0){ js_runonstart("locktimer.init(".($conf['locktime'] - 60).",'".js_escape($lang['willexpire'])."',".$conf['usedraft'].", 'wiki__text')"); } - js_runonstart('scrollToMarker()'); - js_runonstart('focusMarker()'); // init hotkeys - must have been done after init of toolbar # disabled for FS#1958 js_runonstart('initializeHotkeys()'); diff --git a/lib/scripts/behaviour.js b/lib/scripts/behaviour.js new file mode 100644 index 0000000000000000000000000000000000000000..31b82050e9a1ad45beb71b8840e2c800f9c99ff3 --- /dev/null +++ b/lib/scripts/behaviour.js @@ -0,0 +1,91 @@ +/** + * Automatic behaviours + * + * This class wraps various JavaScript functionalities that are triggered + * automatically whenever a certain object is in the DOM or a certain CSS + * class was found + */ + +dw_behaviour = { + + init: function(){ + dw_behaviour.focusMarker(); + dw_behaviour.scrollToMarker(); + dw_behaviour.closeMsgOnClick(); + dw_behaviour.removeHighlightOnClick(); + dw_behaviour.quickSelect(); + dw_behaviour.checkWindowsShares(); + }, + + /** + * Looks for an element with the ID scroll__here at scrolls to it + */ + scrollToMarker: function(){ + var obj = jQuery('#scroll__here'); + if(obj.length) obj[0].scrollIntoView(); + }, + + /** + * Looks for an element with the ID focus__this at sets focus to it + */ + focusMarker: function(){ + var obj = jQuery('#focus__this'); + if(obj.length) obj[0].focus(); + }, + + /** + * Close messages shown by the msg() PHP function by click + */ + closeMsgOnClick: function(){ + jQuery('div.success, div.info, div.error, div.notify').click( + function(e){ + jQuery(e.target).fadeOut('fast'); + } + ); + }, + + /** + * Remove all search highlighting when clicking on a highlighted term + * + * @FIXME would be nice to have it fade out + */ + removeHighlightOnClick: function(){ + jQuery('span.search_hit').click( + function(e){ + jQuery(e.target).removeClass('search_hit'); + } + ); + }, + + /** + * 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> + */ + quickSelect: function(){ + jQuery('select.quickselect') + .change(function(e){ e.target.form.submit(); }) + .parents('form').find('input[type=submit]').hide(); + }, + + /** + * Display error for Windows Shares on browsers other than IE + * + * @author Michael Klier <chi@chimeric.de> + */ + checkWindowsShares: function() { + if(!LANG['nosmblinks']) return true; + if(document.all != null) return true; + + jQuery('a.windows').click(function(){ + alert(LANG['nosmblinks']); + }); + } + +}; + +jQuery(dw_behaviour.init); diff --git a/lib/scripts/media.js b/lib/scripts/media.js index cf4a839d9c1594cf4466e0c1c55a6b8f793284a3..bcdba2a489cd86a277d42b67e05e79656321412a 100644 --- a/lib/scripts/media.js +++ b/lib/scripts/media.js @@ -326,7 +326,8 @@ event.preventDefault(); - cleanMsgArea(); + jQuery.remove('div.success, div.info, div.error, div.notify'); + content = $('#media__content'); content.html('<img src="' + DOKU_BASE + 'lib/images/loading.gif" alt="..." class="load" />'); diff --git a/lib/scripts/script.js b/lib/scripts/script.js index 20e4751900afcf67ed813b2af91e0cbccdc8ad06..9b9ca600c550d3b18864e50024fb982e526358af 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -471,34 +471,6 @@ function closePopups(){ } } -/** - * Looks for an element with the ID scroll__here at scrolls to it - */ -function scrollToMarker(){ - var obj = $('scroll__here'); - if(obj) obj.scrollIntoView(); -} - -/** - * Looks for an element with the ID focus__this at sets focus to it - */ -function focusMarker(){ - var obj = $('focus__this'); - if(obj) obj.focus(); -} - -/** - * Remove messages - */ -function cleanMsgArea(){ - var elems = getElementsByClass('(success|info|error)',document,'div'); - if(elems){ - for(var i=0; i<elems.length; i++){ - elems[i].style.display = 'none'; - } - } -} - /** * disable multiple revisions checkboxes if two are checked * @@ -528,60 +500,6 @@ addInitEvent(function(){ } }); -/** - * 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 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'; - } - } - } -}); - -/** - * Display error for Windows Shares on browsers other than IE - * - * @author Michael Klier <chi@chimeric.de> - */ -function checkWindowsShares() { - if(!LANG['nosmblinks']) return true; - if(document.all != null) return true; - - var elems = getElementsByClass('windows',document,'a'); - if(elems){ - for(var i=0; i<elems.length; i++){ - var share = elems[i]; - addEvent(share,'click',function(){ - alert(LANG['nosmblinks']); - }); - } - } -} - -/** - * Add the event handler for the Windows Shares check - * - * @author Michael Klier <chi@chimeric.de> - */ -addInitEvent(function(){ - checkWindowsShares(); -}); /** * Highlight the section when hovering over the appropriate section edit button