diff --git a/js/bookmark.js b/js/bookmark.js new file mode 100644 index 0000000..e890e3e --- /dev/null +++ b/js/bookmark.js @@ -0,0 +1,70 @@ +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() { + var bookmark_info = this.jar.get('bookmark-info'); + + if ((typeof(bookmark_info) != 'object') || (bookmark_info == null)) { + bookmark_info = this.default; + } + + return bookmark_info; + }, + 'write': function(bookmark_info) { + this.jar.put('bookmark-info', bookmark_info); + if (this.onWrite) { this.onWrite(bookmark_info); } + } +}); + +Event.observe(window, 'load', function() { + var bookmark_info = new BookmarkInfo(); + var info = bookmark_info.read(); + + var hrefs = {}; + $$('#comic-bookmark-holder a').each(function(a) { + var name = $w(a.className).shift(); + hrefs[name] = a; + }); + + 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"]; + }); + }; + + bookmark_info.onWrite = function(i) { set_goto_tag(i); } + set_goto_tag(info); + + Event.observe(hrefs['tag-page'], 'click', function(e) { + Event.stop(e); + info.permalink = permalink; + bookmark_info.write(info); + }); + + Event.observe(hrefs['clear-tag'], 'click', function(e) { + Event.stop(e); + info.permalink = false; + bookmark_info.write(info); + }); + + Event.observe(hrefs['goto-tag'], 'click', function(e) { + if (hrefs['goto-tag'].href == "#") { Event.stop(e); } + }); +}); diff --git a/widgets/BookmarkWidget.inc b/widgets/BookmarkWidget.inc new file mode 100644 index 0000000..bc6415e --- /dev/null +++ b/widgets/BookmarkWidget.inc @@ -0,0 +1,34 @@ + __('Let your readers save their place via a cookie.', 'comicpress'))); + + $this->comicpress = $comicpress; + + add_action('wp_head', array(&$this, 'wp_head')); + + wp_enqueue_script('prototype'); + wp_enqueue_script('cookiejar', get_template_directory_uri() . '/js/cookiejar.js', array('prototype')); + wp_enqueue_script('bookmark', get_template_directory_uri() . '/js/bookmark.js', array('prototype', 'cookiejar')); + } + + function wp_head() { ?> + + +
+ + + +
+