main.phtml 9.7 KB

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