(function (global) {
var // a model for the region of the image about to be cropped
boundingBox,
// an array of draggable elements that modify the crop region
handles = [],
// `overlay` is a canvas element that allows us to darken the portion of the image that will be removed.
overlay,
// `ctx` will be the drawing context for `overlay`
ctx;
function loadImage () {
var // `buffer` is a canvas element that displays the actual image to crop
buffer = document.querySelector('#buffer'),
// `img` is an img element we use to load the img, though we never add it to the DOM
img = document.createElement('img');
img.src = 'https://raw.github.com/Reactive-Extensions/RxJS/master/examples/crop/images/leaf%20twirl.jpg';
// Returns an observable which fires when the image is loaded
return Rx.DOM.fromEvent(img, 'load').select(function () {
overlay.width = img.width;
overlay.height = img.height;
buffer.width = img.width;
buffer.height = img.height;
buffer.getContext('2d').drawImage(img, 0, 0);
return {
width: img.width,
height: img.height
};
});
}
function initBoundingBox(size) {
boundingBox = {
x: 0,
y: 0,
x2: size.width,
y2: size.height
};
}
function createHandles () {
var container = document.getElementById('container');
function createHandle (id, render, updateModel) {
var handle = document.createElement('div');
handle.className += ' handle';
handle.setAttribute('id', id);
container.appendChild(handle);
// `render` allows us to visually update the handle after it has been dragged
handle['render'] = render;
// `updateModel` allows us to...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.