/* ============= Javascript file ============= */ function frameBuster(){ if(($$('#content div.bloghead')[0])||($$('#topleftcol div.blogCarHead')[0])) return; // css rules in order to test if this is a blog page - index, post or cat if ( top != self ){ top.location.href = unescape(window.location.pathname); } } function newSearch(e) { var myEvent = new Event(e); var searchInput= $('searchinput'); searchInput.value=""; searchInput.focus(); myEvent.stop(); } function toggleMain(e) { // toggling function - using the href attribute of the source of the event and switch class from "none" to "selected" var myEvent = new Event(e); var myTarget = myEvent.target; var divToShow = $(myTarget.href.split("#")[1]); // get the closest parent 'div' tag var elemParent = myTarget.getParent(); while(elemParent.getTag() != 'ul') { elemParent = $(elemParent).getParent(); } if(divToShow.getStyle('display')=='none') { // hide every divs var everyDivs = $$(elemParent.getElementsByTagName('a')).getProperty('href'); // #nameoftheid $each(everyDivs, function(singleDiv){ divToHide = singleDiv.split('#')[1]; $(divToHide).setStyle('display', 'none'); }); // remove class to the links $each($(elemParent).getElementsByTagName('a'), function(singleLink) { singleLink.removeClass('selected'); }); //show a single div and add 'selected' class to the clicked link divToShow.setStyle('display', 'block'); myTarget.addClass('selected'); } myEvent.stop(); } function smoothScroll(e) { var myEvent = new Event(e); var target = (!myEvent.target.href) ? myEvent.target.parentNode : myEvent.target; var divToScrollTo = target.href.split('#')[1]; new Fx.Scroll(window).toElement(divToScrollTo); myEvent.stop(); } function printThis(e) { var myEvent = new Event(e); // stop the event window.print(); } function toggleConnectForm(e) { var myEvent = new Event(e); // stop the event myEvent.stop(); // toggle the form connectFormSlider.toggle(); } function toggleSendForm(e) { var myEvent = new Event(e); myEvent.stop(); sendtofriendFormSlider.toggle() } function jumpToUrl(e) { var cururl = $('cnetcategories').getValue(); var myEvent = new Event(e); myEvent.stop(); if(cururl) { //alert('Ceci est un test ne vous affolez pas : ' + cururl); window.location.href=cururl; //window.location.assign(cururl); } } function toggleShare(e) { var myEvent = new Event(e); myEvent.stop(); shareListSlider.toggle() } function selectText(e) { var event = new Event(e); var target = event.target; target.select(); } function delicious(e){ var myEvent = new Event(e); u=location.href; t=document.title; window.open('http://del.icio.us/post?tags=test&v=4&jump=close&url='+u+'&title='+t, 'delicious','toolbar=no,width=700,height=400,scrollbars=yes,resizable=yes'); myEvent.stop(); } function facebook(e){ var myEvent = new Event(e); u=location.href; t=document.title; window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436'); myEvent.stop(); } function digg(e){ var myEvent = new Event(e); u=location.href; t=document.title; window.open('http://digg.com/submit?phase=2&url='+u+'&title='+t+'&topic=tech_news','digg'); myEvent.stop(); } function scoopeo(e){ var myEvent = new Event(e); u=location.href; t=document.title; window.open('http://www.scoopeo.com/scoop/new?newurl='+u+'&title='+t,'Scoopeo'); myEvent.stop(); } /* ============= Init functions ============= */ function initSmoothScroll() { var smooth_links = $$('a.smooth'); $each(smooth_links, function(smooth_link) {smooth_link.addEvent('click', smoothScroll);}); } function initFooter() { //vars var navLinks = $$('#bottomnav a'); var navNames = ["cnetfr","sitemap","networks"]; // add behaviour $each(navLinks, function(myNavLink) {myNavLink.addEvent('click', toggleMain);}); // hide panes $each(navNames, function(myNav){ $(myNav).setStyle('display','none')}); // display default $('cnetfr').setStyle('display', 'block'); } function initImagesAccordion() { if(!$('images')) return; // test 'cause we need that on the hp only var imagesTabs = $$('#images p.navmost a'); var imagesStretchers = $$('#images ul'); var imagesAccordion = new Accordion(imagesTabs, imagesStretchers, {duration:500, opacity: 0, transition: Fx.Transitions.sineInOut, onActive: function(targetElem){ targetElem.addClass('selected'); }, onBackground: function(elem){ elem.removeClass('selected'); } }); /* prevent default behavior */ $each(imagesTabs, function(imageTab){ imageTab.addEvent('click', function(event){ event = new Event(event); event.preventDefault(); }); }) } function initServicesAccordion() { if(!$('services')) return; // test 'cause we need that on the hp only var servicesTabs = $$('#services p.navmost a'); var servicesStretchers = $$('#services ul'); var servicesAccordion = new Accordion(servicesTabs, servicesStretchers, {duration:500, opacity: 0, transition: Fx.Transitions.sineInOut, onActive: function(targetElem){ targetElem.addClass('selected'); }, onBackground: function(elem){ elem.removeClass('selected'); } }); /* prevent default behavior */ $each(servicesTabs, function(serviceTab){ serviceTab.addEvent('click', function(event){ event = new Event(event); event.preventDefault(); }); }) } function initReactionsAccordion() { if(!$('reactions')) return; // test 'cause we need that on the hp only var reactionsTabs = $$('#reactions p.navmost a'); var reactionsStretchers = $$('#reactions ul'); var reactionsAccordion = new Accordion(reactionsTabs, reactionsStretchers, {duration:600, opacity: 0, transition: Fx.Transitions.sineInOut, onActive: function(targetElem){ targetElem.addClass('selected'); }, onBackground: function(elem){ elem.removeClass('selected'); } }); /* prevent default behavior */ $each(reactionsTabs, function(reactionTab){ reactionTab.addEvent('click', function(event){ event = new Event(event); event.preventDefault(); }); }) } function initInfosAccordion() { if(!$('infos')) return; // test 'cause we need that on the hp only var infosTabs = $$('#infos p.navmost a'); var infosStretchers = $$('#infos ul'); var infosAccordion = new Accordion(infosTabs, infosStretchers, {duration:600, opacity: 0, transition: Fx.Transitions.sineInOut, onActive: function(targetElem){ targetElem.addClass('selected'); }, onBackground: function(elem){ elem.removeClass('selected'); } }); /* prevent default behavior */ $each(infosTabs, function(infoTab){ infoTab.addEvent('click', function(event){ event = new Event(event); event.preventDefault(); }); }) } function initMemberZone() { if(!$('memberlogged')) return; var url="http://prvcms.cnetfrance.fr/sandbox/cnet2007/products/templates/rightcol_memberlogged.htm"; var url="/2007/templates/rightcol_memberlogged.htm"; var myElem=$('memberlogged'); new Ajax(url, { method: 'get', //onFailure: function() { alert('casse')}, update: myElem }).request(); } function initConnectForm() { if(!$('connectform')) return; var buttonConnect = $('profileresume'); connectFormSlider= new Fx.Slide('connectform', {duration: 500}); // hide the form connectFormSlider.hide(); // add behavior buttonConnect.addEvent('click', toggleConnectForm) } function initSendForm() { if(!$('sendtofriend')) return; var buttonSendToFriend = $('btsend'); sendtofriendFormSlider= new Fx.Slide('sendtofriend', {duration: 500}); // hide the form sendtofriendFormSlider.hide(); // add behavior buttonSendToFriend.addEvent('click', toggleSendForm) } function initPrintThis() { if(!$('btprint')) return; var buttonPrint = $('btprint'); buttonPrint.addEvent('click', printThis); } function initJumpMenu() { if(!$('cnetcategories')) return; $$('#productfinder button').addEvent('click',jumpToUrl) } function initAislesIe() { // aisles buttons IE compatibility function if(!$('aislesbuttons')) return; if (window.ie) { var subNavItems = $$('#aislesbuttons div'); $each(subNavItems, function(subNavItem) {subNavItem.addEvent('mouseover', function(){subNavItem.addClass('over')});}); $each(subNavItems, function(subNavItem) {subNavItem.addEvent('mouseout', function(){subNavItem.removeClass('over')});}); } } function startList() { // dropdown menu IE compatibility function if (window.ie) { var subNavItems = $$("#subnav li"); //alert(subNavItems); $each(subNavItems, function(subNavItem) {subNavItem.addEvent('mouseover', function(){subNavItem.addClass('over')});}); $each(subNavItems, function(subNavItem) {subNavItem.addEvent('mouseout', function(){subNavItem.removeClass('over')});}); } } function initShare() { // services in news section if(!$('postlist')) return; var buttonShare = $('btpost'); shareListSlider= new Fx.Slide('postlist', {duration: 500}); // hide the form shareListSlider.hide(); // add behavior buttonShare.addEvent('click', toggleShare); // initServices if ($$('#postlist .facebook a')) $$('#postlist .facebook a')[0].addEvent('click', facebook); if ($$('#postlist .digg a')) $$('#postlist .digg a')[0].addEvent('click', digg); if ($$('#postlist .delicious a')) $$('#postlist .delicious a')[0].addEvent('click', delicious); if ($$('#postlist .scoopeo a')) $$('#postlist .scoopeo a')[0].addEvent('click', scoopeo); } function initSharegadget() { if(!$('gpostlist')) return; // initServices if ($$('#gpostlist a.facebook')) $$('#gpostlist a.facebook')[0].addEvent('click', facebook); } function initShareVideoInput() { // only on video stories if(!$('video_player_permalink_text')) return; $('video_player_permalink_text').addEvent('click', selectText); $('video_player_embed_code_text').addEvent('click', selectText); } function initNewSearch() { if(!$$('p.helper a')[0]) return; var myLink = $$('p.helper a')[0]; myLink.addEvent('click', newSearch); } function openVista() { if(Cookie.get("vistawindow")) return; // si le cookie est placé alors on sort vista = navigator.userAgent.toLowerCase().indexOf("windows nt 6.0") > -1; if(vista) { window.open('http://www.cnetfrance.fr/s/2007/vista/sondage.htm','Vista','toolbars=0,width=600,height=400,statusbar=0,scrollbars=1') } Cookie.set("vistawindow", "1", {duration: 10}); // on cale le cookie } /* ============= Launch everything ============= */ var load_method = (window.ie ? 'load' : 'domready'); // ie fix window.addEvent(load_method, frameBuster); window.addEvent(load_method, initNewSearch); window.addEvent(load_method, initShareVideoInput); window.addEvent(load_method, initShare); window.addEvent(load_method, initSharegadget); window.addEvent(load_method, initJumpMenu); window.addEvent(load_method, initPrintThis); window.addEvent(load_method, initSendForm); window.addEvent(load_method, initConnectForm); window.addEvent(load_method, initMemberZone); window.addEvent(load_method, initServicesAccordion); window.addEvent(load_method, initReactionsAccordion); window.addEvent(load_method, initImagesAccordion); window.addEvent(load_method, initInfosAccordion); window.addEvent(load_method, initFooter); window.addEvent(load_method, initSmoothScroll); window.addEvent(load_method, initAislesIe); window.addEvent(load_method, startList); //window.addEvent(load_method, openVista);