/** * Hides elements with a slide animation * * @param {function} fn optional callback to run after hiding * @param {bool} noaria supress aria-expanded state setting * @author Adrian Lang */ jQuery.fn.dw_hide = function(fn, noaria) { if(!noaria) this.attr('aria-expanded', 'false'); return this.slideUp('fast', fn); }; /** * Unhides elements with a slide animation * * @param {function} fn optional callback to run after hiding * @param {bool} noaria supress aria-expanded state setting * @author Adrian Lang */ jQuery.fn.dw_show = function(fn, noaria) { if(!noaria) this.attr('aria-expanded', 'true'); return this.slideDown('fast', fn); }; /** * Toggles visibility of an element using a slide element * * @param {bool} state the current state of the element (optional) * @param {function} fn callback after the state has been toggled * @param {bool} noaria supress aria-expanded state setting */ jQuery.fn.dw_toggle = function(state, fn, noaria) { return this.each(function() { var $this = jQuery(this); if (typeof state === 'undefined') { state = $this.is(':hidden'); } $this[state ? "dw_show" : "dw_hide" ](fn, noaria); }); }; /** * 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 */ var dw_behaviour = { init: function(){ dw_behaviour.focusMarker(); dw_behaviour.scrollToMarker(); dw_behaviour.removeHighlightOnClick(); dw_behaviour.quickSelect(); dw_behaviour.checkWindowsShares(); dw_behaviour.subscription(); dw_behaviour.revisionBoxHandler(); jQuery(document).on('click','#page__revisions input[type=checkbox]', dw_behaviour.revisionBoxHandler ); jQuery('.bounce').effect('bounce', {times:10}, 2000 ); }, /** * Looks for an element with the ID scroll__here at scrolls to it */ scrollToMarker: function(){ var $obj = jQuery('#scroll__here'); if($obj.length) { if($obj.offset().top != 0) { jQuery('html, body').animate({ scrollTop: $obj.offset().top - 100 }, 500); } else { // hidden object have no offset but can still be scrolled into view $obj[0].scrollIntoView(); } } }, /** * Looks for an element with the ID focus__this at sets focus to it */ focusMarker: function(){ jQuery('#focus__this').focus(); }, /** * Remove all search highlighting when clicking on a highlighted term */ removeHighlightOnClick: function(){ jQuery('span.search_hit').click( function(e){ jQuery(e.target).removeClass('search_hit', 1000); } ); }, /** * Autosubmit quick select forms * * When a