Completed
Push — master ( f4255b...0c6fc8 )
by Xu
706:28 queued 666:46
created

cropper.min.js ➔ ... ➔ $(ꞌ[data-method]ꞌ).click   D

Complexity

Conditions 10
Paths 11

Size

Total Lines 1

Duplication

Lines 1
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
c 1
b 0
f 0
nc 11
nop 0
dl 1
loc 1
rs 4.8196

How to fix   Complexity   

Complexity

Complex classes like cropper.min.js ➔ ... ➔ $(ꞌ[data-method]ꞌ).click often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
jQuery(function(){"use strict";var e=jQuery("#image"),r=jQuery("#x"),o=jQuery("#y"),t=jQuery("#height"),a=jQuery("#width"),i={viewMode:1,dragMode:"move",autoCropArea:1,restore:!1,highlight:!1,cropBoxMovable:!1,cropBoxResizable:!1,aspectRatio:1,preview:".img-preview",crop:function(e){r.val(Math.round(e.x)),o.val(Math.round(e.y)),t.val(Math.round(e.height)),a.val(Math.round(e.width)),jQuery("#inputImage").val()||(jQuery(".btn-group button").attr("disabled",!0),jQuery(".cropper-view-box").hide(),jQuery(".cropper-wrap-box").hide())}};e.cropper(i),jQuery(".docs-buttons").on("click","[data-method]",function(){var r,o,t=jQuery(this),a=t.data();if(!t.prop("disabled")&&!t.hasClass("disabled")){if(e.data("cropper")&&a.method){if(void 0!==(a=jQuery.extend({},a)).target&&(r=jQuery(a.target),void 0===a.option))try{a.option=JSON.parse(r.val())}catch(e){console.log(e.message)}if(o=e.cropper(a.method,a.option,a.secondOption),$.isPlainObject(o)&&r)try{r.val(JSON.stringify(o))}catch(e){console.log(e.message)}}return!1}}),jQuery(document.body).on("keydown",function(r){if(e.data("cropper")&&!(this.scrollTop>300))switch(r.which){case 37:r.preventDefault(),e.cropper("move",-1,0);break;case 38:r.preventDefault(),e.cropper("move",0,-1);break;case 39:r.preventDefault(),e.cropper("move",1,0);break;case 40:r.preventDefault(),e.cropper("move",0,1)}});var p,c=jQuery("#inputImage"),n=window.URL||window.webkitURL;n?c.change(function(){var r,o=this.files;e.data("cropper")&&(o&&o.length&&(r=o[0],/^image\/\w+$/.test(r.type)?(p=n.createObjectURL(r),e.one("built.cropper",function(){n.revokeObjectURL(p)}).cropper("reset").cropper("replace",p)):window.alert("Please choose an image file.")),jQuery(".btn-group button").removeAttr("disabled"))}):c.prop("disabled",!0).parent().addClass("disabled")});
0 ignored issues
show
Bug introduced by
The variable e seems to be never initialized.
Loading history...
Bug introduced by
The variable r does not seem to be initialized in case void(0) !== a = jQuery.e...), void(0) === a.option on line 1 is false. Are you sure this can never be the case?
Loading history...
Complexity Best Practice introduced by
There is no return statement if !t.prop("disabled") && !t.hasClass("disabled") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
Bug introduced by
The variable e does not seem to be initialized in case void(0) !== a = jQuery.e...), void(0) === a.option on line 1 is false. Are you sure this can never be the case?
Loading history...
2
//# sourceMappingURL=cropper.min.js.map