From 17e2e2545f2fd3607a14238ecee25eb7a605ce84 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 10 Jun 2011 20:26:04 +0200 Subject: Moved behavioural functions into it's own object and file JavaScript functions adding behaviours based on IDs or class names where moved to their own object into behaviour.js and where jQueryized. --- lib/exe/js.php | 3 +- lib/scripts/behaviour.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/scripts/media.js | 3 +- lib/scripts/script.js | 82 ------------------------------------------- 4 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 lib/scripts/behaviour.js (limited to 'lib') diff --git a/lib/exe/js.php b/lib/exe/js.php index e4c5c2ab8..0d4a08ebd 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 000000000..31b82050e --- /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