diff options
| author | 2012-10-25 15:42:06 +0200 | |
|---|---|---|
| committer | 2012-10-25 15:42:06 +0200 | |
| commit | d21c1bb13875189ab25f7bce4f05cc3fedaa4904 (patch) | |
| tree | 43bc5ca4c728756ac2fa7ede42b50885ae171300 /app/views/javascript/main.phtml | |
| parent | e5767a7fae6e1463727987e09f1c592a8a86577b (diff) | |
correction marquage des articles en js
Diffstat (limited to 'app/views/javascript/main.phtml')
| -rw-r--r-- | app/views/javascript/main.phtml | 102 |
1 files changed, 66 insertions, 36 deletions
diff --git a/app/views/javascript/main.phtml b/app/views/javascript/main.phtml index 1bdde5a8e..c801ba7d0 100644 --- a/app/views/javascript/main.phtml +++ b/app/views/javascript/main.phtml @@ -28,45 +28,85 @@ function slide (new_active, old_active) { } } +function mark_read (active) { + url = active.find ("a.read").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function (data) { + res = jQuery.parseJSON(data); + + active.find ("a.read").attr ("href", res.url); + if (active.hasClass ("not_read")) { + active.removeClass ("not_read"); + active.find ("a.read").html ("Marquer comme non lu"); + } else { + active.addClass ("not_read"); + active.find ("a.read").html ("J'ai fini de lire l'article"); + } + }); +} + +function mark_favorite (active) { + url = active.find ("a.bookmark").attr ("href"); + + $.ajax ({ + type: 'POST', + url: url, + data : { ajax: true } + }).done (function (data) { + res = jQuery.parseJSON(data); + + active.find ("a.bookmark").attr ("href", res.url); + if (active.hasClass ("favorite")) { + active.removeClass ("favorite"); + active.find ("a.bookmark").html ("Ajouter l'article à mes favoris"); + } else { + active.addClass ("favorite"); + active.find ("a.bookmark").html ("Retirer l'article de mes favoris"); + } + }); +} + $(document).ready (function () { if (hide_posts) { $(".post.flux .content").slideToggle (); } + + $(".post.flux").click (function () { + old_active = $(".post.flux.active"); + new_active = $(this); + + if (old_active[0] != new_active[0]) { + slide (new_active, old_active); + } + }); + + $(".post.flux a.read").click (function () { + active = $(this).parents (".post.flux"); + mark_read (active); + + return false; + }); + $(".post.flux a.bookmark").click (function () { + active = $(this).parents (".post.flux"); + mark_favorite (active); + + return false; + }); // 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"); - } - }); + mark_read (active); }); 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"); - } - }); + mark_favorite (active); }); // Touches de navigation @@ -108,14 +148,4 @@ $(document).ready (function () { 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); - } - }); }); |
