comicpress-2.8/js/bookmark.js

100 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

var BookmarkInfo = Class.create({
2009-12-01 02:05:28 +00:00
'def': {
2009-12-21 03:01:07 +00:00
'permalink': false
},
'initialize': function() {
this.jar = new CookieJar({
'expires': 60 * 60 * 24 * 31,
'path': '/'
});
},
'read': function() {
var bookmark_info = this.jar.get('bookmark-info');
2009-12-21 03:01:07 +00:00
if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) {
bookmark_info = this.def;
}
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
return bookmark_info;
},
'write': function(bookmark_info) {
this.jar.put('bookmark-info', bookmark_info);
if (this.onWrite) { this.onWrite(bookmark_info); }
}
});
2009-12-21 03:01:07 +00:00
var ComicBookmark = {};
ComicBookmark.setup = function(id, mode, url, elements) {
var bookmark_info = new BookmarkInfo();
var info = bookmark_info.read();
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
if ($(id)) {
var hrefs = {};
$$('#' + id + ' a').each(function(a) {
2009-11-28 21:46:45 +00:00
var name = $w(a.className).shift();
hrefs[name] = a;
});
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
switch (mode) {
case 'three-button':
var set_goto_tag = function(i) {
hrefs['goto-tag'].href = (i.permalink ? i.permalink : "#");
['goto-tag','clear-tag'].each(function(which) {
hrefs[which].innerHTML = elements[which + '-' + (i.permalink ? "on" : "off")];
});
2009-12-21 03:51:04 +00:00
$H(hrefs).each(function(info) {
info.value[i.permalink ? 'addClassName' : 'removeClassName']('active');
});
2009-12-21 03:01:07 +00:00
};
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
hrefs['tag-page'].innerHTML = elements['tag-page'];
2009-12-21 03:01:07 +00:00
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
hrefs['tag-page'].observe('click', function(e) {
Event.stop(e);
info.permalink = url;
bookmark_info.write(info);
});
2009-11-21 15:46:13 +00:00
2009-12-21 03:01:07 +00:00
hrefs['goto-tag'].observe('click', function(e) {
if (hrefs['goto-tag'].href == "#") { Event.stop(e); }
});
hrefs['clear-tag'].observe('click', function(e) {
Event.stop(e);
info.permalink = false;
bookmark_info.write(info);
});
break;
case 'one-button':
var set_goto_tag = function(i) {
hrefs['bookmark-clicker'].href = (i.permalink ? i.permalink : "#");
hrefs['bookmark-clicker'].innerHTML = elements['bookmark-clicker-' + (i.permalink ? "on" : "off")];
2009-12-21 03:51:04 +00:00
hrefs['bookmark-clicker'][i.permalink ? 'addClassName' : 'removeClassName']('active');
2009-12-21 03:01:07 +00:00
};
bookmark_info.onWrite = function(i) { set_goto_tag(i); }
set_goto_tag(info);
hrefs['bookmark-clicker'].observe('click', function(e) {
var current_link = info.permalink;
info.permalink = (hrefs['bookmark-clicker'].href.match(/#$/)) ? url : false;
bookmark_info.write(info);
if (hrefs['bookmark-clicker'].href.match(/#$/) == null) {
hrefs['bookmark-clicker'].href = url;
Event.stop(e);
} else {
document.location.href = current_link;
Event.stop(e);
}
});
break;
}
}
};