main.phtml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. } else {
  113. old_active.removeClass ("active");
  114. if (hide_posts) {
  115. old_active.children (".content").slideUp (200);
  116. }
  117. }
  118. });
  119. $(".post.flux a.read").click (function () {
  120. active = $(this).parents (".post.flux");
  121. mark_read (active);
  122. return false;
  123. });
  124. $(".post.flux a.bookmark").click (function () {
  125. active = $(this).parents (".post.flux");
  126. mark_favorite (active);
  127. return false;
  128. });
  129. $(".post.flux .content a").click (function () {
  130. url = $(this).attr ("href");
  131. redirect (url, true);
  132. return false;
  133. });
  134. // Touches de manipulation
  135. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  136. // on marque comme lu ou non lu
  137. active = $(".post.flux.active");
  138. mark_read (active);
  139. });
  140. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  141. // on marque tout comme lu
  142. url = $("#top a.read_all").attr ("href");
  143. redirect (url, false);
  144. });
  145. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  146. // on marque comme favori ou non favori
  147. active = $(".post.flux.active");
  148. mark_favorite (active);
  149. });
  150. // Touches de navigation
  151. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  152. old_active = $(".post.flux.active");
  153. last_active = $(".post.flux:last");
  154. new_active = old_active.prev ();
  155. if (new_active[0] instanceof HTMLDivElement) {
  156. slide (new_active, old_active);
  157. } else if (new_active[0] === undefined) {
  158. slide (last_active, old_active);
  159. }
  160. });
  161. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  162. old_active = $(".post.flux.active");
  163. first = $(".post.flux:first");
  164. if (first[0] instanceof HTMLDivElement) {
  165. slide (first, old_active);
  166. }
  167. });
  168. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  169. old_active = $(".post.flux.active");
  170. first_active = $(".post.flux:first");
  171. new_active = old_active.next ();
  172. if (new_active[0] instanceof HTMLDivElement) {
  173. slide (new_active, old_active);
  174. } else if (new_active[0] === undefined) {
  175. slide (first_active, old_active);
  176. }
  177. });
  178. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  179. old_active = $(".post.flux.active");
  180. last = $(".post.flux:last");
  181. if (last[0] instanceof HTMLDivElement) {
  182. slide (last, old_active);
  183. }
  184. });
  185. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  186. url = $(".pager-next a").attr ("href");
  187. redirect (url, false);
  188. });
  189. shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
  190. url = $(".pager-last a").attr ("href");
  191. redirect (url, false);
  192. });
  193. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  194. url = $(".pager-previous a").attr ("href");
  195. redirect (url, false);
  196. });
  197. shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
  198. url = $(".pager-first a").attr ("href");
  199. redirect (url, false);
  200. });
  201. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  202. url = $(".post.flux.active h1.title a").attr ("href");
  203. redirect (url, true);
  204. });
  205. });