aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/main.phtml
blob: 87b53ca9a9d74b9f38b3c409baec492218960ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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);
		}
	});
});