Skip to content

Commit 830ec11

Browse files
committed
corrections sur le scroll infini
2 parents 94cd4ae + ee4ce84 commit 830ec11

File tree

2 files changed

+115
-48
lines changed

2 files changed

+115
-48
lines changed

action.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,24 +395,52 @@
395395
break;
396396

397397
case 'readContent':
398+
if($myUser==false) {
399+
$response_array['status'] = 'noconnect';
400+
$response_array['texte'] = 'Vous devez vous connecter pour cette action.';
401+
header('Content-type: application/json');
402+
echo json_encode($response_array);
403+
exit();
404+
}
398405
if(isset($_['id'])){
399406
$event = $eventManager->load(array('id'=>$_['id']));
400-
if($myUser!=false) $eventManager->change(array('unread'=>'0'),array('id'=>$_['id']));
407+
$eventManager->change(array('unread'=>'0'),array('id'=>$_['id']));
401408
}
402409
break;
403410

404411
case 'unreadContent':
405-
$event = $eventManager->load(array('id'=>$_['id']));
406-
if($myUser!=false) $eventManager->change(array('unread'=>'1'),array('id'=>$_['id']));
412+
if($myUser==false) {
413+
$response_array['status'] = 'noconnect';
414+
$response_array['texte'] = 'Vous devez vous connecter pour cette action.';
415+
header('Content-type: application/json');
416+
echo json_encode($response_array);
417+
exit();
418+
}
419+
if(isset($_['id'])){
420+
$event = $eventManager->load(array('id'=>$_['id']));
421+
$eventManager->change(array('unread'=>'1'),array('id'=>$_['id']));
422+
}
407423
break;
408424

409425
case 'addFavorite':
410-
if($myUser==false) exit('Vous devez vous connecter pour cette action.');
426+
if($myUser==false) {
427+
$response_array['status'] = 'noconnect';
428+
$response_array['texte'] = 'Vous devez vous connecter pour cette action.';
429+
header('Content-type: application/json');
430+
echo json_encode($response_array);
431+
exit();
432+
}
411433
$eventManager->change(array('favorite'=>'1'),array('id'=>$_['id']));
412434
break;
413435

414436
case 'removeFavorite':
415-
if($myUser==false) exit('Vous devez vous connecter pour cette action.');
437+
if($myUser==false) {
438+
$response_array['status'] = 'noconnect';
439+
$response_array['texte'] = 'Vous devez vous connecter pour cette action.';
440+
header('Content-type: application/json');
441+
echo json_encode($response_array);
442+
exit();
443+
}
416444
$eventManager->change(array('favorite'=>'0'),array('id'=>$_['id']));
417445
break;
418446

templates/marigolds/js/script.js

Lines changed: 82 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,38 @@ function toggleFolder(element,folder){
299299
}
300300

301301
function addFavorite(element,id){
302-
$(element).attr('onclick','removeFavorite(this,'+id+');').html('Défavoriser');
302+
var activeScreen = $('#pageTop').html();
303303
$.ajax({
304304
url: "./action.php?action=addFavorite",
305-
data:{id:id}
305+
data:{id:id},
306+
success:function(msg){
307+
if(msg.status == 'noconnect') {
308+
alert(msg.texte)
309+
} else {
310+
if( console && console.log && msg!="" ) console.log(msg);
311+
$(element).attr('onclick','removeFavorite(this,'+id+');').html('Défavoriser');
312+
// on compte combien d'article ont été remis en favoris sur la pages favoris (scroll infini)
313+
if (activeScreen=='favorites') $(window).data('nblus', $(window).data('nblus')-1);
314+
}
315+
}
306316
});
307317
}
308318

309319
function removeFavorite(element,id){
310-
$(element).attr('onclick','addFavorite(this,'+id+');').html('Favoriser');
320+
var activeScreen = $('#pageTop').html();
311321
$.ajax({
312322
url: "./action.php?action=removeFavorite",
313-
data:{id:id}
323+
data:{id:id},
324+
success:function(msg){
325+
if(msg.status == 'noconnect') {
326+
alert(msg.texte)
327+
} else {
328+
if( console && console.log && msg!="" ) console.log(msg);
329+
$(element).attr('onclick','addFavorite(this,'+id+');').html('Favoriser');
330+
// on compte combien d'article ont été remis en favoris sur la pages favoris (scroll infini)
331+
if (activeScreen=='favorites') $(window).data('nblus', $(window).data('nblus')+1);
332+
}
333+
}
314334
});
315335
}
316336

@@ -380,74 +400,93 @@ function changeFeedFolder(element,id){
380400

381401

382402
function readThis(element,id,from,callback){
383-
var hide = ($('#pageTop').html()==''?true:false);
403+
var activeScreen = $('#pageTop').html();
384404
var parent = $(element).parent().parent();
385405
var nextEvent = $('#'+id).next();
386406
//sur les éléments non lus
387407
if(!parent.hasClass('eventRead')){
388-
389-
if(hide){
390-
// cas de la page d'accueil
391-
parent.addClass('eventRead');
392-
parent.fadeOut(200,function(){
393-
if(callback){
394-
//alert(callback);
395-
callback();
396-
}else{
397-
targetThisEvent(nextEvent,true);
398-
}
399-
// on simule un scroll si tous les events sont cachés
400-
if($('article section:last').attr('style')=='display: none;') {
401-
$(window).scrollTop($(document).height());
402-
}
403-
});
404-
// on compte combien d'article ont été lus afin de les soustraires de la requête pour le scroll infini
405-
$(window).data('nblus', $(window).data('nblus')+1);
406-
}else{
407-
// autres cas : favoris, selectedFolder, selectedFeed ...
408-
parent.addClass('eventRead');
409-
targetThisEvent(nextEvent,true);
410-
}
411-
412408
$.ajax({
413409
url: "./action.php?action=readContent",
414410
data:{id:id},
415411
success:function(msg){
416-
if(msg!="") alert('Erreur de lecture : '+msg);
412+
if(msg.status == 'noconnect') {
413+
alert(msg.texte)
414+
} else {
415+
if( console && console.log && msg!="" ) console.log(msg);
416+
switch (activeScreen){
417+
case '':
418+
// cas de la page d'accueil
419+
parent.addClass('eventRead');
420+
parent.fadeOut(200,function(){
421+
if(callback){
422+
callback();
423+
}else{
424+
targetThisEvent(nextEvent,true);
425+
}
426+
// on simule un scroll si tous les events sont cachés
427+
if($('article section:last').attr('style')=='display: none;') {
428+
$(window).scrollTop($(document).height());
429+
}
430+
});
431+
// on compte combien d'article ont été lus afin de les soustraires de la requête pour le scroll infini
432+
$(window).data('nblus', $(window).data('nblus')+1);
433+
break;
434+
case 'selectedFolder':
435+
parent.addClass('eventRead');
436+
targetThisEvent(nextEvent,true);
437+
// on compte combien d'article ont été lus afin de les soustraires de la requête pour le scroll infini
438+
$(window).data('nblus', $(window).data('nblus')+1);
439+
break;
440+
default:
441+
// autres cas : favoris, selectedFeed ...
442+
parent.addClass('eventRead');
443+
targetThisEvent(nextEvent,true);
444+
break;
445+
}
446+
}
417447
}
418448
});
419449
}else{ // sur les éléments lus
420450
// si ce n'est pas un clic sur le titre de l'event
421451
if(from!='title'){
422-
423-
parent.removeClass('eventRead');
424452
$.ajax({
425-
url: "./action.php?action=unreadContent",
426-
data:{id:id},
427-
success:function(msg){
428-
if(msg!="") alert('Erreur de lecture : '+msg);
429-
}
453+
url: "./action.php?action=unreadContent",
454+
data:{id:id},
455+
success:function(msg){
456+
if(msg.status == 'noconnect') {
457+
alert(msg.texte)
458+
} else {
459+
if( console && console.log && msg!="" ) console.log(msg);
460+
Parent.removeClass('eventRead');
461+
// on compte combien d'article ont été remis à non lus
462+
if ( (activeScreen=='') || (activeScreen=='selectedFolder') ) $(window).data('nblus', $(window).data('nblus')-1);
463+
}
464+
}
430465
});
431466
}
432467
}
433468

434469
}
435470

436471
function unReadThis(element,id,from){
437-
var hide = ($('#pageTop').html()==''?true:false);
472+
var activeScreen = $('#pageTop').html();
438473
var parent = $(element).parent().parent();
439474
if(parent.hasClass('eventRead')){
440475
if(from!='title'){
441-
parent.removeClass('eventRead');
442476
$.ajax({
443477
url: "./action.php?action=unreadContent",
444478
data:{id:id},
445479
success:function(msg){
446-
if(msg!="") alert('Erreur de lecture : '+msg);
447-
}
480+
if(msg.status == 'noconnect') {
481+
alert(msg.texte)
482+
} else {
483+
if( console && console.log && msg!="" ) console.log(msg);
484+
parent.removeClass('eventRead');
485+
// on compte combien d'article ont été remis à non lus
486+
if ( (activeScreen=='') || (activeScreen=='selectedFolder') ) $(window).data('nblus', $(window).data('nblus')-1);
487+
}
488+
}
448489
});
449-
// on compte combien d'article ont été remis à non lus (uniquement pour la page d'accueil)
450-
if (hide) $(window).data('nblus', $(window).data('nblus')-1);
451490
}
452491
}
453492

0 commit comments

Comments
 (0)