main.phtml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. $(document).ready (function () {
  28. if (hide_posts) {
  29. $(".post.flux .content").slideToggle ();
  30. }
  31. // Touches de manipulation
  32. shortcut.add("m", function () {
  33. // on marque comme lu ou non lu
  34. active = $(".post.flux.active");
  35. url = active.find ("a.read").attr ("href");
  36. $.ajax ({
  37. type: 'POST',
  38. url: url,
  39. data : { ajax: true }
  40. }).done (function () {
  41. if (active.hasClass ("not_read")) {
  42. active.removeClass ("not_read");
  43. } else {
  44. active.addClass ("not_read");
  45. }
  46. });
  47. });
  48. shortcut.add("f", function () {
  49. // on marque comme favori ou non favori
  50. active = $(".post.flux.active");
  51. url = active.find ("a.bookmark").attr ("href");
  52. $.ajax ({
  53. type: 'POST',
  54. url: url,
  55. data : { ajax: true }
  56. }).done (function () {
  57. if (active.hasClass ("favorite")) {
  58. active.removeClass ("favorite");
  59. } else {
  60. active.addClass ("favorite");
  61. }
  62. });
  63. });
  64. shortcut.add("space", function () {
  65. // On plie / déplie l'article
  66. active = $(".post.flux.active");
  67. active.children (".content").slideToggle (200, function () {
  68. $.smoothScroll({
  69. offset: active.position ().top + 25
  70. });
  71. });
  72. });
  73. // Touches de navigation
  74. shortcut.add("up", function () {
  75. old_active = $(".post.flux.active");
  76. last_active = $(".post.flux:last");
  77. new_active = old_active.prev ();
  78. if (new_active[0] instanceof HTMLDivElement) {
  79. slide (new_active, old_active);
  80. } else {
  81. slide (last_active, old_active);
  82. }
  83. });
  84. shortcut.add("down", function () {
  85. old_active = $(".post.flux.active");
  86. first_active = $(".post.flux:first");
  87. new_active = old_active.next ();
  88. if (new_active[0] instanceof HTMLDivElement) {
  89. slide (new_active, old_active);
  90. } else {
  91. slide (first_active, old_active);
  92. }
  93. });
  94. shortcut.add("right", function () {
  95. url = $(".pager-next a").attr ("href");
  96. if (url === undefined) {
  97. url = $(".pager-first a").attr ("href");
  98. }
  99. redirect (url);
  100. });
  101. shortcut.add("left", function () {
  102. url = $(".pager-previous a").attr ("href");
  103. if (url === undefined) {
  104. url = $(".pager-last a").attr ("href");
  105. }
  106. redirect (url);
  107. });
  108. $(".post.flux").click (function () {
  109. old_active = $(".post.flux.active");
  110. new_active = $(this);
  111. if (old_active[0] != new_active[0]) {
  112. slide (new_active, old_active);
  113. }
  114. });
  115. });