summaryrefslogtreecommitdiff
path: root/lib/scripts/behaviour.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2011-06-10 20:26:04 +0200
committerAndreas Gohr <andi@splitbrain.org>2011-06-13 14:26:34 +0200
commit17e2e2545f2fd3607a14238ecee25eb7a605ce84 (patch)
treeb54585710d4867afa3cbc0e33021806d439f31ec /lib/scripts/behaviour.js
parent427fd3cc91f3a9d5ccfba4cfad402d45b40cf103 (diff)
downloadrpg-17e2e2545f2fd3607a14238ecee25eb7a605ce84.tar.gz
rpg-17e2e2545f2fd3607a14238ecee25eb7a605ce84.tar.bz2
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.
Diffstat (limited to 'lib/scripts/behaviour.js')
-rw-r--r--lib/scripts/behaviour.js91
1 files changed, 91 insertions, 0 deletions
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 <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);