summaryrefslogtreecommitdiff
path: root/lib/scripts
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2007-07-16 20:46:05 +0200
committerAndreas Gohr <andi@splitbrain.org>2007-07-16 20:46:05 +0200
commita06884abe180891c09730983f2b8d13662c3fd34 (patch)
treeee5c49faf32390245e1cf3c720a642e148c775a3 /lib/scripts
parent40cc87038bae8c160922eca41f9f9dde28b04cb5 (diff)
downloadrpg-a06884abe180891c09730983f2b8d13662c3fd34.tar.gz
rpg-a06884abe180891c09730983f2b8d13662c3fd34.tar.bz2
AJAX for the index view
This makes the index view much more responsive by loading sub namespaces through AJAX if JavaScript is available. The used throbber image probably looks bad on dark backgrounds. If someone could provide a better one it would be greatly appreciated. darcs-hash:20070716184605-7ad00-adf298ee3303d50f2b4b6b66e5ea3ff8d8c2bf9a.gz
Diffstat (limited to 'lib/scripts')
-rw-r--r--lib/scripts/index.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/scripts/index.js b/lib/scripts/index.js
new file mode 100644
index 000000000..7d85fd1b6
--- /dev/null
+++ b/lib/scripts/index.js
@@ -0,0 +1,67 @@
+/**
+ * Java Script for index view
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+index = {
+
+ /**
+ * Attach event handlers to all "folders" below the given element
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+ treeattach: function(obj){
+ if(!obj) return;
+
+ var items = getElementsByClass('idx_dir',obj,'a')
+ for(var i=0; i<items.length; i++){
+ var elem = items[i];
+
+ // attach action to make the link clickable by AJAX
+ addEvent(elem,'click',function(event){ return index.toggle(event,this); });
+ }
+ },
+
+ /**
+ * Open or close a subtree using AJAX
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+ toggle: function(event,clicky){
+ var listitem = clicky.parentNode.parentNode;
+
+ // if already open, close by removing the sublist
+ var sublists = listitem.getElementsByTagName('ul');
+ if(sublists.length){
+ listitem.removeChild(sublists[0]);
+ listitem.className='closed';
+ return false;
+ }
+
+ // prepare an AJAX call to fetch the subtree
+ var ajax = new sack(DOKU_BASE + 'lib/exe/ajax.php');
+ ajax.AjaxFailedAlert = '';
+ ajax.encodeURIString = false;
+ if(ajax.failed) return true;
+
+ //prepare the new ul
+ var ul = document.createElement('ul');
+ ul.className = 'idx';
+ ul.innerHTML = '<li><img src="'+DOKU_BASE+'lib/images/throbber.gif" alt="loading..." title="loading..." /></li>';
+ listitem.appendChild(ul);
+ ajax.elementObj = ul;
+ ajax.afterCompletion = function(){ index.treeattach(ul); };
+ ajax.runAJAX(clicky.search.substr(1)+'&call=index');
+ listitem.className='open';
+ return false;
+
+ },
+
+
+}
+
+
+addInitEvent(function(){
+ index.treeattach($('index__tree'));
+});