main.phtml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 = $("#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. $(document).ready (function () {
  90. if (hide_posts) {
  91. $(".post.flux .content").slideToggle ();
  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. // Touches de manipulation
  114. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  115. // on marque comme lu ou non lu
  116. active = $(".post.flux.active");
  117. mark_read (active);
  118. });
  119. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  120. // on marque tout comme lu
  121. url = $("#top a.read_all").attr ("href");
  122. redirect (url, false);
  123. });
  124. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  125. // on marque comme favori ou non favori
  126. active = $(".post.flux.active");
  127. mark_favorite (active);
  128. });
  129. // Touches de navigation
  130. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  131. old_active = $(".post.flux.active");
  132. last_active = $(".post.flux:last");
  133. new_active = old_active.prev ();
  134. if (new_active[0] instanceof HTMLDivElement) {
  135. slide (new_active, old_active);
  136. } else if (new_active[0] === undefined) {
  137. slide (last_active, old_active);
  138. }
  139. });
  140. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  141. old_active = $(".post.flux.active");
  142. first = $(".post.flux:first");
  143. if (first[0] instanceof HTMLDivElement) {
  144. slide (first, old_active);
  145. }
  146. });
  147. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  148. old_active = $(".post.flux.active");
  149. first_active = $(".post.flux:first");
  150. new_active = old_active.next ();
  151. if (new_active[0] instanceof HTMLDivElement) {
  152. slide (new_active, old_active);
  153. } else if (new_active[0] === undefined) {
  154. slide (first_active, old_active);
  155. }
  156. });
  157. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  158. old_active = $(".post.flux.active");
  159. last = $(".post.flux:last");
  160. if (last[0] instanceof HTMLDivElement) {
  161. slide (last, old_active);
  162. }
  163. });
  164. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  165. url = $(".pager-next a").attr ("href");
  166. redirect (url, false);
  167. });
  168. shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
  169. url = $(".pager-last a").attr ("href");
  170. redirect (url, false);
  171. });
  172. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  173. url = $(".pager-previous a").attr ("href");
  174. redirect (url, false);
  175. });
  176. shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
  177. url = $(".pager-first a").attr ("href");
  178. redirect (url, false);
  179. });
  180. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  181. url = $(".post.flux.active h1.title a").attr ("href");
  182. redirect (url, true);
  183. });
  184. $("#categories").height ($('body').height () - $("#categories").position ().top);
  185. });