main.phtml 7.5 KB

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