summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/exe/js.php1
-rw-r--r--lib/scripts/compatibility.js16
-rw-r--r--lib/scripts/index.js104
3 files changed, 70 insertions, 51 deletions
diff --git a/lib/exe/js.php b/lib/exe/js.php
index 0d4a08ebd..25dc8496a 100644
--- a/lib/exe/js.php
+++ b/lib/exe/js.php
@@ -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',
diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js
new file mode 100644
index 000000000..559cc359a
--- /dev/null
+++ b/lib/scripts/compatibility.js
@@ -0,0 +1,16 @@
+/*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);
+ }
+};
diff --git a/lib/scripts/index.js b/lib/scripts/index.js
index da9ce96a4..c575ab618 100644
--- a/lib/scripts/index.js
+++ b/lib/scripts/index.js
@@ -1,6 +1,5 @@
-/*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);