main.phtml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. $(".bigMarkAsRead").click(function() {
  186. url = $(".nav_menu a.read_all").attr ("href");
  187. redirect (url, false);
  188. return false;
  189. });
  190. <?php if ($mark['site'] == 'yes') { ?>
  191. $(".flux .link a").click (function () {
  192. mark_read($(this).parent().parent().parent(), true);
  193. });
  194. <?php } ?>
  195. var box_to_follow = $(window);
  196. var relative_follow = false;
  197. if(is_global_mode()) {
  198. box_to_follow = $("#panel");
  199. relative_follow = true;
  200. }
  201. <?php if ($mark['scroll'] == 'yes') { ?>
  202. box_to_follow.scroll(function() {
  203. $('.flux.not_read:visible').each(function() {
  204. if($(this).children(".flux_content").is(':visible') &&
  205. inMarkViewport($(this), box_to_follow, relative_follow)) {
  206. mark_read($(this), true);
  207. }
  208. });
  209. });
  210. <?php } ?>
  211. <?php if ($auto_load_more == 'yes') { ?>
  212. box_to_follow.scroll(function() {
  213. var boxBot = box_to_follow.scrollTop() + box_to_follow.height();
  214. var load_more_top = $("#load_more").position().top;
  215. if(relative_follow) {
  216. load_more_top += box_to_follow.scrollTop();
  217. }
  218. if(boxBot >= load_more_top) {
  219. load_more_posts ();
  220. }
  221. });
  222. <?php } ?>
  223. }
  224. function init_column_categories () {
  225. if(!is_normal_mode()) {
  226. return;
  227. }
  228. $(".category").addClass ("stick");
  229. $(".categories .category .btn:first-child").width ("160px");
  230. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  231. $(".category + .feeds").not(".active").hide();
  232. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  233. $(".category a.dropdown-toggle").click (function () {
  234. $(this).children ().toggleClass ("i_up");
  235. $(this).parent ().next (".feeds").slideToggle();
  236. return false;
  237. });
  238. }
  239. function init_shortcuts () {
  240. // Touches de manipulation
  241. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  242. // on marque comme lu ou non lu
  243. active = $(".flux.active");
  244. mark_read (active, false);
  245. }, {
  246. 'disable_in_input':true
  247. });
  248. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  249. // on marque tout comme lu
  250. url = $(".nav_menu a.read_all").attr ("href");
  251. redirect (url, false);
  252. }, {
  253. 'disable_in_input':true
  254. });
  255. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  256. // on marque comme favori ou non favori
  257. active = $(".flux.active");
  258. mark_favorite (active);
  259. }, {
  260. 'disable_in_input':true
  261. });
  262. // Touches de navigation
  263. shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
  264. 'disable_in_input':true
  265. });
  266. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  267. old_active = $(".flux.active");
  268. first = $(".flux:first");
  269. if (first.hasClass("flux")) {
  270. toggleContent (first, old_active);
  271. }
  272. }, {
  273. 'disable_in_input':true
  274. });
  275. shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
  276. 'disable_in_input':true
  277. });
  278. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  279. old_active = $(".flux.active");
  280. last = $(".flux:last");
  281. if (last.hasClass("flux")) {
  282. toggleContent (last, old_active);
  283. }
  284. }, {
  285. 'disable_in_input':true
  286. });
  287. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  288. url = $(".pager-next a").attr ("href");
  289. redirect (url, false);
  290. }, {
  291. 'disable_in_input':true
  292. });
  293. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  294. url = $(".pager-previous a").attr ("href");
  295. redirect (url, false);
  296. }, {
  297. 'disable_in_input':true
  298. });
  299. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  300. url_website = $(".flux.active .link a").attr ("href");
  301. <?php if ($mark['site'] == 'yes') { ?>
  302. $(".flux.active").each (function () {
  303. mark_read($(this), true);
  304. });
  305. <?php } ?>
  306. redirect (url_website, true);
  307. }, {
  308. 'disable_in_input':true
  309. });
  310. }
  311. function init_nav_entries() {
  312. $('.nav_entries a.previous_entry').click(function() {
  313. prev_entry();
  314. return false;
  315. });
  316. $('.nav_entries a.next_entry').click(function() {
  317. next_entry();
  318. return false;
  319. });
  320. $('.nav_entries a.up').click(function() {
  321. var active_item = $(".flux.active");
  322. var windowTop = $(window).scrollTop();
  323. var item_top = active_item.position ().top;
  324. if(windowTop > item_top) {
  325. $("html,body").scrollTop (item_top);
  326. } else {
  327. $("html,body").scrollTop (0);
  328. }
  329. return false;
  330. });
  331. }
  332. $(document).ready (function () {
  333. if(is_reader_mode()) {
  334. hide_posts = false;
  335. }
  336. init_posts ();
  337. init_column_categories ();
  338. init_shortcuts ();
  339. init_nav_entries();
  340. });