Commit 0dc5d562 authored by grisel-davy's avatar grisel-davy

Création et affichage du graph des switchs

parent badad163
/* jshint -W071, -W074 */
/* global jQuery:false */
/* Disabled options are:
* W071: This function has too many statements
* W074: This function's cyclomatic complexity is too high
*/
/*
* jQuery ezPlus 1.1.11
* Demo's and documentation:
* http://igorlino.github.io/elevatezoom-plus/
*
* licensed under MIT license.
* http://en.wikipedia.org/wiki/MIT_License
*
*/
if (typeof Object.create !== 'function') {
Object.create = function (obj) {
function F() {
}
F.prototype = obj;
return new F();
};
}
(function ($, window, document, undefined) {
var EZP = {
init: function (options, elem) {
var self = this;
var $galleries;
self.elem = elem;
self.$elem = $(elem);
self.options = $.extend({}, $.fn.ezPlus.options, self.responsiveConfig(options || {}));
self.imageSrc = self.$elem.data(self.options.attrImageZoomSrc) ? self.$elem.data(self.options.attrImageZoomSrc) : self.$elem.attr('src');
if (!self.options.enabled) {
return;
}
//TINT OVERRIDE SETTINGS
if (self.options.tint) {
self.options.lensColour = 'none'; //colour of the lens background
self.options.lensOpacity = '1'; //opacity of the lens
}
//INNER OVERRIDE SETTINGS
if (self.options.zoomType === 'inner') {
self.options.showLens = false;
}
//UUID WHEN MISSING IDENTIFIER
if (self.options.zoomId === -1) {
self.options.zoomId = generateUUID();
}
//Remove alt on hover
self.$elem.parent().removeAttr('title').removeAttr('alt');
self.zoomImage = self.imageSrc;
self.refresh(1);
//Create the image swap from the gallery
$galleries = $(self.options.gallery ? ('#' + self.options.gallery) : self.options.gallerySelector);
$galleries.on('click.zoom', self.options.galleryItem, function (e) {
//Set a class on the currently active gallery image
if (self.options.galleryActiveClass) {
$(self.options.galleryItem, $galleries).removeClass(self.options.galleryActiveClass);
$(this).addClass(self.options.galleryActiveClass);
}
//stop any link on the a tag from working
if (this.tagName === 'A') {
e.preventDefault();
}
//call the swap image function
if ($(this).data(self.options.attrImageZoomSrc)) {
self.zoomImagePre = $(this).data(self.options.attrImageZoomSrc);
}
else {
self.zoomImagePre = $(this).data('image');
}
self.swaptheimage($(this).data('image'), self.zoomImagePre);
if (this.tagName === 'A') {
return false;
}
});
function generateUUID() {
var d = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
return uuid;
}
},
refresh: function (length) {
var self = this;
setTimeout(function () {
self.fetch(self.imageSrc, self.$elem, self.options.minZoomLevel);
}, length || self.options.refresh);
},
fetch: function (imgsrc, element, minZoom) {
//get the image
var self = this;
var newImg = new Image();
newImg.onload = function () {
//set the large image dimensions - used to calculte ratio's
if (newImg.width / element.width() <= minZoom) {
self.largeWidth = element.width() * minZoom;
} else {
self.largeWidth = newImg.width;
}
if (newImg.height / element.height() <= minZoom) {
self.largeHeight = element.height() * minZoom;
} else {
self.largeHeight = newImg.height;
}
//once image is loaded start the calls
self.startZoom();
self.currentImage = self.imageSrc;
//let caller know image has been loaded
self.options.onZoomedImageLoaded(self.$elem);
};
self.setImageSource(newImg, imgsrc); // this must be done AFTER setting onload
return;
},
setImageSource: function (image, src) {
//sets an image's source.
image.src = src;
},
startZoom: function () {
var self = this;
//get dimensions of the non zoomed image
self.nzWidth = self.$elem.width();
self.nzHeight = self.$elem.height();
//activated elements
self.isWindowActive = false;
self.isLensActive = false;
self.isTintActive = false;
self.overWindow = false;
//CrossFade Wrapper
if (self.options.imageCrossfade) {
self.zoomWrap = self.$elem.wrap('<div style="height:' + self.nzHeight + 'px;width:' + self.nzWidth + 'px;" class="zoomWrapper" />');
self.$elem.css('position', 'absolute');
}
self.zoomLock = 1;
self.scrollingLock = false;
self.changeBgSize = false;
self.currentZoomLevel = self.options.zoomLevel;
//get offset of the non zoomed image
self.nzOffset = self.$elem.offset();
//calculate the width ratio of the large/small image
self.widthRatio = (self.largeWidth / self.currentZoomLevel) / self.nzWidth;
self.heightRatio = (self.largeHeight / self.currentZoomLevel) / self.nzHeight;
function getWindowZoomStyle() {
return 'overflow: hidden;' +
'background-position: 0px 0px;text-align:center;' +
'background-color: ' + String(self.options.zoomWindowBgColour) + ';' +
'width: ' + String(self.options.zoomWindowWidth) + 'px;' +
'height: ' + String(self.options.zoomWindowHeight) + 'px;' +
'float: left;' +
'background-size: ' + self.largeWidth / self.currentZoomLevel + 'px ' + self.largeHeight / self.currentZoomLevel + 'px;' +
'display: none;z-index:100;' +
'border: ' + String(self.options.borderSize) + 'px solid ' + self.options.borderColour + ';' +
'background-repeat: no-repeat;' +
'position: absolute;';
}
//if window zoom
if (self.options.zoomType === 'window') {
self.zoomWindowStyle = getWindowZoomStyle();
}
function getInnerZoomStyle() {
//has a border been put on the image? Lets cater for this
var borderWidth = self.$elem.css('border-left-width');
return 'overflow: hidden;' +
'margin-left: ' + String(borderWidth) + ';' +
'margin-top: ' + String(borderWidth) + ';' +
'background-position: 0px 0px;' +
'width: ' + String(self.nzWidth) + 'px;' +
'height: ' + String(self.nzHeight) + 'px;' +
'float: left;' +
'display: none;' +
'cursor:' + (self.options.cursor) + ';' +
'border: ' + String(self.options.borderSize) + 'px solid ' + self.options.borderColour + ';' +
'background-repeat: no-repeat;' +
'position: absolute;';
}
//if inner zoom
if (self.options.zoomType === 'inner') {
self.zoomWindowStyle = getInnerZoomStyle();
}
function getWindowLensStyle() {
// adjust images less than the window height
if (self.nzHeight < self.options.zoomWindowHeight / self.heightRatio) {
self.lensHeight = self.nzHeight;
}
else {
self.lensHeight = String(self.options.zoomWindowHeight / self.heightRatio);
}
if (self.largeWidth < self.options.zoomWindowWidth) {
self.lensWidth = self.nzWidth;
}
else {
self.lensWidth = String(self.options.zoomWindowWidth / self.widthRatio);
}
return 'background-position: 0px 0px;width: ' + String((self.options.zoomWindowWidth) / self.widthRatio) + 'px;' +
'height: ' + String((self.options.zoomWindowHeight) / self.heightRatio) +
'px;float: right;display: none;' +
'overflow: hidden;' +
'z-index: 999;' +
'opacity:' + (self.options.lensOpacity) + ';filter: alpha(opacity = ' + (self.options.lensOpacity * 100) + '); zoom:1;' +
'width:' + self.lensWidth + 'px;' +
'height:' + self.lensHeight + 'px;' +
'background-color:' + (self.options.lensColour) + ';' +
'cursor:' + (self.options.cursor) + ';' +
'border: ' + (self.options.lensBorderSize) + 'px' +
' solid ' + (self.options.lensBorderColour) + ';background-repeat: no-repeat;position: absolute;';
}
//lens style for window zoom
if (self.options.zoomType === 'window') {
self.lensStyle = getWindowLensStyle();
}
//tint style
self.tintStyle = 'display: block;' +
'position: absolute;' +
'background-color: ' + self.options.tintColour + ';' +
'filter:alpha(opacity=0);' +
'opacity: 0;' +
'width: ' + self.nzWidth + 'px;' +
'height: ' + self.nzHeight + 'px;';
//lens style for lens zoom with optional round for modern browsers
self.lensRound = '';
if (self.options.zoomType === 'lens') {
self.lensStyle = 'background-position: 0px 0px;' +
'float: left;display: none;' +
'border: ' + String(self.options.borderSize) + 'px solid ' + self.options.borderColour + ';' +
'width:' + String(self.options.lensSize) + 'px;' +
'height:' + String(self.options.lensSize) + 'px;' +
'background-repeat: no-repeat;position: absolute;';
}
//does not round in all browsers
if (self.options.lensShape === 'round') {
self.lensRound = 'border-top-left-radius: ' + String(self.options.lensSize / 2 + self.options.borderSize) + 'px;' +
'border-top-right-radius: ' + String(self.options.lensSize / 2 + self.options.borderSize) + 'px;' +
'border-bottom-left-radius: ' + String(self.options.lensSize / 2 + self.options.borderSize) + 'px;' +
'border-bottom-right-radius: ' + String(self.options.lensSize / 2 + self.options.borderSize) + 'px;';
}
//create the div's + ""
//self.zoomContainer = $('<div/>').addClass('zoomContainer').css({"position":"relative", "height":self.nzHeight, "width":self.nzWidth});
self.zoomContainer =
$('<div class="zoomContainer" ' +
'uuid="' + self.options.zoomId + '"' +
'style="' +
'position:absolute;' +
'left:' + self.nzOffset.left + 'px;' +
'top:' + self.nzOffset.top + 'px;' +
'height:' + self.nzHeight + 'px;' + '' +
'width:' + self.nzWidth + 'px;' +
'z-index:' + self.options.zIndex + '"></div>');
if (self.$elem.attr('id')) {
self.zoomContainer.attr('id', self.$elem.attr('id') + '-zoomContainer');
}
$(self.options.zoomContainerAppendTo).append(self.zoomContainer);
//this will add overflow hidden and contrain the lens on lens mode
if (self.options.containLensZoom && self.options.zoomType === 'lens') {
self.zoomContainer.css('overflow', 'hidden');
}
if (self.options.zoomType !== 'inner') {
self.zoomLens = $('<div class="zoomLens" style="' + self.lensStyle + self.lensRound + '">&nbsp;</div>')
.appendTo(self.zoomContainer)
.click(function () {
self.$elem.trigger('click');
});
if (self.options.tint) {
self.tintContainer = $('<div/>').addClass('tintContainer');
self.zoomTint = $('<div class="zoomTint" style="' + self.tintStyle + '"></div>');
self.zoomLens.wrap(self.tintContainer);
self.zoomTintcss = self.zoomLens.after(self.zoomTint);
//if tint enabled - set an image to show over the tint
self.zoomTintImage = $('<img style="' +
'position: absolute; left: 0px; top: 0px; max-width: none; ' +
'width: ' + self.nzWidth + 'px; ' +
'height: ' + self.nzHeight + 'px;" ' +
'src="' + self.imageSrc + '">')
.appendTo(self.zoomLens)
.click(function () {
self.$elem.trigger('click');
});
}
}
var targetZoomContainer = isNaN(self.options.zoomWindowPosition) ? 'body' : self.zoomContainer;
//create zoom window
self.zoomWindow = $('<div style="z-index:999;' +
'left:' + (self.windowOffsetLeft) + 'px;' +
'top:' + (self.windowOffsetTop) + 'px;' + self.zoomWindowStyle + '" class="zoomWindow">&nbsp;</div>')
.appendTo(targetZoomContainer).click(function () {
self.$elem.trigger('click');
});
self.zoomWindowContainer = $('<div/>').addClass('zoomWindowContainer').css('width', self.options.zoomWindowWidth);
self.zoomWindow.wrap(self.zoomWindowContainer);
// self.captionStyle = "text-align: left;background-color: black;'+
// 'color: white;font-weight: bold;padding: 10px;font-family: sans-serif;font-size: 11px";
// self.zoomCaption = $('<div class="ezplus-caption" '+
// 'style="'+self.captionStyle+'display: block; width: 280px;">INSERT ALT TAG</div>').appendTo(self.zoomWindow.parent());
if (self.options.zoomType === 'lens') {
self.zoomLens.css('background-image', 'url("' + self.imageSrc + '")');
}
if (self.options.zoomType === 'window') {
self.zoomWindow.css('background-image', 'url("' + self.imageSrc + '")');
}
if (self.options.zoomType === 'inner') {
self.zoomWindow.css('background-image', 'url("' + self.imageSrc + '")');
}
/*-------------------END THE ZOOM WINDOW AND LENS----------------------------------*/
if (self.options.touchEnabled) {
//touch events
self.$elem.bind('touchmove.ezpspace', function (e) {
e.preventDefault();
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
self.setPosition(touch);
});
self.zoomContainer.bind('touchmove.ezpspace', function (e) {
if (self.options.zoomType === 'inner') {
self.showHideWindow('show');
}
e.preventDefault();
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
self.setPosition(touch);
});
self.zoomContainer.bind('touchend.ezpspace', function (e) {
self.showHideWindow('hide');
if (self.options.showLens) {
self.showHideLens('hide');
}
if (self.options.tint && self.options.zoomType !== 'inner') {
self.showHideTint('hide');
}
});
self.$elem.bind('touchend.ezpspace', function (e) {
self.showHideWindow('hide');
if (self.options.showLens) {
self.showHideLens('hide');
}
if (self.options.tint && self.options.zoomType !== 'inner') {
self.showHideTint('hide');
}
});
if (self.options.showLens) {
self.zoomLens.bind('touchmove.ezpspace', function (e) {
e.preventDefault();
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
self.setPosition(touch);
});
self.zoomLens.bind('touchend.ezpspace', function (e) {
self.showHideWindow('hide');
if (self.options.showLens) {
self.showHideLens('hide');
}
if (self.options.tint && self.options.zoomType !== 'inner') {
self.showHideTint('hide');
}
});
}
}
//Needed to work in IE
self.$elem.bind('mousemove.ezpspace', function (e) {
if (self.overWindow === false) {
self.setElements('show');
}
//make sure on orientation change the setposition is not fired
if (self.lastX !== e.clientX || self.lastY !== e.clientY) {
self.setPosition(e);
self.currentLoc = e;
}
self.lastX = e.clientX;
self.lastY = e.clientY;
});
self.zoomContainer.bind('click.ezpspace touchstart.ezpspace', self.options.onImageClick);
self.zoomContainer.bind('mousemove.ezpspace', function (e) {
if (self.overWindow === false) {
self.setElements('show');
}
mouseMoveZoomHandler(e);
});
function mouseMoveZoomHandler(e) {
//self.overWindow = true;
//make sure on orientation change the setposition is not fired
if (self.lastX !== e.clientX || self.lastY !== e.clientY) {
self.setPosition(e);
self.currentLoc = e;
}
self.lastX = e.clientX;
self.lastY = e.clientY;
}
var elementToTrack = null;
if (self.options.zoomType !== 'inner') {
elementToTrack = self.zoomLens;
}
if (self.options.tint && self.options.zoomType !== 'inner') {
elementToTrack = self.zoomTint;
}
if (self.options.zoomType === 'inner') {
elementToTrack = self.zoomWindow;
}
//register the mouse tracking
if (elementToTrack) {
elementToTrack.bind('mousemove.ezpspace', mouseMoveZoomHandler);
}
// lensFadeOut: 500, zoomTintFadeIn
self.zoomContainer.add(self.$elem).mouseenter(function () {
if (self.overWindow === false) {
self.setElements('show');
}
}).mouseleave(function () {
if (!self.scrollLock) {
self.setElements('hide');
self.options.onDestroy(self.$elem);
}
});
//end ove image
if (self.options.zoomType !== 'inner') {
self.zoomWindow.mouseenter(function () {
self.overWindow = true;
self.setElements('hide');
}).mouseleave(function () {
self.overWindow = false;
});
}
//end ove image
// var delta = parseInt(e.originalEvent.wheelDelta || -e.originalEvent.detail);
// $(this).empty();
// return false;
//fix for initial zoom setting
//if (self.options.zoomLevel !== 1) {
// self.changeZoomLevel(self.currentZoomLevel);
//}
//set the min zoomlevel
if (self.options.minZoomLevel) {
self.minZoomLevel = self.options.minZoomLevel;
}
else {
self.minZoomLevel = self.options.scrollZoomIncrement * 2;
}
if (self.options.scrollZoom) {
//see compatibility of mouse events at https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel
self.zoomContainer.add(self.$elem).bind('wheel DOMMouseScroll MozMousePixelScroll', function (e) {
// in IE there is issue with firing of mouseleave - So check whether still scrolling
// and on mouseleave check if scrolllock
self.scrollLock = true;
clearTimeout($.data(this, 'timer'));
$.data(this, 'timer', setTimeout(function () {
self.scrollLock = false;
//do something
}, 250));
var theEvent = e.originalEvent.deltaY || e.originalEvent.detail * -1;
//this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
// e.preventDefault();
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
if (theEvent == 0) {
// fixes last event inversion bug
return false;
}
if (theEvent / 120 > 0) {
var nextZoomLevel = parseFloat(self.currentZoomLevel) - self.options.scrollZoomIncrement;
//scrolling up
if (nextZoomLevel >= parseFloat(self.minZoomLevel)) {
self.changeZoomLevel(nextZoomLevel);
}
}
else {
//scrolling down
//Check if it has to maintain original zoom window aspect ratio or not
if ((!self.fullheight && !self.fullwidth) || !self.options.mantainZoomAspectRatio) {
var nextZoomLevel = parseFloat(self.currentZoomLevel) + self.options.scrollZoomIncrement;
if (self.options.maxZoomLevel) {
if (nextZoomLevel <= self.options.maxZoomLevel) {
self.changeZoomLevel(nextZoomLevel);
}
}
else {
//andy
self.changeZoomLevel(nextZoomLevel);
}
}
}
return false;
});
}
},
destroy: function () {
var self = this;
self.$elem.unbind('ezpspace');
$(self.zoomContainer).remove();
if (self.options.loadingIcon && !!self.spinner && !!self.spinner.length) {
self.spinner.remove();
delete self.spinner;
}
},
getIdentifier: function () {
var self = this;
return self.options.zoomId;
},
setElements: function (type) {
var self = this;
if (!self.options.zoomEnabled) {
return false;
}
if (type === 'show') {
if (self.isWindowSet) {
if (self.options.zoomType === 'inner') {
self.showHideWindow('show');
}
if (self.options.zoomType === 'window') {
self.showHideWindow('show');
}
if (self.options.showLens) {
self.showHideLens('show');
}
if (self.options.tint && self.options.zoomType !== 'inner') {
self.showHideTint('show');
}
}
}
if (type === 'hide') {
if (self.options.zoomType === 'window') {
self.showHideWindow('hide');
}
if (!self.options.tint) {
self.showHideWindow('hide');
}
if (self.options.showLens) {
self.showHideLens('hide');
}
if (self.options.tint) {
self.showHideTint('hide');
}
}
},
setPosition: function (e) {
var self = this;
if (!self.options.zoomEnabled) {
return false;
}
//recaclc offset each time in case the image moves
//this can be caused by other on page elements
self.nzHeight = self.$elem.height();
self.nzWidth = self.$elem.width();
self.nzOffset = self.$elem.offset();
if (self.options.tint && self.options.zoomType !== 'inner') {
self.zoomTint.css({
top: 0,
left: 0
});
}
//set responsive
//will checking if the image needs changing before running this code work faster?
if (self.options.responsive && !self.options.scrollZoom) {
if (self.options.showLens) {
var lensHeight, lensWidth;
if (self.nzHeight < self.options.zoomWindowWidth / self.widthRatio) {
self.lensHeight = self.nzHeight;
}
else {
self.lensHeight = String((self.options.zoomWindowHeight / self.heightRatio));
}
if (self.largeWidth < self.options.zoomWindowWidth) {
self.lensWidth = self.nzWidth;
}
else {
self.lensWidth = (self.options.zoomWindowWidth / self.widthRatio);
}
self.widthRatio = self.largeWidth / self.nzWidth;
self.heightRatio = self.largeHeight / self.nzHeight;
if (self.options.zoomType !== 'lens') {
//possibly dont need to keep recalcalculating
//if the lens is heigher than the image, then set lens size to image size
if (self.nzHeight < self.options.zoomWindowWidth / self.widthRatio) {
self.lensHeight = self.nzHeight;
}
else {
self.lensHeight = String((self.options.zoomWindowHeight / self.heightRatio));
}
if (self.nzWidth < self.options.zoomWindowHeight / self.heightRatio) {
self.lensWidth = self.nzWidth;
}
else {
self.lensWidth = String((self.options.zoomWindowWidth / self.widthRatio));
}
self.zoomLens.css({
'width': self.lensWidth,
'height': self.lensHeight
});
if (self.options.tint) {
self.zoomTintImage.css({
'width': self.nzWidth,
'height': self.nzHeight
});
}
}
if (self.options.zoomType === 'lens') {
self.zoomLens.css({
width: String(self.options.lensSize) + 'px',
height: String(self.options.lensSize) + 'px'
});
}
//end responsive image change
}
}
//container fix
self.zoomContainer.css({
top: self.nzOffset.top,
left: self.nzOffset.left,
width: self.nzWidth, // new code
height: self.nzHeight // new code
});
self.mouseLeft = parseInt(e.pageX - self.nzOffset.left);
self.mouseTop