main.phtml 6.4 KB

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