main.phtml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 (500);
  21. new_active.children (".content").slideDown (500, function () {
  22. $.smoothScroll({
  23. offset: new_active.position ().top
  24. });
  25. });
  26. } else {
  27. $.smoothScroll({
  28. offset: new_active.position ().top
  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. function init_img () {
  90. $(".flux .content img").each (function () {
  91. if ($(this).width () > ($("#stream").width()) / 2) {
  92. $(this).addClass("big");
  93. }
  94. });
  95. }
  96. function init_posts () {
  97. init_img ();
  98. if (hide_posts) {
  99. $(".flux:not(.active) .content").slideUp ();
  100. }
  101. $(".flux").click (function () {
  102. old_active = $(".flux.active");
  103. new_active = $(this);
  104. if (old_active[0] != new_active[0]) {
  105. slide (new_active, old_active);
  106. }
  107. });
  108. $(".flux a.read").click (function () {
  109. active = $(this).parents (".flux");
  110. mark_read (active);
  111. return false;
  112. });
  113. $(".flux a.bookmark").click (function () {
  114. active = $(this).parents (".flux");
  115. mark_favorite (active);
  116. return false;
  117. });
  118. $(".flux .content a").click (function () {
  119. $(this).attr ('target', '_blank');
  120. });
  121. }
  122. $(document).ready (function () {
  123. init_posts ();
  124. // Touches de manipulation
  125. shortcut.add("<?php echo $s['mark_read']; ?>", function () {
  126. // on marque comme lu ou non lu
  127. active = $(".flux.active");
  128. mark_read (active);
  129. });
  130. shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
  131. // on marque tout comme lu
  132. url = $("#top a.read_all").attr ("href");
  133. redirect (url, false);
  134. });
  135. shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
  136. // on marque comme favori ou non favori
  137. active = $(".flux.active");
  138. mark_favorite (active);
  139. });
  140. // Touches de navigation
  141. shortcut.add("<?php echo $s['prev_entry']; ?>", function () {
  142. old_active = $(".flux.active");
  143. last_active = $(".flux:last");
  144. new_active = old_active.prev ();
  145. if (new_active[0] instanceof HTMLDivElement) {
  146. slide (new_active, old_active);
  147. } else if (new_active[0] === undefined) {
  148. slide (last_active, old_active);
  149. }
  150. });
  151. shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
  152. old_active = $(".flux.active");
  153. first = $(".flux:first");
  154. if (first[0] instanceof HTMLDivElement) {
  155. slide (first, old_active);
  156. }
  157. });
  158. shortcut.add("<?php echo $s['next_entry']; ?>", function () {
  159. old_active = $(".flux.active");
  160. first_active = $(".flux:first");
  161. new_active = old_active.next ();
  162. if (new_active[0] instanceof HTMLDivElement) {
  163. slide (new_active, old_active);
  164. } else if (new_active[0] === undefined) {
  165. slide (first_active, old_active);
  166. }
  167. });
  168. shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
  169. old_active = $(".flux.active");
  170. last = $(".flux:last");
  171. if (last[0] instanceof HTMLDivElement) {
  172. slide (last, old_active);
  173. }
  174. });
  175. shortcut.add("<?php echo $s['next_page']; ?>", function () {
  176. url = $(".pager-next a").attr ("href");
  177. redirect (url, false);
  178. });
  179. shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
  180. url = $(".pager-last a").attr ("href");
  181. redirect (url, false);
  182. });
  183. shortcut.add("<?php echo $s['prev_page']; ?>", function () {
  184. url = $(".pager-previous a").attr ("href");
  185. redirect (url, false);
  186. });
  187. shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
  188. url = $(".pager-first a").attr ("href");
  189. redirect (url, false);
  190. });
  191. shortcut.add("<?php echo $s['go_website']; ?>", function () {
  192. url = $(".flux.active .link a").attr ("href");
  193. redirect (url, true);
  194. });
  195. });