Completed
Pull Request — master (#26)
by Juliette
05:21
created

page/interaction.min.js   B

Complexity

Total Complexity 42
Complexity/F 2.47

Size

Lines of Code 1
Function Count 17

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
c 0
b 0
f 0
nc 36
dl 0
loc 1
rs 8.295
wmc 42
mnd 3
bc 41
fnc 17
bpm 2.4117
cpm 2.4705
noi 2

How to fix   Complexity   

Complexity

Complex classes like page/interaction.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
/* Javascript interaction for PHP cheat sheets */
2
jQuery(document).ready(function(){var myAccordion;var phpvForm;var myTabs;var formTabField;var windowTitle;var tabPanels;myAccordion=jQuery("#accordion");myAccordion.accordion({active:false,collapsible:true,icons:{header:"ui-icon-circle-arrow-e",activeHeader:"ui-icon-circle-arrow-s"},heightStyle:"content"});phpvForm=jQuery("#choose-version");phpvForm.on("change","select",function(){phpvForm.submit()});myTabs=jQuery("#tabs");formTabField=jQuery("#phpv-tab");windowTitle=jQuery("title");myTabs.tabs({beforeActivate:function(event,ui){var oldId=ui.oldPanel.find("table").attr("id");if(oldId){jQuery("#"+oldId).thfloat("destroy")}},activate:function(event,ui){var tableId;var tabHref;var tabTab;var tabTitle;tableId=ui.newPanel.find("table").attr("id");if(tableId){jQuery("#"+tableId).thfloat({side:"head",onShow:function(table,block){block.find("th").css("background","")}}).thfloat({side:"foot",onShow:function(table,block){block.find("th").css("background","")}})}jQuery(".hover, .sticky").removeClass("hover sticky");tabHref=ui.newTab.find("a").attr("href");tabTab=ui.newTab.find("a").attr("data-tab");tabTitle=ui.newTab.find("a").attr("data-tab-title");if(tabHref&&tabTab&&tabTitle){var oldTab=ui.oldTab.find("a").attr("data-tab");var oldTitle=ui.oldTab.find("a").attr("data-tab-title");var titleText=windowTitle.text();if(titleText.indexOf(":: "+oldTitle)!==-1){titleText=titleText.replace(":: "+oldTitle,":: "+tabTitle)}else{var oldTabNoUnderscore=oldTab.replace("_"," ");if(titleText.indexOf(":: "+oldTabNoUnderscore)!==-1){titleText=titleText.replace(":: "+oldTabNoUnderscore,":: "+tabTitle)}else{var oldTitlePre=titleText.substring(0,titleText.indexOf(" Cheatsheet for "));titleText=oldTitlePre+titleText.replace(oldTitlePre," :: "+tabTitle)}}if(tabHref.substring(0,1)==="#"){var oldUri=window.location.href;if(oldUri.indexOf("#")!==-1&&window.location.hash==="#"+oldTab){tabHref=oldUri.replace(window.location.hash,tabHref)}else{tabHref=oldUri+tabHref}}else{tabHref=tabHref.substring(0,tabHref.indexOf("/ajax")+1)}history.pushState(null,titleText,tabHref);windowTitle.text(titleText);formTabField.val(tabTab)}},beforeLoad:function(event,ui){if(ui.panel.html()===""){ui.panel.html('<div class="spinner">&nbsp;</div>');ui.jqXHR.error(function(){ui.panel.html("An error occurred while loading the table. Please try again. If it keeps failing, please inform the site owner.")});return true}return false},cache:true,create:function(event,ui){var tabHash=window.location.hash;if(tabHash&&tabHash!==""){if(formTabField.val()===""){formTabField.val(tabHash.replace("#",""))}var tabTitle=ui.tab.find("a").attr("data-tab-title");var titleText=windowTitle.text();var oldTitlePre=titleText.substring(0,titleText.indexOf(" Cheatsheet for "));titleText=oldTitlePre+titleText.replace(oldTitlePre," :: "+tabTitle);windowTitle.text(titleText)}},load:function(event,ui){var tableId=ui.panel.find("table").attr("id");jQuery("#"+tableId).thfloat({side:"head",onShow:function(table,block){block.find("th").css("background","")}}).thfloat({side:"foot",onShow:function(table,block){block.find("th").css("background","")}})}});myTabs.on("click",".fright a",function(){myAccordion.accordion("option","active",1)});jQuery(".ui-tabs-panel th [title]").tooltip({tooltipClass:"th-tooltip",content:function(){var element=jQuery(this);var toolTip;toolTip=element.attr("title");toolTip=toolTip.replace(/\n/g,"<br />");toolTip=toolTip.replace(/\t/g,"&nbsp;&nbsp;&nbsp;&nbsp;");return toolTip}});tabPanels=jQuery(".ui-tabs-panel");tabPanels.on("mouseenter","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;if(rowIdx>1){jQuery(this).parent().addClass("hover")}if(idx>1){jQuery(".ui-tabs-panel td:nth-child("+idx+")").addClass("hover");jQuery(".ui-tabs-panel th:nth-child("+idx+")").addClass("hover");jQuery(".thfloat th:nth-child("+idx+")").addClass("hover")}});tabPanels.on("mouseleave","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;if(rowIdx>1){jQuery(this).parent().removeClass("hover")}if(idx>1){jQuery(".ui-tabs-panel td:nth-child("+idx+")").removeClass("hover");jQuery(".ui-tabs-panel th:nth-child("+idx+")").removeClass("hover");jQuery(".thfloat th:nth-child("+idx+")").removeClass("hover")}});tabPanels.on("click","td, th",function(){var idx=jQuery(this).parent().children("td,th").index(jQuery(this))+1;var rowIdx=jQuery(this).parent().parent().children("tr").index(jQuery(this).parent())+1;var tCells=jQuery(".ui-tabs-panel td:nth-child("+idx+")");var tHeaders=jQuery(".ui-tabs-panel th:nth-child("+idx+")");var fHeaders=jQuery(".thfloat th:nth-child("+idx+")");if(jQuery(this).parent().hasClass("sticky")||jQuery("td:nth-child("+idx+")").hasClass("sticky")||jQuery("th:nth-child("+idx+")").hasClass("sticky")){if(rowIdx>1){jQuery(this).parent().removeClass("sticky")}if(idx>1){tCells.removeClass("sticky");tHeaders.removeClass("sticky");fHeaders.removeClass("sticky")}}else{if(rowIdx>1){jQuery(this).parent().addClass("sticky")}if(idx>1){tCells.addClass("sticky");tHeaders.addClass("sticky");fHeaders.addClass("sticky")}}})});
2 ignored issues
show
Coding Style introduced by
As per coding-style, prefer block-scoped variables using let or const which have better semantics than var.

Since ECMAScript 6, you can create block-scoped vars or constants with the keywords let or const. These variables/constants are only valid in the code block where they have been declared.

Consider the following two pieces of code:

if (true)
 {
    var x = "Hello, Stonehenge!";
}

console.log(x); //prints Hello, Stonehenge! to the console

and

if (true)
 {
    let x = "Hello, Stonehenge!";
}

console.log(x); //ReferenceError: x is not defined

The variable is not defined otuside of its block. This limits bleeding of variables into other contexts.

To know more about this ECMA6 feature, look at the MDN pages on let and const.

Loading history...
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ 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...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3