main.phtml 9.8 KB

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