diff options
author | Adrian Lang <mail@adrianlang.de> | 2011-07-07 16:08:05 +0200 |
---|---|---|
committer | Adrian Lang <mail@adrianlang.de> | 2011-07-10 12:15:25 +0200 |
commit | d10c9a7424d1ef0aace2fd34e1008196d111a88c (patch) | |
tree | 93f439df14ef3b0712f0eb9b3d83e82b6a18d121 /lib/scripts/index.js | |
parent | 881f2ee268e95e0cdd02bf593d89ca9b42d03060 (diff) | |
download | dokuwiki-d10c9a7424d1ef0aace2fd34e1008196d111a88c.tar.gz dokuwiki-d10c9a7424d1ef0aace2fd34e1008196d111a88c.zip |
Rewrite mediamanager JavaScript
Make it faster, prettier, less wrong, add UI effects, use jQuery UI Dialog,
Abstract tree view stuff away into jQuery.dw_tree
Diffstat (limited to 'lib/scripts/index.js')
-rw-r--r-- | lib/scripts/index.js | 98 |
1 files changed, 10 insertions, 88 deletions
diff --git a/lib/scripts/index.js b/lib/scripts/index.js index c575ab618..96d4e2fb9 100644 --- a/lib/scripts/index.js +++ b/lib/scripts/index.js @@ -1,97 +1,19 @@ /*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 - * - * @author Andreas Gohr <andi@splitbrain.org> - * @author Pierre Spring <pierre.spring@caillou.ch> - */ - -var dw_index = { - - /** - * Delay in ms before showing the throbber. - * Used to skip the throbber for fast AJAX calls. - */ - 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" 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, _this) { - e.preventDefault(); - - 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 = 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('fast', - function () { - $listitem.addClass('closed').removeClass('open'); - } - ); - 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.length > 0) { - show_sublist(); - return; - } - - //prepare the new ul - $sublist = jQuery('<ul class="idx"/>'); - - timeout = window.setTimeout( - bind(show_sublist, '<li><img src="' + DOKU_BASE + 'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>'), dw_index.throbber_delay); - +var dw_index = jQuery('#index__tree').dw_tree({deferInit: true, + load_data: function (show_sublist, $clicky) { jQuery.post( DOKU_BASE + 'lib/exe/ajax.php', $clicky[0].search.substr(1) + '&call=index', - function (data) { - window.clearTimeout(timeout); - show_sublist(data); - }, - 'html' + show_sublist, 'html' ); } -}; +}); +jQuery(function () { + var $tree = jQuery('#index__tree'); + + dw_index.$obj = $tree; -jQuery(dw_index.init); + dw_index.init(); +}); |