File FileAPI.js
has 3146 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*! FileAPI 2.0.19 - BSD | git://github.com/mailru/FileAPI.git
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
*/
/*
Function patch
has 229 lines of code (exceeds 25 allowed). Consider refactoring. Open
patch: function (){
api.flashEngine = true;
// FileAPI
_inherit(api, {
Function _send
has 218 lines of code (exceeds 25 allowed). Consider refactoring. Open
_send: function (options, data){
var _this = this, xhr, uid = _this.uid, onLoadFnName = _this.uid + "Load", url = options.url;
api.log('XHR._send:', data);
Function upload
has 142 lines of code (exceeds 25 allowed). Consider refactoring. Open
upload: function (options){
options = _extend({
jsonp: 'callback'
, prepare: api.F
, beforeupload: api.F
Function _apply
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
_apply: function (image, fn){
var
canvas = getCanvas()
, m = this.getMatrix(image)
, ctx = canvas.getContext('2d')
Function getDropFiles
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Open
getDropFiles: function (evt, callback){
var
files = []
, all = []
, items
Function renderImageToCanvas
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
loadImage.renderImageToCanvas = function (
canvas,
img,
sourceX,
sourceY,
Function _send
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
_send: function (options, formData){
if(
formData.nodeName
|| formData.append && api.support.html5
|| api.isArray(formData) && (typeof formData[0] === 'string')
Function _getFormData
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
_getFormData: function (options, data, fn){
var
file = data.file
, name = data.name
, filename = file.name
Function transform
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
Image.transform = function (file, transform, autoOrientation, fn){
function _transform(err, img){
// img -- info object
var
images = {}
Function _readEntryAsFiles
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _readEntryAsFiles(entry, callback){
if( !entry ){
// error
var err = new Error('invalid entry');
entry = new Object(entry);
Function patchCamera
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
patchCamera: function () {
api.Camera.fallback = function (el, options, callback) {
var camId = api.uid();
api.log('FlashAPI.Camera.publish: ' + camId);
flash.publish(el, camId, api.extend(options, {
Function _transform
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _transform(err, img){
// img -- info object
var
images = {}
, queue = api.queue(function (err){
Function getMatrix
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
getMatrix: function (image){
var
m = api.extend({}, this.matrix)
, sw = m.sw = m.sw || image.videoWidth || image.naturalWidth || image.width
, sh = m.sh = m.sh || image.videoHeight || image.naturalHeight || image.height
Function _addFile
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
(function _addFile(file/**Object*/){
if( file.image ){ // This is a FileAPI.Image
queue.inc();
file.toData(function (err, image){
Function onreadystatechange
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
xhr.onreadystatechange = function (){
var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
_this.status = xhr.status;
_this.statusText = xhr.statusText;
Function readAsImage
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
readAsImage: function (file, fn, progress){
if( api.isBlob(file) ){
if( apiURL ){
/** @namespace apiURL.createObjectURL */
var data = apiURL.createObjectURL(file);
Function getFiles
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
getFiles: function (input, filter, callback){
var files = [];
if( callback ){
api.filterFiles(api.getFiles(input), filter, callback);
Function dnd
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
api.event.dnd = function (el, onHover, onDrop){
var _id, _type;
if( !onDrop ){
onDrop = onHover;
Function publish
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Camera.publish = function (el, options, callback){
if( typeof options == 'function' ){
callback = options;
options = {};
}
Function _apply
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
_apply: function (file, fn){
api.log('FlashAPI.Image._apply:', file);
if( _isHtmlFile(file) ){
this.parent.apply(this, arguments);
Function mouseover
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
mouseover: function (evt){
var target = api.event.fix(evt).target;
if( /input/i.test(target.nodeName) && target.type == 'file' && !target.disabled ){
var
Function _makeFlashImage
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _makeFlashImage(opts, base64, fn){
var
key
, flashId = api.uid()
, el = document.createElement('div')
Function load
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
load: function (url, fn){
var xhr = api.getXHR();
if( xhr ){
xhr.open('GET', url, true);
Function _convertFile
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _convertFile(file, fn, useBinaryString){
var blob = file.blob, filename = file.file;
if( filename ){
if( !blob.toDataURL ){
Function _getFilesDataArray
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
_getFilesDataArray: function (data){
var files = [], oFiles = {};
if( isInputFile(data) ){
var tmp = api.getFiles(data);
Function renderImageToCanvas
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
canvas,
img,
sourceX,
sourceY,
sourceWidth,
Function renderImageToCanvas
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
api.renderImageToCanvas = function (canvas, img, sx, sy, sw, sh, dx, dy, dw, dh){
Function queue
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
queue: function (fn){
var
_idx = 0
, _length = 0
, _fail = false
Function _readAs
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _readAs(file, fn, method, encoding){
if( api.isBlob(file) && _hasSupportReadAs(method) ){
var Reader = new FileReader;
// Add event listener
Function toPlainData
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
toPlainData: function (fn){
this._to({}, fn, function (file, data, queue){
if( file.file ){
data.type = file.file;
}
Function detectVerticalSquash
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
loadImage.detectVerticalSquash = function (img, subsampled) {
var naturalHeight = img.naturalHeight || img.height,
canvas = document.createElement('canvas'),
context = canvas.getContext('2d'),
data,
Function getInfo
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
getInfo: function (file, fn){
var info = {}, readers = _infoReader.concat();
if( api.isBlob(file) ){
(function _next(){
Function _isRegularFile
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _isRegularFile(file, callback){
// http://stackoverflow.com/questions/8856628/detecting-folders-directories-in-javascript-filelist-objects
if( !file.type && (safari || ((file.size % 4096) === 0 && (file.size <= 102400))) ){
if( FileReader ){
try {
Function _
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
, callback: _wrap(function _(err, base64){
api.log('FlashAPI.Image._apply.callback:', err);
_unwrap(_);
if( err ){
Function dataURLtoBlob
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
window.ArrayBuffer && window.Uint8Array && function (dataURI) {
var byteString,
arrayBuffer,
intArray,
i,
Function queue
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
var queue = api.queue(function (){
flash.cmd(flashId, 'upload', {
url: _getUrl(options.url.replace(/([a-z]+)=(\?)&?/i, ''))
, data: data
, files: fileId ? files : null
Avoid deeply nested control flow statements. Open
if( _type != 'dragleave' ){
onHover.call(evt[currentTarget], true, evt);
}
Avoid deeply nested control flow statements. Open
if( entry.isDirectory || (entry.isFile && file.name == file.name.normalize('NFC')) ){
items[i] = entry;
}
else {
items[i] = file;
Avoid deeply nested control flow statements. Open
if( !dataURLtoBlob && !api.flashEngine ){
Form.multipart = true;
}
Avoid deeply nested control flow statements. Open
if (((!xhr.status && !xhr.aborted) || 500 == xhr.status || 416 == xhr.status) && ++data.retry <= options.chunkUploadRetry) {
// let's try again the same chunk
// only applicable for recoverable error codes 500 && 416
var delay = xhr.status ? 0 : api.chunkNetworkDownRetryTimeout;
Avoid deeply nested control flow statements. Open
if( !trans[idx].postName ){
addOrigin = 1;
}
Avoid deeply nested control flow statements. Open
if (data.end == data.size - 1) {
// finished
_this.end(xhr.status);
} else {
// next chunk
Avoid deeply nested control flow statements. Open
if (((!xhr.status && !xhr.aborted) || 500 == xhr.status) && (options.retry || 0) < options.uploadRetry) {
options.retry = (options.retry || 0) + 1;
var delay = api.networkDownRetryTimeout;
// inform about recoverable problems
Consider simplifying this complex logical expression. Open
if( ( proxyXHR.statusText != 'abort' || proxyXHR.current ) && data ){
// Mark active job
_complete = false;
// Set current upload file
Consider simplifying this complex logical expression. Open
if( navigator.plugins && typeof navigator.plugins['Shockwave Flash'] == 'object' ){
has = navigator.plugins['Shockwave Flash'].description && !(mime && mime['application/x-shockwave-flash'] && !mime['application/x-shockwave-flash'].enabledPlugin);
}
else {
try {
Consider simplifying this complex logical expression. Open
if (((!xhr.status && !xhr.aborted) || 500 == xhr.status) && (options.retry || 0) < options.uploadRetry) {
options.retry = (options.retry || 0) + 1;
var delay = api.networkDownRetryTimeout;
// inform about recoverable problems
Function _emit
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function _emit(target, fn, name, res, ext){
Similar blocks of code found in 2 locations. Consider refactoring. Open
else {
dw = round(sf >= df ? min(sw, dw) : dh*sf);
dh = round(sf >= df ? dw/sf : min(sh, dh));
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 63.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
else if( strategy == 'min' ){
dw = round(sf < df ? min(sw, dw) : dh*sf);
dh = round(sf < df ? dw/sf : min(sh, dh));
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 63.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
top: box.top + (window.pageYOffset || docEl.scrollTop) - (docEl.clientTop || body.clientTop || 0)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 45.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
, left: box.left + (window.pageXOffset || docEl.scrollLeft) - (docEl.clientLeft || body.clientLeft || 0)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 45.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76