1/*jslint sloppy: true */ 2/*global jQuery, LANG, document, alert */ 3 4/** 5 * Automatic behaviours 6 * 7 * This class wraps various JavaScript functionalities that are triggered 8 * automatically whenever a certain object is in the DOM or a certain CSS 9 * class was found 10 */ 11var dw_behaviour = { 12 13 init: function(){ 14 dw_behaviour.focusMarker(); 15 dw_behaviour.scrollToMarker(); 16 dw_behaviour.closeMsgOnClick(); 17 dw_behaviour.removeHighlightOnClick(); 18 dw_behaviour.quickSelect(); 19 dw_behaviour.checkWindowsShares(); 20 }, 21 22 /** 23 * Looks for an element with the ID scroll__here at scrolls to it 24 */ 25 scrollToMarker: function(){ 26 var $obj = jQuery('#scroll__here'); 27 if($obj.length) { 28 $obj[0].scrollIntoView(); 29 } 30 }, 31 32 /** 33 * Looks for an element with the ID focus__this at sets focus to it 34 */ 35 focusMarker: function(){ 36 jQuery('#focus__this').focus(); 37 }, 38 39 /** 40 * Close messages shown by the msg() PHP function by click 41 */ 42 closeMsgOnClick: function(){ 43 jQuery('div.success, div.info, div.error, div.notify').click( 44 function(e){ 45 jQuery(e.target).fadeOut('fast'); 46 } 47 ); 48 }, 49 50 /** 51 * Remove all search highlighting when clicking on a highlighted term 52 * 53 * @FIXME would be nice to have it fade out 54 */ 55 removeHighlightOnClick: function(){ 56 jQuery('span.search_hit').click( 57 function(e){ 58 jQuery(e.target).removeClass('search_hit'); 59 } 60 ); 61 }, 62 63 /** 64 * Autosubmit quick select forms 65 * 66 * When a <select> tag has the class "quickselect", this script will 67 * automatically submit its parent form when the select value changes. 68 * It also hides the submit button of the form. 69 * 70 * @author Andreas Gohr <andi@splitbrain.org> 71 */ 72 quickSelect: function(){ 73 jQuery('select.quickselect') 74 .change(function(e){ e.target.form.submit(); }) 75 .parents('form').find('input[type=submit]').hide(); 76 }, 77 78 /** 79 * Display error for Windows Shares on browsers other than IE 80 * 81 * @author Michael Klier <chi@chimeric.de> 82 */ 83 checkWindowsShares: function() { 84 if(!LANG.nosmblinks || document.all !== null) { 85 // No warning requested or none necessary 86 return; 87 } 88 89 jQuery('a.windows').live('click', function(){ 90 alert(LANG.nosmblinks); 91 }); 92 } 93 94}; 95 96jQuery(dw_behaviour.init); 97