GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

demo.js ➔ load_sbAdmin2Js   F
last analyzed

Complexity

Conditions 17

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 12
dl 0
loc 16
rs 1.8
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like demo.js ➔ load_sbAdmin2Js 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
app.run(function($rootScope, $transitions, $timeout, $q, $trace){
2
    // http://prismjs.com/extending.html#highlight-all
3
    // Rerun Prism syntax highlighting on the current page
4
    // http://prismjs.com/plugins/normalize-whitespace/
5
    Prism.plugins.NormalizeWhitespace.setDefaults({
6
        // 'remove-trailing': true,
7
        // 'remove-indent': true,
8
        'left-trim': true,
9
        // 'right-trim': true,
10
        /*'break-lines': 80,
11
        'indent': 2,
12
        'remove-initial-line-feed': false,
13
        'tabs-to-spaces': 4,
14
        'spaces-to-tabs': 4*/
15
    });
16
		
17
	$rootScope.imageShowcaseCounter = 0;
18
19
    // multi-language setting
20
    // $rootScope.langInstance = new Lang();
21
    // $rootScope.langInstance.init({
22
    //     defaultLang: 'en',
23
    //     currentLang: 'en',
24
    // });
25
26
    // $rootScope.switchLanguage = function(langCode_iso639){
27
    //     $rootScope.langInstance.change(langCode_iso639)
28
    // }
29
    
30
    // initial the menu after the ng-include finished
31
    $rootScope.$on("$includeContentLoaded", function(event, templateName){
32
    });
33
    // https://docs.angularjs.org/api/ng/service/$location#events
34
    $rootScope.$on("$locationChangeStart", function(event, nUrl, oUrl, newState, oldState){
35
    });
36
    $rootScope.$on("$locationChangeSuccess", function(event, nUrl, oUrl, newState, oldState){
37
    });
38
  
39
    // https://docs.angularjs.org/api/ngRoute/directive/ngView#event-$viewContentLoaded
40
    $rootScope.$on("$viewContentLoaded", function(targetScope){
41
        Prism.highlightAll();
42
        Prism.fileHighlight();
43
44
        $('.nav-tabs a').click(function (e) {
45
            e.preventDefault()
46
            $(this).tab('show')
47
        })
48
    
49
        // if add <base target="_self"> in index.html, no effect.
50
        $('.nav-tabs a').attr('target','_self');
51
		
52
    });
53
54
    // https://ui-router.github.io/guide/transitions#lifecycle-events
55
    $transitions.onFinish({}, function(transition) {
56
        // console.dir("onFinish Transition from " + transition.from().name +
57
        //   " to " + transition.to().name)
58
    });
59
60
    $transitions.onSuccess({}, function(transition) {
61
        load_sbAdmin2Js(transition);
62
		create_custom_modal_listner();
63
        var pageName = transition.to().name;
64
		
65
		
66
		$(".nav-item a").removeClass("active");
67
		$(".nav-item").removeClass("active");
68
		$("[ui-sref="+pageName+"]").addClass("active");
69
		$("[ui-sref="+pageName+"]").parent(".nav-item").addClass("active");
70
71
        // multi-language setting
72
        // $rootScope.langInstance.dynamic('en', '../demo/lang/demoHome.en.json');
73
        // $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/demoHome.zh-hans.json');
74
        // $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/demoHome.zh-hant.json');
75
        
76
        // $rootScope.langInstance.dynamic('en', '../demo/lang/'+pageName+'.en.json');
77
        // $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/'+pageName+'.zh-hans.json');
78
        // $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/'+pageName+'.zh-hant.json');
79
        // $rootScope.langInstance.loadPack($rootScope.langInstance.currentLang, function(err, lang, path){
80
        //     if (!err) {
81
        //     } else {
82
        //         console.log("load language pack failure")
83
        //         console.log(err)
84
        //         console.log(lang)
85
        //         console.log(path)
86
        //     }
87
        // });
88
    })
89
  
90
    function load_sbAdmin2Js(transition){
91
        var toID = transition.$id;
0 ignored issues
show
Unused Code introduced by
The variable toID seems to be never used. Consider removing it.
Loading history...
92
        var toName = transition.to().name;
93
        var childName = toName.split(".");
0 ignored issues
show
Unused Code introduced by
The variable childName seems to be never used. Consider removing it.
Loading history...
94
		
95
		var t = jQuery;
96
		t("#sidebarToggle, #sidebarToggleTop").on("click",function(o){t("body").toggleClass("sidebar-toggled"),t(".sidebar").toggleClass("toggled"),t(".sidebar").hasClass("toggled")&&t(".sidebar .collapse").collapse("hide")}),t(window).resize(function(){t(window).width()<768&&t(".sidebar .collapse").collapse("hide")}),t("body.fixed-nav .sidebar").on("mousewheel DOMMouseScroll wheel",function(o){if(768<t(window).width()){var e=o.originalEvent,l=e.wheelDelta||-e.detail;this.scrollTop+=30*(l<0?1:-1),o.preventDefault()}}),t(document).on("scroll",function(){100<t(this).scrollTop()?t(".scroll-to-top").fadeIn():t(".scroll-to-top").fadeOut()}),t(document).on("click",".scroll-to-top",function(o){var e=t(this);var h=e.attr('href')||e.data('href');t("html, body").stop().animate({scrollTop:t(h).offset().top},1e3,"easeInOutExpo"),o.preventDefault()});
0 ignored issues
show
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...
97
		
98
		// 20191016, keithpoon, change all header color
99
		$("h1").addClass("text-gray-900");
100
		$("h2").addClass("text-gray-900");
101
		$("h3").addClass("text-gray-900");
102
		$("h4").addClass("text-gray-900");
103
		$("h5").addClass("text-gray-800");
104
		$("h6").addClass("text-gray-800");
105
    }
106
	
107
	function create_custom_modal_listner(){
108
		$(document).on('click', '[data-toggle="lightbox"]', function(event){
109
			event.preventDefault();
110
			var jqObj = $(this);
111
			var jsObj = this;
112
			
113
			var modalObj = extract_modal_info(jqObj, jsObj);
114
			
115
			load_custom_modal(modalObj);
116
		});
117
	}
118
	
119
	function extract_modal_info(jqObj, jsObj){
120
		var modalObj = {
121
			modalTitle: "",
122
			modalContent: "",
123
			modalFooter: ""
124
		};
125
			
126
		var elementContent = jqObj.html();
127
		var elementTitle = "";
128
		var elementFooter = "";
129
		
130
		$.each(this.attributes, function() {
131
		// this.attributes is not a plain object, but an array
132
		// of attribute nodes, which contain both the name and value
133
			if(this.specified) {
134
				var attrName = this.name;
135
				var attrValue = this.value;
136
				
137
				if(attrName == "data-title") elementTitle = attrValue;
138
			}
139
		});
140
		
141
		modalObj.modalContent = elementContent;
142
		modalObj.modalTitle = elementTitle;
143
		modalObj.modalFooter = elementFooter;
144
			
145
		return modalObj;
146
	}
147
	
148
	function load_custom_modal(modalObj){
149
		remove_modal();
150
		create_modal(modalObj);
151
	}
152
	
153
	function remove_modal(){
154
		$(".imageShowcaseModal").off();
155
		$(".imageShowcaseModal").remove();
156
		$(".modal-backdrop").off();
157
		$(".modal-backdrop").remove();
158
	}
159
	
160
	/*
161
	function create_modal(modalContent, modalTitle, modalFooter){
162
		if (typeof(modalTitle) == "undefined") modalTitle = "";
163
		if (typeof(modalFooter) == "undefined") modalFooter = "";
164
		*/
165
	function create_modal(modalObj){
166
		var modalContent = modalObj.modalContent;
167
		var modalTitle = modalObj.modalTitle;
168
		var modalFooter = modalObj.modalFooter;
169
		
170
		$rootScope.imageShowcaseCounter += 1;
171
		
172
		var modal_id = "imageShowcase_"+$rootScope.imageShowcaseCounter;
173
		
174
		var modal = ''+
175
'<div class="modal fade imageShowcaseModal" id="'+modal_id+'" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">'+
176
  '<div class="modal-dialog modal-full" role="document">'+
177
    '<div class="modal-content">'+
178
      '<div class="modal-header">'+
179
        '<h5 class="modal-title" id="exampleModalLabel">'+modalTitle+'</h5>'+
180
        '<button type="button" class="close" data-dismiss="modal" aria-label="Close">'+
181
          '<span aria-hidden="true">&times;</span>'+
182
        '</button>'+
183
      '</div>'+
184
      '<div class="modal-body">'+
185
	  modalContent+
186
      '</div>'+
187
      '<div class="modal-footer">'+
188
      modalFooter+
189
      '</div>'+
190
    '</div>'+
191
  '</div>'+
192
'</div>';
193
		$("body").append(modal);
194
		
195
		$("#"+modal_id).modal('show');
196
		$("#"+modal_id+" button.close").click(function(){
197
			$("#"+modal_id).modal('hide');
198
		})
199
	}
200
201
});