summaryrefslogtreecommitdiff
path: root/my-foxmarks.js
blob: 40b65b1836463c92e75cec2381cc73e0a9b00a4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function setup_foxmarks() {
    $.getJSON("bookmarks.json",
              create_html_display
              );
};
 
var default_icon={'src':'folder-item.png'};
 
var templates={
    "separator": function() {
        return [
                'li',{},['hr',{}]
                ];
    },
    "folder" : function() {
        if (this.args.pnid!=null) {
            return [
                    'li',{"class":"folder"},[
                             'p',{"class":"folder-name"},this.args.name,
                             'ul',{ "id":this.nid, "class":"folder" },''
                             ]
                    ];
        }
        else {
            return [
                    'h1',{},this.args.name,
                    'ul',{ "id":this.nid },''
                    ];
        }
    },
    "bookmark" : function() {
        return [
                'li',{},[
                         'img',(this.args.icon ? {"src": this.args.icon} : default_icon),[],
                         'a',{"href":this.args.url},this.args.name
                         ]
                ];
    }
};
 
function create_html_display(marks) {
    jQuery.each(marks["commands"],function() {
            if (this.action == "insert" && this.nid != undefined) {
                if (templates.hasOwnProperty(this.args.ntype)) {
                    var parent;
                    if (this.args.pnid!=null) {
                        parent=$("#"+this.args.pnid);
                    }
                    else {
                        parent=$("body");
                    }
                    //console.debug("applying template for %s to %o on %o",this.args.ntype,this,parent);
                    parent.tplAppend(this,templates[this.args.ntype]);
                }
            }
        });
    $('li.folder').children('p,ul').andSelf().addClass('collapsed');
    $('li.folder').click(function(event){
            //event.preventDefault();
            event.stopPropagation();
            $(this).children('p,ul').andSelf().toggleClass('collapsed');
        });
};
 
$(document).ready(setup_foxmarks);