Skip to content

Commit

Permalink
Task #27 Comic bookmarking.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesgs committed Sep 21, 2015
1 parent 3fb7664 commit eef1b82
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
22 changes: 17 additions & 5 deletions assets/js/bookmark.js
Expand Up @@ -24,33 +24,45 @@
storage : null,
BOOKMARK_HISTORY : 'mangapress-bookmark-history',
BOOKMARK : 'mangapress-bookmark',
$bookmark : null,
init: function() {
this.storage = localStorage;
this.checkItem();
},

checkItem : function() {
var bookmark = JSON.parse(this.storage.getItem(this.BOOKMARK)),
pageHref = window.location.href,
$bookmark = $('#bookmark-comic');
pageHref = window.location.href;

this.$bookmark = $('#bookmark-comic');

if (bookmark == null) {
return;
}

if (bookmark.url == pageHref) {
$bookmark.text($bookmark.data('bookmarkedLabel'));
this.$bookmark.text( this.$bookmark.data('bookmarkedLabel') );
}
},

bookmark : function() {
var href = window.location.href,
pageTitle = window.document.title,
data = {},
d = new Date();
data = {};

var existingBookmarkData = this.storage.getItem(this.BOOKMARK);

if (existingBookmarkData) {
var bookmarkHistory = JSON.parse(this.storage.getItem(this.BOOKMARK_HISTORY));
if (!bookmarkHistory) {
bookmarkHistory = [];
}

bookmarkHistory.push(existingBookmarkData);
this.storage.setItem(this.BOOKMARK_HISTORY, JSON.stringify(bookmarkHistory));

// change label state
this.$bookmark.text( this.$bookmark.data('bookmarkedLabel') );
}

data = {
Expand Down
1 change: 1 addition & 0 deletions includes/template-functions.php
Expand Up @@ -14,6 +14,7 @@
/**
* Bookmark button template tag
* @todo Add l10/i18n functionality
* @todo Define $attrs parameters
* @param array $attrs Attributes
*/
function mangapress_bookmark_button($attrs)
Expand Down
5 changes: 2 additions & 3 deletions mangapress-posts.php
Expand Up @@ -498,14 +498,14 @@ public function get_remove_image_html()
*/
public function save_post($post_id, $post)
{
$flash_messages = MangaPress_Bootstrap::get_instance()->get_helper('flashmessage');

if ($post->post_type !== self::POST_TYPE || empty($_POST))
return $post_id;

if (!wp_verify_nonce(filter_input(INPUT_POST, '_insert_comic'), self::NONCE_INSERT_COMIC))
return $post_id;

$flash_messages = MangaPress_Bootstrap::get_instance()->get_helper('flashmessage');

$image_ID = (int)filter_input(INPUT_POST, '_mangapress_comic_image', FILTER_SANITIZE_NUMBER_INT);
if ($image_ID) {
set_post_thumbnail($post_id, $image_ID);
Expand All @@ -526,7 +526,6 @@ public function save_post($post_id, $post)
}

return $post_id;

}

}
2 changes: 1 addition & 1 deletion templates/single-comic.php
Expand Up @@ -9,7 +9,7 @@
*/
?>
<?php mangapress_comic_navigation(); ?>

<?php var_dump(mangapress_get_comic_term_ID()); ?>
<div class="bookmark">
<?php mangapress_bookmark_button(array()); ?>
</div>
Expand Down

0 comments on commit eef1b82

Please sign in to comment.