summaryrefslogtreecommitdiff
path: root/p/scripts/main.js
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-06-13 18:51:52 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-06-13 18:51:52 +0200
commitf58fdfe93dbf969338fe9cecbd728e0f7add4617 (patch)
treee1629da3361235d1c4ef28944624326491628045 /p/scripts/main.js
parentc053825ff8f9792e692c101585481129b006937b (diff)
parent61f4d5457818204eb28ed394d4f1b97160542baa (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'p/scripts/main.js')
-rw-r--r--p/scripts/main.js372
1 files changed, 319 insertions, 53 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index f0d2bbf7b..f1dd7117c 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1,6 +1,7 @@
"use strict";
var $stream = null,
- isCollapsed = true;
+ isCollapsed = true,
+ shares = 0;
function is_normal_mode() {
return $stream.hasClass('normal');
@@ -20,6 +21,16 @@ function redirect(url, new_tab) {
}
}
+function needsScroll($elem) {
+ var $win = $(window),
+ winTop = $win.scrollTop(),
+ winHeight = $win.height(),
+ winBottom = winTop + winHeight,
+ elemTop = $elem.offset().top,
+ elemBottom = elemTop + $elem.outerHeight();
+ return (elemTop < winTop || elemBottom > winBottom) ? elemTop - (winHeight / 2) : 0;
+}
+
function str2int(str) {
if (str == '') {
return 0;
@@ -96,8 +107,10 @@ function incUnreadsFeed(article, feed_id, nb) {
return isCurrentView;
}
+var pending_feeds = [];
function mark_read(active, only_not_read) {
- if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) {
+ if (active.length === 0 ||
+ (only_not_read === true && !active.hasClass("not_read"))) {
return false;
}
@@ -106,6 +119,16 @@ function mark_read(active, only_not_read) {
return false;
}
+ var feed_url = active.find(".website>a").attr("href"),
+ feed_id = feed_url.substr(feed_url.lastIndexOf('f_')),
+ index_pending = pending_feeds.indexOf(feed_id);
+
+ if (index_pending !== -1) {
+ return false;
+ }
+
+ pending_feeds.push(feed_id);
+
$.ajax({
type: 'POST',
url: url,
@@ -122,9 +145,9 @@ function mark_read(active, only_not_read) {
}
$r.find('.icon').replaceWith(data.icon);
- var feed_url = active.find(".website>a").attr("href"),
- feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
incUnreadsFeed(active, feed_id, inc);
+
+ pending_feeds.splice(index_pending, 1);
});
}
@@ -138,6 +161,16 @@ function mark_favorite(active) {
return false;
}
+ var feed_url = active.find(".website>a").attr("href"),
+ feed_id = feed_url.substr(feed_url.lastIndexOf('f_')),
+ index_pending = pending_feeds.indexOf(feed_id);
+
+ if (index_pending !== -1) {
+ return false;
+ }
+
+ pending_feeds.push(feed_id);
+
$.ajax({
type: 'POST',
url: url,
@@ -168,12 +201,12 @@ function mark_favorite(active) {
elem.setAttribute('data-unread', numberFormat(feed_unreads + inc));
}
}
+
+ pending_feeds.splice(index_pending, 1);
});
}
function toggleContent(new_active, old_active) {
- old_active.removeClass("active").removeClass("current");
-
if (new_active.length === 0) {
return;
}
@@ -189,7 +222,10 @@ function toggleContent(new_active, old_active) {
if (isCollapsed) {
new_active.addClass("active");
}
+ old_active.removeClass("active current");
new_active.addClass("current");
+ } else {
+ new_active.toggleClass('active');
}
var box_to_move = "html,body",
@@ -199,28 +235,27 @@ function toggleContent(new_active, old_active) {
relative_move = true;
}
- var new_pos = new_active.position().top,
- old_scroll = $(box_to_move).scrollTop();
- if (hide_posts) {
+ if (sticky_post) {
+ var new_pos = new_active.position().top - new_active.children('.flux_header').outerHeight(),
+ old_scroll = $(box_to_move).scrollTop();
- new_pos = new_active.position().top;
- old_scroll = $(box_to_move).scrollTop();
+ if (hide_posts) {
+ if (relative_move) {
+ new_pos += old_scroll;
+ }
- if (relative_move) {
- new_pos += old_scroll;
- }
+ if (old_active[0] !== new_active[0]) {
+ new_active.children(".flux_content").first().each(function () {
+ $(box_to_move).scrollTop(new_pos).scrollTop();
+ });
+ }
+ } else {
+ if (relative_move) {
+ new_pos += old_scroll;
+ }
- if (old_active[0] !== new_active[0]) {
- new_active.children(".flux_content").first().each(function () {
- $(box_to_move).scrollTop(new_pos).scrollTop();
- });
+ $(box_to_move).scrollTop(new_pos).scrollTop();
}
- } else {
- if (relative_move) {
- new_pos += old_scroll;
- }
-
- $(box_to_move).scrollTop(new_pos).scrollTop();
}
if (auto_mark_article) {
@@ -239,11 +274,82 @@ function next_entry() {
new_active = old_active.length === 0 ? $(".flux:first") : old_active.nextAll(".flux:first");
toggleContent(new_active, old_active);
- if (!auto_load_more) {
- var last_active = $(".flux:last");
- if (last_active.attr("id") === new_active.attr("id")) {
- load_more_posts();
+ if (new_active.nextAll().length < 3) {
+ load_more_posts();
+ }
+}
+
+function prev_feed() {
+ var active_feed = $("#aside_flux .feeds li.active");
+ if (active_feed.length > 0) {
+ active_feed.prev().find('a.feed').each(function(){this.click();});
+ } else {
+ last_feed();
+ }
+}
+
+function next_feed() {
+ var active_feed = $("#aside_flux .feeds li.active");
+ if (active_feed.length > 0) {
+ active_feed.next().find('a.feed').each(function(){this.click();});
+ } else {
+ first_feed();
+ }
+}
+
+function first_feed() {
+ var feed = $("#aside_flux .feeds.active li:first");
+ if (feed.length > 0) {
+ feed.find('a')[1].click();
+ }
+}
+
+function last_feed() {
+ var feed = $("#aside_flux .feeds.active li:last");
+ if (feed.length > 0) {
+ feed.find('a')[1].click();
+ }
+}
+
+function prev_category() {
+ var active_cat = $("#aside_flux .category.stick.active");
+
+ if (active_cat.length > 0) {
+ var prev_cat = active_cat.parent('li').prev().find('.category.stick a.btn');
+ if (prev_cat.length > 0) {
+ prev_cat[0].click();
+ }
+ } else {
+ last_category();
+ }
+ return;
+}
+
+function next_category() {
+ var active_cat = $("#aside_flux .category.stick.active");
+
+ if (active_cat.length > 0) {
+ var next_cat = active_cat.parent('li').next().find('.category.stick a.btn');
+ if (next_cat.length > 0) {
+ next_cat[0].click();
}
+ } else {
+ first_category();
+ }
+ return;
+}
+
+function first_category() {
+ var cat = $("#aside_flux .category.stick:first");
+ if (cat.length > 0) {
+ cat.find('a.btn')[0].click();
+ }
+}
+
+function last_category() {
+ var cat = $("#aside_flux .category.stick:last");
+ if (cat.length > 0) {
+ cat.find('a.btn')[0].click();
}
}
@@ -252,10 +358,32 @@ function collapse_entry() {
$(".flux.current").toggleClass("active");
}
-function auto_share() {
+function auto_share(key) {
var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]');
- if (share.length) {
+ var shares = share.siblings('.dropdown-menu').find('.item a');
+ if (typeof key === "undefined") {
+ if (!share.length) {
+ return;
+ }
+ // Display the share div
window.location.hash = share.attr('id');
+ // Force scrolling to the share div
+ var scroll = needsScroll(share.closest('.bottom'));
+ if (scroll !== 0) {
+ $('html,body').scrollTop(scroll);
+ }
+ // Force the key value if there is only one action, so we can trigger it automatically
+ if (shares.length === 1) {
+ key = 1;
+ } else {
+ return;
+ }
+ }
+ // Trigger selected share action and hide the share div
+ key = parseInt(key);
+ if (key <= shares.length) {
+ shares[key - 1].click();
+ share.siblings('.dropdown-menu').find('.dropdown-close a')[0].click();
}
}
@@ -390,12 +518,19 @@ function init_shortcuts() {
}, {
'disable_in_input': true
});
+ for(var i = 1; i < 10; i++){
+ shortcut.add(i.toString(), function (e) {
+ auto_share(String.fromCharCode(e.keyCode));
+ }, {
+ 'disable_in_input': true
+ });
+ }
- // Touches de navigation
+ // Touches de navigation pour les articles
shortcut.add(shortcuts.prev_entry, prev_entry, {
'disable_in_input': true
});
- shortcut.add("shift+" + shortcuts.prev_entry, function () {
+ shortcut.add(shortcuts.first_entry, function () {
var old_active = $(".flux.current"),
first = $(".flux:first");
@@ -408,7 +543,7 @@ function init_shortcuts() {
shortcut.add(shortcuts.next_entry, next_entry, {
'disable_in_input': true
});
- shortcut.add("shift+" + shortcuts.next_entry, function () {
+ shortcut.add(shortcuts.last_entry, function () {
var old_active = $(".flux.current"),
last = $(".flux:last");
@@ -418,8 +553,35 @@ function init_shortcuts() {
}, {
'disable_in_input': true
});
+ // Touches de navigation pour les flux
+ shortcut.add("shift+" + shortcuts.prev_entry, prev_feed, {
+ 'disable_in_input': true
+ });
+ shortcut.add("shift+" + shortcuts.next_entry, next_feed, {
+ 'disable_in_input': true
+ });
+ shortcut.add("shift+" + shortcuts.first_entry, first_feed, {
+ 'disable_in_input': true
+ });
+ shortcut.add("shift+" + shortcuts.last_entry, last_feed, {
+ 'disable_in_input': true
+ });
+ // Touches de navigation pour les categories
+ shortcut.add("alt+" + shortcuts.prev_entry, prev_category, {
+ 'disable_in_input': true
+ });
+ shortcut.add("alt+" + shortcuts.next_entry, next_category, {
+ 'disable_in_input': true
+ });
+ shortcut.add("alt+" + shortcuts.first_entry, first_category, {
+ 'disable_in_input': true
+ });
+ shortcut.add("alt+" + shortcuts.last_entry, last_category, {
+ 'disable_in_input': true
+ });
+
shortcut.add(shortcuts.go_website, function () {
- var url_website = $(".flux.active .link a").attr("href");
+ var url_website = $('.flux.current > .flux_header > .title > a').attr("href");
if (auto_mark_site) {
$(".flux.current").each(function () {
@@ -437,11 +599,17 @@ function init_shortcuts() {
}, {
'disable_in_input': true
});
+
+ shortcut.add(shortcuts.focus_search, function () {
+ focus_search();
+ }, {
+ 'disable_in_input': true
+ });
}
function init_stream(divStream) {
- divStream.on('click', '.flux_header', function (e) { //flux_header_toggle
- if ($(e.target).closest('.item.website > a').length > 0) {
+ divStream.on('click', '.flux_header,.flux_content', function (e) { //flux_toggle
+ if ($(e.target).closest('.content, .item.website, .item.link').length > 0) {
return;
}
var old_active = $(".flux.current"),
@@ -468,7 +636,7 @@ function init_stream(divStream) {
return false;
});
- divStream.on('click', '.item.title>a', function (e) {
+ divStream.on('click', '.item.title > a', function (e) {
if (e.ctrlKey) {
return true; //Allow default control-click behaviour such as open in backround-tab
}
@@ -481,7 +649,7 @@ function init_stream(divStream) {
});
if (auto_mark_site) {
- divStream.on('click', '.flux .link a', function () {
+ divStream.on('click', '.flux .link > a', function () {
mark_read($(this).parent().parent().parent(), true);
});
}
@@ -512,37 +680,72 @@ function init_nav_entries() {
}
function init_actualize() {
+ var auto = false;
+
$("#actualize").click(function () {
$.getScript('./?c=javascript&a=actualize').done(function () {
+ if (auto && feed_count < 1) {
+ auto = false;
+ return;
+ }
+
updateFeeds();
});
return false;
});
- if(auto_actualize_feeds) {
- $.getScript('./?c=javascript&a=actualize').done(function () {
- updateFeeds();
- });
+ if (auto_actualize_feeds) {
+ auto = true;
+ $("#actualize").click();
+ }
+}
+
+
+// <notification>
+var notification = null,
+ notification_interval = null,
+ notification_working = false;
+
+function openNotification(msg, status) {
+ if (notification_working === true) {
+ return false;
}
+
+ notification_working = true;
+
+ notification.removeClass();
+ notification.addClass("notification");
+ notification.addClass(status);
+ notification.find(".msg").html(msg);
+ notification.fadeIn(300);
+
+ notification_interval = window.setInterval(closeNotification, 4000);
}
function closeNotification() {
- $(".notification").fadeOut(600, function () {
- $(".notification").remove();
+ notification.fadeOut(600, function() {
+ notification.removeClass();
+ notification.addClass('closed');
+
+ window.clearInterval(notification_interval);
+ notification_working = false;
});
}
function init_notifications() {
- var notif = $(".notification");
- if (notif.length > 0) {
- window.setInterval(closeNotification, 4000);
+ notification = $("#notification");
- notif.find("a.close").click(function () {
- closeNotification();
- return false;
- });
+ notification.find("a.close").click(function () {
+ closeNotification();
+ return false;
+ });
+
+ if (notification.find(".msg").html().length > 0) {
+ notification_working = true;
+ notification_interval = window.setInterval(closeNotification, 4000);
}
}
+// </notification>
function refreshUnreads() {
$.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
@@ -574,7 +777,11 @@ function load_more_posts() {
$.get(url_load_more, function (data) {
box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day'));
$('.pagination').replaceWith($('.pagination', data));
- $('#bigMarkAsRead').attr('href', $('#nav_menu_read_all>a').attr('href'));
+ if (display_order === 'ASC') {
+ $('#nav_menu_read_all>a').attr('href', $('#bigMarkAsRead').attr('href'));
+ } else {
+ $('#bigMarkAsRead').attr('href', $('#nav_menu_read_all>a').attr('href'));
+ }
$('[id^=day_]').each(function (i) {
var ids = $('[id="' + this.id + '"]');
@@ -591,6 +798,10 @@ function load_more_posts() {
});
}
+function focus_search() {
+ $('#search').focus();
+}
+
function init_load_more(box) {
box_load_more = box;
@@ -741,7 +952,7 @@ function init_confirm_action() {
}
function init_print_action() {
- $('.print-article').click(function () {
+ $('.item.share > a[href="#"]').click(function () {
var content = "<html><head><style>"
+ "body { font-family: Serif; text-align: justify; }"
+ "a { color: #000; text-decoration: none; }"
@@ -761,6 +972,57 @@ function init_print_action() {
});
}
+function init_share_observers() {
+ shares = $('.form-group:not(".form-actions")').length;
+
+ $('.post').on('click', '.share.remove', function(e) {
+ e.preventDefault();
+ $(this).parents('.form-group').remove();
+ });
+
+ $('.share.add').on('click', function(e) {
+ var opt = $(this).siblings('select').find(':selected');
+ var row = $(this).parents('form').data(opt.data('form'));
+ row = row.replace('##label##', opt.html(), 'g');
+ row = row.replace('##type##', opt.val(), 'g');
+ row = row.replace('##help##', opt.data('help'), 'g');
+ row = row.replace('##key##', shares, 'g');
+ $(this).parents('.form-group').before(row);
+ shares++;
+
+ return false;
+ });
+}
+
+function init_feed_observers() {
+ $('select[id="category"]').on('change', function() {
+ var detail = $('#new_category_name').parent();
+ if ($(this).val() === 'nc') {
+ detail.show();
+ detail.find('input').focus();
+ } else {
+ detail.hide();
+ }
+ });
+}
+
+function init_password_observers() {
+ $('input[type="password"] + a.btn.toggle-password').on('click', function(e) {
+ var button = $(this);
+ var passwordField = $(this).siblings('input[type="password"]');
+
+ passwordField.attr('type', 'text');
+ button.addClass('active');
+
+ setTimeout(function() {
+ passwordField.attr('type', 'password');
+ button.removeClass('active');
+ }, 2000);
+
+ return false;
+ });
+}
+
function init_all() {
if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) {
if (window.console) {
@@ -790,6 +1052,10 @@ function init_all() {
init_shortcuts();
init_print_action();
window.setInterval(refreshUnreads, 120000);
+ } else {
+ init_share_observers();
+ init_feed_observers();
+ init_password_observers();
}
if (window.console) {