main.phtml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 inMarkViewport(flux) {
  121. var top = flux.position().top;
  122. var height = flux.height();
  123. var begin = top + 3 * height / 4;
  124. var bot = Math.min(begin + 75, top + height);
  125. var windowTop = $(window).scrollTop();
  126. var windowBot = windowTop + $(window).height() / 2;
  127. return (windowBot >= begin && windowBot <= bot);
  128. }
  129. function init_posts () {
  130. init_img ();
  131. <?php if($this->conf->lazyload() == 'yes') { ?>
  132. $(".flux .content img").lazyload();
  133. <?php } ?>
  134. if (hide_posts) {
  135. $(".flux:not(.active) .flux_content").hide ();
  136. }
  137. var flux_header_toggle = $(".flux_header .item.title, .flux_header .item.date");
  138. flux_header_toggle.unbind('click'); // évite d'associer 2 fois le toggle
  139. flux_header_toggle.click (function () {
  140. old_active = $(".flux.active");
  141. new_active = $(this).parent ().parent ();
  142. toggleContent (new_active, old_active);
  143. });
  144. $(".flux a.read").click (function () {
  145. active = $(this).parents (".flux");
  146. mark_read (active, false);
  147. return false;
  148. });
  149. $(".flux a.bookmark").click (function () {
  150. active = $(this).parents (".flux");
  151. mark_favorite (active);
  152. return false;
  153. });
  154. $(".flux .content a").click (function () {
  155. $(this).attr ('target', '_blank');
  156. });
  157. <?php if ($mark['site'] == 'yes') { ?>
  158. $(".flux .link a").click (function () {
  159. mark_read($(this).parent().parent().parent(), true);
  160. });
  161. <?php } ?>
  162. <?php if ($mark['scroll'] == 'yes') { ?>
  163. $(window).scroll(function() {
  164. $('.flux.not_read:visible').each(function() {
  165. if($(this).children(".flux_content").is(':visible') &&
  166. inMarkViewport($(this))) {
  167. mark_read($(this), true);
  168. }
  169. });
  170. });
  171. <?php } ?>
  172. }
  173. function init_column_categories () {
  174. if(!is_normal_mode()) {
  175. return;
  176. }
  177. $(".category").addClass ("stick");
  178. $(".categories .category .btn:first-child").width ("160px");
  179. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  180. $(".category + .feeds").not(".active").hide();
  181. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  182. $(".category a.dropdown-toggle").click (function () {
  183. $(this).children ().toggleClass ("i_up");
  184. $(this).parent ().next (".feeds").slideToggle();
  185. return false;
  186. });
  187. }
  188. function init_shortcuts () {
  189. // Touches de manipulation
  190. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  191. // on marque comme lu ou non lu
  192. active = $(".flux.active");
  193. mark_read (active, false);
  194. }, {
  195. 'disable_in_input':true
  196. });
  197. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  198. // on marque tout comme lu
  199. url = $(".nav_menu a.read_all").attr ("href");
  200. redirect (url, false);
  201. }, {
  202. 'disable_in_input':true
  203. });
  204. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  205. // on marque comme favori ou non favori
  206. active = $(".flux.active");
  207. mark_favorite (active);
  208. }, {
  209. 'disable_in_input':true
  210. });
  211. // Touches de navigation
  212. shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
  213. 'disable_in_input':true
  214. });
  215. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  216. old_active = $(".flux.active");
  217. first = $(".flux:first");
  218. if (first.hasClass("flux")) {
  219. toggleContent (first, old_active);
  220. }
  221. }, {
  222. 'disable_in_input':true
  223. });
  224. shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
  225. 'disable_in_input':true
  226. });
  227. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  228. old_active = $(".flux.active");
  229. last = $(".flux:last");
  230. if (last.hasClass("flux")) {
  231. toggleContent (last, old_active);
  232. }
  233. }, {
  234. 'disable_in_input':true
  235. });
  236. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  237. url = $(".pager-next a").attr ("href");
  238. redirect (url, false);
  239. }, {
  240. 'disable_in_input':true
  241. });
  242. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  243. url = $(".pager-previous a").attr ("href");
  244. redirect (url, false);
  245. }, {
  246. 'disable_in_input':true
  247. });
  248. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  249. url_website = $(".flux.active .link a").attr ("href");
  250. <?php if ($mark['site'] == 'yes') { ?>
  251. $(".flux.active").each (function () {
  252. mark_read($(this), true);
  253. });
  254. <?php } ?>
  255. redirect (url_website, true);
  256. }, {
  257. 'disable_in_input':true
  258. });
  259. }
  260. function init_nav_entries() {
  261. $('.nav_entries a.previous_entry').click(function() {
  262. prev_entry();
  263. return false;
  264. });
  265. $('.nav_entries a.next_entry').click(function() {
  266. next_entry();
  267. return false;
  268. });
  269. }
  270. $(document).ready (function () {
  271. if(is_reader_mode()) {
  272. hide_posts = false;
  273. }
  274. init_posts ();
  275. init_column_categories ();
  276. init_shortcuts ();
  277. init_nav_entries();
  278. });