comicpress-2.8/js/bookmark.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

var button_images = {
'clear-tag': {
'off': '3a.gif', 'on': '3.gif'
},
'goto-tag': {
'off': '2a.gif', 'on': '2.gif'
}
};
var BookmarkInfo = Class.create({
'default': {
'permalink': false
},
'initialize': function() {
this.jar = new CookieJar({
'expires': 60 * 60 * 24 * 31,
'path': '/'
});
},
'read': function() {
2009-11-21 15:46:13 +00:00
var bookmark_info = this.jar.get('bookmark-info');
if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
2009-11-21 15:46:13 +00:00
bookmark_info = this.default;
}
2009-11-21 15:46:13 +00:00
return bookmark_info;
},
'write': function(bookmark_info) {
2009-11-21 15:46:13 +00:00
this.jar.put('bookmark-info', bookmark_info);
if (this.onWrite) { this.onWrite(bookmark_info); }
}
});
2009-11-21 15:46:13 +00:00
Event.observe(window, 'load', function() {
var bookmark_info = new BookmarkInfo();
var info = bookmark_info.read();
2009-11-21 15:46:13 +00:00
2009-11-28 21:46:45 +00:00
if ($('comic-bookmark-holder')) {
var hrefs = {};
$$('#comic-bookmark-holder a').each(function(a) {
var name = $w(a.className).shift();
hrefs[name] = a;
});
2009-11-21 15:46:13 +00:00
2009-11-28 21:46:45 +00:00
var set_goto_tag = function(i) {
hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
[ 'goto-tag','clear-tag' ].each(function(which) {
hrefs[which].select('img')[0].src = image_root + button_images[which][i.permalink ? "on" : "off"];
});
};
2009-11-21 15:46:13 +00:00
2009-11-28 21:46:45 +00:00
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
2009-11-28 21:46:45 +00:00
Event.observe(hrefs['tag-page'], 'click', function(e) {
Event.stop(e);
info.permalink = permalink;
bookmark_info.write(info);
});
2009-11-21 15:46:13 +00:00
2009-11-28 21:46:45 +00:00
Event.observe(hrefs['clear-tag'], 'click', function(e) {
Event.stop(e);
info.permalink = false;
bookmark_info.write(info);
});
2009-11-21 15:46:13 +00:00
2009-11-28 21:46:45 +00:00
Event.observe(hrefs['goto-tag'], 'click', function(e) {
if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
});
}
});