Kaynağa Gözat

ajout des touches de raccourcis et de tout le javascript

Marien Fressinaud 13 yıl önce
ebeveyn
işleme
a928ebf1d0

+ 4 - 0
app/App_FrontController.php

@@ -13,6 +13,10 @@ class App_FrontController extends FrontController {
 		Session::init ();
 		
 		View::prependStyle (Url::display ('/theme/base.css'));
+		View::appendScript (Url::display ('/scripts/jquery.js'));
+		View::appendScript (Url::display ('/scripts/smoothscroll.js'));
+		View::appendScript (Url::display ('/scripts/shortcut.js'));
+		View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
 		View::_param ('conf', Session::param ('conf', new RSSConfiguration ()));
 	}
 	

+ 13 - 4
app/controllers/entryController.php

@@ -1,6 +1,19 @@
 <?php
 
 class entryController extends ActionController {
+	public function firstAction () {
+		$ajax = Request::param ('ajax');
+		if ($ajax) {
+			$this->view->_useLayout (false);
+		}
+	}
+	public function lastAction () {
+		$ajax = Request::param ('ajax');
+		if (!$ajax) {
+			Request::forward (array (), true);
+		}
+	}
+
 	public function readAction () {
 		$id = Request::param ('id');
 		$is_read = Request::param ('is_read');
@@ -26,8 +39,6 @@ class entryController extends ActionController {
 			
 			$entryDAO->updateEntry ($entry->id (), $values);
 		}
-		
-		Request::forward (array (), true);
 	}
 	
 	public function bookmarkAction () {
@@ -52,7 +63,5 @@ class entryController extends ActionController {
 				$entryDAO->updateEntry ($entry->id (), $values);
 			}
 		}
-		
-		Request::forward (array (), true);
 	}
 }

+ 11 - 0
app/controllers/javascriptController.php

@@ -0,0 +1,11 @@
+<?php
+
+class javascriptController extends ActionController {
+	public function firstAction () {
+		$this->view->_useLayout (false);
+	}
+	
+	public function mainAction () {
+	
+	}
+}

+ 3 - 2
app/layout/layout.phtml

@@ -2,8 +2,9 @@
 <html lang="fr">
 	<head>
 		<meta charset="utf-8">
-		<?php echo self::headTitle(); ?>
-		<?php echo self::headStyle(); ?>
+		<?php echo self::headTitle (); ?>
+		<?php echo self::headStyle (); ?>
+		<?php echo self::headScript (); ?>
 	</head>
 	<body>
 <div id="global">

+ 3 - 3
app/views/configure/display.phtml

@@ -22,11 +22,11 @@
 		
 		<label>Afficher les articles dépliés par défaut</label>
 		<div class="radio_group">
-			<input type="radio" name="display_posts" id="radio_yes" value="yes"<?php echo $this->conf->displayPosts () ? ' checked="checked"' : ''; ?> />
+			<input type="radio" name="display_posts" id="radio_yes" value="yes"<?php echo $this->conf->displayPosts () == 'yes' ? ' checked="checked"' : ''; ?> />
 			<label for="radio_yes">Oui</label>
 			<br />
-			<input type="radio" name="display_posts" id="radio_no" value="no"<?php echo !$this->conf->displayPosts () ? ' checked="checked"' : ''; ?> />
-			<label for="radio_no">Non</label>
+			<input type="radio" name="display_posts" id="radio_no" value="no"<?php echo $this->conf->displayPosts () == 'no' ? ' checked="checked"' : ''; ?> />
+			<label for="radio_no">Non<noscript> - <strong>nécessite que javascript soit activé</strong></noscript></label>
 		</div>
 		
 		<input type="submit" value="Valider" />

+ 10 - 8
app/views/index/index.phtml

@@ -1,3 +1,5 @@
+<?php $items = $this->entryPaginator->items (); ?>
+<?php if (!empty ($items)) { ?>
 <div id="top">
 	<a class="read_all" href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'read', 'params' => array ('is_read' => 1))); ?>">Tout marquer comme lu</a><!--
 	<?php if (Session::param ('mode', 'all') == 'not_read') { ?>
@@ -8,8 +10,6 @@
 </div>
 
 <div id="stream">
-<?php $items = $this->entryPaginator->items (); ?>
-<?php if (!empty ($items)) { ?>
 	<?php $this->entryPaginator->render ('pagination.phtml', 'page'); ?>
 	
 	<?php foreach ($items as $item) { ?>
@@ -27,23 +27,25 @@
 		
 		<div class="after">
 			<?php if (!$item->isRead ()) { ?>
-			<a href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'read', 'params' => array ('id' => $item->id (), 'is_read' => 1))); ?>">J'ai fini de lire l'article</a><!--
+			<a class="read" href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'read', 'params' => array ('id' => $item->id (), 'is_read' => 1))); ?>">J'ai fini de lire l'article</a><!--
 			<?php } else { ?>
-			<a href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'read', 'params' => array ('id' => $item->id (), 'is_read' => 0))); ?>">Marquer comme non lu</a><!--
+			<a class="read" href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'read', 'params' => array ('id' => $item->id (), 'is_read' => 0))); ?>">Marquer comme non lu</a><!--
 			<?php } ?>
 			
 			<?php if (!$item->isFavorite ()) { ?>
-			--><a href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'bookmark', 'params' => array ('id' => $item->id (), 'is_favorite' => 1))); ?>">Ajouter l'article à mes favoris</a>
+			--><a class="bookmark" href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'bookmark', 'params' => array ('id' => $item->id (), 'is_favorite' => 1))); ?>">Ajouter l'article à mes favoris</a>
 			<?php } else { ?>
-			--><a href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'bookmark', 'params' => array ('id' => $item->id (), 'is_favorite' => 0))); ?>">Retirer l'article de mes favoris</a>
+			--><a class="bookmark" href="<?php echo Url::display (array ('c' => 'entry', 'a' => 'bookmark', 'params' => array ('id' => $item->id (), 'is_favorite' => 0))); ?>">Retirer l'article de mes favoris</a>
 			<?php } ?>
 		</div>
 	</div>
 	<?php } ?>
 	
 	<?php $this->entryPaginator->render ('pagination.phtml', 'page'); ?>
+</div>
 <?php } else { ?>
-	<div class="post flux">
+<div class="table">
+	<div class="nothing">
 		<p>
 			Il n'y a aucun flux à afficher.
 		<?php if (Session::param ('mode', 'all') == 'not_read') { ?>
@@ -51,5 +53,5 @@
 		<?php }	?>
 		</p>
 	</div>
-<?php } ?>
 </div>
+<?php } ?>

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

@@ -0,0 +1,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);
+		}
+	});
+});

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
public/scripts/jquery.js


+ 223 - 0
public/scripts/shortcut.js

@@ -0,0 +1,223 @@
+/**
+ * http://www.openjs.com/scripts/events/keyboard_shortcuts/
+ * Version : 2.01.B
+ * By Binny V A
+ * License : BSD
+ */
+shortcut = {
+	'all_shortcuts':{},//All the shortcuts are stored in this array
+	'add': function(shortcut_combination,callback,opt) {
+		//Provide a set of default options
+		var default_options = {
+			'type':'keydown',
+			'propagate':false,
+			'disable_in_input':false,
+			'target':document,
+			'keycode':false
+		}
+		if(!opt) opt = default_options;
+		else {
+			for(var dfo in default_options) {
+				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
+			}
+		}
+
+		var ele = opt.target;
+		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
+		var ths = this;
+		shortcut_combination = shortcut_combination.toLowerCase();
+
+		//The function to be called at keypress
+		var func = function(e) {
+			e = e || window.event;
+			
+			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
+				var element;
+				if(e.target) element=e.target;
+				else if(e.srcElement) element=e.srcElement;
+				if(element.nodeType==3) element=element.parentNode;
+
+				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
+			}
+	
+			//Find Which key is pressed
+			if (e.keyCode) code = e.keyCode;
+			else if (e.which) code = e.which;
+			var character = String.fromCharCode(code).toLowerCase();
+			
+			if(code == 188) character=","; //If the user presses , when the type is onkeydown
+			if(code == 190) character="."; //If the user presses , when the type is onkeydown
+
+			var keys = shortcut_combination.split("+");
+			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
+			var kp = 0;
+			
+			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
+			var shift_nums = {
+				"`":"~",
+				"1":"!",
+				"2":"@",
+				"3":"#",
+				"4":"$",
+				"5":"%",
+				"6":"^",
+				"7":"&",
+				"8":"*",
+				"9":"(",
+				"0":")",
+				"-":"_",
+				"=":"+",
+				";":":",
+				"'":"\"",
+				",":"<",
+				".":">",
+				"/":"?",
+				"\\":"|"
+			}
+			//Special Keys - and their codes
+			var special_keys = {
+				'esc':27,
+				'escape':27,
+				'tab':9,
+				'space':32,
+				'return':13,
+				'enter':13,
+				'backspace':8,
+	
+				'scrolllock':145,
+				'scroll_lock':145,
+				'scroll':145,
+				'capslock':20,
+				'caps_lock':20,
+				'caps':20,
+				'numlock':144,
+				'num_lock':144,
+				'num':144,
+				
+				'pause':19,
+				'break':19,
+				
+				'insert':45,
+				'home':36,
+				'delete':46,
+				'end':35,
+				
+				'pageup':33,
+				'page_up':33,
+				'pu':33,
+	
+				'pagedown':34,
+				'page_down':34,
+				'pd':34,
+	
+				'left':37,
+				'up':38,
+				'right':39,
+				'down':40,
+	
+				'f1':112,
+				'f2':113,
+				'f3':114,
+				'f4':115,
+				'f5':116,
+				'f6':117,
+				'f7':118,
+				'f8':119,
+				'f9':120,
+				'f10':121,
+				'f11':122,
+				'f12':123
+			}
+	
+			var modifiers = { 
+				shift: { wanted:false, pressed:false},
+				ctrl : { wanted:false, pressed:false},
+				alt  : { wanted:false, pressed:false},
+				meta : { wanted:false, pressed:false}	//Meta is Mac specific
+			};
+                        
+			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
+			if(e.shiftKey)	modifiers.shift.pressed = true;
+			if(e.altKey)	modifiers.alt.pressed = true;
+			if(e.metaKey)   modifiers.meta.pressed = true;
+                        
+			for(var i=0; k=keys[i],i<keys.length; i++) {
+				//Modifiers
+				if(k == 'ctrl' || k == 'control') {
+					kp++;
+					modifiers.ctrl.wanted = true;
+
+				} else if(k == 'shift') {
+					kp++;
+					modifiers.shift.wanted = true;
+
+				} else if(k == 'alt') {
+					kp++;
+					modifiers.alt.wanted = true;
+				} else if(k == 'meta') {
+					kp++;
+					modifiers.meta.wanted = true;
+				} else if(k.length > 1) { //If it is a special key
+					if(special_keys[k] == code) kp++;
+					
+				} else if(opt['keycode']) {
+					if(opt['keycode'] == code) kp++;
+
+				} else { //The special keys did not match
+					if(character == k) kp++;
+					else {
+						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
+							character = shift_nums[character]; 
+							if(character == k) kp++;
+						}
+					}
+				}
+			}
+			
+			if(kp == keys.length && 
+						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
+						modifiers.shift.pressed == modifiers.shift.wanted &&
+						modifiers.alt.pressed == modifiers.alt.wanted &&
+						modifiers.meta.pressed == modifiers.meta.wanted) {
+				callback(e);
+	
+				if(!opt['propagate']) { //Stop the event
+					//e.cancelBubble is supported by IE - this will kill the bubbling process.
+					e.cancelBubble = true;
+					e.returnValue = false;
+	
+					//e.stopPropagation works in Firefox.
+					if (e.stopPropagation) {
+						e.stopPropagation();
+						e.preventDefault();
+					}
+					return false;
+				}
+			}
+		}
+		this.all_shortcuts[shortcut_combination] = {
+			'callback':func, 
+			'target':ele, 
+			'event': opt['type']
+		};
+		//Attach the function with the event
+		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
+		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
+		else ele['on'+opt['type']] = func;
+	},
+
+	//Remove the shortcut - just specify the shortcut and I will remove the binding
+	'remove':function(shortcut_combination) {
+		shortcut_combination = shortcut_combination.toLowerCase();
+		var binding = this.all_shortcuts[shortcut_combination];
+		delete(this.all_shortcuts[shortcut_combination])
+		if(!binding) return;
+		var type = binding['event'];
+		var ele = binding['target'];
+		var callback = binding['callback'];
+
+		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
+		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
+		else ele['on'+type] = false;
+	}
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 2 - 0
public/scripts/smoothscroll.js


+ 8 - 2
public/theme/base.css

@@ -33,7 +33,7 @@ a {
 		}
 
 /* LISTES */
-ul {
+ul, ol {
 	margin: 10px 0 10px 30px;
 	line-height: 190%;
 }
@@ -240,6 +240,10 @@ form {
 		background: #eee;
 		border-radius: 5px;
 		box-shadow: 0 1px 3px #aaa;
+		
+		-moz-transition: border-color .10s ease-out;
+		-webkit-transition: border-color .10s ease-out;
+		transition: border-color .10s ease-out;
 	}
 		.post.flux .before {
 			color: #666;
@@ -264,7 +268,6 @@ form {
 					border-radius: 0 0 5px 5px;
 					box-shadow: 0 1px 3px #aaa;
 				}
-		/* temporaire !!! */
 		.post.flux .content {
 			/*display: none;*/
 		}
@@ -299,6 +302,9 @@ form {
 			border-left: 5px solid #FFC300;
 			background: #FFF6DA;
 		}
+		.post.flux.active {
+			border-left: 5px solid #0062BE;
+		}
 
 /*** PAGINATION ***/
 .pagination {

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor