main.phtml 5.5 KB

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