westdc-zf1/public/static/js/custom/models/categorymap.js

75 lines
1.5 KiB
JavaScript

(function( $ ){
var methods = {
subnode : function(title,lft,rgt){
html = '<div class="btn disabled pull-left">' + title + '</div>';
return html;
},
topnode : function(title,lft,rgt){
html = '<div class="btn btn-large btn-block disabled" style="width:100%;">' + title + '</div>';
return html;
},
getSubNodes : function (data,lft,rgt){
nodes = new Array();
for(i in data)
{
if(data[i].lft > lft && data[i].rgt < rgt)
{
nodes.push(data[i]);
}
}
return nodes;
},
getTopNodes : function(data){
nodes = new Array();
for(i in data)
{
if(data[i].tid == 0)
{
nodes.push(data[i]);
}
}
return nodes;
}
}
$.fn.categorymap = function( options ) {
var settings = $.extend( {
'data':''
}, options);
return this.each(function() {
console.log(settings.data);
var data = $.parseJSON(settings.data);
var subtype = 0;
var html = "";
var top = methods.getTopNodes(settings.data);
for(i in top)
{
if( top[i].rgt - top[i].lft>1 )
{
html += '<div style="width:'+ (top[i].rgt-top[i].lft)*100+'px;" class="pull-left">';
html += methods.topnode(top[i].title,top[i].lft,top[i].rgt);
node = methods.getSubNodes(top[i].title,top[i].lft,top[i].rgt);
if(node.length>0)
{
for(d in node)
{
html += methods.subnode(node[d].title,node[d].lft,node[d].rgt);
}
}
html += '</div>';
}else{
subtype++;
}
}
$(this).html(html);
console.log(subtype);
});
};
})( jQuery );