4
0

main.phtml 9.8 KB

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