2 if(typeof
Sarissa ==
"undefined")
throw "jsTree xml_flat: Sarissa is not included.";
4 $.extend($.tree.datastores, {
5 "xml_flat" : function () {
7 get :
function(obj, t, opts) {
9 if(!obj || $(obj).size() == 0) {
10 obj = t.container.children(
"ul").children(
"li");
17 obj.each(
function () {
19 str += _this.get(
this, t, opts);
25 if(!opts) var opts = {};
26 if(!opts.outer_attrib) opts.outer_attrib = [
"id",
"rel",
"class" ];
27 if(!opts.inner_attrib) opts.inner_attrib = [ ];
28 if(!opts.callback) str +=
'<root>';
31 str +=
' parent_id="' + (obj.parents(
"li:eq(0)").size() ? obj.parents(
"li:eq(0)").attr(
"id") : 0) +
'" ';
32 for(var i in opts.outer_attrib) {
33 if(!opts.outer_attrib.hasOwnProperty(i))
continue;
34 var val = (opts.outer_attrib[i] ==
"class") ? obj.attr(opts.outer_attrib[i]).toString().replace(/(^| )last( |$)/ig,
" ").replace(/(^| )(leaf|closed|open)( |$)/ig,
" ") : obj.attr(opts.outer_attrib[i]);
35 if(typeof val !=
"undefined" && val.toString().replace(
" ",
"").length > 0) str +=
' ' + opts.outer_attrib[i] +
'="' + val.toString() +
'" ';
41 if(t.settings.languages.length) {
42 for(var i in t.settings.languages) {
43 if(!t.settings.languages.hasOwnProperty(i))
continue;
44 str += this.process_inner(obj.children(
"a." + t.settings.languages[i]), t, opts, t.settings.languages[i]);
48 str += this.process_inner(obj.children(
"a"), t, opts);
53 if(obj.children(
"ul").size() > 0) {
56 obj.children(
"ul").children(
"li").each(
function () {
57 str += _this.get(
this, t, opts);
59 opts.callback =
false;
61 if(!opts.callback) str +=
'</root>';
64 process_inner :
function(obj, t, opts, lang) {
66 if(lang) str +=
' lang="' + lang +
'" ';
67 if(opts.inner_attrib.length || obj.children(
"ins").get(0).style.backgroundImage.toString().length || obj.children(
"ins").get(0).className.length) {
68 if(obj.children(
"ins").get(0).style.className.length) {
69 str +=
' icon="' + obj.children(
"ins").get(0).style.className +
'" ';
71 if(obj.children(
"ins").get(0).style.backgroundImage.length) {
72 str +=
' icon="' + obj.children(
"ins").get(0).style.backgroundImage.replace(
"url(",
"").replace(
")",
"") +
'" ';
74 if(opts.inner_attrib.length) {
75 for(var j in opts.inner_attrib) {
76 if(!opts.inner_attrib.hasOwnProperty(j))
continue;
77 var val = obj.attr(opts.inner_attrib[j]);
78 if(typeof val !=
"undefined" && val.toString().replace(
" ",
"").length > 0) str +=
' ' + opts.inner_attrib[j] +
'="' + val.toString() +
'" ';
83 str +=
'><![CDATA[' + t.get_text(obj,lang) +
']]></name>';
87 parse :
function(data, t, opts, callback) {
88 var processor =
new XSLTProcessor();
89 processor.importStylesheet($.tree.datastores.xml_flat.xsl);
91 var result = $((
new XMLSerializer()).serializeToString(processor.transformToDocument(data)));
92 if(result.is(
"ul")) result = result.html();
93 else result = result.find(
"ul").html();
94 if(callback) callback.call(null,result);
99 load :
function(data, t, opts, callback) {
101 callback.call(null, (
new DOMParser()).parseFromString(opts.static,
'text/xml'));
105 'type' : opts.method,
109 'success' :
function (d, textStatus) {
110 callback.call(null, d);
112 'error' :
function (xhttp, textStatus, errorThrown) {
113 callback.call(null,
false);
114 t.error(errorThrown +
" " + textStatus);
122 $.tree.datastores.xml_flat.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/xml" /><xsl:template match="/"><ul><xsl:for-each select="//item[not(@parent_id) or @parent_id=0]"><xsl:call-template name="nodes"><xsl:with-param name="node" select="." /><xsl:with-param name="is_last" select="number(position() = last())" /></xsl:call-template></xsl:for-each></ul></xsl:template><xsl:template name="nodes"><xsl:param name="node" /><xsl:param name="theme_path" /><xsl:param name="theme_name" /><xsl:param name="is_last" /><xsl:variable name="children" select="count(//item[@parent_id=$node/attribute::id]) > 0" /><li><xsl:attribute name="class"><xsl:if test="$is_last = true()"> last </xsl:if><xsl:choose><xsl:when test="@state = \'open\'"> open </xsl:when><xsl:when test="$children or @hasChildren or @state = \'closed\'"> 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() != \'parent_id\' and name() != \'hasChildren\' and name() != \'class\' and name() != \'state\'"><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="." /></a></xsl:for-each><xsl:if test="$children or @hasChildren"><ul><xsl:for-each select="//item[@parent_id=$node/attribute::id]"><xsl:call-template name="nodes"><xsl:with-param name="node" select="." /><xsl:with-param name="is_last" select="number(position() = last())" /></xsl:call-template></xsl:for-each></ul></xsl:if></li></xsl:template></xsl:stylesheet>',
'text/xml');