main.phtml 10 KB

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