-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathCore.Navigation.js
55 lines (52 loc) · 2.23 KB
/
Core.Navigation.js
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
/*globals Core, define, require*/
(function () {
var coreNavigation = function (communication, moduleGrouping) {
var slice = [].slice,
currentModuleGroup = "",
startModuleGroup = function (moduleGroupName) {
if (moduleGroupName !== currentModuleGroup) {
moduleGrouping.stopModuleGroupingAndStartAnotherGrouping(currentModuleGroup, moduleGroupName);
currentModuleGroup = moduleGroupName;
}
},
navigateTo = function (moduleGroup, raisesEvents, args) {
var i, arrayLength, event;
startModuleGroup(moduleGroup);
if (raisesEvents !== undefined) {
for (i = 0, arrayLength = raisesEvents.length; i < arrayLength; i++) {
event = raisesEvents[i];
communication.notify(event, args[i]);
}
}
communication.notify("NavigationFinished");
},
loadAndNavigateTo = function (moduleGroup, raisesEvents, args) {
require([moduleGroup], function () {
navigateTo(moduleGroup, raisesEvents, args);
});
};
return {
addNavigation: function (navigationItem) {
var wrapper = function () {
navigateTo(navigationItem.startsModuleGroup, navigationItem.raisesEvents, slice.call(arguments, 0));
};
communication.addListener(navigationItem.listensTo, wrapper);
},
addLoadAndNavigate: function (navigationItem) {
var wrapper = function () {
loadAndNavigateTo(navigationItem.startsModuleGroup, navigationItem.raisesEvents, slice.call(arguments, 0));
};
communication.addListener(navigationItem.listensTo, wrapper);
}
};
};
if (typeof define === "function" && define.amd) {
define("Core.Navigation", ["Core", "Core.Communication", "Core.ModuleGrouping"], function (core, coreCommunication, coreModuleGrouping) {
core.Navigation = coreNavigation(coreCommunication, coreModuleGrouping);
return core.Navigation;
});
}
else {
Core.Navigation = coreNavigation(Core.Communication, Core.ModuleGrouping);
}
})();