Skip to content

Commit

Permalink
add other deps
Browse files Browse the repository at this point in the history
  • Loading branch information
danengle committed Feb 28, 2014
1 parent cb67d21 commit a04f8b0
Show file tree
Hide file tree
Showing 4 changed files with 417 additions and 4 deletions.
12 changes: 8 additions & 4 deletions vendor/assets/javascripts/jquery-fileupload/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//=require jquery-fileupload/vendor/jquery.ui.widget
//=require jquery-fileupload/vendor/load-image
//=require jquery-fileupload/vendor/canvas-to-blob
//=require jquery-fileupload/vendor/tmpl
//=require jquery-fileupload/jquery.iframe-transport
//=require jquery-fileupload/jquery.fileupload
//=require jquery-fileupload/jquery.fileupload-ui
//=require jquery-fileupload/jquery.fileupload-jquery-ui
//=require jquery-fileupload/jquery.fileupload-process
//=require jquery-fileupload/jquery.fileupload-validate
//=require jquery-fileupload/jquery.fileupload-image
//=require jquery-fileupload/jquery.fileupload-audio
//=require jquery-fileupload/jquery.fileupload-video
//=require jquery-fileupload/jquery.fileupload-validate
//=require jquery-fileupload/jquery.fileupload-ui
//=require jquery-fileupload/jquery.fileupload-jquery-ui
//=require jquery-fileupload/locale
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* JavaScript Canvas to Blob 2.0.5
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
* Based on stackoverflow user Stoive's code snippet:
* http://stackoverflow.com/q/4998908
*/

/*jslint nomen: true, regexp: true */
/*global window, atob, Blob, ArrayBuffer, Uint8Array, define */

(function (window) {
'use strict';
var CanvasPrototype = window.HTMLCanvasElement &&
window.HTMLCanvasElement.prototype,
hasBlobConstructor = window.Blob && (function () {
try {
return Boolean(new Blob());
} catch (e) {
return false;
}
}()),
hasArrayBufferViewSupport = hasBlobConstructor && window.Uint8Array &&
(function () {
try {
return new Blob([new Uint8Array(100)]).size === 100;
} catch (e) {
return false;
}
}()),
BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
window.MozBlobBuilder || window.MSBlobBuilder,
dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
window.ArrayBuffer && window.Uint8Array && function (dataURI) {
var byteString,
arrayBuffer,
intArray,
i,
mimeString,
bb;
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
// Convert base64 to raw binary data held in a string:
byteString = atob(dataURI.split(',')[1]);
} else {
// Convert base64/URLEncoded data component to raw binary data:
byteString = decodeURIComponent(dataURI.split(',')[1]);
}
// Write the bytes of the string to an ArrayBuffer:
arrayBuffer = new ArrayBuffer(byteString.length);
intArray = new Uint8Array(arrayBuffer);
for (i = 0; i < byteString.length; i += 1) {
intArray[i] = byteString.charCodeAt(i);
}
// Separate out the mime component:
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// Write the ArrayBuffer (or ArrayBufferView) to a blob:
if (hasBlobConstructor) {
return new Blob(
[hasArrayBufferViewSupport ? intArray : arrayBuffer],
{type: mimeString}
);
}
bb = new BlobBuilder();
bb.append(arrayBuffer);
return bb.getBlob(mimeString);
};
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
if (CanvasPrototype.mozGetAsFile) {
CanvasPrototype.toBlob = function (callback, type, quality) {
if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
callback(dataURLtoBlob(this.toDataURL(type, quality)));
} else {
callback(this.mozGetAsFile('blob', type));
}
};
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
CanvasPrototype.toBlob = function (callback, type, quality) {
callback(dataURLtoBlob(this.toDataURL(type, quality)));
};
}
}
if (typeof define === 'function' && define.amd) {
define(function () {
return dataURLtoBlob;
});
} else {
window.dataURLtoBlob = dataURLtoBlob;
}
}(this));
228 changes: 228 additions & 0 deletions vendor/assets/javascripts/jquery-fileupload/vendor/load-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*
* JavaScript Load Image 1.3.1
* https://github.com/blueimp/JavaScript-Load-Image
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* iOS image scaling fixes based on
* https://github.com/stomita/ios-imagefile-megapixel
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/

/*jslint nomen: true, bitwise: true */
/*global window, document, URL, webkitURL, Blob, File, FileReader, define */

(function ($) {
'use strict';

// Loads an image for a given File object.
// Invokes the callback with an img or optional canvas
// element (if supported by the browser) as parameter:
var loadImage = function (file, callback, options) {
var img = document.createElement('img'),
url,
oUrl;
img.onerror = callback;
img.onload = function () {
if (oUrl && !(options && options.noRevoke)) {
loadImage.revokeObjectURL(oUrl);
}
callback(loadImage.scale(img, options));
};
if ((window.Blob && file instanceof Blob) ||
// Files are also Blob instances, but some browsers
// (Firefox 3.6) support the File API but not Blobs:
(window.File && file instanceof File)) {
url = oUrl = loadImage.createObjectURL(file);
// Store the file type for resize processing:
img._type = file.type;
} else {
url = file;
}
if (url) {
img.src = url;
return img;
}
return loadImage.readFile(file, function (e) {
var target = e.target;
if (target && target.result) {
img.src = target.result;
} else {
callback(e);
}
});
},
// The check for URL.revokeObjectURL fixes an issue with Opera 12,
// which provides URL.createObjectURL but doesn't properly implement it:
urlAPI = (window.createObjectURL && window) ||
(window.URL && URL.revokeObjectURL && URL) ||
(window.webkitURL && webkitURL);

// Detects subsampling in JPEG images:
loadImage.detectSubsampling = function (img) {
var iw = img.width,
ih = img.height,
canvas,
ctx;
if (iw * ih > 1024 * 1024) { // only consider mexapixel images
canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
ctx = canvas.getContext('2d');
ctx.drawImage(img, -iw + 1, 0);
// subsampled image becomes half smaller in rendering size.
// check alpha channel value to confirm image is covering edge pixel or not.
// if alpha value is 0 image is not covering, hence subsampled.
return ctx.getImageData(0, 0, 1, 1).data[3] === 0;
}
return false;
};

// Detects vertical squash in JPEG images:
loadImage.detectVerticalSquash = function (img, ih) {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
data,
sy,
ey,
py,
alpha;
canvas.width = 1;
canvas.height = ih;
ctx.drawImage(img, 0, 0);
data = ctx.getImageData(0, 0, 1, ih).data;
// search image edge pixel position in case it is squashed vertically:
sy = 0;
ey = ih;
py = ih;
while (py > sy) {
alpha = data[(py - 1) * 4 + 3];
if (alpha === 0) {
ey = py;
} else {
sy = py;
}
py = (ey + sy) >> 1;
}
return (py / ih) || 1;
};

// Renders image to canvas while working around iOS image scaling bugs:
// https://github.com/blueimp/JavaScript-Load-Image/issues/13
loadImage.renderImageToCanvas = function (img, canvas, width, height) {
var iw = img.width,
ih = img.height,
ctx = canvas.getContext('2d'),
vertSquashRatio,
d = 1024, // size of tiling canvas
tmpCanvas = document.createElement('canvas'),
tmpCtx,
dw,
dh,
dx,
dy,
sx,
sy;
ctx.save();
if (loadImage.detectSubsampling(img)) {
iw /= 2;
ih /= 2;
}
vertSquashRatio = loadImage.detectVerticalSquash(img, ih);
tmpCanvas.width = tmpCanvas.height = d;
tmpCtx = tmpCanvas.getContext('2d');
dw = Math.ceil(d * width / iw);
dh = Math.ceil(d * height / ih / vertSquashRatio);
dy = 0;
sy = 0;
while (sy < ih) {
dx = 0;
sx = 0;
while (sx < iw) {
tmpCtx.clearRect(0, 0, d, d);
tmpCtx.drawImage(img, -sx, -sy);
ctx.drawImage(tmpCanvas, 0, 0, d, d, dx, dy, dw, dh);
sx += d;
dx += dw;
}
sy += d;
dy += dh;
}
ctx.restore();
tmpCanvas = tmpCtx = null;
};

// Scales the given image (img or canvas HTML element)
// using the given options.
// Returns a canvas object if the browser supports canvas
// and the canvas option is true or a canvas object is passed
// as image, else the scaled image:
loadImage.scale = function (img, options) {
options = options || {};
var canvas = document.createElement('canvas'),
width = img.width,
height = img.height,
scale = Math.max(
(options.minWidth || width) / width,
(options.minHeight || height) / height
);
if (scale > 1) {
width = Math.ceil(width * scale);
height = Math.ceil(height * scale);
}
scale = Math.min(
(options.maxWidth || width) / width,
(options.maxHeight || height) / height
);
if (scale < 1) {
width = Math.ceil(width * scale);
height = Math.ceil(height * scale);
}
if (img.getContext || (options.canvas && canvas.getContext)) {
canvas.width = width;
canvas.height = height;
if (img._type === 'image/jpeg') {
loadImage
.renderImageToCanvas(img, canvas, width, height);
} else {
canvas.getContext('2d')
.drawImage(img, 0, 0, width, height);
}
return canvas;
}
img.width = width;
img.height = height;
return img;
};

loadImage.createObjectURL = function (file) {
return urlAPI ? urlAPI.createObjectURL(file) : false;
};

loadImage.revokeObjectURL = function (url) {
return urlAPI ? urlAPI.revokeObjectURL(url) : false;
};

// Loads a given File object via FileReader interface,
// invokes the callback with the event object (load or error).
// The result can be read via event.target.result:
loadImage.readFile = function (file, callback) {
if (window.FileReader && FileReader.prototype.readAsDataURL) {
var fileReader = new FileReader();
fileReader.onload = fileReader.onerror = callback;
fileReader.readAsDataURL(file);
return fileReader;
}
return false;
};

if (typeof define === 'function' && define.amd) {
define(function () {
return loadImage;
});
} else {
$.loadImage = loadImage;
}
}(this));
Loading

0 comments on commit a04f8b0

Please sign in to comment.