1 | import {SharedUiComponent} from "./shareduicomponent";
|
2 |
|
3 | export default class cjsSharedPopup extends SharedUiComponent {
|
4 | constructor() {
|
5 | super();
|
6 | this.componentId = "cjsSharedPopup";
|
7 | this.template = require("./cjs-shared-popup.html");
|
8 | }
|
9 | isNative() {
|
10 | return false;
|
11 |
|
12 | }
|
13 | controller($scope) {
|
14 | var self = $scope.componentDefinition;
|
15 | self.scope = $scope;
|
16 | self.defaultController = function() { };
|
17 |
|
18 | $scope.hideModal = function() {
|
19 | var routeScope = self.app.scopesForRoutes[self.route];
|
20 | if (self.data.closeCallback) {
|
21 | routeScope.$eval(self.data.closeCallback)(self.data);
|
22 | }
|
23 |
|
24 |
|
25 | self.app.setSharedUiComponentState(routeScope, "cjs-shared-popup", false, true, self.data);
|
26 | };
|
27 | $scope.runOnMainScope = function(funcName, params) {
|
28 | var routeScope = self.app.scopesForRoutes[self.route];
|
29 | if (routeScope) {
|
30 | routeScope.$eval(funcName).apply(undefined, params);
|
31 | }
|
32 | };
|
33 | $scope.runOnMainScopeAndClose = function(funcName, params) {
|
34 | $scope.hideModal();
|
35 | var routeScope = self.app.scopesForRoutes[self.route];
|
36 | if (routeScope) {
|
37 | routeScope.$eval(funcName).apply(undefined, params);
|
38 | }
|
39 | };
|
40 |
|
41 | }
|
42 | setState(self, route, active, available, data) {
|
43 | self.data = data;
|
44 | self.route = route;
|
45 |
|
46 | if (window.NativeNav) {
|
47 | if (active && !self.popuptrigger) {
|
48 | self.scrollX = window.scrollX;
|
49 | self.scrollY = window.scrollY;
|
50 | self.originRect = null;
|
51 | if (data.element && data.element.length) {
|
52 | self.originRect = data.element[0].getBoundingClientRect();
|
53 | }
|
54 | window.NativeNav.startNativeTransition("popup", self.originRect, function() {
|
55 | angular.element("body").addClass("cjs-shared-popup-active");
|
56 | if (screen.width < 600) {
|
57 | document.getElementById("viewport").setAttribute("content", "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0");
|
58 | } else {
|
59 | document.getElementById("viewport").setAttribute("content", "width=500, height=500, initial-scale=1, maximum-scale=1, user-scalable=0");
|
60 | }
|
61 | window.scrollTo(0, 0);
|
62 | self.popuptrigger = {};
|
63 | self.nativeTransition = true;
|
64 | self.app.scopesForRoutes[self.route].$apply();
|
65 | window.NativeNav.finishNativeTransition();
|
66 | },
|
67 | self.scope.hideModal
|
68 | );
|
69 | } else if (!active && self.popuptrigger) {
|
70 | window.NativeNav.startNativeTransition("closepopup", self.originRect, function() {
|
71 | angular.element("body").removeClass("cjs-shared-popup-active");
|
72 | document.getElementById("viewport").setAttribute("content", "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0");
|
73 | self.popuptrigger = null;
|
74 | self.app.scopesForRoutes[self.route].$apply();
|
75 | window.scrollTo(self.scrollX, self.scrollY);
|
76 | window.NativeNav.finishNativeTransition();
|
77 | });
|
78 | }
|
79 | } else {
|
80 | if (!active) {
|
81 | self.popuptrigger = null;
|
82 | } else {
|
83 | self.popuptrigger = {
|
84 | element: data.element,
|
85 | additionalClasses: data.additionalClasses
|
86 | };
|
87 | }
|
88 | }
|
89 | }
|
90 | }
|