2 if(typeof
Sarissa ==
"undefined")
throw "jsTree xml_nested: Sarissa is not included.";
4 $.extend($.tree.datastores, {
5 "xml_nested" : function () {
7 get :
function(obj, tree, opts) {
9 if(!obj || $(obj).size() == 0) {
10 obj = tree.container.children(
"ul").children(
"li");
17 obj.each(
function () {
18 str += _this.get(
this, tree, $.
extend(
true, {}, opts, { callback :
true }));
24 if(!opts) var opts = {};
25 if(!opts.outer_attrib) opts.outer_attrib = [
"id",
"rel",
"class" ];
26 if(!opts.inner_attrib) opts.inner_attrib = [ ];
27 if(!opts.callback) str +=
'<root>';
30 for(var i in opts.outer_attrib) {
31 if(!opts.outer_attrib.hasOwnProperty(i))
continue;
32 var val = (opts.outer_attrib[i] ==
"class") ? obj.attr(opts.outer_attrib[i]).replace(/(^| )last( |$)/ig,
" ").replace(/(^| )(leaf|closed|open)( |$)/ig,
" ") : obj.attr(opts.outer_attrib[i]);
33 if(typeof val !=
"undefined" && val.toString().replace(
" ",
"").length > 0) str +=
' ' + opts.outer_attrib[i] +
'="' + val.toString() +
'" ';
39 if(tree.settings.languages.length) {
40 for(var i in tree.settings.languages) {
41 if(!tree.settings.languages.hasOwnProperty(i))
continue;
42 str += this.process_inner(obj.children(
"a." + tree.settings.languages[i]), tree, opts, tree.settings.languages[i]);
46 str += this.process_inner(obj.children(
"a"), tree, opts);
50 if(obj.children(
"ul").size() > 0) {
52 obj.children(
"ul").children(
"li").each(
function () {
53 str += _this.get(
this, tree, $.
extend(
true, {}, opts, { callback :
true }));
58 if(!opts.callback) str +=
'</root>';
61 process_inner :
function(obj, tree, opts, lang) {
63 if(lang) str +=
' lang="' + lang +
'" ';
64 if(opts.inner_attrib.length || obj.children(
"ins").get(0).style.backgroundImage.toString().length || obj.children(
"ins").get(0).className.length) {
65 if(obj.children(
"ins").get(0).style.className.length) {
66 str +=
' icon="' + obj.children(
"ins").get(0).style.className +
'" ';
68 if(obj.children(
"ins").get(0).style.backgroundImage.length) {
69 str +=
' icon="' + obj.children(
"ins").get(0).style.backgroundImage.replace(
"url(",
"").replace(
")",
"") +
'" ';
71 if(opts.inner_attrib.length) {
72 for(var j in opts.inner_attrib) {
73 if(!opts.inner_attrib.hasOwnProperty(j))
continue;
74 var val = obj.attr(opts.inner_attrib[j]);
75 if(typeof val !=
"undefined" && val.toString().replace(
" ",
"").length > 0) str +=
' ' + opts.inner_attrib[j] +
'="' + val.toString() +
'" ';
80 str +=
'><![CDATA[' + tree.get_text(obj,lang) +
']]></name>';
83 parse :
function(data, tree, opts, callback) {
84 var processor =
new XSLTProcessor();
85 processor.importStylesheet($.tree.datastores.xml_nested.xsl);
87 var result = $((
new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace(
'<?xml version="1.0"?>',
''));
89 if(result.size() > 1) result = result.eq(1);
90 if(result.is(
"ul")) result = result.html();
91 else result = result.find(
"ul:eq(0)").html();
92 if(callback) callback.call(null,result);
97 load :
function(data, tree, opts, callback) {
99 callback.call(null, (
new DOMParser()).parseFromString(opts.staticData,
'text/xml'));
103 'type' : opts.method,
107 'success' :
function (d, textStatus) {
108 callback.call(null, d);
110 'error' :
function (xhttp, textStatus, errorThrown) {
111 callback.call(null,
false);
112 tree.error(errorThrown +
" " + textStatus);
120 $.tree.datastores.xml_nested.xsl = (
new DOMParser()).parseFromString(
'<?xml version="1.0" encoding="utf-8" ?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ><xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" standalone="no" indent="no" media-type="text/html" /><xsl:template match="/"><xsl:call-template name="nodes"><xsl:with-param name="node" select="/root" /></xsl:call-template></xsl:template><xsl:template name="nodes"><xsl:param name="node" /><ul><xsl:for-each select="$node/item"><xsl:variable name="children" select="count(./item) > 0" /><li><xsl:attribute name="class"><xsl:if test="position() = last()"> last </xsl:if><xsl:choose><xsl:when test="@state = \'open\'"> open </xsl:when><xsl:when test="$children or @hasChildren"> closed </xsl:when><xsl:otherwise> leaf </xsl:otherwise></xsl:choose><xsl:value-of select="@class" /></xsl:attribute><xsl:for-each select="@*"><xsl:if test="name() != \'class\' and name() != \'state\' and name() != \'hasChildren\'"><xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute></xsl:if></xsl:for-each><xsl:for-each select="content/name"><a href=""><xsl:attribute name="class"><xsl:value-of select="@lang" /><xsl:value-of select="@class" /></xsl:attribute><xsl:attribute name="style"><xsl:value-of select="@style" /></xsl:attribute><xsl:for-each select="@*"><xsl:if test="name() != \'style\' and name() != \'class\'"><xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute></xsl:if></xsl:for-each><ins><xsl:if test="string-length(attribute::icon) > 0"><xsl:choose><xsl:when test="not(contains(@icon,\'/\'))"><xsl:attribute name="class"><xsl:value-of select="@icon" /></xsl:attribute></xsl:when><xsl:otherwise><xsl:attribute name="style">background-image:url(<xsl:value-of select="@icon" />);</xsl:attribute></xsl:otherwise></xsl:choose></xsl:if><xsl:text> </xsl:text></ins><xsl:value-of select="current()" /></a></xsl:for-each><xsl:if test="$children or @hasChildren"><xsl:call-template name="nodes"><xsl:with-param name="node" select="current()" /></xsl:call-template></xsl:if></li></xsl:for-each></ul></xsl:template></xsl:stylesheet>',
'text/xml');