- $(window).resize(function() {
- imageDimensions.galleryWidth = image.parent().width();
- imageDimensions.galleryHeight = image.parent().height();
- });
-
- function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
- return {
- maxX: 0,
- maxY: 0,
- minX: galleryWidth - imageWidth,
- minY: galleryHeight - imageHeight
- }
- }
-
- function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
- var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
- return {
- x: Math.min(b.maxX, Math.max(b.minX, x)),
- y: Math.min(b.maxY, Math.max(b.minY, y))
- }
- }
-
- function onMouseMove(event) {
- var position = normalizePosition(
- event.clientX - origin.x + imageOrigin.left,
- event.clientY - origin.y + imageOrigin.top,
- imageDimensions.galleryWidth,
- imageDimensions.galleryHeight,
- imageDimensions.width,
- imageDimensions.height
- );
- image.css({position: 'absolute', top: position.y, left: position.x});
- return false;
- }
+ $(window).resize(function() {
+ imageDimensions.galleryWidth = image.parent().width();
+ imageDimensions.galleryHeight = image.parent().height();
+ });
+
+ function bounds(galleryWidth, galleryHeight, imageWidth, imageHeight) {
+ return {
+ maxX: 0,
+ maxY: 0,
+ minX: galleryWidth - imageWidth,
+ minY: galleryHeight - imageHeight
+ }
+ }
+
+ function normalizePosition(x, y, galleryWidth, galleryHeight, imageWidth, imageHeight) {
+ var b = bounds(galleryWidth, galleryHeight, imageWidth, imageHeight);
+ return {
+ x: Math.min(b.maxX, Math.max(b.minX, x)),
+ y: Math.min(b.maxY, Math.max(b.minY, y))
+ }
+ }
+
+ function onMouseMove(event) {
+ var position = normalizePosition(
+ event.clientX - origin.x + imageOrigin.left,
+ event.clientY - origin.y + imageOrigin.top,
+ imageDimensions.galleryWidth,
+ imageDimensions.galleryHeight,
+ imageDimensions.width,
+ imageDimensions.height
+ );
+ image.css({position: 'absolute', top: position.y, left: position.x});
+ return false;
+ }
+
+ function setZoom(factor) {
+ zoomFactor = factor;
+ }
+
+ function zoom() {
+ imageDimensions.width = imageDimensions.originWidth * zoomFactor;
+ imageDimensions.height = imageDimensions.originHeight * zoomFactor;
+ var position = normalizePosition(
+ image.position().left,
+ image.position().top,
+ imageDimensions.galleryWidth,
+ imageDimensions.galleryHeight,
+ imageDimensions.width,
+ imageDimensions.height
+ );
+ console.log(image.position(), imageDimensions, position);
+ image.css({width: imageDimensions.width, height: imageDimensions.height,
+ left: position.x, top: position.y});
+
+ }
+
+ function onMouseUp(event) {
+ $(document)
+ .unbind('mousemove.gallery')
+ .unbind('mouseup.gallery');
+ return false;
+ }
+
+ image.bind('mousedown', function(event) {
+ origin = {
+ x: event.clientX,
+ y: event.clientY
+ };
+ imageOrigin = image.position();
+ $(document)
+ .bind('mousemove.gallery', onMouseMove)
+ .bind('mouseup.gallery', onMouseUp);
+ return false;
+ });
+
+ function updateGallery(url) {
+ $.ajax({
+ url: url,
+ type: 'GET',
+ dataType: 'json',
+
+ success: function(data) {
+ element.data('images', data);
+ pn.val(1);
+ pn.change();
+ $('img', element).show();
+ },