dekiapi(); /* Based on CollapsibleTree template, by neilw, 2009 Completely rewritten by Blake Harms to add AJAX Version: 1.7b Changelog: 1.2 - Fixed a MAJOR bug where IE didn't read XML properly 1.3 - Fixed XML parsing for all major browsers. 1.5 - Added Ajax checks for subpage #s and added depth to the bullets 1.5.1 - Removed click function from pages that do not have subpages 1.6 - Fixes for German language - Thanks Baum! 1.7b - BETA: Converted to use page IDs as links, to fix all character encoding and URL escaping issues (neilw) 1.7c - @himikel 2010-04-30: Change pageid non-standard html tag with name that is standard (solve parsing problems) required to use modified WikiTree template to change Wiki.Tree pageid tag 1.7d - @himikel 2010-07-14: Added secure option to avoid anonymous authentication, using modified WikiTree template 1.7e - @himikel 2010-12-23: Escape decoding applied to subtree urls */ // NOTE: This template requires the file "collapse_icons.gif" to be installed in the location // specified below //@himikel mod 2010-11-09: Using local image resources var icons = "/skins/local/collapse_icons.gif"; var loaderLocation = "/skins/local/loadinfo.net.gif"; //var icons = "http://developer.mindtouch.com/@api/deki/files/4538/=collapse_icons.gif"; //var loaderLocation = "http://developer.mindtouch.com/@api/deki/files/4568/=loadinfo.net.gif"; // USAGE: template.collapsibleList(path, slide) // "path": Path for wiki.tree to load. // "slide": if true, use "slide" effect to show/hide subtrees (default: false) // Args var path = __request.args.path ?? args.path ?? $0 ?? $path ?? page.path; //@himikel mod 2010/04/30 var slide = __request.args.slide ?? args.slide ?? $1 ?? $slide ?? false; //@himikel mod 2010/04/30 //@himikel #add 2010-07-14: Added secure option to avoid anonymous authentication var secure = __request.args.secure ?? args.secure ?? $2 ?? $secure ?? true; // Output <html> <head> // // First script element is unique to each template call, passing args to the common code // <script type="text/javascript">" DekiWiki.$(document).ready(function($) { collapse_list(Deki.$('#" .. @id .. "').find('ul'),0, "..json.emit(slide).."); }); "</script> // // This script element is always the same, so only one copy will end up on the page even if the // template is called multiple times // <script type="text/javascript">" var collapseIcon_hide = '0px -64px'; var collapseIcon_show = '0px -80px'; function readXML(str){ var xml; if ($.browser.msie && typeof str == 'string') { xml = new ActiveXObject('Microsoft.XMLDOM'); xml.async = false; xml.loadXML(str); } else { var parser = new DOMParser(); xml = parser.parseFromString(str, 'text/xml'); } return xml; } function collapse_list(ul, depth, slide){ Deki.$(ul).children().each(function(){ var $child = Deki.$(this).css({'margin-left':'0', 'padding-left':'0', 'list-style-type':'none'}).prepend( '<img src=\"/skins/common/icons/icon-trans.gif\" style=\"background-image:url(".. icons .. ")\" /> '); var $img = $child.children('img:first'); var child_id = $child.children('a:first').attr('name'); // Check each item for subpages, if they have them, add the + button, if not, set depth. Deki.$.ajax({ url: '/@api/deki/pages/'+child_id+'/subpages', type: 'GET', data: { limit:0 }, dataType: ($.browser.msie) ? 'text' : 'xml', complete: function(data) { var xml = readXML(data.responseText); var count = Deki.$('subpages',xml).attr('totalcount'); if(count > 0 ){ $img.css('background-position', collapseIcon_show); } else { $img.css('background-position', '0px -'+(16+16*(depth%3))+'px') .css('cursor','auto') .unbind('click'); } } }); // Take action when expand or collapse icon is clicked $img.css('background-position', collapseIcon_show) .css('cursor','pointer') .click(function(){ $self= Deki.$(this); $parent = $self.parent(); var subpages = $parent.children('ul:first'); if(subpages.css('display') == 'none'){ // subpages is hidden //show sublist if(slide) subpages.slideDown('fast'); else subpages.show(); $self.css('background-position',collapseIcon_hide); } else if(subpages.html() && subpages.html().length > 0){ // subpages is not hidden //hide sublist if(slide) subpages.slideUp('fast'); else subpages.hide(); $self.css('background-position',collapseIcon_show); } else { // the hard part... // loader icon. $self.css('background-image','url("..loaderLocation..")'); //strip all empty uls $parent.find('ul').each(function(){ if(! subpages.html() || subpages.html().length <= 0){ Deki.$(this).remove(); } }); // collect parent's page id. var link = $parent.find('a'); var pageid = link.attr('name'); // load list with ajax // create and immediately hide the list subpages = Deki.$('<ul></ul>').css('display','none'); Deki.$.ajax({ url: '/@api/deki/pages/'+pageid+'/subpages', type: 'GET', dataType: ($.browser.msie) ? 'text' : 'xml', complete: function(data) { var xml = readXML(data.responseText); var titles = Deki.$('title',xml); var paths = Deki.$('path', xml); if(titles.length > 0 ){ // Pre-populate list for(var i=0; i< titles.length;i++){ var pageid = Deki.$(titles[i]).parent().attr('id'); var $child = Deki.$('<li></li>') .append(Deki.$('<a></a>') .text(Deki.$(titles[i]).text()) //@himikel #mod-1.7e 2010-12-23: - Escape decoding applied to subtree urls .attr({'href':'/index.php?title='+Deki.url.encode(unescape('/' + Deki.$(paths[i]).text())), 'name':pageid })) //.attr({'href':'/index.php?title=_&curid='+pageid, 'name':pageid })) .appendTo(subpages); } /* // Now get the true URI for each item, and set the href subpages.find('a').each(function() { var $a = $(this); var pageid = $a.attr('name'); Deki.$.ajax({ url: '/@api/deki/pages/'+pageid+'/info', type: 'GET', dataType: ($.browser.msie) ? 'text' : 'xml', complete: function(data) { var xml = readXML(data.responseText); //@himikel #mod-1.7e 2010-12-23: - Escape decoding applied to subtree urls $a.attr('href', unescape(Deki.url.decode(escape($('page', xml).child(':first').text())))); } }); }); */ $self.css('background-image','url("..icons..")') .css('background-position', collapseIcon_hide); $parent.append(subpages); if(slide) subpages.slideDown('fast') else subpages.show(); collapse_list(subpages, depth+1, slide); } else { $self.css('background-image','url("..icons..")') .css('background-position', '0px -'+(16+16*(depth%3))+'px'); } } }); } }); }); } "</script> </head> // Content goes in the body <body> <p /> // This is a marker to help find the list that follows <div id=(@id)> Wiki.Template("Template:@himikel/WikiTree",{ path: path, depth: 1, pageidtag: "name", secure: secure }) </div>; </body> </html>
Webgune hau MindTouch Core "DekiWiki" software askearekin dabil
Hemengo edukiak Creative Commons BY-NC-SA baimen baten mende daude