diff options
author | dakkar <dakkar@thenautilus.net> | 2009-04-16 20:46:49 +0200 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2009-04-16 20:46:49 +0200 |
commit | db586f633f5f904bf39c2ae052011a3e5def1962 (patch) | |
tree | 669a889869bf15b846a050db9125978bb826dd68 /my-foxmarks.js | |
download | my-foxmarks-db586f633f5f904bf39c2ae052011a3e5def1962.tar.gz my-foxmarks-db586f633f5f904bf39c2ae052011a3e5def1962.tar.bz2 my-foxmarks-db586f633f5f904bf39c2ae052011a3e5def1962.zip |
first version
Diffstat (limited to 'my-foxmarks.js')
-rw-r--r-- | my-foxmarks.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/my-foxmarks.js b/my-foxmarks.js new file mode 100644 index 0000000..1b085bd --- /dev/null +++ b/my-foxmarks.js @@ -0,0 +1,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); |