summaryrefslogtreecommitdiff
path: root/p/scripts/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'p/scripts/main.js')
-rw-r--r--p/scripts/main.js122
1 files changed, 84 insertions, 38 deletions
diff --git a/p/scripts/main.js b/p/scripts/main.js
index f64927c14..f1b82900e 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -244,20 +244,19 @@ function toggleContent(new_active, old_active) {
new_active.toggleClass('active');
}
- var box_to_move = "html,body",
- relative_move = false;
- if (context['current_view'] == 'global') {
- box_to_move = "#panel";
- relative_move = true;
- }
+ var relative_move = context['current_view'] === 'global',
+ box_to_move = $(relative_move ? "#panel" : "html,body");
if (context['sticky_post']) {
var prev_article = new_active.prevAll('.flux'),
- new_pos = new_active.position().top,
- old_scroll = $(box_to_move).scrollTop();
+ new_pos = new_active.offset().top,
+ old_scroll = box_to_move.scrollTop();
- if (prev_article.length > 0 && new_pos - prev_article.position().top <= 150) {
- new_pos = prev_article.position().top;
+ if (prev_article.length > 0 && new_pos - prev_article.offset().top <= 150) {
+ new_pos = prev_article.offset().top;
+ if (relative_move) {
+ new_pos -= box_to_move.offset().top;
+ }
}
if (context['hide_posts']) {
@@ -267,7 +266,7 @@ function toggleContent(new_active, old_active) {
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 {
@@ -275,7 +274,7 @@ function toggleContent(new_active, old_active) {
new_pos += old_scroll;
}
- $(box_to_move).scrollTop(new_pos).scrollTop();
+ box_to_move.scrollTop(new_pos).scrollTop();
}
}
@@ -451,11 +450,8 @@ function auto_share(key) {
}
}
-function inMarkViewport(flux, box_to_follow, relative_follow) {
- var top = flux.position().top;
- if (relative_follow) {
- top += box_to_follow.scrollTop();
- }
+function inMarkViewport(flux, box_to_follow) {
+ var top = flux.offset().top;
var height = flux.height(),
begin = top + 3 * height / 4,
bot = Math.min(begin + 75, top + height),
@@ -466,17 +462,15 @@ function inMarkViewport(flux, box_to_follow, relative_follow) {
}
function init_posts() {
- var box_to_follow = $(window),
- relative_follow = false;
- if (context['current_view'] == 'global') {
+ var box_to_follow = $(window);
+ if (context['current_view'] === 'global') {
box_to_follow = $("#panel");
- relative_follow = true;
}
if (context['auto_mark_scroll']) {
box_to_follow.scroll(function () {
$('.not_read:visible').each(function () {
- if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow, relative_follow)) {
+ if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow)) {
mark_read($(this), true);
}
});
@@ -490,10 +484,7 @@ function init_posts() {
return;
}
var boxBot = box_to_follow.scrollTop() + box_to_follow.height(),
- load_more_top = load_more.position().top;
- if (relative_follow) {
- load_more_top += box_to_follow.scrollTop();
- }
+ load_more_top = load_more.offset().top;
if (boxBot >= load_more_top) {
load_more_posts();
}
@@ -765,7 +756,7 @@ function init_nav_entries() {
$nav_entries.find('.up').click(function () {
var active_item = $(".flux.current"),
windowTop = $(window).scrollTop(),
- item_top = active_item.position().top;
+ item_top = active_item.offset().top;
if (windowTop > item_top) {
$("html,body").scrollTop(item_top);
@@ -776,6 +767,31 @@ function init_nav_entries() {
});
}
+// <actualize>
+var feed_processed = 0;
+
+function updateFeed(feeds, feeds_count) {
+ var feed = feeds.pop();
+ if (feed == undefined) {
+ return;
+ }
+
+ $.ajax({
+ type: 'POST',
+ url: feed['url'],
+ }).complete(function (data) {
+ feed_processed++;
+ $("#actualizeProgress .progress").html(feed_processed + " / " + feeds_count);
+ $("#actualizeProgress .title").html(feed['title']);
+
+ if (feed_processed === feeds_count) {
+ window.location.reload();
+ } else {
+ updateFeed(feeds, feeds_count);
+ }
+ });
+}
+
function init_actualize() {
var auto = false;
@@ -786,14 +802,25 @@ function init_actualize() {
ajax_loading = true;
- $.getScript('./?c=javascript&a=actualize').done(function () {
- if (auto && feed_count < 1) {
+ $.getJSON('./?c=javascript&a=actualize').done(function (data) {
+ if (auto && data.feeds.length < 1) {
auto = false;
ajax_loading = false;
return false;
}
-
- updateFeeds();
+ if (data.feeds.length === 0) {
+ openNotification(data.feedback_no_refresh, "good");
+ ajax_loading = false;
+ return;
+ }
+ //Progress bar
+ var feeds_count = data.feeds.length;
+ $('body').after('<div id="actualizeProgress" class="notification good">' + data.feedback_actualize +
+ '<br /><span class="title">/</span><br /><span class="progress">0 / ' + feeds_count +
+ '</span></div>');
+ for (var i = 10; i > 0; i--) {
+ updateFeed(data.feeds, feeds_count);
+ }
});
return false;
@@ -804,7 +831,7 @@ function init_actualize() {
$("#actualize").click();
}
}
-
+// </actualize>
// <notification>
var notification = null,
@@ -872,7 +899,7 @@ function notifs_html5_show(nb) {
var notification = new window.Notification(i18n['notif_title_articles'], {
icon: "../themes/icons/favicon-256.png",
- body: i18n['notif_body_articles'].replace("\d", nb),
+ body: i18n['notif_body_articles'].replace('%d', nb),
tag: "freshRssNewArticles"
});
@@ -880,7 +907,7 @@ function notifs_html5_show(nb) {
window.location.reload();
}
- if (context['html5_notif_timeout'] !== 0){
+ if (context['html5_notif_timeout'] !== 0) {
setTimeout(function() {
notification.close();
}, context['html5_notif_timeout'] * 1000);
@@ -908,7 +935,7 @@ function refreshUnreads() {
if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view?
(nbUnreads - feed_unreads > 0)) {
- $('#new-article').show();
+ $('#new-article').attr('aria-hidden', 'false').show();
new_articles = true;
};
});
@@ -1131,10 +1158,10 @@ function init_feed_observers() {
$('select[id="category"]').on('change', function() {
var detail = $('#new_category_name').parent();
if ($(this).val() === 'nc') {
- detail.show();
+ detail.attr('aria-hidden', 'false').show();
detail.find('input').focus();
} else {
- detail.hide();
+ detail.attr('aria-hidden', 'true').hide();
}
});
}
@@ -1254,14 +1281,32 @@ function init_configuration_alert() {
});
}
+function init_subscription() {
+ $('body').on('click', '.bookmarkClick', function (e) {
+ return false;
+ });
+}
+
+function parseJsonVars() {
+ var jsonVars = document.getElementById('jsonVars'),
+ json = JSON.parse(jsonVars.innerHTML);
+ jsonVars.outerHTML = '';
+ window.context = json.context;
+ window.shortcuts = json.shortcuts;
+ window.url = json.url;
+ window.i18n = json.i18n;
+ window.icons = json.icons;
+}
+
function init_all() {
- if (!(window.$ && window.context)) {
+ if (!window.$) {
if (window.console) {
console.log('FreshRSS waiting for JS…');
}
window.setTimeout(init_all, 50);
return;
}
+ parseJsonVars();
init_notifications();
init_confirm_action();
$stream = $('#stream');
@@ -1278,6 +1323,7 @@ function init_all() {
init_notifs_html5();
window.setInterval(refreshUnreads, 120000);
} else {
+ init_subscription();
init_crypto_form();
init_share_observers();
init_remove_observers();