From a928ebf1d010433d81d3afe5a6981f7ca391b9c7 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 22 Oct 2012 22:11:23 +0200 Subject: ajout des touches de raccourcis et de tout le javascript --- app/views/javascript/main.phtml | 130 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 app/views/javascript/main.phtml (limited to 'app/views/javascript') 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 @@ +conf->displayPosts () == 'no') { ?> +var hide_posts = true; + +var hide_posts = false; + + +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); + } + }); +}); -- cgit v1.2.3