(function ($) { if(typeof Sarissa == "undefined") throw "jsTree xml_nested: Sarissa is not included."; $.extend($.tree.datastores, { "xml_nested" : function () { return { get : function(obj, tree, opts) { var str = ""; if(!obj || $(obj).size() == 0) { obj = tree.container.children("ul").children("li"); } else obj = $(obj); if(obj.size() > 1) { var _this = this; var str = ''; obj.each(function () { str += _this.get(this, tree, $.extend(true, {}, opts, { callback : true })); }); str += ''; return str; } if(!opts) var opts = {}; if(!opts.outer_attrib) opts.outer_attrib = [ "id", "rel", "class" ]; if(!opts.inner_attrib) opts.inner_attrib = [ ]; if(!opts.callback) str += ''; str += ' 0) str += ' ' + opts.outer_attrib[i] + '="' + val.toString() + '" '; delete val; } str += '>'; str += ''; if(tree.settings.languages.length) { for(var i in tree.settings.languages) { if(!tree.settings.languages.hasOwnProperty(i)) continue; str += this.process_inner(obj.children("a." + tree.settings.languages[i]), tree, opts, tree.settings.languages[i]); } } else { str += this.process_inner(obj.children("a"), tree, opts); } str += ''; if(obj.children("ul").size() > 0) { var _this = this; obj.children("ul").children("li").each(function () { str += _this.get(this, tree, $.extend(true, {}, opts, { callback : true })); }); } str += ''; if(!opts.callback) str += ''; return str; }, process_inner : function(obj, tree, opts, lang) { var str = ' 0) str += ' ' + opts.inner_attrib[j] + '="' + val.toString() + '" '; delete val; } } } str += '>'; return str; }, parse : function(data, tree, opts, callback) { var processor = new XSLTProcessor(); processor.importStylesheet($.tree.datastores.xml_nested.xsl); var result = $((new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace('','')); // Opera bug if(result.size() > 1) result = result.eq(1); if(result.is("ul")) result = result.html(); else result = result.find("ul:eq(0)").html(); if(callback) callback.call(null,result); // Disabled because of Chrome issues // if(callback) callback.call(null,(new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace(/^]*>/i,"").replace(/<\/ul>$/i,"")); }, load : function(data, tree, opts, callback) { if(opts.staticData) { callback.call(null, (new DOMParser()).parseFromString(opts.staticData,'text/xml')); } else { $.ajax({ 'type' : opts.method, 'url' : opts.url, 'data' : data, 'dataType' : "xml", 'success' : function (d, textStatus) { callback.call(null, d); }, 'error' : function (xhttp, textStatus, errorThrown) { callback.call(null, false); tree.error(errorThrown + " " + textStatus); } }); } } } } }); $.tree.datastores.xml_nested.xsl = (new DOMParser()).parseFromString('','text/xml'); })(jQuery);