From d10c9a7424d1ef0aace2fd34e1008196d111a88c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Thu, 7 Jul 2011 16:08:05 +0200 Subject: 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 --- lib/scripts/tree.js | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 lib/scripts/tree.js (limited to 'lib/scripts/tree.js') diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js new file mode 100644 index 000000000..46b0f6695 --- /dev/null +++ b/lib/scripts/tree.js @@ -0,0 +1,94 @@ +/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true, sloppy: true */ +/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ + +jQuery.fn.dw_tree = function(overrides) { + var dw_tree = { + + /** + * Delay in ms before showing the throbber. + * Used to skip the throbber for fast AJAX calls. + */ + throbber_delay: 500, + + $obj: this, + + toggle_selector: 'a.idx_dir', + + init: function () { + this.$obj.delegate(this.toggle_selector, 'click', this, + this.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 + * @author Ben Coburn + * @author Pierre Spring + */ + toggle: function (e) { + var $listitem, $sublist, timeout, $clicky, show_sublist, dw_tree; + + e.preventDefault(); + + $clicky = jQuery(this); + $listitem = $clicky.closest('li'); + $sublist = $listitem.find('ul').first(); + dw_tree = e.data; + + // if already open, close by hiding the sublist + if ($listitem.hasClass('open')) { + $sublist.dw_hide(function () { + dw_tree.close($clicky); + $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.dw_show(); + }; + + // just show if already loaded + if ($sublist.length > 0) { + show_sublist(); + return; + } + + //prepare the new ul + $sublist = jQuery('
    '); + + timeout = window.setTimeout( + bind(show_sublist, '
  • loading...
  • '), dw_tree.throbber_delay); + + dw_tree.load_data(function (data) { + window.clearTimeout(timeout); + show_sublist(data); + }, $clicky); + }, + + close: function ($clicky) { + }, + + load_data: function (show_data, $clicky) { + show_data(); + } + }; + + jQuery.extend(dw_tree, overrides); + + if (!overrides.deferInit) { + dw_tree.init(); + } + + return dw_tree; +}; -- cgit v1.2.3 From a1dee2b998bc3dc8436bb076435d405ec412e054 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 11 Jul 2011 22:17:27 +0200 Subject: Fix some bugs and glitches in (mediamanager) tree * Fix selector in subtree loading callback * Remove HTML inconsistencies between AJAX and plain PHP lists * Unify icon and CSS class switching in dw_tree and dw_mediamanager --- lib/scripts/tree.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/scripts/tree.js') diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js index 46b0f6695..98d3f55d4 100644 --- a/lib/scripts/tree.js +++ b/lib/scripts/tree.js @@ -29,33 +29,34 @@ jQuery.fn.dw_tree = function(overrides) { * @author Pierre Spring */ toggle: function (e) { - var $listitem, $sublist, timeout, $clicky, show_sublist, dw_tree; + var $listitem, $sublist, timeout, $clicky, show_sublist, dw_tree, opening; e.preventDefault(); + dw_tree = e.data; $clicky = jQuery(this); $listitem = $clicky.closest('li'); $sublist = $listitem.find('ul').first(); - dw_tree = e.data; + opening = $listitem.hasClass('closed'); + $listitem.toggleClass('open closed'); + dw_tree.toggle_display($clicky, opening); // if already open, close by hiding the sublist - if ($listitem.hasClass('open')) { - $sublist.dw_hide(function () { - dw_tree.close($clicky); - $listitem.addClass('closed').removeClass('open'); - }); + if (!opening) { + $sublist.dw_hide(); return; } show_sublist = function (data) { - if (!$listitem.hasClass('open') || $sublist.parent().length === 0) { - $listitem.append($sublist).addClass('open').removeClass('closed'); - } $sublist.hide(); - if (data) { + if (typeof data !== 'undefined') { $sublist.html(data); } - $sublist.dw_show(); + if ($listitem.hasClass('open')) { + // Only show if user didn’t close the list since starting + // to load the content + $sublist.dw_show(); + } }; // just show if already loaded @@ -66,6 +67,7 @@ jQuery.fn.dw_tree = function(overrides) { //prepare the new ul $sublist = jQuery('
      '); + $listitem.append($sublist); timeout = window.setTimeout( bind(show_sublist, '
    • loading...
    • '), dw_tree.throbber_delay); @@ -76,7 +78,7 @@ jQuery.fn.dw_tree = function(overrides) { }, $clicky); }, - close: function ($clicky) { + toggle_display: function ($clicky, opening) { }, load_data: function (show_data, $clicky) { -- cgit v1.2.3 From ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 4 Sep 2011 13:52:43 +0200 Subject: tmp --- lib/scripts/tree.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/scripts/tree.js') diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js index 98d3f55d4..96763053d 100644 --- a/lib/scripts/tree.js +++ b/lib/scripts/tree.js @@ -1,6 +1,3 @@ -/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true, sloppy: true */ -/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ - jQuery.fn.dw_tree = function(overrides) { var dw_tree = { -- cgit v1.2.3 From 1ffc211ddb46bfabe649bbacd1e36bc8e035afa3 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Sun, 4 Sep 2011 15:32:41 +0200 Subject: Revert tmp commits This reverts commit ba6c070edd92ca0fc8a6ee85d51769d64a19ee7c. This reverts commit 923510088dda99cb2790b15308593e47369d4f01. --- lib/scripts/tree.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/scripts/tree.js') diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js index 96763053d..98d3f55d4 100644 --- a/lib/scripts/tree.js +++ b/lib/scripts/tree.js @@ -1,3 +1,6 @@ +/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true, sloppy: true */ +/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ + jQuery.fn.dw_tree = function(overrides) { var dw_tree = { -- cgit v1.2.3 From 5e7a292691951a0fa0a18f06c8b9bcfb509a032d Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Fri, 9 Sep 2011 22:26:16 +0200 Subject: Various JavaScript improvements, JSLint, jQuery --- lib/scripts/tree.js | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/scripts/tree.js') diff --git a/lib/scripts/tree.js b/lib/scripts/tree.js index 98d3f55d4..96763053d 100644 --- a/lib/scripts/tree.js +++ b/lib/scripts/tree.js @@ -1,6 +1,3 @@ -/*jslint white: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: false, newcap: true, immed: true, sloppy: true */ -/*global jQuery, window, DOKU_BASE, DEPRECATED, bind*/ - jQuery.fn.dw_tree = function(overrides) { var dw_tree = { -- cgit v1.2.3