diff options
| author | 2012-10-22 22:11:23 +0200 | |
|---|---|---|
| committer | 2012-10-22 22:11:23 +0200 | |
| commit | a928ebf1d010433d81d3afe5a6981f7ca391b9c7 (patch) | |
| tree | 94cbb70710abf65c1e993b272bade0958e5b4e01 /app/views/javascript | |
| parent | 0426541acbeb44d240e6dbf7a93f3a104bea61b4 (diff) | |
ajout des touches de raccourcis et de tout le javascript
Diffstat (limited to 'app/views/javascript')
| -rw-r--r-- | app/views/javascript/main.phtml | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml new file mode 100644 index 000000000..87b53ca9a --- /dev/null +++ b/app/views/javascript/main.phtml @@ -0,0 +1,130 @@ +<?php if ($this->conf->displayPosts () == 'no') { ?> +var hide_posts = true; +<?php } else { ?> +var hide_posts = false; +<?php } ?> + +function redirect (url) { + if (url) { + location.href = url; + } +} + +function slide (new_active, old_active) { + old_active.removeClass ("active"); + new_active.addClass ("active"); + + if (hide_posts) { + old_active.children (".content").slideUp (200); + new_active.children (".content").slideDown (200, function () { + $.smoothScroll({ + offset: new_active.position ().top + 25 + }); + }); + } else { + $.smoothScroll({ + offset: new_active.position ().top + 25 + }); + } +} + +$(document).ready (function () { + if (hide_posts) { + $(".post.flux .content").slideToggle (); + } + + // Touches de manipulation + shortcut.add("m", function () { + // on marque comme lu ou non lu + active = $(".post.flux.active"); + url = active.find ("a.read").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function () { + if (active.hasClass ("not_read")) { + active.removeClass ("not_read"); + } else { + active.addClass ("not_read"); + } + }); + }); + shortcut.add("f", function () { + // on marque comme favori ou non favori + active = $(".post.flux.active"); + url = active.find ("a.bookmark").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function () { + if (active.hasClass ("favorite")) { + active.removeClass ("favorite"); + } else { + active.addClass ("favorite"); + } + }); + }); + shortcut.add("space", function () { + // On plie / déplie l'article + active = $(".post.flux.active"); + active.children (".content").slideToggle (200, function () { + $.smoothScroll({ + offset: active.position ().top + 25 + }); + }); + }); + + // Touches de navigation + shortcut.add("up", function () { + old_active = $(".post.flux.active"); + last_active = $(".post.flux:last"); + new_active = old_active.prev (); + + if (new_active[0] instanceof HTMLDivElement) { + slide (new_active, old_active); + } else { + slide (last_active, old_active); + } + }); + shortcut.add("down", function () { + old_active = $(".post.flux.active"); + first_active = $(".post.flux:first"); + new_active = old_active.next (); + + if (new_active[0] instanceof HTMLDivElement) { + slide (new_active, old_active); + } else { + slide (first_active, old_active); + } + }); + shortcut.add("right", function () { + url = $(".pager-next a").attr ("href"); + if (url === undefined) { + url = $(".pager-first a").attr ("href"); + } + + redirect (url); + }); + shortcut.add("left", function () { + url = $(".pager-previous a").attr ("href"); + if (url === undefined) { + url = $(".pager-last a").attr ("href"); + } + + redirect (url); + }); + + + $(".post.flux").click (function () { + old_active = $(".post.flux.active"); + new_active = $(this); + + if (old_active[0] != new_active[0]) { + slide (new_active, old_active); + } + }); +}); |
