main.phtml 5.5 KB

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