main.phtml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php if ($this->conf->displayPosts () == 'no') { ?>
  2. var hide_posts = true;
  3. <?php } else { ?>
  4. var hide_posts = false;
  5. <?php } ?>
  6. <?php $s = $this->conf->shortcuts (); ?>
  7. function redirect (url, new_tab) {
  8. if (url) {
  9. if (new_tab) {
  10. window.open (url);
  11. } else {
  12. location.href = url;
  13. }
  14. }
  15. }
  16. function slide (new_active, old_active) {
  17. old_active.removeClass ("active");
  18. new_active.addClass ("active");
  19. if (hide_posts) {
  20. old_active.children (".content").slideUp (500);
  21. new_active.children (".content").slideDown (500, function () {
  22. $.smoothScroll({
  23. offset: new_active.position ().top
  24. });
  25. });
  26. } else {
  27. $.smoothScroll({
  28. offset: new_active.position ().top
  29. });
  30. }
  31. }
  32. function mark_read (active) {
  33. if (active[0] === undefined) {
  34. return false;
  35. }
  36. url = active.find ("a.read").attr ("href");
  37. if (url === undefined) {
  38. return false;
  39. }
  40. $.ajax ({
  41. type: 'POST',
  42. url: url,
  43. data : { ajax: true }
  44. }).done (function (data) {
  45. res = jQuery.parseJSON(data);
  46. active.find ("a.read").attr ("href", res.url);
  47. if (active.hasClass ("not_read")) {
  48. active.removeClass ("not_read");
  49. } else {
  50. active.addClass ("not_read");
  51. }
  52. });
  53. }
  54. function mark_favorite (active) {
  55. if (active[0] === undefined) {
  56. return false;
  57. }
  58. url = active.find ("a.bookmark").attr ("href");
  59. if (url === undefined) {
  60. return false;
  61. }
  62. $.ajax ({
  63. type: 'POST',
  64. url: url,
  65. data : { ajax: true }
  66. }).done (function (data) {
  67. res = jQuery.parseJSON(data);
  68. active.find ("a.bookmark").attr ("href", res.url);
  69. if (active.hasClass ("favorite")) {
  70. active.removeClass ("favorite");
  71. } else {
  72. active.addClass ("favorite");
  73. }
  74. });
  75. }
  76. function init_img () {
  77. $(".flux .content img").each (function () {
  78. if ($(this).width () > ($("#stream").width()) / 2) {
  79. $(this).addClass("big");
  80. }
  81. });
  82. }
  83. function init_posts () {
  84. init_img ();
  85. if (hide_posts) {
  86. $(".flux:not(.active) .content").slideUp ();
  87. }
  88. $(".flux").click (function () {
  89. old_active = $(".flux.active");
  90. new_active = $(this);
  91. if (old_active[0] != new_active[0]) {
  92. slide (new_active, old_active);
  93. }
  94. });
  95. $(".flux a.read").click (function () {
  96. active = $(this).parents (".flux");
  97. mark_read (active);
  98. return false;
  99. });
  100. $(".flux a.bookmark").click (function () {
  101. active = $(this).parents (".flux");
  102. mark_favorite (active);
  103. return false;
  104. });
  105. $(".flux .content a").click (function () {
  106. $(this).attr ('target', '_blank');
  107. });
  108. }
  109. $(document).ready (function () {
  110. init_posts ();
  111. // Touches de manipulation
  112. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  113. // on marque comme lu ou non lu
  114. active = $(".flux.active");
  115. mark_read (active);
  116. });
  117. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  118. // on marque tout comme lu
  119. url = $("#top a.read_all").attr ("href");
  120. redirect (url, false);
  121. });
  122. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  123. // on marque comme favori ou non favori
  124. active = $(".flux.active");
  125. mark_favorite (active);
  126. });
  127. // Touches de navigation
  128. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  129. old_active = $(".flux.active");
  130. last_active = $(".flux:last");
  131. new_active = old_active.prevAll (".flux:first");
  132. if (new_active.hasClass("flux")) {
  133. slide (new_active, old_active);
  134. } else if (new_active[0] === undefined) {
  135. slide (last_active, old_active);
  136. }
  137. });
  138. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  139. old_active = $(".flux.active");
  140. first = $(".flux:first");
  141. if (first.hasClass("flux")) {
  142. slide (first, old_active);
  143. }
  144. });
  145. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  146. old_active = $(".flux.active");
  147. first_active = $(".flux:first");
  148. new_active = old_active.nextAll (".flux:first");
  149. if (new_active.hasClass("flux")) {
  150. slide (new_active, old_active);
  151. } else if (new_active[0] === undefined) {
  152. slide (first_active, old_active);
  153. }
  154. });
  155. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  156. old_active = $(".flux.active");
  157. last = $(".flux:last");
  158. if (last.hasClass("flux")) {
  159. slide (last, old_active);
  160. }
  161. });
  162. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  163. url = $(".pager-next a").attr ("href");
  164. redirect (url, false);
  165. });
  166. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  167. url = $(".pager-previous a").attr ("href");
  168. redirect (url, false);
  169. });
  170. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  171. url = $(".flux.active .link a").attr ("href");
  172. redirect (url, true);
  173. });
  174. });