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