main.phtml 7.6 KB

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