main.phtml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 (200);
  21. new_active.children (".content").slideDown (200, function () {
  22. $.smoothScroll({
  23. offset: new_active.position ().top
  24. });
  25. });
  26. } else {
  27. $.smoothScroll({
  28. offset: new_active.position ().top + 25
  29. });
  30. }
  31. }
  32. function add_not_read (nb) {
  33. span_not_read = $("#categories li.all span.nb_not_read");
  34. html = span_not_read.html ();
  35. regex = /(\d+)/;
  36. nb_not_read = parseInt (regex.exec (html)[1]) + nb;
  37. span_not_read.html (nb_not_read);
  38. }
  39. function mark_read (active) {
  40. if (active[0] === undefined) {
  41. return false;
  42. }
  43. url = active.find ("a.read").attr ("href");
  44. if (url === undefined) {
  45. return false;
  46. }
  47. $.ajax ({
  48. type: 'POST',
  49. url: url,
  50. data : { ajax: true }
  51. }).done (function (data) {
  52. res = jQuery.parseJSON(data);
  53. active.find ("a.read").attr ("href", res.url);
  54. if (active.hasClass ("not_read")) {
  55. active.removeClass ("not_read");
  56. active.find ("a.read").html ("Marquer comme non lu");
  57. add_not_read (-1);
  58. } else {
  59. active.addClass ("not_read");
  60. active.find ("a.read").html ("J'ai fini de lire l'article");
  61. add_not_read (1);
  62. }
  63. });
  64. }
  65. function mark_favorite (active) {
  66. if (active[0] === undefined) {
  67. return false;
  68. }
  69. url = active.find ("a.bookmark").attr ("href");
  70. if (url === undefined) {
  71. return false;
  72. }
  73. $.ajax ({
  74. type: 'POST',
  75. url: url,
  76. data : { ajax: true }
  77. }).done (function (data) {
  78. res = jQuery.parseJSON(data);
  79. active.find ("a.bookmark").attr ("href", res.url);
  80. if (active.hasClass ("favorite")) {
  81. active.removeClass ("favorite");
  82. active.find ("a.bookmark").html ("Ajouter l'article à mes favoris");
  83. } else {
  84. active.addClass ("favorite");
  85. active.find ("a.bookmark").html ("Retirer l'article de mes favoris");
  86. }
  87. });
  88. }
  89. function init_posts () {
  90. if (hide_posts) {
  91. $(".post.flux:not(.active) .content").slideUp ();
  92. }
  93. $(".post.flux").click (function () {
  94. old_active = $(".post.flux.active");
  95. new_active = $(this);
  96. if (old_active[0] != new_active[0]) {
  97. slide (new_active, old_active);
  98. }
  99. });
  100. $(".post.flux a.read").click (function () {
  101. active = $(this).parents (".post.flux");
  102. mark_read (active);
  103. return false;
  104. });
  105. $(".post.flux a.bookmark").click (function () {
  106. active = $(this).parents (".post.flux");
  107. mark_favorite (active);
  108. return false;
  109. });
  110. $(".post.flux .content a").click (function () {
  111. $(this).attr ('target', '_blank');
  112. });
  113. }
  114. $(document).ready (function () {
  115. init_posts ();
  116. // Touches de manipulation
  117. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  118. // on marque comme lu ou non lu
  119. active = $(".post.flux.active");
  120. mark_read (active);
  121. });
  122. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  123. // on marque tout comme lu
  124. url = $("#top a.read_all").attr ("href");
  125. redirect (url, false);
  126. });
  127. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  128. // on marque comme favori ou non favori
  129. active = $(".post.flux.active");
  130. mark_favorite (active);
  131. });
  132. // Touches de navigation
  133. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  134. old_active = $(".post.flux.active");
  135. last_active = $(".post.flux:last");
  136. new_active = old_active.prev ();
  137. if (new_active[0] instanceof HTMLDivElement) {
  138. slide (new_active, old_active);
  139. } else if (new_active[0] === undefined) {
  140. slide (last_active, old_active);
  141. }
  142. });
  143. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  144. old_active = $(".post.flux.active");
  145. first = $(".post.flux:first");
  146. if (first[0] instanceof HTMLDivElement) {
  147. slide (first, old_active);
  148. }
  149. });
  150. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  151. old_active = $(".post.flux.active");
  152. first_active = $(".post.flux:first");
  153. new_active = old_active.next ();
  154. if (new_active[0] instanceof HTMLDivElement) {
  155. slide (new_active, old_active);
  156. } else if (new_active[0] === undefined) {
  157. slide (first_active, old_active);
  158. }
  159. });
  160. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  161. old_active = $(".post.flux.active");
  162. last = $(".post.flux:last");
  163. if (last[0] instanceof HTMLDivElement) {
  164. slide (last, old_active);
  165. }
  166. });
  167. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  168. url = $(".pager-next a").attr ("href");
  169. redirect (url, false);
  170. });
  171. shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
  172. url = $(".pager-last a").attr ("href");
  173. redirect (url, false);
  174. });
  175. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  176. url = $(".pager-previous a").attr ("href");
  177. redirect (url, false);
  178. });
  179. shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
  180. url = $(".pager-first a").attr ("href");
  181. redirect (url, false);
  182. });
  183. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  184. url = $(".post.flux.active h1.title a").attr ("href");
  185. redirect (url, true);
  186. });
  187. $("#categories").height ($('body').height () - $("#categories").position ().top);
  188. });