1
|
|
View Code Duplication |
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
|
|
|
// multi-language setting |
18
|
|
|
// $rootScope.langInstance = new Lang(); |
19
|
|
|
// $rootScope.langInstance.init({ |
20
|
|
|
// defaultLang: 'en', |
21
|
|
|
// currentLang: 'en', |
22
|
|
|
// }); |
23
|
|
|
|
24
|
|
|
// $rootScope.switchLanguage = function(langCode_iso639){ |
25
|
|
|
// $rootScope.langInstance.change(langCode_iso639) |
26
|
|
|
// } |
27
|
|
|
|
28
|
|
|
// initial the menu after the ng-include finished |
29
|
|
|
$rootScope.$on("$includeContentLoaded", function(event, templateName){ |
30
|
|
|
}); |
31
|
|
|
// https://docs.angularjs.org/api/ng/service/$location#events |
32
|
|
|
$rootScope.$on("$locationChangeStart", function(event, nUrl, oUrl, newState, oldState){ |
33
|
|
|
}); |
34
|
|
|
$rootScope.$on("$locationChangeSuccess", function(event, nUrl, oUrl, newState, oldState){ |
35
|
|
|
}); |
36
|
|
|
|
37
|
|
|
// https://docs.angularjs.org/api/ngRoute/directive/ngView#event-$viewContentLoaded |
38
|
|
|
$rootScope.$on("$viewContentLoaded", function(targetScope){ |
39
|
|
|
Prism.highlightAll(); |
40
|
|
|
Prism.fileHighlight(); |
41
|
|
|
|
42
|
|
|
$('.nav-tabs a').click(function (e) { |
43
|
|
|
e.preventDefault() |
44
|
|
|
$(this).tab('show') |
45
|
|
|
}) |
46
|
|
|
|
47
|
|
|
// if add <base target="_self"> in index.html, no effect. |
48
|
|
|
$('.nav-tabs a').attr('target','_self'); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
// https://ui-router.github.io/guide/transitions#lifecycle-events |
52
|
|
|
$transitions.onFinish({}, function(transition) { |
53
|
|
|
// console.dir("onFinish Transition from " + transition.from().name + |
54
|
|
|
// " to " + transition.to().name) |
55
|
|
|
}); |
56
|
|
|
|
57
|
|
|
$transitions.onSuccess({}, function(transition) { |
58
|
|
|
load_sbAdmin2Js(transition); |
59
|
|
|
var pageName = transition.to().name; |
|
|
|
|
60
|
|
|
|
61
|
|
|
// multi-language setting |
62
|
|
|
// $rootScope.langInstance.dynamic('en', '../demo/lang/demoHome.en.json'); |
63
|
|
|
// $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/demoHome.zh-hans.json'); |
64
|
|
|
// $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/demoHome.zh-hant.json'); |
65
|
|
|
|
66
|
|
|
// $rootScope.langInstance.dynamic('en', '../demo/lang/'+pageName+'.en.json'); |
67
|
|
|
// $rootScope.langInstance.dynamic('zh-hans', '../demo/lang/'+pageName+'.zh-hans.json'); |
68
|
|
|
// $rootScope.langInstance.dynamic('zh-hant', '../demo/lang/'+pageName+'.zh-hant.json'); |
69
|
|
|
// $rootScope.langInstance.loadPack($rootScope.langInstance.currentLang, function(err, lang, path){ |
70
|
|
|
// if (!err) { |
71
|
|
|
// } else { |
72
|
|
|
// console.log("load language pack failure") |
73
|
|
|
// console.log(err) |
74
|
|
|
// console.log(lang) |
75
|
|
|
// console.log(path) |
76
|
|
|
// } |
77
|
|
|
// }); |
78
|
|
|
}) |
79
|
|
|
|
80
|
|
|
function load_sbAdmin2Js(transition){ |
81
|
|
|
var toID = transition.$id; |
|
|
|
|
82
|
|
|
var toName = transition.to().name; |
83
|
|
|
var childName = toName.split("."); |
84
|
|
|
|
85
|
|
|
// initial the menu after the ng-include finished |
86
|
|
|
$('#side-menu').metisMenu('dispose'); |
87
|
|
|
$('ul.nav a[class="active"]').removeClass("active") |
88
|
|
|
$('#side-menu').metisMenu(); |
89
|
|
|
|
90
|
|
|
$(window).bind("load resize", function() { |
91
|
|
|
var topOffset = 50; |
92
|
|
|
var width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width; |
93
|
|
|
if (width < 768) { |
94
|
|
|
$('div.navbar-collapse').addClass('collapse'); |
95
|
|
|
topOffset = 100; // 2-row-menu |
96
|
|
|
} else { |
97
|
|
|
$('div.navbar-collapse').removeClass('collapse'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
var height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1; |
101
|
|
|
height = height - topOffset; |
102
|
|
|
if (height < 1) height = 1; |
103
|
|
|
if (height > topOffset) { |
104
|
|
|
$("#page-wrapper").css("min-height", (height) + "px"); |
105
|
|
|
} |
106
|
|
|
}); |
107
|
|
|
|
108
|
|
|
// keithpoon, 20180221, remove all class for single page application |
109
|
|
|
var element = $('ul.nav a[ui-sref]').filter(function() { |
110
|
|
|
var uiSref = $(this).attr('ui-sref') |
111
|
|
|
|
112
|
|
|
if(toName == uiSref) |
113
|
|
|
return true; |
114
|
|
|
if(childName.length>0) |
115
|
|
|
{ |
116
|
|
|
if(uiSref.indexOf('.') == 0) |
117
|
|
|
return uiSref.substring(1) == childName[childName.length-1]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return false; |
121
|
|
|
}).addClass('active').parent(); |
122
|
|
|
|
123
|
|
|
while (true) { |
124
|
|
|
if (element.is('li')) { |
125
|
|
|
element = element.parent().addClass('in').parent(); |
126
|
|
|
} else { |
127
|
|
|
break; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
}); |