summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2014-09-20 22:14:04 +0200
committerczaks <marcin@6irc.net>2014-09-20 22:14:04 +0200
commit7e8bf0ec497f4dc437369b6c5f8061c347733d84 (patch)
tree47665ca9c7b2e9dd08d20e56cd7d827699d22ddd /js
parentf5820d2aae45f60b6e6998b9ec2997c68a66fbf6 (diff)
parent7288f1dec786844a159af30f0286be5912b13db6 (diff)
Merge branch 'master' of github.com:vichan-devel/Tinyboard
Diffstat (limited to 'js')
-rw-r--r--js/favorites.js75
-rw-r--r--js/quick-reply.js2
2 files changed, 77 insertions, 0 deletions
diff --git a/js/favorites.js b/js/favorites.js
new file mode 100644
index 00000000..30bf12d0
--- /dev/null
+++ b/js/favorites.js
@@ -0,0 +1,75 @@
+/*
+ * favorites.js - Allow user to favorite boards and put them in the bar
+ *
+ * Copyright (c) 2014 Fredrick Brennan <admin@8chan.co>
+ *
+ * Usage:
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/favorites.js';
+ */
+
+if (!localStorage.favorites) {
+ localStorage.favorites = '[]';
+}
+
+function favorite(board) {
+ var favorites = JSON.parse(localStorage.favorites);
+ favorites.push(board);
+ localStorage.favorites = JSON.stringify(favorites);
+};
+
+function unfavorite(board) {
+ var favorites = JSON.parse(localStorage.favorites);
+ var index = $.inArray(board, favorites);
+ if (~index) {
+ favorites.splice(index, 1);
+ }
+ localStorage.favorites = JSON.stringify(favorites);
+};
+
+function handle_boards(data) {
+ var boards = new Array();
+ data = JSON.parse(data);
+
+ $.each(data, function(k, v) {
+ boards.push('<a href="/'+v+'">'+v+'</a>');
+ })
+
+ if (boards[0]) {
+ return $('<span class="favorite-boards"></span>').append(' [ '+boards.slice(0,10).join(" / ")+' ] ');
+ }
+}
+
+function add_favorites() {
+ $('.favorite-boards').remove();
+
+ var boards = handle_boards(localStorage.favorites);
+
+ $('.boardlist').append(boards);
+};
+
+if (active_page == 'thread' || active_page == 'index') {
+ $(document).ready(function(){
+ var favorites = JSON.parse(localStorage.favorites);
+ var is_board_favorite = ~$.inArray(board_name, favorites);
+ console.log(is_board_favorite);
+
+ $('header>h1').append('<a id="favorite-star" href="#" data-active="'+(is_board_favorite ? 'true' : 'false')+'" style="color: '+(is_board_favorite ? 'yellow' : 'grey')+'; text-decoration:none">\u2605</span>');
+ add_favorites();
+
+ $('#favorite-star').on('click', function(e) {
+ e.preventDefault();
+ if (!$(this).data('active')) {
+ favorite(board_name);
+ add_favorites();
+ $(this).css('color', 'yellow');
+ $(this).data('active', true);
+ } else {
+ unfavorite(board_name);
+ add_favorites();
+ $(this).css('color', 'grey');
+ $(this).data('active', false);
+ }
+ });
+ });
+}
diff --git a/js/quick-reply.js b/js/quick-reply.js
index 93cab334..07fe4aef 100644
--- a/js/quick-reply.js
+++ b/js/quick-reply.js
@@ -266,6 +266,8 @@
$postForm.find('input[type="file"]').parent()
.removeAttr('colspan')
.after($('<td class="spoiler"></td>').append(this, ' ', $('<label for="q-spoiler-image">').text(_('Spoiler Image'))));
+ } else if ($(this).attr('name') == 'no_country') {
+ $td.find('label,input[type="checkbox"]').remove();
} else {
$(tr).remove();
}