Skip to content
Snippets Groups Projects
Commit cd06d16f authored by Adrian Lang's avatar Adrian Lang
Browse files

Fix index Javascript, introduce compatibility.js

  * Removed "use strict" statement, since it does not work with our script file
    joining (the statement has to be the first in a file or function)
  * Make index a global object again to allow overriding and enhancing
  * Use prefix dw_ for index object
  * Reintroduce index.treeattach
  * Support deprecated index.toggle calling convention
  * Add $ prefix for jQuery variables
  * Use slide animation for freshly loaded sublists as well
  * Fix various errors
parent 4b938509
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,7 @@ function js_out(){
DOKU_INC.'lib/scripts/linkwiz.js',
DOKU_INC.'lib/scripts/media.js',
DOKU_INC.'lib/scripts/subscriptions.js',
DOKU_INC.'lib/scripts/compatibility.js',
# disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js',
DOKU_TPLINC.'script.js',
DOKU_INC.'lib/scripts/behaviour.js',
......
/*jslint sloppy: true */
/*global dw_index, DEPRECATED */
var index = {
throbber_delay: dw_index.throbber_delay,
toggle: function () {
DEPRECATED();
dw_index.toggle.apply(dw_index, arguments);
},
treeattach: function () {
DEPRECATED();
dw_index.treeattach.apply(dw_index, arguments);
}
};
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, strict: true, newcap: true, immed: true */
/*global jQuery, window, DOKU_BASE*/
"use strict";
/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true */
/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/
/**
* Javascript for index view
......@@ -9,87 +8,90 @@
* @author Pierre Spring <pierre.spring@caillou.ch>
*/
(function ($) {
var throbber_delay, toggle;
var dw_index = {
/**
/**
* Delay in ms before showing the throbber.
* Used to skip the throbber for fast AJAX calls.
*/
throbber_delay = 500;
throbber_delay: 500,
/**
* Initialize tree when the DOM is ready.
*/
init: function () {
dw_index.treeattach('#index__tree');
},
treeattach: function (obj) {
jQuery(obj).delegate('a.idx_dir', 'click', dw_index.toggle);
},
/**
* Open or close a subtree using AJAX
* The contents of subtrees are "cached" untill the page is reloaded.
* The contents of subtrees are "cached" until the page is reloaded.
* A "loading" indicator is shown only when the AJAX call is slow.
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Ben Coburn <btcoburn@silicodon.net>
* @author Pierre Spring <pierre.spring@caillou.ch>
*/
toggle = function (e) {
toggle: function (e, _this) {
e.preventDefault();
var listitem, sublist, timeout, ul, clicky;
var $listitem, $sublist, timeout, $clicky, show_sublist;
if (_this) {
DEPRECATED('Use dw_index.toggle(e) (or dw_index.toggle.call(clicky, e) if you need to override clicky), not dw_index.toggle(e, clicky)');
}
clicky = $(this);
listitem = clicky.parentsUntil('li').last().parent();
sublist = listitem.find('ul').first();
$clicky = jQuery(_this || this);
$listitem = $clicky.closest('li');
$sublist = $listitem.find('ul').first();
// if already open, close by removing the sublist
if (listitem.hasClass('open')) {
sublist.slideUp(
if ($listitem.hasClass('open')) {
$sublist.slideUp('fast',
function () {
listitem.addClass('closed').removeClass('open');
$listitem.addClass('closed').removeClass('open');
}
);
e.preventDefault();
return;
}
show_sublist = function (data) {
if (!$listitem.hasClass('open') || $sublist.parent().length === 0) {
$listitem.append($sublist).addClass('open').removeClass('closed');
}
$sublist.hide();
if (data) {
$sublist.html(data);
}
$sublist.slideDown('fast');
};
// just show if already loaded
if (sublist.size() > 0 && !listitem.hasClass('open')) {
listitem.addClass('open').removeClass('closed');
sublist.slideDown();
e.preventDefault();
if ($sublist.length > 0) {
show_sublist();
return;
}
//prepare the new ul
ul = $('<ul class="idx"/>');
timeout = window.setTimeout(function () {
// show the throbber as needed
if (!listitem.hasClass('open')) {
ul.html('<li><img src="' + DOKU_BASE + 'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>');
listitem
.append(ul)
.addClass('open')
.removeClass('closed');
}
}, throbber_delay);
$sublist = jQuery('<ul class="idx"/>');
$.post(
timeout = window.setTimeout(
bind(show_sublist, '<li><img src="' + DOKU_BASE + 'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>'), dw_index.throbber_delay);
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
clicky.attr('search').substr(1) + '&call=index',
$clicky[0].search.substr(1) + '&call=index',
function (data) {
window.clearTimeout(timeout);
ul.html(data);
if (listitem.className !== 'open') {
if (ul.parent().size() === 0) {
// if the UL has not been attached when showing the
// throbber, then let's do it now.
listitem.append(ul);
}
listitem.addClass('open').removeClass('closed');
}
show_sublist(data);
},
'html'
);
e.preventDefault();
};
}
};
$(function () {
// Initialze tree when the DOM is ready.
$('#index__tree').delegate('a.idx_dir', 'click', toggle);
});
}(jQuery));
\ No newline at end of file
jQuery(dw_index.init);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment