Passed
Branch master (53d0e8)
by Chris
08:37
created

vendor/uix/assets/js/uix-modals.min.js   B

Complexity

Total Complexity 47
Complexity/F 2.61

Size

Lines of Code 1
Function Count 18

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 47
eloc 1
mnd 29
bc 29
fnc 18
dl 0
loc 1
rs 8.64
bpm 1.6111
cpm 2.6111
noi 9
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like vendor/uix/assets/js/uix-modals.min.js 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
!function(a){var b,c,d,e=null,f={},g=[],h=[],i=function(){if(g.length||h.length){var a=g.length?g[g.length-1]:h[h.length-1],i=d.width(),j=d.height(),k=f[a].config.height,l=k,m=f[a].config.width,n=0,o=!1,p=!1;if(e&&b.addClass("has-uix-modal"),n=(j-f[a].config.height)/2.2,0>n&&(n=0),k+2*f[a].config.padding>j&&e&&(k=j-2*f[a].config.padding,l="100%",e&&e.css({paddingTop:f[a].config.padding,paddingBottom:f[a].config.padding}),p=!0),m+2*f[a].config.padding>=i&&(m="100%",e&&e.css({paddingLeft:f[a].config.padding,paddingRight:f[a].config.padding}),p=!0),!0===p&&(700>=i&&i>600?(e&&(k=j-2*f[a].config.padding),m=i,l=k-2*f[a].config.padding,m="100%",n=0,e&&e.css({padding:f[a].config.padding})):600>=i&&(e&&(k=j),m=i,l="100%",n=0,e&&e.css({padding:0}))),e&&e.is(":hidden")&&(o=!0,e.show()),f[a].header&&(e&&e.show(),k-=f[a].header.outerHeight(),f[a].closer.css({padding:f[a].header.outerHeight()/2-.5}),f[a].title.css({paddingRight:f[a].closer.outerWidth()})),f[a].footer&&(e&&e.show(),k-=f[a].footer.outerHeight()),e&&o===!0&&(e.hide(),o=!1),k!=l&&f[a].body.css({height:k}),f[a].modal.css({width:m}),f[a].config.sticky&&f[a].config.minimized){var q={},r=f[a].title.outerHeight()-f[a].modal.outerHeight();f[a].config.sticky.indexOf("bottom")>-1?q["margin-bottom"]=r:f[a].config.sticky.indexOf("top")>-1&&(q["margin-top"]=r),f[a].modal.css(q),f[a].config.sticky.length>=3&&(c.css("margin-"+f[a].config.sticky[0],f[a].title.outerHeight()),p?f[a].modal.css(f[a].config.sticky[1],0):f[a].modal.css(f[a].config.sticky[1],parseFloat(f[a].config.sticky[2])))}return e&&(f[a].modal.css({marginTop:n,height:l}),setTimeout(function(){f[a].modal.addClass("uix-animate")},10),e.fadeIn(f[a].config.speed)),f}},j=function(c){var d=a(c).data("modal"),h=0,i={};if(c&&f[d].config.sticky)return f[d].config.minimized?(f[d].config.minimized=!1,h=0):(f[d].config.minimized=!0,h=f[d].title.outerHeight()-f[d].modal.outerHeight()),f[d].config.sticky.indexOf("bottom")>-1?i["margin-bottom"]=h:f[d].config.sticky.indexOf("top")>-1&&(i["margin-top"]=h),void f[d].modal.stop().animate(i,f[d].config.speed);var j;g.length&&(j=g.pop(),f[j].modal.hasClass("uix-animate")&&!g.length?(f[j].modal.removeClass("uix-animate"),setTimeout(function(){f[j].modal.remove(),delete f[j]},500)):e&&f[j].modal.hide(0,function(){a(this).remove(),delete f[j]})),g.length?f[g[g.length-1]].modal.show():(e&&e.fadeOut(250,function(){a(this).remove(),e=null}),b.removeClass("has-uix-modal"))};a.uixModal=function(b,d){var k=a.extend(!0,{element:"div",height:550,width:620,padding:12,speed:250,content:conduitModal},b);k.trigger=d,e||k.sticky||(e=a("<div>",{"class":"uix-backdrop"}),k.focus||e.on("click",function(a){a.target==this&&j()}),c.append(e),e.hide());var l=k.element,m=k.modal;if(g.length&&g[g.length-1]!==m&&f[g[g.length-1]].modal.hide(),"undefined"==typeof f[m]?(k.sticky&&(k.sticky=k.sticky.split(" "),k.sticky.length<2&&(k.sticky=null),h.push(m)),f[m]={config:k,modal:a("<"+l+">",{id:m+"_uixModal",tabIndex:-1,"ariaLabelled-by":m+"_uixModalLable","class":"uix-modal-wrap"+(k.sticky?" uix-sticky-modal "+k.sticky[0]+"-"+k.sticky[1]:"")})},k.sticky||g.push(m)):(f[m].config=k,f[m].modal.empty()),k.animate&&e){var n=k.animate.split(" "),o=k.speed+"ms",p=k.animateEase?k.animateEase:"ease";1===n.length&&(n[1]=0),f[m].modal.css({transform:"translate("+n[0]+", "+n[1]+")","-web-kit-transition":"transform "+o+" "+p,"-moz-transition":"transform "+o+" "+p,transition:"transform "+o+" "+p})}if(f[m].body=a("<div>",{"class":"uix-modal-body",id:m+"_uixModalBody"}),f[m].content=a("<div>",{"class":"uix-modal-content",id:m+"_uixModalContent"}),f[m].content.css({margin:k.padding}),f[m].body.append(f[m].content).appendTo(f[m].modal),e?e.append(f[m].modal):f[m].modal.appendTo(a("body")),k.footer)if(f[m].footer=a("<div>",{"class":"uix-modal-footer",id:m+"_uixModalFooter"}),f[m].footer.css({padding:k.padding}),f[m].footer.appendTo(f[m].modal),"function"==typeof window[k.footer])f[m].footer.append(window[k.footer](k,f[m]));else if("string"==typeof k.footer)try{var q=a(k.footer);f[m].footer.html(q.html())}catch(r){f[m].footer.html(k.footer)}if(k.title){var s="prependTo";f[m].header=a("<div>",{"class":"uix-modal-title",id:m+"_uixModalTitle"}),f[m].closer=a("<a>",{href:"#close","class":"uix-modal-closer","data-dismiss":"modal","aria-hidden":"true",id:m+"_uixModalCloser"}).html("&times;"),f[m].title=a("<h3>",{"class":"modal-label",id:m+"_uixModalLable"}),f[m].title.html(k.title).appendTo(f[m].header),f[m].title.css({padding:k.padding}),f[m].title.append(f[m].closer),f[m].config.sticky?(f[m].config.minimized&&!0!==f[m].config.minimized&&(setTimeout(function(){f[m].title.trigger("click")},parseInt(f[m].config.minimized)),f[m].config.minimized=!1),f[m].closer.hide(),f[m].title.addClass("uix-modal-closer").data("modal",m).appendTo(f[m].header),f[m].config.sticky.indexOf("top")>-1&&(s="appendTo")):f[m].closer.data("modal",m).appendTo(f[m].header),f[m].header[s](f[m].modal)}if(f[m].modal.outerHeight(k.height),f[m].modal.outerWidth(k.width),k.content)if("function"==typeof k.content)f[m].content.append(k.content(k,f[m]));else if("string"==typeof k.content)try{var t=a(k.content);t.length?(f[m].content.append(t.detach()),t.show()):f[m].content.html(k.content)}catch(r){f[m].content.html(k.content)}return i(),f[m]},a.fn.uixModal=function(e){return b=a("html"),c=a("body"),d=a(window),e||(e={}),e=a.extend({},this.data(),e),a.uixModal(e,this)},window.addEventListener?(window.addEventListener("resize",i,!1),window.addEventListener("keypress",function(a){27===a.keyCode&&null!==e&&e.trigger("click")},!1)):window.attachEvent?window.attachEvent("onresize",i):window.onresize=i,a(document).on("click","[data-modal]:not(.uix-modal-closer)",function(b){b.preventDefault(),a(this).uixModal()}),a(document).on("click",".uix-modal-closer",function(b){b.preventDefault(),a(window).trigger("close.modal")}),a(window).on("close.modal",function(a){j()}),a(window).on("modal.init",function(b){a("[data-modal][data-autoload]").each(function(){a(this).uixModal()})}),a(window).load(function(){a(window).trigger("modal.init")})}(jQuery);
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if g.length || h.length 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...
Unused Code introduced by
The parameter a is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The assignment to variable m seems to be never used. Consider removing it.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable conduitModal seems to be never declared. If this is a global, consider adding a /** global: conduitModal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The assignment to variable o seems to be never used. Consider removing it.
Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Unused Code introduced by
The parameter b is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...