(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o max) { return max; } return value; } module.exports = assertBetween; },{}],11:[function(require,module,exports){ 'use strict'; function assertKeyValuePair(key, value) { if (typeof key === 'object') { return key; } var returnValue = {}; returnValue[key] = value; return returnValue; } module.exports = assertKeyValuePair; },{}],12:[function(require,module,exports){ 'use strict'; /** * @param {fabric.Image} obj * @param {int} width * @param {int} height * @param {string} units * @return {Object} * axis: STRING, * dim: OBJECT( width: NUMBER, height: NUMBER), * width: NUMBER, * height: NUMBER, * ppmm: NUMBER */ function calcCrop(obj, width, height, units) { var cropRatio = width / height; var objRatio = obj.width / obj.height; var returnValue = { image: obj, axis: objRatio > cropRatio ? 'x' : 'y', dim: { width: Number(width), height: Number(height), units: units }, width: obj.width * obj.scaleX, height: obj.height * obj.scaleY, objectRatio: objRatio, cropRatio: cropRatio }; if (objRatio > cropRatio) { returnValue.width *= cropRatio / objRatio; } else { returnValue.height /= cropRatio / objRatio; } // Pixels per millimeter returnValue.ppmm = returnValue.width / ((returnValue.dim.width * obj.scaleX) * 10); return returnValue; } module.exports = calcCrop; },{}],13:[function(require,module,exports){ 'use strict'; function isAspectChanged(x1, y1, x2, y2) { return (Math.abs(x1 / y1 - x2 / y2) > 0.01); } module.exports = isAspectChanged; },{}],14:[function(require,module,exports){ 'use strict'; function isFullscreen() { return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement; } module.exports = isFullscreen; },{}],15:[function(require,module,exports){ 'use strict'; function isMobile() { return $(window).width() < 768; } module.exports = isMobile; },{}],16:[function(require,module,exports){ 'use strict'; var MouseMetrics = { previousMouseData: { x: null, y: null }, deletePreviousMouseData: function() { MouseMetrics.previousMouseData = { x: null, y: null }; }, setPreviousMouseData: function(values) { MouseMetrics.previousMouseData = { x: values.x || null, y: values.y || null, }; }, }; module.exports = MouseMetrics; },{}],17:[function(require,module,exports){ 'use strict'; /** * @param {fabric.Object} obj * @param {Object} bounds * @return {fabric.Object} */ function setPositionInside(obj, bounds) { ['left', 'top'].forEach(function (v) { if (obj[v] < bounds[v].min) { obj.set(v, bounds[v].min).setCoords(); } if (obj[v] > bounds[v].max) { obj.set(v, bounds[v].max).setCoords(); } }); return obj; } module.exports = setPositionInside; },{}],18:[function(require,module,exports){ 'use strict'; /** * @param {Object} obj * @param {Object} properties */ function setProperties(obj, properties) { for (var o in properties) { if (properties.hasOwnProperty(o)) { Object.defineProperty(obj, o, properties[o]); } } } module.exports = setProperties; },{}],19:[function(require,module,exports){ 'use strict'; function supportsFullscreen() { return document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullScreen || document.documentElement.mozRequestFullScreen || document.documentElement.msRequestFullscreen; } module.exports = supportsFullscreen; },{}],20:[function(require,module,exports){ 'use strict'; var isFullscreen = require('./is-fullscreen'); /** * Toggles the full screen state for passed DOM object * @param {HTMLElement} elm */ function toggleFullscreen(elem) { if (isFullscreen()) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } return; } if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullScreen) { elem.webkitRequestFullScreen(); } else if (elem.mozRequestFullScreen) { elem.mozRequestFullScreen(); } else if (elem.msRequestFullscreen) { elem.msRequestFullscreen(); } } module.exports = toggleFullscreen; },{"./is-fullscreen":14}],21:[function(require,module,exports){ 'use strict'; var config = require('./includes/config'); var util = require('./includes/util'); /** * This is just an example usage of the image editor. Also this is used for testing. * This code can be pretty messy, but that is fine because nothing of this will come to * production. */ (function() { var $document = $(document); var $window = $(window); var $wrapper = $('#wrapper'); var $formControl = $('#form-control'); var editor = null; // Inputs for the editor var $input = { w: $formControl.find('input[name="w"]'), h: $formControl.find('input[name="h"]'), units: $formControl.find('select[name="units"]'), image_id: $formControl.find('input[name="image_id"]'), mirror: $formControl.find('input[name="mirror"]'), noCrop: $formControl.find('input[name="no-crop"]'), border: $formControl.find('select[name="canvas-border"]'), }; var imageUrl = '//images.photowall.com/products/' + $input.image_id.val() + '.jpg?h=450'; function getOptimalDimension(values, currentDimension, ratio) { if (currentDimension === 'h') { values.width = Math.round(values.height * ratio); } else { values.height = Math.round(values.width / ratio); } return values; } function handleDimensionChange() { var noCropIsChecked = $input.noCrop.is(':checked'); var data = editor.canvas.getViewport().getData(); var values = { width: $input.w.val(), height: $input.h.val(), }; if (noCropIsChecked) { var currentDimension = $(this).attr('name') === 'h' ? 'h' : 'w'; values = getOptimalDimension(values, currentDimension, data.objectRatio); } $input.w.val(values.width); $input.h.val(values.height); editor.crop(values.width, values.height, $input.units.val()); } function handleMirrorChange() { editor.canvas.getMirror().set(this.checked); } function handleNoCropChange() { $input.w.trigger('input'); } function handleFrameChange() { if ($(this).val() === 'none') { editor.canvas.toggle3D(false); } editor.canvas.getViewport().setFrame($(this).val()); } function handleResize() { var width = $wrapper.width(); var height = util.isFullscreen() ? $window.height() : $wrapper.height(); if (util.isFullscreen()) { editor.canvas.getHighResolutionUrl('//images.photowall.com/products/' + $input.image_id.val() + '.jpg?h=1000'); console.log('resized fullscreen'); } editor.canvas.resize({width: width, height: height}); } function getWrapperData() { var $navbar = $('.image-editor__navbar'); var isFullScreen = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement; var isMobile = $window.width() <= config.screenSizes.mobile.max; var windowHeight = window.innerHeight ? window.innerHeight : $window.height(); var windowWidth = window.innerWidth ? window.innerWidth : $window.width(); return { width: isFullScreen ? windowWidth : (isMobile ? windowWidth : $wrapper.width()), height: isFullScreen ? windowHeight : (isMobile ? windowHeight - $navbar.height() : $wrapper.height()) }; } function eventHandlers() { $input.w.on('input', handleDimensionChange); $input.h.on('input', handleDimensionChange); $input.mirror.on('change', handleMirrorChange); $input.noCrop.on('change', handleNoCropChange); $input.border.on('change', handleFrameChange); $document .on('PIE:dragged', function() { console.log('Dragged the image/dragbar!'); }) .on('PIE:needs-dragging', function(e, data) { console.log('Image needs dragging on: ' + data.axis); }) .on('PIE:dragbar-click', function(e, data) { console.log('Clicked on a dragbar! Axis: ' + data.axis); }) .on('PIE:image-start-load', function() { console.log('Start loading image'); }) .on('PIE:image-end-load', function() { console.log('Image loaded'); }); $window.on('resize', handleResize); } function init() { editor = new ImageEditor('canvas-editor', { type: 'canvas', buttons: { showThreeD: '3d', hideThreeD: 'Flat', showMurals: 'show-murals', hideMurals: 'hide-murals', showRulers: 'show-rulers', hideRulers: 'hide-rulers', showFullscreen: 'show-fullscreen', hideFullscreen: 'exit-fullscreen', }, dimensions: getWrapperData() }) .loadImage(imageUrl, function() { $input.w.trigger('input'); handleResize(); }); eventHandlers(); } init(); }()); },{"./includes/config":1,"./includes/util":9}]},{},[21]);