main.phtml 3.9 KB

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