Browse Source

nombre de non lus est màj directement en js

Marien Fressinaud 13 years ago
parent
commit
b5c39ef5ef
3 changed files with 36 additions and 2 deletions
  1. 1 1
      app/layout/aside.phtml
  2. 1 1
      app/models/RSSConfiguration.php
  3. 34 0
      app/views/javascript/main.phtml

+ 1 - 1
app/layout/aside.phtml

@@ -7,7 +7,7 @@
 	<ul id="menu">
 		<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
 			<a href="<?php echo Url::display (array ()); ?>">
-				Flux RSS <?php if ($this->nb_not_read > 0) { ?><span>(<?php echo $this->nb_not_read; ?> non lu<?php echo $this->nb_not_read > 1 ? 's' : ''; ?>)</span><?php } ?>
+				Flux RSS <span class="nb_not_read"><?php if ($this->nb_not_read > 0) { ?>(<?php echo $this->nb_not_read; ?> non lu<?php echo $this->nb_not_read > 1 ? 's' : ''; ?>)<?php } ?></span>
 			</a>
 			
 			<?php if (isset ($this->cat_aside)) { ?>

+ 1 - 1
app/models/RSSConfiguration.php

@@ -100,7 +100,7 @@ class RSSConfigurationDAO extends Model_array {
 	public $shortcuts = array (
 		'mark_read' => 'r',
 		'mark_favorite' => 'f',
-		'go_website' => 'enter',
+		'go_website' => 'space',
 		'next_entry' => 'page_down',
 		'prev_entry' => 'page_up',
 		'next_page' => 'right',

+ 34 - 0
app/views/javascript/main.phtml

@@ -34,6 +34,31 @@ function slide (new_active, old_active) {
 	}
 }
 
+function add_not_read (nb) {
+	span_not_read = $("#main_aside #menu a span.nb_not_read");
+	
+	html = span_not_read.html ();
+	if (html == "" && nb > 0) {
+		nb_not_read = nb;
+	} else if (html != "") {
+		regex = /\((\d+) non lus?\)/;
+		nb_not_read = parseInt (regex.exec (html)[1]) + nb;
+	} else {
+		nb_not_read = 0;
+	}
+	
+	pluriel = "";
+	if (nb_not_read > 1) {
+		pluriel = "s";
+	}
+	
+	if (nb_not_read > 0) {
+		span_not_read.html ("(" + nb_not_read + " non lu" + pluriel + ")");
+	} else {
+		span_not_read.html ("");
+	}
+}
+
 function mark_read (active) {
 	if (active[0] === undefined) {
 		return false;
@@ -52,9 +77,11 @@ function mark_read (active) {
 		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);
 		}
 	});
 }
@@ -104,6 +131,7 @@ $(document).ready (function () {
 		}
 	});
 	
+	
 	$(".post.flux a.read").click (function () {
 		active = $(this).parents (".post.flux");
 		mark_read (active);
@@ -116,6 +144,12 @@ $(document).ready (function () {
 	
 		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 () {