CSIT Fix for SDC-2585
[sdc.git] / catalog-ui / src / app / view-models / welcome / welcome-view.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 'use strict';
22
23 export interface IWelcomeViewMode {
24     onCloseButtonClick():void;
25 }
26
27 export class WelcomeViewModel {
28
29     firstLoad:boolean = true;
30     alreadyAnimated:Array<number> = [];
31
32     static '$inject' = [
33         '$scope',
34         '$state'
35     ];
36
37     constructor(private $scope:IWelcomeViewMode,
38                 private $state:ng.ui.IStateService
39                ) {
40         this.init();
41         this.initScope();
42         window.setTimeout(():void => {
43             this.loadImages(():void=> {
44                 window.setTimeout(():void =>{
45                     $(".sdc-welcome-new-page").addClass("animated fadeIn");
46                 },1000);
47             });
48         },0);
49     }
50
51     private initScope = ():void => {
52         let timeout = window.setTimeout(():void => {
53             this.$state.go("dashboard", {});
54         }, 4000);
55         this.$scope.onCloseButtonClick = ():void => {
56             window.clearTimeout(timeout);
57             this.$state.go("dashboard", {});
58         }
59     };
60
61     private init = ():void => {
62         let viewModelsHtmlBasePath:string = 'src/app/view-models/';
63         $('body').keyup((e):void=> {
64             if (e.keyCode == 27) { // escape key maps to keycode `27`
65                 this.$state.go('dashboard');
66             }
67         });
68     };
69
70     private loadImages = (callback:Function):void => {
71         let src = $('.sdc-welcome-wrapper').css('background-image');
72         let url = src.match(/\((.*?)\)/)[1].replace(/('|")/g,'');
73
74         let img = new Image();
75         img.onload = function() {
76             callback();
77         };
78         img.src = url;
79     };
80     
81 }