var g_oCDR2 = {}; if (window.addEvent) { window.addEvent('load', function(){ g_oCDR2 = new CDR2(); }); } var CDR2 = 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.bCeraboxLoaded = false; this.bCeraboxJSFilesLoaded = false; this.bCeraboxCSSFilesLoaded = false; this.bPendingCeraboxLoading = false; this.nVirtualCursorPosition = 0; /*Position de la selection*/ this.nPreviousVirtualCursorPosition = 0; this.nVendorResultsItems =0; this.nCouponResultsItems =0; this.win_vendor = false; this.win_current = window; this.sCommentContentID = '';/*Current form container for multiple comments block on a page*/ this.startup(); //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() { window.addEvent('resize',this.onWindowResize.bind(this)); this.buildCerabox(); this.registerShowCodeEvent(); this.registerShowVendorWindowEvent(); }, onWindowResize:function() { //this.updatePositionSearchBoxLR(); }, /** * Cerabox */ buildCerabox:function() { if(!this.bCeraboxLoaded && !this.bPendingCeraboxLoading) { this.bPendingCeraboxLoading = true; this.loadCeraboxScripts(); } else { $$('.need_help_btn').cerabox( { 'width':800, 'height':600, 'group':false }); } }, loadCeraboxScripts:function() { var myScript = Asset.javascript('/Js/cerabox.min.js', { onLoad: this.onCeraboxJSFilesLoaded.bind(this) }); var myCSS = Asset.css('/Css/cerabox.css',{ onLoad: this.onCeraboxCSSFilesLoaded.bind(this) }); }, onCeraboxJSFilesLoaded:function() { this.bCeraboxJSFilesLoaded = true; if(this.bCeraboxJSFilesLoaded && this.bCeraboxCSSFilesLoaded) { this.bCeraboxLoaded = true; this.bPendingCeraboxLoading = false; this.buildCerabox(); } }, onCeraboxCSSFilesLoaded:function() { this.bCeraboxCSSFilesLoaded = true; if(this.bCeraboxJSFilesLoaded && this.bCeraboxCSSFilesLoaded) { this.bCeraboxLoaded = true; this.bPendingCeraboxLoading = false; this.buildCerabox(); } }, onBtnGetCodeClick:function(event) { var oBtn = event.target; var sBtnGetCodeID = oBtn.id; var sHiddenCodeID = sBtnGetCodeID.replace('btn_get_code_','hidden_code_'); var sHiddenExplanationID = sBtnGetCodeID.replace('btn_get_code_','coupon_code_explanation_'); var sLinkID = sBtnGetCodeID.replace('btn_get_code_','aff_link_'); $$('#'+sBtnGetCodeID)[0].style.display='none'; $$('#'+sHiddenCodeID+' .label_display_code')[0].style.display='none'; $$('#'+sHiddenCodeID)[0].className='hidden_code_container revealed'; $$('#'+sHiddenCodeID+' .coupon_code')[0].style.display='block'; $$('#'+sHiddenExplanationID)[0].style.display='block'; var oElemAffLink = $(sLinkID); this.openVendorWindow(oElemAffLink.href); }, openVendorWindow:function(sURL) { var window_size = window.getSize(); var window_position = {x:window.screenLeft||window.screenX,y:window.screenTop||window.screenY} //var optionString = "top="+Math.round((window_size.y/2))+",left="+window_position.x+",width="+window_size.x+",height="+Math.round((window_size.y/2)); //var optionString = "top="+Math.round((window_size.y/2))+",left="+window_position.x+",width="+window_size.x+",height="+Math.round(window_size.y*2/3)+",menubar=yes,toolbar=no,location=yes,status=yes,resizable=yes,scrollbars=yes"; var optionString = "top="+Math.round(window_size.y)+",left="+window_position.x+",width="+window_size.x+",height="+Math.round(window_size.y*2/3)+",menubar=yes,toolbar=no,location=yes,status=yes,resizable=yes,scrollbars=yes"; this.win_vendor = window.open(sURL,'Vendor_window',optionString); g_oCDR2.win_current.focus(); }, registerShowCodeEvent:function() { var aButtons = $$('.btn_get_code'); Array.each(aButtons, function(btn,index) { btn.addEvent('click',function(e){g_oCDR2.onBtnGetCodeClick.call(g_oCDR2,e);}); }, this ); }, registerShowVendorWindowEvent:function() { var aButtons = $$('.btn_show_vendor'); Array.each(aButtons, function(btn,index) { btn.addEvent('click',function(e) { g_oCDR2.onBtnShowVendorWindowClick.call(g_oCDR2,e); }); }, this ); }, onBtnShowVendorWindowClick:function(event) { if(!this.win_vendor.closed) this.win_vendor.focus(); else { var oBtn = event.target; var sBtnShowVendorWindowID = oBtn.id; var sLinkID = sBtnShowVendorWindowID.replace('btn_show_vendor_','aff_link_'); var oElemAffLink = $(sLinkID); this.openVendorWindow(oElemAffLink.href); this.win_vendor.focus(); } }, /* * GESTION DES COMMENTAIRES * Demande au serveur les pages de commentaires * Gestion de la pagination coté client avec les champs cachés */ showNextCommentPage:function(sContentID) { this.sCommentContentID = sContentID; if(!this.pendingUpdateCommentListRequest) { this.getCommentCurrentPage(); this.pendingUpdateCommentListRequest = true; this.nCurrentCommentPage++; this.updateCommentCurrentPage(); $$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')[0].style.display='block'; this.updateCommentPage(sContentID); } }, updateCommentPage:function(sContentID) { var htmlRequest = new Request({ url: "/comment/getCommentsByPage/"+sContentID+'/'+this.nCurrentCommentPage, encoding:'UTF-8', onComplete: this.onCompleteUpdateCommentDisplayList.bind(this), onFailure: this.onFailureUpdateCommentDisplayList.bind(this) }).send(); //Loader var sLoader = '
'; $(this.sCommentContentID+'_comment_container').innerHTML += sLoader; }, showPreviousCommentPage:function(sContentID) { this.sCommentContentID = sContentID; if(!this.pendingUpdateCommentListRequest) { this.getCommentCurrentPage(); this.pendingUpdateCommentListRequest = true; this.nCurrentCommentPage--; this.updateCommentCurrentPage(); if(this.nCurrentCommentPage==1) $$('#comment_block_'+this.sCommentContentID+' .btn_comment_previous_page')[0].style.display='none'; this.updateCommentPage(sContentID); } }, onCompleteUpdateCommentDisplayList:function(responseHTML) { $(this.sCommentContentID+'_comment_container').innerHTML = responseHTML; var aChildren = $$('#'+this.sCommentContentID+'_comment_container .item'); //console.log(aChildren.length); if(aChildren.length