aboutsummaryrefslogtreecommitdiff
path: root/app/views/javascript/main.phtml
blob: 710b04988fdbff9a4fda0c9e48ec26eb8b2f7678 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php if ($this->conf->displayPosts () == 'no') { ?>
var hide_posts = true;
<?php } else { ?>
var hide_posts = false;
<?php } ?>

<?php $s = $this->conf->shortcuts (); ?>

function redirect (url, new_tab) {
	if (url) {
		if (new_tab) {
			window.open (url);
		} else {
			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
		});
	}
}

function add_not_read (nb) {
	span_not_read = $("#categories li.all span.nb_not_read");
	
	html = span_not_read.html ();
	
	regex = /(\d+)/;
	nb_not_read = parseInt (regex.exec (html)[1]) + nb;
	
	span_not_read.html (nb_not_read);
}

function mark_read (active) {
	if (active[0] === undefined) {
		return false;
	}
	
	url =  active.find ("a.read").attr ("href");
	if (url === undefined) {
		return false;
	}
	
	$.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");
			add_not_read (-1);
		} else {
			active.addClass ("not_read");
			active.find ("a.read").html ("J'ai fini de lire l'article");
			add_not_read (1);
		}
	});
}

function mark_favorite (active) {
	if (active[0] === undefined) {
		return false;
	}

	url =  active.find ("a.bookmark").attr ("href");
	if (url === undefined) {
		return false;
	}
	
	$.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;
	});
	
	$(".post.flux .content a").click (function () {
		url = $(this).attr ("href");
		redirect (url, true);
		return false;
	});

	// Touches de manipulation
	shortcut.add("<?php echo $s['mark_read']; ?>", function () {
		// on marque comme lu ou non lu
		active = $(".post.flux.active");
		mark_read (active);
	});
	shortcut.add("shift+<?php echo $s['mark_read']; ?>", function () {
		// on marque tout comme lu
		url = $("#top a.read_all").attr ("href");
		redirect (url, false);
	});
	shortcut.add("<?php echo $s['mark_favorite']; ?>", function () {
		// on marque comme favori ou non favori
		active = $(".post.flux.active");
		mark_favorite (active);
	});
	
	// Touches de navigation
	shortcut.add("<?php echo $s['prev_entry']; ?>", 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 if (new_active[0] === undefined) {
			slide (last_active, old_active);
		}
	});
	shortcut.add("shift+<?php echo $s['prev_entry']; ?>", function () {
		old_active = $(".post.flux.active");
		first = $(".post.flux:first");
		
		if (first[0] instanceof HTMLDivElement) {
			slide (first, old_active);
		}
	});
	shortcut.add("<?php echo $s['next_entry']; ?>", 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 if (new_active[0] === undefined) {
			slide (first_active, old_active);
		}
	});
	shortcut.add("shift+<?php echo $s['next_entry']; ?>", function () {
		old_active = $(".post.flux.active");
		last = $(".post.flux:last");
		
		if (last[0] instanceof HTMLDivElement) {
			slide (last, old_active);
		}
	});
	shortcut.add("<?php echo $s['next_page']; ?>", function () {
		url = $(".pager-next a").attr ("href");
		redirect (url, false);
	});
	shortcut.add("shift+<?php echo $s['next_page']; ?>", function () {
		url = $(".pager-last a").attr ("href");
		redirect (url, false);
	});
	shortcut.add("<?php echo $s['prev_page']; ?>", function () {
		url = $(".pager-previous a").attr ("href");
		redirect (url, false);
	});
	shortcut.add("shift+<?php echo $s['prev_page']; ?>", function () {
		url = $(".pager-first a").attr ("href");
		redirect (url, false);
	});
	shortcut.add("<?php echo $s['go_website']; ?>", function () {
		url = $(".post.flux.active h1.title a").attr ("href");
		
		redirect (url, true);
	});
});