main.phtml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. ?>
  10. function is_reader_mode() {
  11. var stream = $("#stream.reader");
  12. return stream.html() != null;
  13. }
  14. function is_normal_mode() {
  15. var stream = $("#stream.normal");
  16. return stream.html() != null;
  17. }
  18. function redirect (url, new_tab) {
  19. if (url) {
  20. if (new_tab) {
  21. window.open (url);
  22. } else {
  23. location.href = url;
  24. }
  25. }
  26. }
  27. function toggleContent (new_active, old_active) {
  28. old_active.removeClass ("active");
  29. if (old_active[0] != new_active[0]) {
  30. new_active.addClass ("active");
  31. }
  32. if (hide_posts) {
  33. old_active.children (".flux_content").toggle (0);
  34. if (old_active[0] != new_active[0]) {
  35. new_active.children (".flux_content").toggle (0, function () {
  36. $("html,body").scrollTop (new_active.position ().top);
  37. });
  38. }
  39. } else {
  40. $("html,body").scrollTop (new_active.position ().top);
  41. }
  42. <?php if ($mark['article'] == 'yes') { ?>
  43. mark_read(new_active, true);
  44. <?php } ?>
  45. }
  46. function mark_read (active, only_not_read) {
  47. if (active[0] === undefined || (
  48. only_not_read === true && !active.hasClass("not_read"))) {
  49. return false;
  50. }
  51. url = active.find ("a.read").attr ("href");
  52. if (url === undefined) {
  53. return false;
  54. }
  55. $.ajax ({
  56. type: 'POST',
  57. url: url,
  58. data : { ajax: true }
  59. }).done (function (data) {
  60. res = jQuery.parseJSON(data);
  61. active.find ("a.read").attr ("href", res.url);
  62. if (active.hasClass ("not_read")) {
  63. active.removeClass ("not_read");
  64. } else {
  65. active.addClass ("not_read");
  66. }
  67. });
  68. }
  69. function mark_favorite (active) {
  70. if (active[0] === undefined) {
  71. return false;
  72. }
  73. url = active.find ("a.bookmark").attr ("href");
  74. if (url === undefined) {
  75. return false;
  76. }
  77. $.ajax ({
  78. type: 'POST',
  79. url: url,
  80. data : { ajax: true }
  81. }).done (function (data) {
  82. res = jQuery.parseJSON(data);
  83. active.find ("a.bookmark").attr ("href", res.url);
  84. if (active.hasClass ("favorite")) {
  85. active.removeClass ("favorite");
  86. } else {
  87. active.addClass ("favorite");
  88. }
  89. });
  90. }
  91. function init_img () {
  92. $(".flux_content .content img").each (function () {
  93. if ($(this).width () > ($(".flux_content .content").width()) / 2) {
  94. $(this).addClass("big");
  95. }
  96. });
  97. }
  98. function init_posts () {
  99. <?php if ($mark['page'] == 'yes') { ?>
  100. if ($(".flux.not_read")[0] != undefined) {
  101. url = $(".nav_menu a.read_all").attr ("href");
  102. redirect (url, false);
  103. }
  104. <?php } ?>
  105. init_img ();
  106. <?php if($this->conf->lazyload() == 'yes') { ?>
  107. $(".flux .content img").lazyload();
  108. <?php } ?>
  109. if (hide_posts) {
  110. $(".flux:not(.active) .flux_content").hide ();
  111. }
  112. $(".flux_header .item.title, .flux_header .item.date").click (function () {
  113. old_active = $(".flux.active");
  114. new_active = $(this).parent ().parent ();
  115. toggleContent (new_active, old_active);
  116. });
  117. $(".flux a.read").click (function () {
  118. active = $(this).parents (".flux");
  119. mark_read (active, false);
  120. return false;
  121. });
  122. $(".flux a.bookmark").click (function () {
  123. active = $(this).parents (".flux");
  124. mark_favorite (active);
  125. return false;
  126. });
  127. $(".flux .content a").click (function () {
  128. $(this).attr ('target', '_blank');
  129. });
  130. <?php if ($mark['site'] == 'yes') { ?>
  131. $(".flux .link a").click (function () {
  132. mark_read($(this).parent().parent().parent(), true);
  133. });
  134. <?php } ?>
  135. }
  136. function init_column_categories () {
  137. if(!is_normal_mode()) {
  138. return;
  139. }
  140. $(".category").addClass ("stick");
  141. $(".categories .category .btn:first-child").width ("160px");
  142. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  143. $(".category + .feeds").not(".active").hide();
  144. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  145. $(".category a.dropdown-toggle").click (function () {
  146. $(this).children ().toggleClass ("i_up");
  147. $(this).parent ().next (".feeds").slideToggle();
  148. return false;
  149. });
  150. }
  151. function init_shortcuts () {
  152. // Touches de manipulation
  153. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  154. // on marque comme lu ou non lu
  155. active = $(".flux.active");
  156. mark_read (active, false);
  157. }, {
  158. 'disable_in_input':true
  159. });
  160. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  161. // on marque tout comme lu
  162. url = $(".nav_menu a.read_all").attr ("href");
  163. redirect (url, false);
  164. }, {
  165. 'disable_in_input':true
  166. });
  167. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  168. // on marque comme favori ou non favori
  169. active = $(".flux.active");
  170. mark_favorite (active);
  171. }, {
  172. 'disable_in_input':true
  173. });
  174. // Touches de navigation
  175. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  176. old_active = $(".flux.active");
  177. last_active = $(".flux:last");
  178. new_active = old_active.prevAll (".flux:first");
  179. if (new_active.hasClass("flux")) {
  180. toggleContent (new_active, old_active);
  181. } else if (old_active[0] === undefined &&
  182. new_active[0] === undefined) {
  183. toggleContent (last_active, old_active);
  184. }
  185. }, {
  186. 'disable_in_input':true
  187. });
  188. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  189. old_active = $(".flux.active");
  190. first = $(".flux:first");
  191. if (first.hasClass("flux")) {
  192. toggleContent (first, old_active);
  193. }
  194. }, {
  195. 'disable_in_input':true
  196. });
  197. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  198. old_active = $(".flux.active");
  199. first_active = $(".flux:first");
  200. new_active = old_active.nextAll (".flux:first");
  201. if (new_active.hasClass("flux")) {
  202. toggleContent (new_active, old_active);
  203. } else if (old_active[0] === undefined &&
  204. new_active[0] === undefined) {
  205. toggleContent (first_active, old_active);
  206. }
  207. }, {
  208. 'disable_in_input':true
  209. });
  210. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  211. old_active = $(".flux.active");
  212. last = $(".flux:last");
  213. if (last.hasClass("flux")) {
  214. toggleContent (last, old_active);
  215. }
  216. }, {
  217. 'disable_in_input':true
  218. });
  219. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  220. url = $(".pager-next a").attr ("href");
  221. redirect (url, false);
  222. }, {
  223. 'disable_in_input':true
  224. });
  225. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  226. url = $(".pager-previous a").attr ("href");
  227. redirect (url, false);
  228. }, {
  229. 'disable_in_input':true
  230. });
  231. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  232. url = $(".flux.active .link a").attr ("href");
  233. <?php if ($mark['site'] == 'yes') { ?>
  234. $(".flux.active").each (function () {
  235. mark_read($(this), true);
  236. });
  237. <?php } ?>
  238. redirect (url, true);
  239. }, {
  240. 'disable_in_input':true
  241. });
  242. }
  243. $(document).ready (function () {
  244. if(is_reader_mode()) {
  245. hide_posts = false;
  246. }
  247. init_posts ();
  248. init_column_categories ();
  249. init_shortcuts ();
  250. });