aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 15:53:10 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-10-09 15:53:10 +0200
commitf97d4b3b6cca4a55636bbd50158f3c57666b0f08 (patch)
tree3ca9dd42155228292f0842d65b9b6d90e9140639 /app/views/javascript
parente51ceb6812e3736aa9b9ce1f2d5181f5b4b6aaa3 (diff)
parent444b1552364b39761c3278c7da5152fd3998f216 (diff)
Merge branch 'master' into hotfixes
Diffstat (limited to 'app/views/javascript')
-rw-r--r--app/views/javascript/actualize.phtml75
-rw-r--r--app/views/javascript/main.phtml415
-rw-r--r--app/views/javascript/nbUnreadsPerFeed.phtml8
-rw-r--r--app/views/javascript/nonce.phtml2
4 files changed, 53 insertions, 447 deletions
diff --git a/app/views/javascript/actualize.phtml b/app/views/javascript/actualize.phtml
index fa6e67ddb..74cef4998 100644
--- a/app/views/javascript/actualize.phtml
+++ b/app/views/javascript/actualize.phtml
@@ -1,45 +1,56 @@
-var feeds = new Array ();
-<?php foreach ($this->feeds as $feed) { ?>
-feeds.push ("<?php echo Url::display (array ('c' => 'feed', 'a' => 'actualize', 'params' => array ('id' => $feed->id (), 'ajax' => '1')), 'php'); ?>");
-<?php } ?>
+"use strict";
+var feeds = [<?php foreach ($this->feeds as $feed) { ?>{<?php
+ ?>url: "<?php echo Minz_Url::display(array('c' => 'feed', 'a' => 'actualize', 'params' => array('id' => $feed->id(), 'ajax' => '1')), 'php'); ?>",<?php
+ ?>title: "<?php echo $feed->name(); ?>"<?php
+?>},<?php } ?>],
+ feed_processed = 0,
+ feed_count = feeds.length;
-function initProgressBar (init) {
+function initProgressBar(init) {
if (init) {
- $("body").after ("\<div id=\"actualizeProgress\" class=\"actualizeProgress\">\
- <?php echo Translate::t ('refresh'); ?> <span class=\"progress\">0 / " + feeds.length + "</span><br />\
- <progress id=\"actualizeProgressBar\" value=\"0\" max=\"" + feeds.length + "\"></progress>\
+ $("body").after("\<div id=\"actualizeProgress\" class=\"notification good\">\
+ <?php echo _t('refresh'); ?><br /><span class=\"title\">/</span><br />\
+ <span class=\"progress\">0 / " + feed_count + "</span>\
</div>");
} else {
- window.location.reload ();
+ window.location.reload();
}
}
-function updateProgressBar (i) {
- $("#actualizeProgressBar").val(i);
- $("#actualizeProgress .progress").html (i + " / " + feeds.length);
+function updateProgressBar(i, title_feed) {
+ $("#actualizeProgress .progress").html(i + " / " + feed_count);
+ $("#actualizeProgress .title").html(title_feed);
}
-function updateFeeds () {
- initProgressBar (true);
-
- var i = 0;
- for (var f in feeds) {
- $.ajax ({
- type: 'POST',
- url: feeds[f],
- }).done (function (data) {
- i++;
- updateProgressBar (i);
+function updateFeeds() {
+ if (feed_count === 0) {
+ openNotification("<?php echo _t('no_feed_to_refresh'); ?>", "good");
+ ajax_loading = false;
+ return;
+ }
+ initProgressBar(true);
- if (i == feeds.length) {
- initProgressBar (false);
- }
- });
+ for (var i = 0; i < 10; i++) {
+ updateFeed();
}
}
-$(document).ready (function () {
- $("#actualize").click (function () {
- updateFeeds ();
- return false;
+function updateFeed() {
+ var feed = feeds.pop();
+ if (feed == undefined) {
+ return;
+ }
+
+ $.ajax({
+ type: 'POST',
+ url: feed['url'],
+ }).complete(function (data) {
+ feed_processed++;
+ updateProgressBar(feed_processed, feed['title']);
+
+ if (feed_processed === feed_count) {
+ initProgressBar(false);
+ } else {
+ updateFeed();
+ }
});
-});
+}
diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml
deleted file mode 100644
index 03c60cc52..000000000
--- a/app/views/javascript/main.phtml
+++ /dev/null
@@ -1,415 +0,0 @@
-<?php if ($this->conf->displayPosts () == 'no') { ?>
-var hide_posts = true;
-<?php } else { ?>
-var hide_posts = false;
-<?php } ?>
-
-<?php
- $s = $this->conf->shortcuts ();
- $mark = $this->conf->markWhen ();
- $auto_load_more = $this->conf->autoLoadMore ()
-?>
-
-function is_reader_mode() {
- var stream = $("#stream.reader");
- return stream.html() != null;
-}
-
-function is_normal_mode() {
- var stream = $("#stream.normal");
- return stream.html() != null;
-}
-
-function is_global_mode() {
- var stream = $("#stream.global");
- return stream.html() != null;
-}
-
-function redirect (url, new_tab) {
- if (url) {
- if (new_tab) {
- window.open (url);
- } else {
- location.href = url;
- }
- }
-}
-
-function toggleContent (new_active, old_active) {
- old_active.removeClass ("active");
- if (old_active[0] != new_active[0]) {
- new_active.addClass ("active");
- }
-
- var box_to_move = "html,body";
- var relative_move = false;
- if(is_global_mode()) {
- box_to_move = "#panel";
- relative_move = true;
- }
-
- var new_pos = new_active.position ().top,
- old_scroll = $(box_to_move).scrollTop (),
- new_scroll = old_scroll;
- if (hide_posts) {
- old_active.children (".flux_content").toggle (0);
-
- new_pos = new_active.position ().top;
- old_scroll = $(box_to_move).scrollTop ();
-
- if(relative_move) {
- new_pos += old_scroll;
- }
-
- if (old_active[0] != new_active[0]) {
- new_active.children (".flux_content").toggle (0, function () {
- new_scroll = $(box_to_move).scrollTop (new_pos).scrollTop ();
- });
- }
- } else {
- if(relative_move) {
- new_pos += old_scroll;
- }
-
- new_scroll = $(box_to_move).scrollTop (new_pos).scrollTop ();
- }
-
- if ((new_scroll === old_scroll) && $.fn.lazyload) {
- $(window).trigger ("scroll"); //When no scroll was done, generate fake scroll event for LazyLoad to load images
- }
-
- <?php if ($mark['article'] == 'yes') { ?>
- mark_read(new_active, true);
- <?php } ?>
-}
-
-function mark_read (active, only_not_read) {
- if (active[0] === undefined || (
- only_not_read === true && !active.hasClass("not_read"))) {
- return false;
- }
-
- url = active.find ("a.read").attr ("href");
- if (url === undefined) {
- return false;
- }
-
- $.ajax ({
- type: 'POST',
- url: url,
- data : { ajax: true }
- }).done (function (data) {
- res = jQuery.parseJSON(data);
-
- active.find ("a.read").attr ("href", res.url);
-
- if (active.hasClass ("not_read")) {
- active.removeClass ("not_read");
- } else if(only_not_read !== true || active.hasClass("not_read")) {
- active.addClass ("not_read");
- }
- });
-}
-
-function mark_favorite (active) {
- if (active[0] === undefined) {
- return false;
- }
-
- url = active.find ("a.bookmark").attr ("href");
- if (url === undefined) {
- return false;
- }
-
- $.ajax ({
- type: 'POST',
- url: url,
- data : { ajax: true }
- }).done (function (data) {
- res = jQuery.parseJSON(data);
-
- active.find ("a.bookmark").attr ("href", res.url);
- if (active.hasClass ("favorite")) {
- active.removeClass ("favorite");
- } else {
- active.addClass ("favorite");
- }
- });
-}
-
-function prev_entry() {
- old_active = $(".flux.active");
- last_active = $(".flux:last");
- new_active = old_active.prevAll (".flux:first");
-
- if (new_active.hasClass("flux")) {
- toggleContent (new_active, old_active);
- } else if (old_active[0] === undefined &&
- new_active[0] === undefined) {
- toggleContent (last_active, old_active);
- }
-}
-
-function next_entry() {
- old_active = $(".flux.active");
- first_active = $(".flux:first");
- last_active = $(".flux:last");
- new_active = old_active.nextAll (".flux:first");
-
- if (new_active.hasClass("flux")) {
- toggleContent (new_active, old_active);
- } else if (old_active[0] === undefined &&
- new_active[0] === undefined) {
- toggleContent (first_active, old_active);
- }
-
- <?php if ($auto_load_more !== 'yes') { ?>
- if(last_active.attr("id") == new_active.attr("id")) {
- load_more_posts ();
- }
- <?php } ?>
-}
-
-function init_img () {
- var maxWidth = $(".flux_content .content").width() / 2;
- $(".flux_content .content img").each (function () {
- if ($(this).width () > maxWidth) {
- $(this).addClass("big");
- }
- });
-}
-
-function inMarkViewport(flux, box_to_follow, relative_follow) {
- var top = flux.position().top;
- if(relative_follow) {
- top += box_to_follow.scrollTop();
- }
- var height = flux.height();
- var begin = top + 3 * height / 4;
- var bot = Math.min(begin + 75, top + height);
-
- var windowTop = box_to_follow.scrollTop();
- var windowBot = windowTop + box_to_follow.height() / 2;
-
- return (windowBot >= begin && windowBot <= bot);
-}
-
-function init_posts () {
- init_img ();
- <?php if($this->conf->lazyload() == 'yes') { ?>
- if(is_global_mode()) {
- $(".flux .content img").lazyload({
- container: $("#panel")
- });
- } else {
- $(".flux .content img").lazyload();
- }
- <?php } ?>
-
- if (hide_posts) {
- $(".flux:not(.active) .flux_content").hide ();
- }
-
- var box_to_follow = $(window);
- var relative_follow = false;
- if(is_global_mode()) {
- box_to_follow = $("#panel");
- relative_follow = true;
- }
-
- <?php if ($mark['scroll'] == 'yes') { ?>
- box_to_follow.scroll(function() {
- $('.flux.not_read:visible').each(function() {
- if($(this).children(".flux_content").is(':visible') &&
- inMarkViewport($(this), box_to_follow, relative_follow)) {
- mark_read($(this), true);
- }
- });
- });
- <?php } ?>
-
- <?php if ($auto_load_more == 'yes') { ?>
- box_to_follow.scroll(function() {
- var load_more = $("#load_more");
- if (!load_more.is(':visible')) return;
- var boxBot = box_to_follow.scrollTop() + box_to_follow.height();
- var load_more_top = load_more.position().top;
- if(relative_follow) {
- load_more_top += box_to_follow.scrollTop();
- }
-
- if(boxBot >= load_more_top) {
- load_more_posts ();
- }
- });
- <?php } ?>
-}
-
-function init_column_categories () {
- if(!is_normal_mode()) {
- return;
- }
-
- $(".category").addClass ("stick");
- $(".categories .category .btn:first-child").width ("160px");
- $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
-
- $(".category + .feeds").not(".active").hide();
- $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
-
- $(".category a.dropdown-toggle").click (function () {
- $(this).children ().toggleClass ("i_up");
- $(this).parent ().next (".feeds").slideToggle();
- return false;
- });
-}
-
-function init_shortcuts () {
- // Touches de manipulation
- shortcut.add("<?php echo $s['mark_read']; ?>", function () {
- // on marque comme lu ou non lu
- active = $(".flux.active");
- mark_read (active, false);
- }, {
- 'disable_in_input':true
- });
- shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
- // on marque tout comme lu
- url = $(".nav_menu a.read_all").attr ("href");
- redirect (url, false);
- }, {
- 'disable_in_input':true
- });
- shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
- // on marque comme favori ou non favori
- active = $(".flux.active");
- mark_favorite (active);
- }, {
- 'disable_in_input':true
- });
-
- // Touches de navigation
- shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
- 'disable_in_input':true
- });
- shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
- old_active = $(".flux.active");
- first = $(".flux:first");
-
- if (first.hasClass("flux")) {
- toggleContent (first, old_active);
- }
- }, {
- 'disable_in_input':true
- });
- shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
- 'disable_in_input':true
- });
- shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
- old_active = $(".flux.active");
- last = $(".flux:last");
-
- if (last.hasClass("flux")) {
- toggleContent (last, old_active);
- }
- }, {
- 'disable_in_input':true
- });
- shortcut.add("<?php echo $s['go_website']; ?>", function () {
- url_website = $(".flux.active .link a").attr ("href");
-
- <?php if ($mark['site'] == 'yes') { ?>
- $(".flux.active").each (function () {
- mark_read($(this), true);
- });
- <?php } ?>
-
- redirect (url_website, true);
- }, {
- 'disable_in_input':true
- });
-}
-
-function init_stream_delegates(divStream) {
- divStream.on('click', '.flux_header .item.title, .flux_header .item.date', function (e) { //flux_header_toggle
- old_active = $(".flux.active");
- new_active = $(this).parent ().parent ();
- if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone
- <?php if ($mark['article'] == 'yes') { ?>
- mark_read(new_active, true);
- <?php } ?>
- return true;
- }
- toggleContent (new_active, old_active);
- });
-
- divStream.on('click', '.flux a.read', function () {
- active = $(this).parents (".flux");
- mark_read (active, false);
-
- return false;
- });
-
- divStream.on('click', '.flux a.bookmark', function () {
- active = $(this).parents (".flux");
- mark_favorite (active);
-
- return false;
- });
-
- divStream.on('click', '.flux .content a', function () {
- $(this).attr ('target', '_blank');
- });
-
- divStream.on('click', '.item.title>a',function (e) {
- if (e.ctrlKey) return true; //Allow default control-click behaviour such as open in backround-tab
- $(this).parent ().click (); //Will perform toggle flux_content
- return false;
- });
-
- divStream.on('click', '.bigMarkAsRead', function() {
- url = $(".nav_menu a.read_all").attr ("href");
- redirect (url, false);
- return false;
- });
-
- <?php if ($mark['site'] == 'yes') { ?>
- divStream.on('click', '.flux .link a', function () {
- mark_read($(this).parent().parent().parent(), true);
- });
- <?php } ?>
-}
-
-function init_nav_entries() {
- $('.nav_entries a.previous_entry').click(function() {
- prev_entry();
- return false;
- });
- $('.nav_entries a.next_entry').click(function() {
- next_entry();
- return false;
- });
- $('.nav_entries a.up').click(function() {
- var active_item = $(".flux.active");
- var windowTop = $(window).scrollTop();
- var item_top = active_item.position ().top;
-
- if(windowTop > item_top) {
- $("html,body").scrollTop (item_top);
- } else {
- $("html,body").scrollTop (0);
- }
- return false;
- });
-}
-
-$(document).ready (function () {
- if(is_reader_mode()) {
- hide_posts = false;
- }
- init_posts ();
- init_column_categories ();
- init_shortcuts ();
- init_stream_delegates($('#stream'));
- init_nav_entries();
-});
diff --git a/app/views/javascript/nbUnreadsPerFeed.phtml b/app/views/javascript/nbUnreadsPerFeed.phtml
new file mode 100644
index 000000000..68f98ce9e
--- /dev/null
+++ b/app/views/javascript/nbUnreadsPerFeed.phtml
@@ -0,0 +1,8 @@
+<?php
+$result = array();
+foreach ($this->categories as $cat) {
+ foreach ($cat->feeds() as $feed) {
+ $result[$feed->id()] = $feed->nbNotRead();
+ }
+}
+echo json_encode($result);
diff --git a/app/views/javascript/nonce.phtml b/app/views/javascript/nonce.phtml
new file mode 100644
index 000000000..4ac46c8fc
--- /dev/null
+++ b/app/views/javascript/nonce.phtml
@@ -0,0 +1,2 @@
+<?php
+echo json_encode(array('salt1' => $this->salt1, 'nonce' => $this->nonce));