var g_oFemmezine = {};
if (window.addEvent) {
window.addEvent('load', function(){
g_oFemmezine = new Femmezine();
});
}
window.addEvent('domready', function() {
jsli.Transformation();
});
var Femmezine = new Class(
{
/*
* Constructeur
* On récupere l'URL consultée
*/
initialize:function()
{
this.oURI = new URI();
this.sCurrentURL = this.oURI.toString(); /* URL de la page*/
this.pendingUpdateForumDisplayListRequest = false; /* Pour ignorer les requetes en double*/
this.pendingUpdateCommentListRequest = false; /* pour ignorer les requetes en double pour les commentaires*/
this.nCurrentCommentPage = 1; /* Par défaut la page une de commentaires est affichée*/
this.startup();
this.sCommentContentID = 0;
this.nCurrentSlide = 0; /* Slide affiche par défaut*/
//debugger;
},
/*
* What are we going to do on the current page ?
*/
startup:function()
{
this.sDirectory =this.oURI.get('directory');
this.sFile = this.oURI.get('file');
this.sPage = this.sDirectory;
if(this.sFile)
{
this.sPage+=this.sFile;
}
switch(this.sPage)
{
case '/':
this.launchHomePageActions();
/*Pas de break*/
default:
this.launchDefaultActions();
}
},
/*
* Lance les traitements par défaut suite au chargement de la page
*/
launchDefaultActions:function()
{
/*if (typeof sForumID != 'undefined')
this.updateForumDisplayList();*/
/*Y'a t-il un slider ?*/
if($('slider_container'))
{
}
},
/*
* On ajoute Femmezine aux favoris
*/
addToFavourite:function()
{
var SITE_URL = 'http://www.femmezine.fr';
var SITE_FAV_TITLE = 'Femmezine, votre magazine feminin';
sUrl=SITE_URL;
sTitle=SITE_FAV_TITLE;
if (navigator.appName != 'Microsoft Internet Explorer')
window.sidebar.addPanel(sTitle,sUrl,sTitle);
else
window.external.AddFavorite(sUrl,sTitle);
return false;
},
/*
* Mise à jour du forum affiché
*/
updateForumDisplayList:function()
{
if(!this.pendingUpdateForumDisplayListRequest)
{
this.pendingUpdateForumDisplayListRequest = true;
var htmlRequest = new Request({
url: "/forum/getLastPostList/"+sForumID,
encoding:'UTF-8',
onComplete: this.onCompleteUpdateForumDisplayList.bind(this),
onFailure: this.onFailureUpdateForumDisplayList.bind(this)
}).send();
//Loader
var sLoader = '';
$('last_posts_container').innerHTML = sLoader + $('last_posts_container').innerHTML;
}
},
/*
* On a fini d'afficher la liste
*/
onCompleteUpdateForumDisplayList : function(responseHTML)
{
$('last_posts_container').innerHTML = responseHTML;
this.pendingUpdateForumDisplayListRequest = false;
},
/*
* En cas d'echec
*/
onFailureUpdateForumDisplayList : function(xhr)
{
$('last_posts_container').innerHTML = '
Impossible de mettre à jour la liste
';
this.pendingUpdateForumDisplayListRequest =false;
},
selectForum:function(sId)
{
sForumID = sId;
this.updateForumDisplayList();
},
launchHomePageActions:function()
{
$('manchette_elements').addEvent('mouseover',this.onManchetteOver.bind(this));
$('manchette_elements').addEvent('mouseout',this.onManchetteOut.bind(this));
/*On pre-charge les images*/
this.preloadManchettePics();
/*Le premier slide*/
this.nCurrentSlide = 0;
/*On change d'image toutes les 5 secondes*/
this.nIdManchetteTimer = this.showNextNews.periodical(5000,this);
this.buildManchetteSlider();
},
onManchetteOver:function()
{
clearInterval(this.nIdManchetteTimer);
this.nIdManchetteTimer=0;
},
onManchetteOut:function()
{
if(this.nIdManchetteTimer==0)
this.nIdManchetteTimer = this.showNextNews.periodical(5000,this);
},
/*
* Affiche la news qui a cet index
*/
showThisNews:function(nIndex)
{
clearInterval(this.nIdManchetteTimer);
var nOldSlide = this.nCurrentSlide;
this.nCurrentSlide = nIndex;
var oOldSlide = $('manchette_'+g_oManchetteData[nOldSlide].id);
var oNewSlide = $('manchette_'+g_oManchetteData[this.nCurrentSlide].id);
this.swapManchettePics(oOldSlide,oNewSlide);
},
/*
* Affiche le prochain slide
*/
showNextNews:function()
{
var nOldSlide = this.nCurrentSlide;
this.nCurrentSlide++;
if(this.nCurrentSlide==g_oManchetteData.length)
{
this.nCurrentSlide = 0;
}
//console.log('manchette_'+g_oManchetteData[nOldSlide].id);
var oOldSlide = $('manchette_'+g_oManchetteData[nOldSlide].id);
var oNewSlide = $('manchette_'+g_oManchetteData[this.nCurrentSlide].id);
this.swapManchettePics(oOldSlide,oNewSlide);
},
/*
* Echange deux elements via un fading
*/
swapManchettePics:function(oOld,oNew)
{
if(oOld)
{
oOld.fade('out');
}
if(oNew)
{
oNew.fade('in');
}
},
/*
* Precharge les images
*/
preloadManchettePics:function()
{
if(typeof g_oManchetteData!='undefined')
{
this.aManchettePicsToLoad = new Array();
g_oManchetteData.each(function(oArticle)
{
this.aManchettePicsToLoad.push('/files/images/home/manchette/'+oArticle.img);
}
,this);
this.aManchettePics = new Asset.images(this.aManchettePicsToLoad,
{
onComplete: this.onManchettePicsLoaded.bind(this),
onProgress: this.onManchettePicsProgress.bind(this),
onError: this.onManchettePicsError.bind(this)
}
);
}
},
onManchettePicsError:function(counter,index)
{
/*
* On défini le container des images et du bandeau
*/
var oSlideContainer = new Element('div', {
'opacity' : 0,
'id' :'manchette_'+g_oManchetteData[counter].id,
'styles' : {
'position' : 'absolute',
'top' : '0px',
'background-color':'#FFF',
'width':'656px',
'height':'348px',
'border':'solid 1px #CCC'
}
});
oSlideContainer.innerHTML='Image non disponible
';
var oLinkContainer = new Element('a',
{
href:g_oManchetteData[counter].href
}
);
var bandeau='';
oSlideContainer.appendChild(oLinkContainer);
$('manchette_elements').appendChild(oSlideContainer);
oSlideContainer.innerHTML+=bandeau;
},
/*
* A chaque image chargée, on l'ajoute au DOM
*/
onManchettePicsProgress:function(counter,index)
{
/*
* On défini le container des images et du bandeau
*/
var oSlideContainer = new Element('div', {
'opacity' : 0,
'id' :'manchette_'+g_oManchetteData[index].id,
'styles' : {
'position' : 'absolute',
'top' : '0px',
'visibility':'hidden'
}
});
var oLinkContainer = new Element('a',
{
href:g_oManchetteData[index].href
}
);
var bandeau='';
var oPic = this.aManchettePics[index];
oPic.id=g_oManchetteData[index].id;
oLinkContainer.appendChild(oPic);
oSlideContainer.appendChild(oLinkContainer);
$('manchette_elements').appendChild(oSlideContainer);
oSlideContainer.innerHTML+=bandeau;
},
/*
* Toutes les images chargées
*/
onManchettePicsLoaded:function()
{
$$('.manchette_articles_list li').each(function(item,index)
{
item.addEvent('mouseover',this.showThisNews.bind(this,index));
},this);
},
buildManchetteSlider:function()
{
this.oManchetteSlider = new Fx.Scroll($('manchette_slider'));
},
onManchettePreviousButtonClick:function()
{
this.oManchetteSlider.toLeft();
},
onManchetteNextButtonClick:function()
{
var aList = $$('#manchette_slider ul li');
var oLastElem = aList[aList.length-1];
this.oManchetteSlider.toElementEdge(oLastElem);
},
/*
* GESTION DES COMMENTAIRES
* Demande au serveur les pages de commentaires
* Gestion de la pagination coté client avec les champs cachés
*/
showNextCommentPage:function(sArticleID, type)
{
var type = (typeof type === "undefined") ? "article" : type;
if(!this.pendingUpdateCommentListRequest)
{
this.getCommentCurrentPage();
this.pendingUpdateCommentListRequest = true;
this.nCurrentCommentPage++;
this.updateCommentCurrentPage();
//$$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')
var suffix = "";
if(type == "code"){
suffix = "_coupon_"+sArticleID;
this.sCommentContentID = sArticleID;
}
$$('#comment_block'+suffix+' .btn_comment_previous_page')[0].style.display='block';
this.updateCommentPage(sArticleID, type);
}
},
updateCommentPage:function(sArticleID, type)
{
var prefix = "";
if(type == "code"){
prefix = "coupon_"+sArticleID+"_";
}
var htmlRequest = new Request({
url: "/comment/getCommentsByPage/"+sArticleID+'/'+this.nCurrentCommentPage+"/"+type,
encoding:'ISO-8859-1',
onComplete: this.onCompleteUpdateCommentDisplayList.bind(this),
onFailure: this.onFailureUpdateCommentDisplayList.bind(this)
}).send();
//Loader
var sLoader = '';
$(prefix+'comment_container').innerHTML += sLoader;
},
showPreviousCommentPage:function(sArticleID, type)
{
var type = (typeof type === "undefined") ? "article" : type;
var suffix = "";
if(type == "code"){
suffix = "_coupon_"+sArticleID;
this.sCommentContentID = sArticleID;
}
if(!this.pendingUpdateCommentListRequest)
{
this.getCommentCurrentPage();
this.pendingUpdateCommentListRequest = true;
this.nCurrentCommentPage--;
this.updateCommentCurrentPage();
if(this.nCurrentCommentPage==1)
$$('#comment_block'+suffix+' .btn_comment_previous_page')[0].style.display='none';
this.updateCommentPage(sArticleID, type);
}
},
onCompleteUpdateCommentDisplayList:function(responseHTML)
{
var suffix = "";
var prefix = "";
if(this.sCommentContentID){
suffix = "_coupon_"+this.sCommentContentID;
prefix = "coupon_"+this.sCommentContentID+"_";
}
$(prefix+'comment_container').innerHTML = responseHTML;
var aChildren = $$('#'+prefix+'comment_container .item');
//console.log(aChildren.length);
if(aChildren.lengthImpossible de mettre à jour la liste';
this.pendingUpdateCommentListRequest =false;
},
getCommentCurrentPage:function()
{
this.nCurrentCommentPage = $('current_comment_page').value;
return this.nCurrentCommentPage;
},
updateCommentCurrentPage:function()
{
$('current_comment_page').value=this.nCurrentCommentPage;
},
/*
* On verifie le formulaire de commentaires
*/
checkCommentForm:function(sContent_id)
{
var sMsg = '';
var prefix = "";
if(sContent_id)
prefix = sContent_id+'_';
if($(prefix+'comment_message').value=='')
{
sMsg+='Vous devez saisir un commentaire\n';
$(prefix+'comment_message').style.border='solid 1px red';
}
else
{
$(prefix+'comment_message').style.border='solid 1px black';
}
if(sMsg=='')
{
$(prefix+'comment_message').style.display='none';
return true;
}
else
{
alert(sMsg);
return false;
}
},
sendCommentForm:function(sContent_id)
{
var prefix = "";
if(sContent_id){
this.sCommentContentID = sContent_id;
prefix = sContent_id+'_';
}
else{
}
if(this.checkCommentForm(sContent_id))
{
var code_id = 0;
var msg = encodeURIComponent($(prefix+'comment_message').value);
var pseudo = encodeURIComponent($(prefix+'pseudo').value);
var uid = encodeURIComponent($(prefix+'uid').value);
var article_id = encodeURIComponent($('article_id').value);
if(sContent_id){
code_id = encodeURIComponent($('code_id').value);
}
var url = encodeURIComponent($('url').value);
var parent_cat = encodeURIComponent($('parent_cat').value);
var category_name = encodeURIComponent($('category_name').value);
var rnd = Math.random()*1000000;
var myRequest = new Request({url: '/comment/submitComment/'+rnd,
onComplete: this.onCompleteSubmitComment.bind(this),
onFailure: this.onFailureSubmitComment.bind(this)});
var sData = 'message='+msg+'&pseudo='+pseudo+'&uid='+uid+'&article_id='+article_id+'&code_id='+code_id+'&url='+url+'&parent_cat='+parent_cat+'&category_name='+category_name;
myRequest.send({
method:'post',
data:sData
});
}
},
onCompleteSubmitComment:function(responseHTML)
{
if(this.sCommentContentID){
this.onCompleteSubmitCommentCode(responseHTML);
return false;
}
console.log(responseHTML);
var aChildren = $$('#comment_container .item');
var nOldNumberItem = aChildren.length;
$('comment_container').innerHTML = responseHTML;
var nNewNumberItem = aChildren.length;
$('comment_submit_button').style.display='block';
$('comment_message').value = '';
$('comment_message').style.display = 'block';
//Si l'iframe est presente
if($('user_panel'))
$('user_panel').src = "/sso/showUserPanel/"+Math.random();
document.location = '#comment_list_bottom';
//on affiche le block -> soumis avec succes
$('comment_status').style.display = 'block';
$('comments_count').value++;
//on met a jour le label qui affiche le nombre de commentaires
$('label_comments_count').innerHTML = $('comments_count').value;
//$$('.btn_comment_next_page')[0].style.display='none';
var nCommentsCount = $('comments_count').value;
if((nCommentsCount%10)==1 && nCommentsCount>10)
{
$('last_page').value=parseInt($('last_page').value)+1;
}
this.nCurrentCommentPage = parseInt($('last_page').value);
this.updateCommentCurrentPage();
/*
* On met a jour les boutons PAGE PREC/SUIV
*/
//si on est sur la derniere page, on affiche precedent et on masque suivant
if(this.nCurrentCommentPage==$('last_page').value && nCommentsCount>10)
{
$$('.btn_comment_previous_page')[0].style.display='block';
$$('.btn_comment_next_page')[0].style.display='none';
}
/*Si c'est la premiere page*/
if(this.nCurrentCommentPage==1)
{
$$('.btn_comment_previous_page')[0].style.display='none';
if(nNewNumberItem<10)
{
$$('.btn_comment_next_page')[0].style.display='none';
}
if(nCommentsCount>10)
{
$$('.btn_comment_next_page')[0].style.display='block';
}
}
if(this.nCurrentCommentPage>1 && this.nCurrentCommentPage<$('last_page').value)
{
$$('.btn_comment_previous_page')[0].style.display='block';
$$('.btn_comment_next_page')[0].style.display='block';
}
},
onCompleteSubmitCommentCode:function(responseHTML){
var prefix = this.sCommentContentID+'_';
var suffix = "_"+this.sCommentContentID;
var aChildren = $$('#comment_container .item');
var nOldNumberItem = aChildren.length;
$(prefix+'comment_container').innerHTML = responseHTML;
var nNewNumberItem = aChildren.length;
$(prefix+'comment_submit_button').style.display='block';
$(prefix+'comment_message').value = '';
$(prefix+'comment_message').style.display = 'block';
//Si l'iframe est presente
if($('user_panel'))
$('user_panel').src = "/sso/showUserPanel/"+Math.random();
document.location = '#comment_list_bottom'+suffix;
//on affiche le block -> soumis avec succes
$(prefix+'comment_status').style.display = 'block';
$(prefix+'comments_count').value++;
//on met a jour le label qui affiche le nombre de commentaires
$(prefix+'label_comments_count').innerHTML = $(prefix+'comments_count').value;
//$$('.btn_comment_next_page')[0].style.display='none';
var nCommentsCount = $(prefix+'comments_count').value;
if((nCommentsCount%10)==1 && nCommentsCount>10)
{
$(prefix+'last_page').value=parseInt($(prefix+'last_page').value)+1;
}
this.nCurrentCommentPage = parseInt($(prefix+'last_page').value);
this.updateCommentCurrentPage();
/*
* On met a jour les boutons PAGE PREC/SUIV
*/
//si on est sur la derniere page, on affiche precedent et on masque suivant
if(this.nCurrentCommentPage==$(prefix+'last_page').value && nCommentsCount>10)
{
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')[0].style.display='block';
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_next_page')[0].style.display='none';
}
/*Si c'est la premiere page*/
if(this.nCurrentCommentPage==1)
{
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')[0].style.display='none';
if(nNewNumberItem<10)
{
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_next_page')[0].style.display='none';
}
if(nCommentsCount>10)
{
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_next_page')[0].style.display='block';
}
}
if(this.nCurrentCommentPage>1 && this.nCurrentCommentPage<$(prefix+'last_page').value)
{
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')[0].style.display='block';
$$('#comment_block_'+this.sCommentContentID+' .btn_comment_next_page')[0].style.display='block';
}
},
onFailureSubmitComment:function()
{
alert('Votre message n\'a pas pu aboutir à destination');
$('comment_submit_button').style.display='block';
}
}
);