您可能會喜歡......

2017年6月1日 星期四

Label VB語法

var label_tree= new Object();

function tn(tag)
{
return tag.substring(1,tag.length-1);
}

function build_node(tree,idx,cnt)
{
if(!tree[idx[0]]){
tree[idx[0]]=new Object();
tree[idx[0]]['_cnt']=0;
tree[idx[0]]['_item']=new Array();
}
tree[idx[0]]['_cnt'] = parseInt(tree[idx[0]]['_cnt']) + parseInt(cnt);
if(idx.length==1){
return tree[idx[0]];
}
return build_node(tree[idx[0]],idx.slice(1),cnt);
}
function add_label(_name,_cnt,_url,_dir)
{
var e1 = new RegExp("\\[(.+?)\\]","g");
var e = new RegExp("\\[(.+)\\]","g");
var m = _name.match(e);
var tag = _name;
var obj=new Object();
obj['tag']=_name;
obj['cnt']=_cnt;
obj['dir']=_dir;
obj['url']=_url;
if(m){
obj['tag']= _name.substring(m[0].length,_name.length);
var m1 = _name.match(e1);
if(m1){
node=build_node(label_tree,m1,_cnt);
if(node){
node['_item'].push(obj);
}
}
}
else{
if(!label_tree['_item']){
label_tree['_item']=new Array();
}
label_tree['_item'].push(obj);
}
}
function menu_exp(id)
{
var ul=document.getElementById("ul_"+id);
var li=document.getElementById("li_"+id);
if (ul.style.display=="none"){
ul.style.display="block"
li.style.backgroundImage="url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfsQSCKIJXEN4RuEBmkJlORaXHdQGSp9KKG4vODY2v-Z6p4-xLBIxNh_7V1WITqJ8Y5Yio_mXYppUHdwt8m9A4_yH9Fx07T-t6n7rxnzMVNlODcOviDx4ouC2PRPOad7927tkl3agvJX8/)"
}
else {
ul.style.display="none"
li.style.backgroundImage="url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijn1_PrUCzuf_lINx6T3tcqIFBo_4v53_w-_xiiReIhA9L3y5jK02eP7JlgrhZ-X48XX_C_hpNst1X8GD0rsa55rVmKpt6poTZnScApq5P6REsodKThVVhGYJcAhF2zwqhg3Y80IdLUPY/)"
}
}
function draw_obj(obj)
{
document.write("<li style='padding-left: 0px>'");
document.write("<img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5U6QOd0bHmH1PSaah-TpVGdI95aJf13U-14upMplW7WSMlNu0t59FtBZgko154n4BNqianeNv7XECt8bb0nkFge38fmyn0fvjL_0ugFfsPP8zIMNynUunR0FaWXl95K6qrDTwJ32KWPw/s1600/icon-yellow-bullet.png' /><a dir='"+obj['dir']+"' href='"+obj['url']+"'>"+obj['tag']+"</a>");
document.write("<span dir='"+obj['dir']+"'>("+obj['cnt']+")</span>");
document.write("</li>\n");
}
function draw_tree(tree)
{
for(var tag in tree){
if(tag!='_item'&& tag!='_cnt'){
var rid = Math.random();
document.write("<li class=submenu id=li_"+rid+" onclick=menu_exp('"+rid+"'); style='font-weight:bold;padding-left: 20px;background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijn1_PrUCzuf_lINx6T3tcqIFBo_4v53_w-_xiiReIhA9L3y5jK02eP7JlgrhZ-X48XX_C_hpNst1X8GD0rsa55rVmKpt6poTZnScApq5P6REsodKThVVhGYJcAhF2zwqhg3Y80IdLUPY/) no-repeat left 0px;cursor: pointer'>");
document.write(tn(tag));
document.write("("+tree[tag]['_cnt']+")");
document.write("</li>");
document.write("<ul id=ul_"+rid+" style='display:none;padding-left: 20px'>");
draw_tree(tree[tag]);
document.write("</ul>\n");
}
}
if(tree['_item']){
for(var i=0;i < tree['_item'].length;i++){
draw_obj(tree['_item'][i]);
}
}
}
</script>
<script>
add_label('[he][test]test1','1','http://uclassroom.blogspot.tw/search/label/%5Bhe%5D%5Btest%5Dtest1','ltr');
</script>
<script>
add_label('[my][test]test3','1','http://uclassroom.blogspot.tw/search/label/%5Bmy%5D%5Btest%5Dtest3','ltr');
</script>
<script>
add_label('[my][test]test4','1','http://uclassroom.blogspot.tw/search/label/%5Bmy%5D%5Btest%5Dtest4','ltr');
</script>
<script>
add_label('[you][test]test2','1','http://uclassroom.blogspot.tw/search/label/%5Byou%5D%5Btest%5Dtest2','ltr');
</script>
<ul>
<script>
draw_tree(label_tree);

沒有留言:

張貼留言