2 * Hides elements with a slide animation
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>
8 jQuery.fn.dw_hide = function(fn, noaria) {
9 if(!noaria) this.attr('aria-expanded', 'false');
10 return this.slideUp('fast', fn);
14 * Unhides elements with a slide animation
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>
20 jQuery.fn.dw_show = function(fn, noaria) {
21 if(!noaria) this.attr('aria-expanded', 'true');
22 return this.slideDown('fast', fn);
26 * Toggles visibility of an element using a slide element
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
32 jQuery.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');
38 $this[state ? "dw_show" : "dw_hide" ](fn, noaria);
43 * Automatic behaviours
45 * This class wraps various JavaScript functionalities that are triggered
46 * automatically whenever a certain object is in the DOM or a certain CSS
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 dw_behaviour.pageRestoreConfirm();
59 dw_behaviour.securityCheck();
61 dw_behaviour.revisionBoxHandler();
62 jQuery(document).on('click','#page__revisions input[type=checkbox]',
63 dw_behaviour.revisionBoxHandler
66 jQuery('.bounce').effect('bounce', {times:10}, 2000 );
70 * Looks for an element with the ID scroll__here at scrolls to it
72 scrollToMarker: function(){
73 var $obj = jQuery('#scroll__here');
75 if($obj.offset().top != 0) {
76 jQuery('html, body').animate({
77 scrollTop: $obj.offset().top - 100
80 // hidden object have no offset but can still be scrolled into view
81 $obj[0].scrollIntoView();
87 * Display confirm dialog on page restore action
89 pageRestoreConfirm: function(){
90 jQuery('#dokuwiki__pagetools li.revert a').on('click',
92 return confirm(LANG.restore_confirm);
98 * Looks for an element with the ID focus__this at sets focus to it
100 focusMarker: function(){
101 jQuery('#focus__this').trigger('focus');
105 * Remove all search highlighting when clicking on a highlighted term
107 removeHighlightOnClick: function(){
108 jQuery('span.search_hit').on('click',
110 jQuery(e.target).removeClass('search_hit', 1000);
116 * Autosubmit quick select forms
118 * When a <select> or <input> tag has the class "quickselect", this script will
119 * automatically submit its parent form when the select value changes.
120 * It also hides the submit button of the form.
122 * This includes a workaround a weird behaviour when the submit button has a name
124 * @link https://trackjs.com/blog/when-form-submit-is-not-a-function/
125 * @author Andreas Gohr <andi@splitbrain.org>
127 quickSelect: function(){
128 jQuery('.quickselect')
129 .change(function(e){ HTMLFormElement.prototype.submit.call(e.target.form); })
130 .closest('form').find(':button').not('.show').hide();
134 * Display error for Windows Shares on browsers other than IE
136 * @author Michael Klier <chi@chimeric.de>
138 checkWindowsShares: function() {
139 if(!LANG.nosmblinks || navigator.userAgent.match(/(Trident|MSIE|Edge)/)) {
140 // No warning requested or none necessary
144 jQuery('a.windows').on('click', function(){
145 alert(LANG.nosmblinks.replace(/\\n/,"\n"));
150 * Hide list subscription style if target is a page
152 * @author Adrian Lang <lang@cosmocode.de>
153 * @author Pierre Spring <pierre.spring@caillou.ch>
155 subscription: function(){
156 var $form, $list, $digest;
158 $form = jQuery('#subscribe__form');
159 if (0 === $form.length) return;
161 $list = $form.find("input[name='sub_style'][value='list']");
162 $digest = $form.find("input[name='sub_style'][value='digest']");
164 $form.find("input[name='sub_target']")
167 var $this = jQuery(this), show_list;
168 if (!$this.prop('checked')) {
172 show_list = $this.val().match(/:$/);
173 $list.parent().dw_toggle(show_list);
174 if (!show_list && $list.prop('checked')) {
175 $digest.prop('checked', 'checked');
184 * disable multiple revisions checkboxes if two are checked
186 * @author Andreas Gohr <andi@splitbrain.org>
187 * @author Anika Henke <anika@selfthinker.org>
189 revisionBoxHandler: function() {
190 var $revisions = jQuery('#page__revisions');
191 var $all = jQuery('input[type="checkbox"][name="rev2[]"]', $revisions);
192 var $checked = $all.filter(':checked');
193 var $button = jQuery('button', $revisions);
195 if($checked.length < 2) {
196 $all.prop('disabled', false);
197 $button.prop('disabled', true);
199 $all.prop('disabled', true);
200 $button.prop('disabled', false);
201 $checked.each(function(i) {
202 jQuery(this).prop('disabled', false);
204 jQuery(this).prop('checked', false);
211 * Check that access to the data directory is properly secured
213 * A successful check (a 403 error was returned when loading the image) is saved
214 * to session storage and not repeated again until the next browser session. This
215 * avoids overeager security bans (see #3363)
217 securityCheck: function () {
218 var $checkDiv = jQuery('#security__check');
219 if (!$checkDiv.length) return;
220 if (sessionStorage.getItem('dw-security-check:' + DOKU_BASE)) {
221 // check was already executed successfully
226 var img = new Image();
227 img.onerror = function () {
228 // successful check will not be repeated during session
230 sessionStorage.setItem('dw-security-check:' + DOKU_BASE, true);
232 img.onload = function () {
233 // check failed, display a warning message
234 $checkDiv.html(LANG.data_insecure);
235 $checkDiv.addClass('error');
237 img.src = $checkDiv.data('src') + '?t=' + Date.now();
241 jQuery(dw_behaviour.init);