main.phtml 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. $auto_load_more = $this->conf->autoLoadMore ()
  10. ?>
  11. function is_reader_mode() {
  12. var stream = $("#stream.reader");
  13. return stream.html() != null;
  14. }
  15. function is_normal_mode() {
  16. var stream = $("#stream.normal");
  17. return stream.html() != null;
  18. }
  19. function redirect (url, new_tab) {
  20. if (url) {
  21. if (new_tab) {
  22. window.open (url);
  23. } else {
  24. location.href = url;
  25. }
  26. }
  27. }
  28. function toggleContent (new_active, old_active) {
  29. old_active.removeClass ("active");
  30. if (old_active[0] != new_active[0]) {
  31. new_active.addClass ("active");
  32. }
  33. if (hide_posts) {
  34. old_active.children (".flux_content").toggle (0);
  35. if (old_active[0] != new_active[0]) {
  36. new_active.children (".flux_content").toggle (0, function () {
  37. $("html,body").scrollTop (new_active.position ().top);
  38. });
  39. }
  40. } else {
  41. $("html,body").scrollTop (new_active.position ().top);
  42. }
  43. <?php if ($mark['article'] == 'yes') { ?>
  44. mark_read(new_active, true);
  45. <?php } ?>
  46. }
  47. function mark_read (active, only_not_read) {
  48. if (active[0] === undefined || (
  49. only_not_read === true && !active.hasClass("not_read"))) {
  50. return false;
  51. }
  52. url = active.find ("a.read").attr ("href");
  53. if (url === undefined) {
  54. return false;
  55. }
  56. $.ajax ({
  57. type: 'POST',
  58. url: url,
  59. data : { ajax: true }
  60. }).done (function (data) {
  61. res = jQuery.parseJSON(data);
  62. active.find ("a.read").attr ("href", res.url);
  63. if (active.hasClass ("not_read")) {
  64. active.removeClass ("not_read");
  65. } else if(only_not_read !== true || active.hasClass("not_read")) {
  66. active.addClass ("not_read");
  67. }
  68. });
  69. }
  70. function mark_favorite (active) {
  71. if (active[0] === undefined) {
  72. return false;
  73. }
  74. url = active.find ("a.bookmark").attr ("href");
  75. if (url === undefined) {
  76. return false;
  77. }
  78. $.ajax ({
  79. type: 'POST',
  80. url: url,
  81. data : { ajax: true }
  82. }).done (function (data) {
  83. res = jQuery.parseJSON(data);
  84. active.find ("a.bookmark").attr ("href", res.url);
  85. if (active.hasClass ("favorite")) {
  86. active.removeClass ("favorite");
  87. } else {
  88. active.addClass ("favorite");
  89. }
  90. });
  91. }
  92. function prev_entry() {
  93. old_active = $(".flux.active");
  94. last_active = $(".flux:last");
  95. new_active = old_active.prevAll (".flux:first");
  96. if (new_active.hasClass("flux")) {
  97. toggleContent (new_active, old_active);
  98. } else if (old_active[0] === undefined &&
  99. new_active[0] === undefined) {
  100. toggleContent (last_active, old_active);
  101. }
  102. }
  103. function next_entry() {
  104. old_active = $(".flux.active");
  105. first_active = $(".flux:first");
  106. last_active = $(".flux:last");
  107. new_active = old_active.nextAll (".flux:first");
  108. if(last_active.attr("id") == new_active.attr("id")) {
  109. load_more_posts ();
  110. }
  111. if (new_active.hasClass("flux")) {
  112. toggleContent (new_active, old_active);
  113. } else if (old_active[0] === undefined &&
  114. new_active[0] === undefined) {
  115. toggleContent (first_active, old_active);
  116. }
  117. }
  118. function init_img () {
  119. $(".flux_content .content img").each (function () {
  120. if ($(this).width () > ($(".flux_content .content").width()) / 2) {
  121. $(this).addClass("big");
  122. }
  123. });
  124. }
  125. function inMarkViewport(flux) {
  126. var top = flux.position().top;
  127. var height = flux.height();
  128. var begin = top + 3 * height / 4;
  129. var bot = Math.min(begin + 75, top + height);
  130. var windowTop = $(window).scrollTop();
  131. var windowBot = windowTop + $(window).height() / 2;
  132. return (windowBot >= begin && windowBot <= bot);
  133. }
  134. function init_posts () {
  135. init_img ();
  136. <?php if($this->conf->lazyload() == 'yes') { ?>
  137. $(".flux .content img").lazyload();
  138. <?php } ?>
  139. if (hide_posts) {
  140. $(".flux:not(.active) .flux_content").hide ();
  141. }
  142. var flux_header_toggle = $(".flux_header .item.title, .flux_header .item.date");
  143. flux_header_toggle.unbind('click'); // évite d'associer 2 fois le toggle
  144. flux_header_toggle.click (function () {
  145. old_active = $(".flux.active");
  146. new_active = $(this).parent ().parent ();
  147. toggleContent (new_active, old_active);
  148. });
  149. $(".flux a.read").click (function () {
  150. active = $(this).parents (".flux");
  151. mark_read (active, false);
  152. return false;
  153. });
  154. $(".flux a.bookmark").click (function () {
  155. active = $(this).parents (".flux");
  156. mark_favorite (active);
  157. return false;
  158. });
  159. $(".flux .content a").click (function () {
  160. $(this).attr ('target', '_blank');
  161. });
  162. <?php if ($mark['site'] == 'yes') { ?>
  163. $(".flux .link a").click (function () {
  164. mark_read($(this).parent().parent().parent(), true);
  165. });
  166. <?php } ?>
  167. <?php if ($mark['scroll'] == 'yes') { ?>
  168. $(window).scroll(function() {
  169. $('.flux.not_read:visible').each(function() {
  170. if($(this).children(".flux_content").is(':visible') &&
  171. inMarkViewport($(this))) {
  172. mark_read($(this), true);
  173. }
  174. });
  175. });
  176. <?php } ?>
  177. <?php if ($auto_load_more == 'yes') { ?>
  178. $(window).scroll(function() {
  179. var windowBot = $(window).scrollTop() + $(window).height();
  180. var load_more_top = $("#load_more").position().top;
  181. if(windowBot >= load_more_top) {
  182. load_more_posts ();
  183. }
  184. });
  185. <?php } ?>
  186. }
  187. function init_column_categories () {
  188. if(!is_normal_mode()) {
  189. return;
  190. }
  191. $(".category").addClass ("stick");
  192. $(".categories .category .btn:first-child").width ("160px");
  193. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  194. $(".category + .feeds").not(".active").hide();
  195. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  196. $(".category a.dropdown-toggle").click (function () {
  197. $(this).children ().toggleClass ("i_up");
  198. $(this).parent ().next (".feeds").slideToggle();
  199. return false;
  200. });
  201. }
  202. function init_shortcuts () {
  203. // Touches de manipulation
  204. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  205. // on marque comme lu ou non lu
  206. active = $(".flux.active");
  207. mark_read (active, false);
  208. }, {
  209. 'disable_in_input':true
  210. });
  211. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  212. // on marque tout comme lu
  213. url = $(".nav_menu a.read_all").attr ("href");
  214. redirect (url, false);
  215. }, {
  216. 'disable_in_input':true
  217. });
  218. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  219. // on marque comme favori ou non favori
  220. active = $(".flux.active");
  221. mark_favorite (active);
  222. }, {
  223. 'disable_in_input':true
  224. });
  225. // Touches de navigation
  226. shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
  227. 'disable_in_input':true
  228. });
  229. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  230. old_active = $(".flux.active");
  231. first = $(".flux:first");
  232. if (first.hasClass("flux")) {
  233. toggleContent (first, old_active);
  234. }
  235. }, {
  236. 'disable_in_input':true
  237. });
  238. shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
  239. 'disable_in_input':true
  240. });
  241. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  242. old_active = $(".flux.active");
  243. last = $(".flux:last");
  244. if (last.hasClass("flux")) {
  245. toggleContent (last, old_active);
  246. }
  247. }, {
  248. 'disable_in_input':true
  249. });
  250. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  251. url = $(".pager-next a").attr ("href");
  252. redirect (url, false);
  253. }, {
  254. 'disable_in_input':true
  255. });
  256. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  257. url = $(".pager-previous a").attr ("href");
  258. redirect (url, false);
  259. }, {
  260. 'disable_in_input':true
  261. });
  262. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  263. url_website = $(".flux.active .link a").attr ("href");
  264. <?php if ($mark['site'] == 'yes') { ?>
  265. $(".flux.active").each (function () {
  266. mark_read($(this), true);
  267. });
  268. <?php } ?>
  269. redirect (url_website, true);
  270. }, {
  271. 'disable_in_input':true
  272. });
  273. }
  274. function init_nav_entries() {
  275. $('.nav_entries a.previous_entry').click(function() {
  276. prev_entry();
  277. return false;
  278. });
  279. $('.nav_entries a.next_entry').click(function() {
  280. next_entry();
  281. return false;
  282. });
  283. $('.nav_entries a.up').click(function() {
  284. var active_item = $(".flux.active");
  285. var windowTop = $(window).scrollTop();
  286. var item_top = active_item.position ().top;
  287. if(windowTop > item_top) {
  288. $("html,body").scrollTop (item_top);
  289. } else {
  290. $("html,body").scrollTop (0);
  291. }
  292. return false;
  293. });
  294. }
  295. $(document).ready (function () {
  296. if(is_reader_mode()) {
  297. hide_posts = false;
  298. }
  299. init_posts ();
  300. init_column_categories ();
  301. init_shortcuts ();
  302. init_nav_entries();
  303. });