main.phtml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. <?php if($this->conf->lazyload() == 'yes') { ?>
  108. $(".flux .content img").lazyload();
  109. <?php } ?>
  110. if (hide_posts) {
  111. $(".flux:not(.active) .flux_content").hide ();
  112. }
  113. $(".flux_header .item.title, .flux_header .item.date").click (function () {
  114. old_active = $(".flux.active");
  115. new_active = $(this).parent ().parent ();
  116. toggleContent (new_active, old_active);
  117. });
  118. $(".flux a.read").click (function () {
  119. active = $(this).parents (".flux");
  120. mark_read (active, false);
  121. return false;
  122. });
  123. $(".flux a.bookmark").click (function () {
  124. active = $(this).parents (".flux");
  125. mark_favorite (active);
  126. return false;
  127. });
  128. $(".flux .content a").click (function () {
  129. $(this).attr ('target', '_blank');
  130. });
  131. <?php if ($mark['site'] == 'yes') { ?>
  132. $(".flux .link a").click (function () {
  133. mark_read($(this).parent().parent().parent(), true);
  134. });
  135. <?php } ?>
  136. }
  137. function init_column_categories () {
  138. $(".category").addClass ("stick");
  139. $(".categories .category .btn:first-child").width ("160px");
  140. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  141. $(".category + .feeds").not(".active").hide();
  142. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  143. $(".category a.dropdown-toggle").click (function () {
  144. $(this).children ().toggleClass ("i_up");
  145. $(this).parent ().next (".feeds").slideToggle();
  146. return false;
  147. });
  148. }
  149. function init_shortcuts () {
  150. // Touches de manipulation
  151. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  152. // on marque comme lu ou non lu
  153. active = $(".flux.active");
  154. mark_read (active, false);
  155. }, {
  156. 'disable_in_input':true
  157. });
  158. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  159. // on marque tout comme lu
  160. url = $(".nav_menu a.read_all").attr ("href");
  161. redirect (url, false);
  162. }, {
  163. 'disable_in_input':true
  164. });
  165. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  166. // on marque comme favori ou non favori
  167. active = $(".flux.active");
  168. mark_favorite (active);
  169. }, {
  170. 'disable_in_input':true
  171. });
  172. // Touches de navigation
  173. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  174. old_active = $(".flux.active");
  175. last_active = $(".flux:last");
  176. new_active = old_active.prevAll (".flux:first");
  177. if (new_active.hasClass("flux")) {
  178. toggleContent (new_active, old_active);
  179. } else if (old_active[0] === undefined &&
  180. new_active[0] === undefined) {
  181. toggleContent (last_active, old_active);
  182. }
  183. }, {
  184. 'disable_in_input':true
  185. });
  186. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  187. old_active = $(".flux.active");
  188. first = $(".flux:first");
  189. if (first.hasClass("flux")) {
  190. toggleContent (first, old_active);
  191. }
  192. }, {
  193. 'disable_in_input':true
  194. });
  195. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  196. old_active = $(".flux.active");
  197. first_active = $(".flux:first");
  198. new_active = old_active.nextAll (".flux:first");
  199. if (new_active.hasClass("flux")) {
  200. toggleContent (new_active, old_active);
  201. } else if (old_active[0] === undefined &&
  202. new_active[0] === undefined) {
  203. toggleContent (first_active, old_active);
  204. }
  205. }, {
  206. 'disable_in_input':true
  207. });
  208. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  209. old_active = $(".flux.active");
  210. last = $(".flux:last");
  211. if (last.hasClass("flux")) {
  212. toggleContent (last, old_active);
  213. }
  214. }, {
  215. 'disable_in_input':true
  216. });
  217. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  218. url = $(".pager-next a").attr ("href");
  219. redirect (url, false);
  220. }, {
  221. 'disable_in_input':true
  222. });
  223. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  224. url = $(".pager-previous a").attr ("href");
  225. redirect (url, false);
  226. }, {
  227. 'disable_in_input':true
  228. });
  229. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  230. url = $(".flux.active .link a").attr ("href");
  231. <?php if ($mark['site'] == 'yes') { ?>
  232. $(".flux.active").each (function () {
  233. mark_read($(this), true);
  234. });
  235. <?php } ?>
  236. redirect (url, true);
  237. }, {
  238. 'disable_in_input':true
  239. });
  240. }
  241. $(document).ready (function () {
  242. init_posts ();
  243. init_column_categories ();
  244. init_shortcuts ();
  245. });