main.phtml 6.9 KB

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