/** * Fichier : global.js * Description : fonctions JS génériques * Auteur : Hamza Iqbal - hiqbal[at]actualys.com * Copyright: Actualys ******************************************/ /** * Initialisation ******************************************/ $(document).ready( function() { rolloverImg(); videInputFocus(); if($.fancybox) $('a.eurorscg_fancy_pict').fancybox(); $('.eurorscg_context_menu').ready(function() { accordionContextMenu(); }); }); /** * Rollover ******************************************/ var rolloverImg = function() { preloadRolloverImg(); $(".eurorscg_rollover").hover ( function () {$(this).attr( 'src', rolloverNewImg($(this).attr('src')) );}, function () {$(this).attr( 'src', rolloverOldimage($(this).attr('src')) );} ); } var preloadRolloverImg = function() { $(window).bind('load', function() { $('.eurorscg_rollover').each( function() { $('').attr( 'src', rolloverNewImg( $(this).attr('src') ) ); }); }); } var rolloverNewImg = function(src) { return src.substring(0, src.search(/(\.[a-z]+)$/) ) + '_on' + src.match(/(\.[a-z]+)$/)[0]; } var rolloverOldimage = function(src) { return src.replace(/_on\./, '.'); } /** * Vide la valeur des champs input au focus ******************************************/ var videInputFocus = function() { var input = $('input.eurorscg_input_focus[value!=""]'); input.each( function() { $(this).focus( function() {if(this.value == this.defaultValue) this.value='';}); $(this).blur( function() {if(this.value == '') this.value=this.defaultValue;}); }); }; /** * Gestion du menu ******************************************/ $(document).ready(function() { function megaHoverOver(){ $(this).find(".eurorscg_sub").stop().fadeTo('fast', 1).show(); var active_left = false; var active_right = false; if ($(this).prev().hasClass('eurorscg_nav_active')) { active_left = true; } if ($(this).next().hasClass('eurorscg_nav_active')) { active_right = true; } $(this).each(function () { if ($(this).hasClass('eurorscg_nav_li')) { $(this).addClass('eurorscg_nav_on'); if (active_left) { $(this).prev().addClass('eurorscg_nav_on_without_left'); $(this).addClass('eurorscg_nav_on_without_top_right'); } if (active_right) { $(this).next().addClass('eurorscg_nav_on_without_right'); $(this).addClass('eurorscg_nav_on_without_top_left'); } } }); //Calculate width of all ul's (function($) { jQuery.fn.calcSubWidth = function() { rowWidth = 0; //Calculate row $(this).find("ul").each(function() { rowWidth += $(this).width(); }); }; })(jQuery); if ( $(this).find(".eurorscg_row").length > 0 ) { //If row exists... var biggestRow = 0; //Calculate each row $(this).find(".eurorscg_row").each(function() { $(this).calcSubWidth(); //Find biggest row if(rowWidth > biggestRow) { biggestRow = rowWidth; } }); //Set width $(this).find(".eurorscg_sub").css({'width' :biggestRow}); $(this).find(".eurorscg_row:last").css({'margin':'0'}); } else { //If row does not exist... $(this).calcSubWidth(); //Set Width $(this).find(".eurorscg_sub").css({'width' : rowWidth}); } } function megaHoverOut(){ $(this).find(".eurorscg_sub").stop().fadeTo('fast', 0, function() { $(this).hide(); }); $(this).removeClass('eurorscg_nav_on'); $(this).prev().removeClass('eurorscg_nav_on_without_left'); $(this).next().removeClass('eurorscg_nav_on_without_right'); $(this).removeClass('eurorscg_nav_on_without_top_left'); $(this).removeClass('eurorscg_nav_on_without_top_right'); } var config = { sensitivity: 1, // number = sensitivity threshold (must be 1 or higher) interval: 0, // number = milliseconds for onMouseOver polling interval over: megaHoverOver, // function = onMouseOver callback (REQUIRED) timeout: 0, // number = milliseconds delay before onMouseOut out: megaHoverOut // function = onMouseOut callback (REQUIRED) }; $("ul.eurorscg_id_navigation li .eurorscg_sub").css({'opacity':'0'}); $("ul.eurorscg_id_navigation li").hoverIntent(config); }); /** * Accordeon Menu contextuel ******************************************/ var accordionContextMenu = function() { var context_menu = $('.eurorscg_context_menu'); context_menu.each(function() { var cm = $(this); var title = cm.find('h2'); var list = cm.find('ul'); //var class = 'eurorscg_context_menu_on'; if(!cm.hasClass('eurorscg_context_menu_on')) list.hide(); title.click(function() { if(cm.hasClass('eurorscg_context_menu_on')) { list.slideToggle('fast', function() { cm.removeClass('eurorscg_context_menu_on'); }); } else { cm.addClass('eurorscg_context_menu_on'); list.slideToggle('fast'); } }); }); };