summaryrefslogtreecommitdiff
blob: aafdff8095d2cdcf107e28b97eb910f177b2939a (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport">
    <title></title>

    <script type="text/javascript">

        (function() {

            var appName, appUrl, appIcon, cssPath, originUrl, height;
            var appBar,
                    closeBtnBox,
                    closeBtn,
                    iconBox,
                    appInfo,
                    appTitle,
                    appLink,
                    openBtnBox,
                    openBtn,
                    openText;


            var DOMLoadTimer = setInterval(function () {
                if (/loading|loaded|complete/i.test(document.readyState)) {
                    clearInterval(DOMLoadTimer);
                    documentLoaded();
                }
            }, 10);

            function documentLoaded() {
                parseParams();
                loadCssStyle();
                initializeBar();
                resizeElements();
                translate("-100%");
                document.body.style.display = "block";

                window.onhashchange = onHashChange;

                // show the bar
                setTimeout(function(){
                    show();
                }, 300);
            }

            function parseParams(){
                var hash = window.location.hash.split("#")[1];

                var params = hash.split("&");
                for (var i=0; i<params.length; i++){
                    var item = params[i].split("=");
                    var prop = item[0];
                    var value = item[1];

                    switch (prop){
                        case "appName": appName = value; break;
                        case "appUrl": appUrl = value; break;
                        case "appIcon": appIcon = value; break;
                        case "cssPath": cssPath = value; break;
                        case "originUrl": originUrl = decodeURIComponent(value); break;
                        case "height": height = value; break;
                        case "openText": openText = decodeURIComponent(value); break;
                        default: break;
                    }
                }
            }

            function loadCssStyle(){
                var _dc = (new Date()).getTime();
                var css = document.createElement("link");
                css.type = 'text/css';
                css.rel = 'stylesheet';
                css.href = cssPath+'?_dc='+_dc;
                css.async = true;
                (document.head || document.getElementsByTagName('head')[0]).appendChild(css);
            }

            function initializeBar(){

                appBar = document.querySelector("app-bar");
                closeBtnBox = document.querySelector("app-box.close");
                closeBtn = document.querySelector("app-box.close app-text");
                iconBox = document.querySelector("app-box.icon");
                appInfo = document.querySelector("app-info");
                appTitle = document.querySelector("app-info app-title");
                appLink = document.querySelector("app-info app-link");
                openBtnBox = document.querySelector("app-box.open");
                openBtn = document.querySelector("app-box.open app-text");

                // hide icon container if the app doesn't have an icon
                if (appIcon && appIcon.length > 0) {
                    var icon = document.querySelector("app-box.icon app-icon");
                    icon.style.backgroundImage = "url('" + appIcon + "')";
                } else {
                    iconBox.style.display = 'none';
                }

                appTitle.innerHTML = decodeURIComponent(appName);
                appLink.innerHTML = decodeURIComponent(appUrl);

                // set bar height
                appBar.style.height = height + "px";

                // set open button text
                openBtn.innerHTML = openText;

                // add events
                closeBtnBox.addEventListener("click", function(){hide();}, false);
                iconBox.addEventListener("click", function(){openApp();}, false);
                appInfo.addEventListener("click", function(){openApp();}, false);
                openBtnBox.addEventListener("click", function(){openApp();}, false);
            }


            function resizeElements(){

                // set bar height
                appBar.style.height = height + "px";

                // resize close btn box
                closeBtnBox.style.width = Math.round(0.35*height) + "px";

                // resize close btn font size
                closeBtn.style.fontSize = Math.round(0.22*height) + "px";

                // resize icon box
                iconBox.style.width = Math.round(0.70*height) + "px";
                iconBox.style.height = Math.round(0.70*height) + "px";

                // resize app title font size
                appTitle.style.fontSize = Math.round(0.18*height) + "px";

                // resize app link font size
                appLink.style.fontSize = Math.round(0.13*height) + "px";

                // resize app info padding left
                appInfo.style.paddingLeft = Math.round(0.1*height) + "px";

                // resize open btn box
                openBtnBox.style.width = Math.round(0.7*height) + "px";

                // resize open btn font size
                openBtn.style.fontSize = Math.round(0.14*height) + "px";

                // resize bar box shadow
                var shadow = Math.round(height * 0.1);
                appBar.style.boxShadow = "0px 0px "+shadow+"px rgba(164, 164, 164, 0.7)";
            }


            function onHashChange(){
                parseParams();
                resizeElements();
            }


            function translate(translateValue, time){
                time = time || 0;

                var style = {
                    '-webkit-transition': 'all '+time+'s ease',
                    '-moz-transition': 'all '+time+'s ease',
                    '-o-transition': 'all '+time+'s ease',
                    'transition': 'all '+time+'s ease',
                    '-webkit-transform': 'translate3d(0px, ' + translateValue + ', 0px)',
                    '-moz-transform': 'translate3d(0px, ' + translateValue + ', 0px)',
                    '-ms-transform': 'translate3d(0px, ' + translateValue + ', 0px)',
                    '-o-transform': 'translate3d(0px, ' + translateValue + ', 0px)',
                    'transform': 'translate3d(0px, ' + translateValue + ', 0px)'
                };

                appBar = document.querySelector("app-bar");

                for (var prop in style){
                    appBar.style[prop] = style[prop];
                }
            }


            function show(){
                translate("0%", 0.3);
            }

            function hide(){
                translate("-105%", 0.3);

                // change opener window hash
                var origin = originUrl.split("#")[0];
                window.parent.location = origin + "#app_action=closebar";
            }

            function openApp(){
                // change opener window hash
                var origin = originUrl.split("#")[0];
                window.parent.location = origin + "#app_action=openapp";
            }

        }());

    </script>

</head>

<body style="display:none">
<app-bar>
    <app-box class="close"><app-text>x</app-text></app-box>

    <app-box class="icon">
        <app-icon style=""></app-icon>
    </app-box>

    <app-info>
        <app-title></app-title>
        <app-link></app-link>
    </app-info>

    <app-box class="open"><app-text></app-text></app-box>
</app-bar>
</body>
</html>