This repository was archived by the owner on Sep 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathcore.js
More file actions
189 lines (165 loc) · 5.87 KB
/
Copy pathcore.js
File metadata and controls
189 lines (165 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
var mod_core = angular.module("ct.ui.router.extras.core", [ "ui.router" ]);
mod_core.config([ '$stateProvider', '$injector', 'uirextras_coreProvider', function ($stateProvider, $injector, uirextras_coreProvider) {
// Decorate any state attribute in order to get access to the internal state representation.
$stateProvider.decorator('parent', function (state, parentFn) {
// Capture each internal UI-Router state representations as opposed to the user-defined state object.
// The internal state is, e.g., the state returned by $state.$current as opposed to $state.current
var core = uirextras_coreProvider.$get();
core.internalStates[state.self.name] = state;
// Add an accessor for the internal state from the user defined state
state.self.$$state = function () {
return core.internalStates[state.self.name];
};
angular.forEach(core.stateRegisteredCallbacks, function(callback) { callback(state); });
return parentFn(state);
});
}]);
var DEBUG = false;
var forEach = angular.forEach;
var extend = angular.extend;
var isArray = angular.isArray;
var map = function (collection, callback) {
"use strict";
var result = [];
forEach(collection, function (item, index) {
result.push(callback(item, index));
});
return result;
};
var keys = function (collection) {
"use strict";
return map(collection, function (collection, key) {
return key;
});
};
var filter = function (collection, callback) {
"use strict";
var result = [];
forEach(collection, function (item, index) {
if (callback(item, index)) {
result.push(item);
}
});
return result;
};
var filterObj = function (collection, callback) {
"use strict";
var result = {};
forEach(collection, function (item, index) {
if (callback(item, index)) {
result[index] = item;
}
});
return result;
};
// Duplicates code in UI-Router common.js
function ancestors(first, second) {
var path = [];
for (var n in first.path) {
if (first.path[n] !== second.path[n]) break;
path.push(first.path[n]);
}
return path;
}
// Duplicates code in UI-Router common.js
function objectKeys(object) {
if (Object.keys) {
return Object.keys(object);
}
var result = [];
angular.forEach(object, function (val, key) {
result.push(key);
});
return result;
}
/**
* like objectKeys, but includes keys from prototype chain.
* @param object the object whose prototypal keys will be returned
* @param ignoreKeys an array of keys to ignore
*/
// Duplicates code in UI-Router common.js
function protoKeys(object, ignoreKeys) {
var result = [];
for (var key in object) {
if (!ignoreKeys || ignoreKeys.indexOf(key) === -1)
result.push(key);
}
return result;
}
// Duplicates code in UI-Router common.js
function arraySearch(array, value) {
if (Array.prototype.indexOf) {
return array.indexOf(value, Number(arguments[2]) || 0);
}
var len = array.length >>> 0, from = Number(arguments[2]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) from += len;
for (; from < len; from++) {
if (from in array && array[from] === value) return from;
}
return -1;
}
// Duplicates code in UI-Router common.js
// Added compatibility code (isArray check) to support both 0.2.x and 0.3.x series of UI-Router.
function inheritParams(currentParams, newParams, $current, $to) {
var parents = ancestors($current, $to), parentParams, inherited = {}, inheritList = [];
for (var i in parents) {
if (!parents[i].params) continue;
// This test allows compatibility with 0.2.x and 0.3.x (optional and object params)
parentParams = isArray(parents[i].params) ? parents[i].params : objectKeys(parents[i].params);
if (!parentParams.length) continue;
for (var j in parentParams) {
if (arraySearch(inheritList, parentParams[j]) >= 0) continue;
inheritList.push(parentParams[j]);
inherited[parentParams[j]] = currentParams[parentParams[j]];
}
}
return extend({}, inherited, newParams);
}
function inherit(parent, extra) {
return extend(new (extend(function () { }, {prototype: parent}))(), extra);
}
mod_core.provider("uirextras_core", function() {
var stateRegisteredCallbacks = [];
function onStateRegistered(callback) { stateRegisteredCallbacks.push(callback); }
var _StickyState; // internal reference to $stickyStateProvider
var internalStates = {}; // Map { statename -> InternalStateObj } holds internal representation of all states
var root; // Root state, internal representation
var pendingTransitions = []; // One transition may supersede another. This holds references to all pending transitions
var pendingRestore; // The restore function from the superseded transition
var inactivePseudoState; // This pseudo state holds all the inactive states' locals (resolved state data, such as views etc)
var reactivatingLocals = { }; // This is a prent locals to the inactivePseudoState locals, used to hold locals for states being reactivated
var versionHeuristics = { // Heuristics used to guess the current UI-Router Version
hasParamSet: false
};
var core = {
nr: Math.round(Math.random()*1000),
internalStates: internalStates,
stateRegisteredCallbacks: stateRegisteredCallbacks,
_StickyState: _StickyState,
root: root,
pendingTransitions: pendingTransitions,
pendingRestore: pendingRestore,
inactivePseudoState: inactivePseudoState,
reactivatingLocals: reactivatingLocals,
versionHeuristics: versionHeuristics,
onStateRegistered: onStateRegistered,
forEach: forEach,
extend: extend,
isArray: isArray,
map: map,
keys: keys,
filter: filter,
filterObj: filterObj,
ancestors: ancestors,
objectKeys: objectKeys,
protoKeys: protoKeys,
arraySearch: arraySearch,
inheritParams: inheritParams,
inherit: inherit
};
angular.extend(this, core);
this.$get = function() {
return core;
};
});