1/** 2 * Hides elements with a slide animation 3 * 4 * @param {function} fn optional callback to run after hiding 5 * @param {bool} noaria supress aria-expanded state setting 6 * @author Adrian Lang <mail@adrianlang.de> 7 */ 8jQuery.fn.dw_hide = function(fn, noaria) { 9 if(!noaria) this.attr('aria-expanded', 'false'); 10 return this.slideUp('fast', fn); 11}; 12 13/** 14 * Unhides elements with a slide animation 15 * 16 * @param {function} fn optional callback to run after hiding 17 * @param {bool} noaria supress aria-expanded state setting 18 * @author Adrian Lang <mail@adrianlang.de> 19 */ 20jQuery.fn.dw_show = function(fn, noaria) { 21 if(!noaria) this.attr('aria-expanded', 'true'); 22 return this.slideDown('fast', fn); 23}; 24 25/** 26 * Toggles visibility of an element using a slide element 27 * 28 * @param {bool} state the current state of the element (optional) 29 * @param {function} fn callback after the state has been toggled 30 * @param {bool} noaria supress aria-expanded state setting 31 */ 32jQuery.fn.dw_toggle = function(state, fn, noaria) { 33 return this.each(function() { 34 var $this = jQuery(this); 35 if (typeof state === 'undefined') { 36 state = $this.is(':hidden'); 37 } 38 $this[state ? "dw_show" : "dw_hide" ](fn, noaria); 39 }); 40}; 41 42/** 43 * Automatic behaviours 44 * 45 * This class wraps various JavaScript functionalities that are triggered 46 * automatically whenever a certain object is in the DOM or a certain CSS 47 * class was found 48 */ 49var dw_behaviour = { 50 51 init: function(){ 52 dw_behaviour.focusMarker(); 53 dw_behaviour.scrollToMarker(); 54 dw_behaviour.removeHighlightOnClick(); 55 dw_behaviour.quickSelect(); 56 dw_behaviour.checkWindowsShares(); 57 dw_behaviour.subscription(); 58 59 dw_behaviour.revisionBoxHandler(); 60 jQuery(document).on('click','#page__revisions input[type=checkbox]', 61 dw_behaviour.revisionBoxHandler 62 ); 63 64 jQuery('.bounce').effect('bounce', {times:10}, 2000 ); 65 }, 66 67 /** 68 * Looks for an element with the ID scroll__here at scrolls to it 69 */ 70 scrollToMarker: function(){ 71 var $obj = jQuery('#scroll__here'); 72 if($obj.length) { 73 if($obj.offset().top != 0) { 74 jQuery('html, body').animate({ 75 scrollTop: $obj.offset().top - 100 76 }, 500); 77 } else { 78 // hidden object have no offset but can still be scrolled into view 79 $obj[0].scrollIntoView(); 80 } 81 } 82 }, 83 84 /** 85 * Looks for an element with the ID focus__this at sets focus to it 86 */ 87 focusMarker: function(){ 88 jQuery('#focus__this').focus(); 89 }, 90 91 /** 92 * Remove all search highlighting when clicking on a highlighted term 93 */ 94 removeHighlightOnClick: function(){ 95 jQuery('span.search_hit').click( 96 function(e){ 97 jQuery(e.target).removeClass('search_hit', 1000); 98 } 99 ); 100 }, 101 102 /** 103 * Autosubmit quick select forms 104 * 105 * When a <select> tag has the class "quickselect", this script will 106 * automatically submit its parent form when the select value changes. 107 * It also hides the submit button of the form. 108 * 109 * @author Andreas Gohr <andi@splitbrain.org> 110 */ 111 quickSelect: function(){ 112 jQuery('select.quickselect') 113 .change(function(e){ e.target.form.submit(); }) 114 .closest('form').find(':button').not('.show').hide(); 115 }, 116 117 /** 118 * Display error for Windows Shares on browsers other than IE 119 * 120 * @author Michael Klier <chi@chimeric.de> 121 */ 122 checkWindowsShares: function() { 123 if(!LANG.nosmblinks || navigator.userAgent.match(/(Trident|MSIE|Edge)/)) { 124 // No warning requested or none necessary 125 return; 126 } 127 128 jQuery('a.windows').on('click', function(){ 129 alert(LANG.nosmblinks.replace(/\\n/,"\n")); 130 }); 131 }, 132 133 /** 134 * Hide list subscription style if target is a page 135 * 136 * @author Adrian Lang <lang@cosmocode.de> 137 * @author Pierre Spring <pierre.spring@caillou.ch> 138 */ 139 subscription: function(){ 140 var $form, $list, $digest; 141 142 $form = jQuery('#subscribe__form'); 143 if (0 === $form.length) return; 144 145 $list = $form.find("input[name='sub_style'][value='list']"); 146 $digest = $form.find("input[name='sub_style'][value='digest']"); 147 148 $form.find("input[name='sub_target']") 149 .click( 150 function () { 151 var $this = jQuery(this), show_list; 152 if (!$this.prop('checked')) { 153 return; 154 } 155 156 show_list = $this.val().match(/:$/); 157 $list.parent().dw_toggle(show_list); 158 if (!show_list && $list.prop('checked')) { 159 $digest.prop('checked', 'checked'); 160 } 161 } 162 ) 163 .filter(':checked') 164 .click(); 165 }, 166 167 /** 168 * disable multiple revisions checkboxes if two are checked 169 * 170 * @author Andreas Gohr <andi@splitbrain.org> 171 * @author Anika Henke <anika@selfthinker.org> 172 */ 173 revisionBoxHandler: function() { 174 var $revisions = jQuery('#page__revisions'); 175 var $all = jQuery('input[type=checkbox]', $revisions); 176 var $checked = $all.filter(':checked'); 177 var $button = jQuery('button', $revisions); 178 179 if($checked.length < 2) { 180 $all.removeAttr('disabled'); 181 $button.attr('disabled', true); 182 } else { 183 $all.attr('disabled', true); 184 $button.removeAttr('disabled'); 185 $checked.each(function(i) { 186 jQuery(this).removeAttr('disabled'); 187 if(i>1) { 188 jQuery(this).attr('checked', false); 189 } 190 }); 191 } 192 } 193}; 194 195jQuery(dw_behaviour.init); 196