function hexToRgb(string) { if(!string || typeof string !== 'string') return false; if( string.substring(0,1) == '#' && (string.length == 4 || string.length == 7) && /^[0-9a-fA-F]+$/.test(string.substring(1, string.length)) ){ string = string.substring(1, string.length); if(string.length == 3) string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2]; return 'rgb(' + parseInt(string[0] + string[1], 16).toString() + ',' + parseInt(string[2] + string[3], 16).toString() + ',' + parseInt(string[4] + string[5], 16).toString() + ')'; } else return false; } function getHexString(var_rgbString) { var_rgbString = hexToRgb(var_rgbString); //var rgbString = "rgb(0, 70, 300)"; // get this in whatever way. if(!var_rgbString) return; var parts = var_rgbString.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); var hexString = ''; // parts now should be ["rgb(0, 70, 255", "0", "70", "255"] if(parts){ delete (parts[0]); for (var i = 1; i <= 3; ++i) { parts[i] = parts[i]*1.2; parts[i] = (parts[i]>255)? 255 : parts[i]; parts[i] = (parts[i]<50)? 50 : parts[i]; //console.log(parts[i]); parts[i] = parseInt(parts[i]).toString(16); if (parts[i].length == 1) parts[i] = '0' + parts[i]; } hexString = "#"+parts.join('').toUpperCase(); // "#0070FF" return hexString; } } $(document).ready(function(){ var first_color = "#424656"; var second_color = "#C3BBED"; var first_color_opacity = getHexString(first_color); var second_color_opacity = getHexString(second_color); $(".block-signataires").css("background-color", first_color); $(".block-Link").css("background-color", first_color); $(".block-signer-petition").css("background-color", first_color_opacity); $(".block-objectif").css("background-color", first_color_opacity); $(".opacity_reseaux .couriel").css("background-color", first_color); $(".opacity_reseaux .none").css("background-color", first_color_opacity); $(".opacity_jesigne .none").css("background-color", second_color); $(".opacity_jesigne .couriel").css("background-color", second_color_opacity); $(".petition.active").css("background-color", second_color_opacity); $(".tab1").css("background-color", second_color_opacity); $(".tab2").css("background-color", second_color_opacity); $("#content-area .block-onglets .voir-plus").css("background-color", second_color_opacity); $('#petition_tabs_controller li').click(function(){ $('#petition_tabs_target >div').hide(); $('#' + $(this).find('a').attr('rel')).show(); $('#petition_tabs_controller li').removeClass('active'); $('#petition_tabs_controller li').css("background-color",''); $(this).addClass('active'); $(this).css("background-color", second_color_opacity); return false; }) });