File FileAPI.js
has 3098 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*! FileAPI 2.0.7 - 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 266 lines of code (exceeds 25 allowed). Consider refactoring. Open
patch: function (){
api.flashEngine = true;
// FileAPI
_inherit(api, {
Function _send
has 216 lines of code (exceeds 25 allowed). Consider refactoring. Open
_send: function (options, data){
var _this = this, xhr, uid = _this.uid, onloadFuncName = _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 renderImageToCanvas
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
loadImage.renderImageToCanvas = function (
canvas,
img,
sourceX,
sourceY,
Function _send
has 76 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 66 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 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 onreadystatechange
has 48 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 getMatrix
has 47 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 readAsImage
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
readAsImage: function (file, fn, progress){
if( api.isFile(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 _addFile
has 43 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 mouseover
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
mouseover: function (evt){
if (!flash.disableMouseover) {
var target = api.event.fix(evt).target;
if( /input/i.test(target.nodeName) && target.type == 'file' && !target.disabled ){
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 _readEntryAsFiles
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _readEntryAsFiles(entry, callback){
if( !entry ){
// error
callback('invalid entry');
}
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 _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 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 _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 getDropFiles
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
getDropFiles: function (evt, callback){
var
files = []
, dataTransfer = _getDataTransfer(evt)
, entrySupport = _isArray(dataTransfer.items) && dataTransfer.items[0] && _getAsEntry(dataTransfer.items[0])
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 renderImageToCanvas
has 10 arguments (exceeds 4 allowed). Consider refactoring. Open
canvas,
img,
sourceX,
sourceY,
sourceWidth,
Function queue
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
queue: function (fn){
var
_idx = 0
, _length = 0
, _fail = false
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 _readAs
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _readAs(file, fn, as, encoding){
if( api.isBlob(file) && _hasSupportReadAs(as) ){
var Reader = new FileReader;
// Add event listener
Function queue
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
var queue = api.queue(function (){
flash.uploadInProgress = true;
flash.cmd(flashId, 'upload', {
url: _getUrl(options.url.replace(/([a-z]+)=(\?)&?/i, ''))
, data: data
Function select
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
select: function (evt){
try {
var
inp = flash.getInput(evt.flashId)
, uid = api.uid(inp)
Function getInfo
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
getInfo: function (file, fn){
var info = {}, readers = _infoReader.concat();
if( api.isFile(file) ){
(function _next(){
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 _
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,
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( _type != 'dragleave' ){
onHover.call(evt[currentTarget], true, evt);
}
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 (((!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
Avoid deeply nested control flow statements. Open
if( !wrapper ){
api.log('[err] FlashAPI.mouseover: js-fileapi-wrapper not found');
return;
}
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 (((!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( 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 {
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
outStr += b64.charAt(enc1) + b64.charAt(enc2) + b64.charAt(enc3) + b64.charAt(enc4);
- 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 46.
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