Completed
Push — master ( c90dfa...c2f681 )
by Juliette
23s
created

$(document).ready   D

Complexity

Conditions 10
Paths 20

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
c 0
b 0
f 0
nc 20
nop 2
dl 0
loc 1
rs 4.8196

How to fix   Complexity   

Complexity

Complex classes like $(document).ready 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
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