1 | import template from "./viewport2.html";
|
2 | @Directive({
|
3 | template: template,
|
4 | selector: "viewport",
|
5 | injections: ["$compile", "$injector"]
|
6 | })
|
7 | class Viewport2 {
|
8 | constructor(scope, element, attrs, $compile, $injector) {
|
9 | this.$compile = $compile;
|
10 | this.$injector = $injector;
|
11 | this.element = element;
|
12 | this.scope = scope;
|
13 | element.removeClass("viewport-preload");
|
14 | element.addClass("viewport2");
|
15 |
|
16 | var self = this;
|
17 | scope.go = function(a, b, c) { self.go(a, b, c); };
|
18 |
|
19 | scope.changePage = scope.go;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | }
|
26 | go(route) {
|
27 | if (typeof route == "string") {
|
28 |
|
29 | route = route.split("/").slice(1);
|
30 | }
|
31 | console.log("going to " + route);
|
32 |
|
33 | var page = this.app.topLevelRoutes.getPageForRoute(route);
|
34 |
|
35 | if (!page) {
|
36 | console.error("Invalid route " + route);
|
37 | return;
|
38 | }
|
39 |
|
40 | this.currentPage = page;
|
41 |
|
42 | if (this.currentPageElement) {
|
43 | this.currentPageElement.remove();
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 | var pageEl = $("<div>New Page</div>");
|
49 |
|
50 | pageEl.html(page.template);
|
51 |
|
52 | this.element.append(pageEl);
|
53 |
|
54 | var newScope = this.scope.$new();
|
55 | var ctrl = page.pageCtrl[page.pageCtrl.length - 1];
|
56 | newScope.ctrl = page;
|
57 |
|
58 | var sharedUi = this.$injector.get("sharedUi");
|
59 | var loadStatus = this.$injector.get("loadStatus");
|
60 |
|
61 | ctrl(newScope, sharedUi, loadStatus);
|
62 |
|
63 | this.$compile(pageEl)(newScope);
|
64 |
|
65 |
|
66 |
|
67 | this.currentPageElement = pageEl;
|
68 | console.log(page.parentSections);
|
69 | for (var i = 0; i < page.parentSections.length; i++) {
|
70 | var section = page.parentSections[i];
|
71 | section.activated(newScope);
|
72 | if (section.scopeName) {
|
73 | newScope[section.scopeName] = section;
|
74 | }
|
75 | }
|
76 |
|
77 |
|
78 | page.activated(newScope);
|
79 |
|
80 |
|
81 |
|
82 | }
|
83 | }
|
84 |
|
85 | export default Viewport2; |
\ | No newline at end of file |