4
0

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