main.phtml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php if ($this->conf->displayPosts () == 'no') { ?>
  2. var hide_posts = true;
  3. <?php } else { ?>
  4. var hide_posts = false;
  5. <?php } ?>
  6. <?php
  7. $s = $this->conf->shortcuts ();
  8. $mark = $this->conf->markWhen ();
  9. $auto_load_more = $this->conf->autoLoadMore ()
  10. ?>
  11. function is_reader_mode() {
  12. var stream = $("#stream.reader");
  13. return stream.html() != null;
  14. }
  15. function is_normal_mode() {
  16. var stream = $("#stream.normal");
  17. return stream.html() != null;
  18. }
  19. function is_global_mode() {
  20. var stream = $("#stream.global");
  21. return stream.html() != null;
  22. }
  23. function redirect (url, new_tab) {
  24. if (url) {
  25. if (new_tab) {
  26. window.open (url);
  27. } else {
  28. location.href = url;
  29. }
  30. }
  31. }
  32. function toggleContent (new_active, old_active) {
  33. old_active.removeClass ("active");
  34. if (old_active[0] != new_active[0]) {
  35. new_active.addClass ("active");
  36. }
  37. var box_to_move = "html,body";
  38. var relative_move = false;
  39. if(is_global_mode()) {
  40. box_to_move = "#panel";
  41. relative_move = true;
  42. }
  43. if (hide_posts) {
  44. old_active.children (".flux_content").toggle (0);
  45. var new_pos = new_active.position ().top;
  46. if(relative_move) {
  47. new_pos += $(box_to_move).scrollTop();
  48. }
  49. if (old_active[0] != new_active[0]) {
  50. new_active.children (".flux_content").toggle (0, function () {
  51. $(box_to_move).scrollTop (new_pos);
  52. });
  53. }
  54. } else {
  55. $(box_to_move).scrollTop (new_active.position ().top);
  56. }
  57. <?php if ($mark['article'] == 'yes') { ?>
  58. mark_read(new_active, true);
  59. <?php } ?>
  60. }
  61. function mark_read (active, only_not_read) {
  62. if (active[0] === undefined || (
  63. only_not_read === true && !active.hasClass("not_read"))) {
  64. return false;
  65. }
  66. url = active.find ("a.read").attr ("href");
  67. if (url === undefined) {
  68. return false;
  69. }
  70. $.ajax ({
  71. type: 'POST',
  72. url: url,
  73. data : { ajax: true }
  74. }).done (function (data) {
  75. res = jQuery.parseJSON(data);
  76. active.find ("a.read").attr ("href", res.url);
  77. if (active.hasClass ("not_read")) {
  78. active.removeClass ("not_read");
  79. } else if(only_not_read !== true || active.hasClass("not_read")) {
  80. active.addClass ("not_read");
  81. }
  82. });
  83. }
  84. function mark_favorite (active) {
  85. if (active[0] === undefined) {
  86. return false;
  87. }
  88. url = active.find ("a.bookmark").attr ("href");
  89. if (url === undefined) {
  90. return false;
  91. }
  92. $.ajax ({
  93. type: 'POST',
  94. url: url,
  95. data : { ajax: true }
  96. }).done (function (data) {
  97. res = jQuery.parseJSON(data);
  98. active.find ("a.bookmark").attr ("href", res.url);
  99. if (active.hasClass ("favorite")) {
  100. active.removeClass ("favorite");
  101. } else {
  102. active.addClass ("favorite");
  103. }
  104. });
  105. }
  106. function prev_entry() {
  107. old_active = $(".flux.active");
  108. last_active = $(".flux:last");
  109. new_active = old_active.prevAll (".flux:first");
  110. if (new_active.hasClass("flux")) {
  111. toggleContent (new_active, old_active);
  112. } else if (old_active[0] === undefined &&
  113. new_active[0] === undefined) {
  114. toggleContent (last_active, old_active);
  115. }
  116. }
  117. function next_entry() {
  118. old_active = $(".flux.active");
  119. first_active = $(".flux:first");
  120. last_active = $(".flux:last");
  121. new_active = old_active.nextAll (".flux:first");
  122. if(last_active.attr("id") == new_active.attr("id")) {
  123. load_more_posts ();
  124. }
  125. if (new_active.hasClass("flux")) {
  126. toggleContent (new_active, old_active);
  127. } else if (old_active[0] === undefined &&
  128. new_active[0] === undefined) {
  129. toggleContent (first_active, old_active);
  130. }
  131. }
  132. function init_img () {
  133. $(".flux_content .content img").each (function () {
  134. if ($(this).width () > ($(".flux_content .content").width()) / 2) {
  135. $(this).addClass("big");
  136. }
  137. });
  138. }
  139. function inMarkViewport(flux, box_to_follow, relative_follow) {
  140. var top = flux.position().top;
  141. if(relative_follow) {
  142. top += box_to_follow.scrollTop();
  143. }
  144. var height = flux.height();
  145. var begin = top + 3 * height / 4;
  146. var bot = Math.min(begin + 75, top + height);
  147. var windowTop = box_to_follow.scrollTop();
  148. var windowBot = windowTop + box_to_follow.height() / 2;
  149. return (windowBot >= begin && windowBot <= bot);
  150. }
  151. function init_posts () {
  152. init_img ();
  153. <?php if($this->conf->lazyload() == 'yes') { ?>
  154. if(is_global_mode()) {
  155. $(".flux .content img").lazyload({
  156. container: $("#panel")
  157. });
  158. } else {
  159. $(".flux .content img").lazyload();
  160. }
  161. <?php } ?>
  162. if (hide_posts) {
  163. $(".flux:not(.active) .flux_content").hide ();
  164. }
  165. var flux_header_toggle = $(".flux_header .item.title, .flux_header .item.date");
  166. flux_header_toggle.unbind('click'); // évite d'associer 2 fois le toggle
  167. flux_header_toggle.click (function () {
  168. old_active = $(".flux.active");
  169. new_active = $(this).parent ().parent ();
  170. toggleContent (new_active, old_active);
  171. });
  172. $(".flux a.read").click (function () {
  173. active = $(this).parents (".flux");
  174. mark_read (active, false);
  175. return false;
  176. });
  177. $(".flux a.bookmark").click (function () {
  178. active = $(this).parents (".flux");
  179. mark_favorite (active);
  180. return false;
  181. });
  182. $(".flux .content a").click (function () {
  183. $(this).attr ('target', '_blank');
  184. });
  185. <?php if ($mark['site'] == 'yes') { ?>
  186. $(".flux .link a").click (function () {
  187. mark_read($(this).parent().parent().parent(), true);
  188. });
  189. <?php } ?>
  190. var box_to_follow = $(window);
  191. var relative_follow = false;
  192. if(is_global_mode()) {
  193. box_to_follow = $("#panel");
  194. relative_follow = true;
  195. }
  196. <?php if ($mark['scroll'] == 'yes') { ?>
  197. box_to_follow.scroll(function() {
  198. $('.flux.not_read:visible').each(function() {
  199. if($(this).children(".flux_content").is(':visible') &&
  200. inMarkViewport($(this), box_to_follow, relative_follow)) {
  201. mark_read($(this), true);
  202. }
  203. });
  204. });
  205. <?php } ?>
  206. <?php if ($auto_load_more == 'yes') { ?>
  207. box_to_follow.scroll(function() {
  208. var boxBot = box_to_follow.scrollTop() + box_to_follow.height();
  209. var load_more_top = $("#load_more").position().top;
  210. if(relative_follow) {
  211. load_more_top += box_to_follow.scrollTop();
  212. }
  213. if(boxBot >= load_more_top) {
  214. load_more_posts ();
  215. }
  216. });
  217. <?php } ?>
  218. }
  219. function init_column_categories () {
  220. if(!is_normal_mode()) {
  221. return;
  222. }
  223. $(".category").addClass ("stick");
  224. $(".categories .category .btn:first-child").width ("160px");
  225. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  226. $(".category + .feeds").not(".active").hide();
  227. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  228. $(".category a.dropdown-toggle").click (function () {
  229. $(this).children ().toggleClass ("i_up");
  230. $(this).parent ().next (".feeds").slideToggle();
  231. return false;
  232. });
  233. }
  234. function init_shortcuts () {
  235. // Touches de manipulation
  236. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  237. // on marque comme lu ou non lu
  238. active = $(".flux.active");
  239. mark_read (active, false);
  240. }, {
  241. 'disable_in_input':true
  242. });
  243. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  244. // on marque tout comme lu
  245. url = $(".nav_menu a.read_all").attr ("href");
  246. redirect (url, false);
  247. }, {
  248. 'disable_in_input':true
  249. });
  250. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  251. // on marque comme favori ou non favori
  252. active = $(".flux.active");
  253. mark_favorite (active);
  254. }, {
  255. 'disable_in_input':true
  256. });
  257. // Touches de navigation
  258. shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
  259. 'disable_in_input':true
  260. });
  261. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  262. old_active = $(".flux.active");
  263. first = $(".flux:first");
  264. if (first.hasClass("flux")) {
  265. toggleContent (first, old_active);
  266. }
  267. }, {
  268. 'disable_in_input':true
  269. });
  270. shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
  271. 'disable_in_input':true
  272. });
  273. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  274. old_active = $(".flux.active");
  275. last = $(".flux:last");
  276. if (last.hasClass("flux")) {
  277. toggleContent (last, old_active);
  278. }
  279. }, {
  280. 'disable_in_input':true
  281. });
  282. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  283. url = $(".pager-next a").attr ("href");
  284. redirect (url, false);
  285. }, {
  286. 'disable_in_input':true
  287. });
  288. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  289. url = $(".pager-previous a").attr ("href");
  290. redirect (url, false);
  291. }, {
  292. 'disable_in_input':true
  293. });
  294. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  295. url_website = $(".flux.active .link a").attr ("href");
  296. <?php if ($mark['site'] == 'yes') { ?>
  297. $(".flux.active").each (function () {
  298. mark_read($(this), true);
  299. });
  300. <?php } ?>
  301. redirect (url_website, true);
  302. }, {
  303. 'disable_in_input':true
  304. });
  305. }
  306. function init_nav_entries() {
  307. $('.nav_entries a.previous_entry').click(function() {
  308. prev_entry();
  309. return false;
  310. });
  311. $('.nav_entries a.next_entry').click(function() {
  312. next_entry();
  313. return false;
  314. });
  315. $('.nav_entries a.up').click(function() {
  316. var active_item = $(".flux.active");
  317. var windowTop = $(window).scrollTop();
  318. var item_top = active_item.position ().top;
  319. if(windowTop > item_top) {
  320. $("html,body").scrollTop (item_top);
  321. } else {
  322. $("html,body").scrollTop (0);
  323. }
  324. return false;
  325. });
  326. }
  327. $(document).ready (function () {
  328. if(is_reader_mode()) {
  329. hide_posts = false;
  330. }
  331. init_posts ();
  332. init_column_categories ();
  333. init_shortcuts ();
  334. init_nav_entries();
  335. });