main.phtml 6.5 KB

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