Skip to content
Snippets Groups Projects
onload_utils.js 3.46 KiB
///////////////////////////////////////////////////////////////////////////////
// Retaille les images / flash .... des boîtes pour bien rentrer dans les
// divisions tout en gardant les proportions
///////////////////////////////////////////////////////////////////////////////
function resizeElement(element, maxw, keep_ratio) {
	var height = element.height();
	var width = element.width();

	if ((width > maxw) && (maxw > 0)){
		if (keep_ratio && (height>0)) {
			var newh = Math.round(height*(maxw/width));
			element.height(newh);
		}
		element.width(maxw);
	}
}


function autoResizeTags(tags, keep_ratio){
	var children_selector = tags.join(',');

	$('.auto_resize').each(function(){
		var mywidth = $(this).width();
		var parent_width = $(this).parent('div').width();
		if (mywidth < parent_width)
			maxwidth = mywidth;
		else
			maxwidth = parent_width;

		$(this).find(children_selector).each(function(){
			resizeElement($(this), maxwidth, keep_ratio);
		});
		$(this).removeClass('auto_resize');
	});
}


// Active auto-resize pour tous les objets Flash, Images des elémenents
// avec la classe "auto_resize"
var resize_func = function(){
	autoResizeTags(new Array("embed", "object", "img"), true)}

if (typeof jQuery != "undefined") 
	$(document).ready(resize_func);




//Les liens qui référencent des sites externes doivent être ouverts dans un nouvel onglet
var setupAnchorsTarget = function() {
  var internalLink = new RegExp('/' + window.location.host + '/');
  $('a[href^="http"]').each(function() {
    if (!internalLink.test($(this).attr('href')) 
	&& (undefined == this.onclick) 
	&& (undefined == $(this).data('events') || undefined == $(this).data('events').click)) {
      if ($.browser.msie || !!navigator.userAgent.match(/Trident/)) {
	// Otherwise IE doesn't send HTTP Referer
	this.target = '_blank';
	return;
      }

      $(this).click(function(event) {
	event.preventDefault();
	event.stopPropagation();
	window.open(this.href, '_blank');
      });
    }
  });
}


var autoHideShowConfigurationModule = function() {
  autoHideShowTagOnParentHover('.configuration_module', 'div.boite');
  autoHideShowTagOnParentHover('.edit_article', 'div.boite');
  autoHideShowTagOnParentHover('.select_kiosque_form', 'div.boite');
  autoHideShowTagOnParentHover('.edit_menu', '#menu_horizontal');
  autoHideShowTagOnParentHover('.newsadd', 'div.boite');

}

var autoHideShowTagOnParentHover = function (child_selector, parent_selector) {
  hide_selector = parent_selector + ' ' + child_selector;
  $(hide_selector).hide();
  $(child_selector).parents(parent_selector).hover(
    function() {
      $(this).find(child_selector).fadeIn();
    },

    function() {
      if (!$(this).find('select').is(":focus")) 
				$(parent_selector).find(child_selector).fadeOut();
    }
  );
  
}



var initializeImgHover = function() {
  var images = $('img[data-hover]');
  images.each(function(index, element) {
		var image = $(element);
		image.attr('data-out', image.attr('src'));

		if(image.parents('.menu').length==0)
	    image.hover(function(){image.attr('src', image.data('hover'));},
									function(){image.attr('src', image.data('out'));});

		image.parents('.menu').hover(function(){image.attr('src', image.data('hover'));},
																 function(){image.attr('src', image.data('out'));});
  });
}



var initializeReseauxSociaux = function() {
	$('.reseaux-sociaux[data-article-url]').each(
		function(index,element) {
			$element = $(element);
			$element.load($element.attr('data-article-url'));
		}
	);
}