main.phtml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php if ($this->conf->displayPosts () == 'no') { ?>
  2. var hide_posts = true;
  3. <?php } else { ?>
  4. var hide_posts = false;
  5. <?php } ?>
  6. function redirect (url) {
  7. if (url) {
  8. location.href = url;
  9. }
  10. }
  11. function slide (new_active, old_active) {
  12. old_active.removeClass ("active");
  13. new_active.addClass ("active");
  14. if (hide_posts) {
  15. old_active.children (".content").slideUp (200);
  16. new_active.children (".content").slideDown (200, function () {
  17. $.smoothScroll({
  18. offset: new_active.position ().top + 25
  19. });
  20. });
  21. } else {
  22. $.smoothScroll({
  23. offset: new_active.position ().top + 25
  24. });
  25. }
  26. }
  27. function mark_read (active) {
  28. url = active.find ("a.read").attr ("href");
  29. $.ajax ({
  30. type: 'POST',
  31. url: url,
  32. data : { ajax: true }
  33. }).done (function (data) {
  34. res = jQuery.parseJSON(data);
  35. active.find ("a.read").attr ("href", res.url);
  36. if (active.hasClass ("not_read")) {
  37. active.removeClass ("not_read");
  38. active.find ("a.read").html ("Marquer comme non lu");
  39. } else {
  40. active.addClass ("not_read");
  41. active.find ("a.read").html ("J'ai fini de lire l'article");
  42. }
  43. });
  44. }
  45. function mark_favorite (active) {
  46. url = active.find ("a.bookmark").attr ("href");
  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.bookmark").attr ("href", res.url);
  54. if (active.hasClass ("favorite")) {
  55. active.removeClass ("favorite");
  56. active.find ("a.bookmark").html ("Ajouter l'article à mes favoris");
  57. } else {
  58. active.addClass ("favorite");
  59. active.find ("a.bookmark").html ("Retirer l'article de mes favoris");
  60. }
  61. });
  62. }
  63. $(document).ready (function () {
  64. if (hide_posts) {
  65. $(".post.flux .content").slideToggle ();
  66. }
  67. $(".post.flux").click (function () {
  68. old_active = $(".post.flux.active");
  69. new_active = $(this);
  70. if (old_active[0] != new_active[0]) {
  71. slide (new_active, old_active);
  72. }
  73. });
  74. $(".post.flux a.read").click (function () {
  75. active = $(this).parents (".post.flux");
  76. mark_read (active);
  77. return false;
  78. });
  79. $(".post.flux a.bookmark").click (function () {
  80. active = $(this).parents (".post.flux");
  81. mark_favorite (active);
  82. return false;
  83. });
  84. // Touches de manipulation
  85. shortcut.add("m", function () {
  86. // on marque comme lu ou non lu
  87. active = $(".post.flux.active");
  88. mark_read (active);
  89. });
  90. shortcut.add("f", function () {
  91. // on marque comme favori ou non favori
  92. active = $(".post.flux.active");
  93. mark_favorite (active);
  94. });
  95. // Touches de navigation
  96. shortcut.add("page_up", function () {
  97. old_active = $(".post.flux.active");
  98. last_active = $(".post.flux:last");
  99. new_active = old_active.prev ();
  100. if (new_active[0] instanceof HTMLDivElement) {
  101. slide (new_active, old_active);
  102. } else if (new_active[0] === undefined) {
  103. slide (last_active, old_active);
  104. }
  105. });
  106. shortcut.add("page_down", function () {
  107. old_active = $(".post.flux.active");
  108. first_active = $(".post.flux:first");
  109. new_active = old_active.next ();
  110. if (new_active[0] instanceof HTMLDivElement) {
  111. slide (new_active, old_active);
  112. } else if (new_active[0] === undefined) {
  113. slide (first_active, old_active);
  114. }
  115. });
  116. shortcut.add("right", function () {
  117. url = $(".pager-next a").attr ("href");
  118. if (url === undefined) {
  119. url = $(".pager-first a").attr ("href");
  120. }
  121. redirect (url);
  122. });
  123. shortcut.add("left", function () {
  124. url = $(".pager-previous a").attr ("href");
  125. if (url === undefined) {
  126. url = $(".pager-last a").attr ("href");
  127. }
  128. redirect (url);
  129. });
  130. });