main.phtml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 is_global_mode() {
  20. var stream = $("#stream.global");
  21. return stream.html() != null;
  22. }
  23. function redirect (url, new_tab) {
  24. if (url) {
  25. if (new_tab) {
  26. window.open (url);
  27. } else {
  28. location.href = url;
  29. }
  30. }
  31. }
  32. function toggleContent (new_active, old_active) {
  33. old_active.removeClass ("active");
  34. if (old_active[0] != new_active[0]) {
  35. new_active.addClass ("active");
  36. }
  37. var box_to_move = "html,body";
  38. var relative_move = false;
  39. if(is_global_mode()) {
  40. box_to_move = "#panel";
  41. relative_move = true;
  42. }
  43. var new_pos = new_active.position ().top,
  44. old_scroll = $(box_to_move).scrollTop (),
  45. new_scroll = old_scroll;
  46. if (hide_posts) {
  47. old_active.children (".flux_content").toggle (0);
  48. if(relative_move) {
  49. new_pos += old_scroll;
  50. }
  51. if (old_active[0] != new_active[0]) {
  52. new_active.children (".flux_content").toggle (0, function () {
  53. new_scroll = $(box_to_move).scrollTop (new_pos).scrollTop ();
  54. });
  55. }
  56. } else {
  57. new_scroll = $(box_to_move).scrollTop (new_pos).scrollTop ();
  58. }
  59. if ((new_scroll === old_scroll) && $.fn.lazyload) {
  60. $(window).trigger ("scroll"); //When no scroll was done, generate fake scroll event for LazyLoad to load images
  61. }
  62. <?php if ($mark['article'] == 'yes') { ?>
  63. mark_read(new_active, true);
  64. <?php } ?>
  65. }
  66. function mark_read (active, only_not_read) {
  67. if (active[0] === undefined || (
  68. only_not_read === true && !active.hasClass("not_read"))) {
  69. return false;
  70. }
  71. url = active.find ("a.read").attr ("href");
  72. if (url === undefined) {
  73. return false;
  74. }
  75. $.ajax ({
  76. type: 'POST',
  77. url: url,
  78. data : { ajax: true }
  79. }).done (function (data) {
  80. res = jQuery.parseJSON(data);
  81. active.find ("a.read").attr ("href", res.url);
  82. if (active.hasClass ("not_read")) {
  83. active.removeClass ("not_read");
  84. } else if(only_not_read !== true || active.hasClass("not_read")) {
  85. active.addClass ("not_read");
  86. }
  87. });
  88. }
  89. function mark_favorite (active) {
  90. if (active[0] === undefined) {
  91. return false;
  92. }
  93. url = active.find ("a.bookmark").attr ("href");
  94. if (url === undefined) {
  95. return false;
  96. }
  97. $.ajax ({
  98. type: 'POST',
  99. url: url,
  100. data : { ajax: true }
  101. }).done (function (data) {
  102. res = jQuery.parseJSON(data);
  103. active.find ("a.bookmark").attr ("href", res.url);
  104. if (active.hasClass ("favorite")) {
  105. active.removeClass ("favorite");
  106. } else {
  107. active.addClass ("favorite");
  108. }
  109. });
  110. }
  111. function prev_entry() {
  112. old_active = $(".flux.active");
  113. last_active = $(".flux:last");
  114. new_active = old_active.prevAll (".flux:first");
  115. if (new_active.hasClass("flux")) {
  116. toggleContent (new_active, old_active);
  117. } else if (old_active[0] === undefined &&
  118. new_active[0] === undefined) {
  119. toggleContent (last_active, old_active);
  120. }
  121. }
  122. function next_entry() {
  123. old_active = $(".flux.active");
  124. first_active = $(".flux:first");
  125. last_active = $(".flux:last");
  126. new_active = old_active.nextAll (".flux:first");
  127. if (new_active.hasClass("flux")) {
  128. toggleContent (new_active, old_active);
  129. } else if (old_active[0] === undefined &&
  130. new_active[0] === undefined) {
  131. toggleContent (first_active, old_active);
  132. }
  133. <?php if ($auto_load_more !== 'yes') { ?>
  134. if(last_active.attr("id") == new_active.attr("id")) {
  135. load_more_posts ();
  136. }
  137. <?php } ?>
  138. }
  139. function init_img () {
  140. var maxWidth = $(".flux_content .content").width() / 2;
  141. $(".flux_content .content img").each (function () {
  142. if ($(this).width () > maxWidth) {
  143. $(this).addClass("big");
  144. }
  145. });
  146. }
  147. function inMarkViewport(flux, box_to_follow, relative_follow) {
  148. var top = flux.position().top;
  149. if(relative_follow) {
  150. top += box_to_follow.scrollTop();
  151. }
  152. var height = flux.height();
  153. var begin = top + 3 * height / 4;
  154. var bot = Math.min(begin + 75, top + height);
  155. var windowTop = box_to_follow.scrollTop();
  156. var windowBot = windowTop + box_to_follow.height() / 2;
  157. return (windowBot >= begin && windowBot <= bot);
  158. }
  159. function init_posts () {
  160. init_img ();
  161. <?php if($this->conf->lazyload() == 'yes') { ?>
  162. if(is_global_mode()) {
  163. $(".flux .content img").lazyload({
  164. container: $("#panel")
  165. });
  166. } else {
  167. $(".flux .content img").lazyload();
  168. }
  169. <?php } ?>
  170. if (hide_posts) {
  171. $(".flux:not(.active) .flux_content").hide ();
  172. }
  173. var box_to_follow = $(window);
  174. var relative_follow = false;
  175. if(is_global_mode()) {
  176. box_to_follow = $("#panel");
  177. relative_follow = true;
  178. }
  179. <?php if ($mark['scroll'] == 'yes') { ?>
  180. box_to_follow.scroll(function() {
  181. $('.flux.not_read:visible').each(function() {
  182. if($(this).children(".flux_content").is(':visible') &&
  183. inMarkViewport($(this), box_to_follow, relative_follow)) {
  184. mark_read($(this), true);
  185. }
  186. });
  187. });
  188. <?php } ?>
  189. <?php if ($auto_load_more == 'yes') { ?>
  190. box_to_follow.scroll(function() {
  191. var load_more = $("#load_more");
  192. if (!load_more.is(':visible')) return;
  193. var boxBot = box_to_follow.scrollTop() + box_to_follow.height();
  194. var load_more_top = load_more.position().top;
  195. if(relative_follow) {
  196. load_more_top += box_to_follow.scrollTop();
  197. }
  198. if(boxBot >= load_more_top) {
  199. load_more_posts ();
  200. }
  201. });
  202. <?php } ?>
  203. }
  204. function init_column_categories () {
  205. if(!is_normal_mode()) {
  206. return;
  207. }
  208. $(".category").addClass ("stick");
  209. $(".categories .category .btn:first-child").width ("160px");
  210. $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>");
  211. $(".category + .feeds").not(".active").hide();
  212. $(".category.active a.dropdown-toggle i").toggleClass ("i_up");
  213. $(".category a.dropdown-toggle").click (function () {
  214. $(this).children ().toggleClass ("i_up");
  215. $(this).parent ().next (".feeds").slideToggle();
  216. return false;
  217. });
  218. }
  219. function init_shortcuts () {
  220. // Touches de manipulation
  221. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  222. // on marque comme lu ou non lu
  223. active = $(".flux.active");
  224. mark_read (active, false);
  225. }, {
  226. 'disable_in_input':true
  227. });
  228. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  229. // on marque tout comme lu
  230. url = $(".nav_menu a.read_all").attr ("href");
  231. redirect (url, false);
  232. }, {
  233. 'disable_in_input':true
  234. });
  235. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  236. // on marque comme favori ou non favori
  237. active = $(".flux.active");
  238. mark_favorite (active);
  239. }, {
  240. 'disable_in_input':true
  241. });
  242. // Touches de navigation
  243. shortcut.add("<?php echo $s['prev_entry']; ?>", prev_entry, {
  244. 'disable_in_input':true
  245. });
  246. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  247. old_active = $(".flux.active");
  248. first = $(".flux:first");
  249. if (first.hasClass("flux")) {
  250. toggleContent (first, old_active);
  251. }
  252. }, {
  253. 'disable_in_input':true
  254. });
  255. shortcut.add("<?php echo $s['next_entry']; ?>", next_entry, {
  256. 'disable_in_input':true
  257. });
  258. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  259. old_active = $(".flux.active");
  260. last = $(".flux:last");
  261. if (last.hasClass("flux")) {
  262. toggleContent (last, old_active);
  263. }
  264. }, {
  265. 'disable_in_input':true
  266. });
  267. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  268. url_website = $(".flux.active .link a").attr ("href");
  269. <?php if ($mark['site'] == 'yes') { ?>
  270. $(".flux.active").each (function () {
  271. mark_read($(this), true);
  272. });
  273. <?php } ?>
  274. redirect (url_website, true);
  275. }, {
  276. 'disable_in_input':true
  277. });
  278. }
  279. function init_stream_delegates() {
  280. var divStream = $('#stream');
  281. divStream.on('click', '.flux_header .item.title, .flux_header .item.date', function (e) { //flux_header_toggle
  282. old_active = $(".flux.active");
  283. new_active = $(this).parent ().parent ();
  284. if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone
  285. <?php if ($mark['article'] == 'yes') { ?>
  286. mark_read(new_active, true);
  287. <?php } ?>
  288. return true;
  289. }
  290. toggleContent (new_active, old_active);
  291. });
  292. divStream.on('click', '.flux a.read', function () {
  293. active = $(this).parents (".flux");
  294. mark_read (active, false);
  295. return false;
  296. });
  297. divStream.on('click', '.flux a.bookmark', function () {
  298. active = $(this).parents (".flux");
  299. mark_favorite (active);
  300. return false;
  301. });
  302. divStream.on('click', '.flux .content a', function () {
  303. $(this).attr ('target', '_blank');
  304. });
  305. divStream.on('click', '.item.title>a',function (e) {
  306. if (e.ctrlKey) return true; //Allow default control-click behaviour such as open in backround-tab
  307. $(this).parent ().click (); //Will perform toggle flux_content
  308. return false;
  309. });
  310. divStream.on('click', '.bigMarkAsRead', function() {
  311. url = $(".nav_menu a.read_all").attr ("href");
  312. redirect (url, false);
  313. return false;
  314. });
  315. <?php if ($mark['site'] == 'yes') { ?>
  316. divStream.on('click', '.flux .link a', function () {
  317. mark_read($(this).parent().parent().parent(), true);
  318. });
  319. <?php } ?>
  320. }
  321. function init_nav_entries() {
  322. $('.nav_entries a.previous_entry').click(function() {
  323. prev_entry();
  324. return false;
  325. });
  326. $('.nav_entries a.next_entry').click(function() {
  327. next_entry();
  328. return false;
  329. });
  330. $('.nav_entries a.up').click(function() {
  331. var active_item = $(".flux.active");
  332. var windowTop = $(window).scrollTop();
  333. var item_top = active_item.position ().top;
  334. if(windowTop > item_top) {
  335. $("html,body").scrollTop (item_top);
  336. } else {
  337. $("html,body").scrollTop (0);
  338. }
  339. return false;
  340. });
  341. }
  342. $(document).ready (function () {
  343. if(is_reader_mode()) {
  344. hide_posts = false;
  345. }
  346. init_posts ();
  347. init_column_categories ();
  348. init_shortcuts ();
  349. init_stream_delegates();
  350. init_nav_entries();
  351. });