main.phtml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 = false) {
  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 mark_read (active) {
  33. if (active[0] === undefined) {
  34. return false;
  35. }
  36. url = active.find ("a.read").attr ("href");
  37. $.ajax ({
  38. type: 'POST',
  39. url: url,
  40. data : { ajax: true }
  41. }).done (function (data) {
  42. res = jQuery.parseJSON(data);
  43. active.find ("a.read").attr ("href", res.url);
  44. if (active.hasClass ("not_read")) {
  45. active.removeClass ("not_read");
  46. active.find ("a.read").html ("Marquer comme non lu");
  47. } else {
  48. active.addClass ("not_read");
  49. active.find ("a.read").html ("J'ai fini de lire l'article");
  50. }
  51. });
  52. }
  53. function mark_favorite (active) {
  54. if (active[0] === undefined) {
  55. return false;
  56. }
  57. url = active.find ("a.bookmark").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.bookmark").attr ("href", res.url);
  65. if (active.hasClass ("favorite")) {
  66. active.removeClass ("favorite");
  67. active.find ("a.bookmark").html ("Ajouter l'article à mes favoris");
  68. } else {
  69. active.addClass ("favorite");
  70. active.find ("a.bookmark").html ("Retirer l'article de mes favoris");
  71. }
  72. });
  73. }
  74. $(document).ready (function () {
  75. if (hide_posts) {
  76. $(".post.flux .content").slideToggle ();
  77. }
  78. $(".post.flux").click (function () {
  79. old_active = $(".post.flux.active");
  80. new_active = $(this);
  81. if (old_active[0] != new_active[0]) {
  82. slide (new_active, old_active);
  83. } else {
  84. old_active.removeClass ("active");
  85. if (hide_posts) {
  86. old_active.children (".content").slideUp (200);
  87. }
  88. }
  89. });
  90. $(".post.flux a.read").click (function () {
  91. active = $(this).parents (".post.flux");
  92. mark_read (active);
  93. return false;
  94. });
  95. $(".post.flux a.bookmark").click (function () {
  96. active = $(this).parents (".post.flux");
  97. mark_favorite (active);
  98. return false;
  99. });
  100. // Touches de manipulation
  101. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  102. // on marque comme lu ou non lu
  103. active = $(".post.flux.active");
  104. mark_read (active);
  105. });
  106. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  107. // on marque tout comme lu
  108. url = $("#top a.read_all").attr ("href");
  109. redirect (url);
  110. });
  111. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  112. // on marque comme favori ou non favori
  113. active = $(".post.flux.active");
  114. mark_favorite (active);
  115. });
  116. // Touches de navigation
  117. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  118. old_active = $(".post.flux.active");
  119. last_active = $(".post.flux:last");
  120. new_active = old_active.prev ();
  121. if (new_active[0] instanceof HTMLDivElement) {
  122. slide (new_active, old_active);
  123. } else if (new_active[0] === undefined) {
  124. slide (last_active, old_active);
  125. }
  126. });
  127. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  128. old_active = $(".post.flux.active");
  129. first = $(".post.flux:first");
  130. if (first[0] instanceof HTMLDivElement) {
  131. slide (first, old_active);
  132. }
  133. });
  134. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  135. old_active = $(".post.flux.active");
  136. first_active = $(".post.flux:first");
  137. new_active = old_active.next ();
  138. if (new_active[0] instanceof HTMLDivElement) {
  139. slide (new_active, old_active);
  140. } else if (new_active[0] === undefined) {
  141. slide (first_active, old_active);
  142. }
  143. });
  144. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  145. old_active = $(".post.flux.active");
  146. last = $(".post.flux:last");
  147. if (last[0] instanceof HTMLDivElement) {
  148. slide (last, old_active);
  149. }
  150. });
  151. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  152. url = $(".pager-next a").attr ("href");
  153. redirect (url);
  154. });
  155. shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
  156. url = $(".pager-last a").attr ("href");
  157. redirect (url);
  158. });
  159. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  160. url = $(".pager-previous a").attr ("href");
  161. redirect (url);
  162. });
  163. shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
  164. url = $(".pager-first a").attr ("href");
  165. redirect (url);
  166. });
  167. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  168. url = $(".post.flux.active h1.title a").attr ("href");
  169. redirect (url, true);
  170. });
  171. });