]> git.proxmox.com Git - sencha-touch.git/blame - src/examples/kiva/.sencha/app/microloader/testing.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / examples / kiva / .sencha / app / microloader / testing.js
CommitLineData
c4685c84
TL
1/**
2 * Sencha Blink - Testing
3 * @author Jacky Nguyen <jacky@sencha.com>
4 */
5(function(global) {
6 var head = global.document.head || global.document.getElementsByTagName('head')[0],
7 Ext = global.Ext;
8
9 if (typeof Ext == 'undefined') {
10 global.Ext = Ext = {};
11 }
12
13 function write(content) {
14 document.write(content);
15 }
16
17 function addMeta(name, content) {
18 var meta = document.createElement('meta');
19
20 meta.setAttribute('name', name);
21 meta.setAttribute('content', content);
22 head.appendChild(meta);
23 }
24
25 Ext.blink = function(options) {
26 var scripts = options.js || [],
27 styleSheets = options.css || [],
28 i, ln, path, platform, theme, exclude;
29
30 if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
31 var msViewportStyle = document.createElement("style");
32 msViewportStyle.appendChild(
33 document.createTextNode(
34 "@media screen and (orientation: portrait) {" +
35 "@-ms-viewport {width: 320px !important;}" +
36 "}" +
37 "@media screen and (orientation: landscape) {" +
38 "@-ms-viewport {width: 560px !important;}" +
39 "}"
40 )
41 );
42 document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
43 }
44 addMeta('viewport', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no');
45 addMeta('apple-mobile-web-app-capable', 'yes');
46 addMeta('apple-touch-fullscreen', 'yes');
47
48 Ext.microloaded = true;
49
50 var filterPlatform = window.Ext.filterPlatform = function(platform) {
51 var profileMatch = false,
52 ua = navigator.userAgent,
53 j, jln;
54
55 platform = [].concat(platform);
56
57 function isPhone(ua) {
58 var isMobile = /Mobile(\/|\s)/.test(ua);
59
60 // Either:
61 // - iOS but not iPad
62 // - Android 2
63 // - Android with "Mobile" in the UA
64
65 return /(iPhone|iPod)/.test(ua) ||
66 (!/(Silk)/.test(ua) && (/(Android)/.test(ua) && (/(Android 2)/.test(ua) || isMobile))) ||
67 (/(BlackBerry|BB)/.test(ua) && isMobile) ||
68 /(Windows Phone)/.test(ua);
69 }
70
71 function isTablet(ua) {
72 return !isPhone(ua) && (/iPad/.test(ua) || /Android|Silk/.test(ua) || /(RIM Tablet OS)/.test(ua) ||
73 (/MSIE 10/.test(ua) && /; Touch/.test(ua)));
74 }
75
76 // Check if the ?platform parameter is set in the URL
77 var paramsString = window.location.search.substr(1),
78 paramsArray = paramsString.split("&"),
79 params = {},
80 testPlatform, i;
81
82 for (i = 0; i < paramsArray.length; i++) {
83 var tmpArray = paramsArray[i].split("=");
84 params[tmpArray[0]] = tmpArray[1];
85 }
86
87 testPlatform = params.platform;
88 if (testPlatform) {
89 return platform.indexOf(testPlatform) != -1;
90 }
91
92 for (j = 0, jln = platform.length; j < jln; j++) {
93 switch (platform[j]) {
94 case 'phone':
95 profileMatch = isPhone(ua);
96 break;
97 case 'tablet':
98 profileMatch = isTablet(ua);
99 break;
100 case 'desktop':
101 profileMatch = !isPhone(ua) && !isTablet(ua);
102 break;
103 case 'ios':
104 profileMatch = /(iPad|iPhone|iPod)/.test(ua);
105 break;
106 case 'android':
107 profileMatch = /(Android|Silk)/.test(ua);
108 break;
109 case 'blackberry':
110 profileMatch = /(BlackBerry|BB)/.test(ua);
111 break;
112 case 'safari':
113 profileMatch = /Safari/.test(ua) && !(/(BlackBerry|BB)/.test(ua));
114 break;
115 case 'chrome':
116 profileMatch = /Chrome/.test(ua);
117 break;
118 case 'ie10':
119 profileMatch = /MSIE 10/.test(ua);
120 break;
121 case 'windows':
122 profileMatch = /MSIE 10/.test(ua) || /Trident/.test(ua);
123 break;
124 case 'tizen':
125 profileMatch = /Tizen/.test(ua);
126 break;
127 case 'firefox':
128 profileMatch = /Firefox/.test(ua);
129 }
130 if (profileMatch) {
131 return true;
132 }
133 }
134 return false;
135 };
136
137 for (i = 0,ln = styleSheets.length; i < ln; i++) {
138 path = styleSheets[i];
139
140 if (typeof path != 'string') {
141 platform = path.platform;
142 exclude = path.exclude;
143 theme = path.theme;
144 path = path.path;
145 }
146
147 if (platform) {
148 if (!filterPlatform(platform) || filterPlatform(exclude)) {
149 continue;
150 }
151 if(!Ext.theme) {
152 Ext.theme = {};
153 }
154 if(!Ext.theme.name) {
155 Ext.theme.name = theme || 'Default';
156 }
157 }
158 write('<link rel="stylesheet" href="'+path+'">');
159 }
160
161 for (i = 0,ln = scripts.length; i < ln; i++) {
162 path = scripts[i];
163
164 if (typeof path != 'string') {
165 platform = path.platform;
166 exclude = path.exclude;
167 path = path.path;
168 }
169
170 if (platform) {
171 if (!filterPlatform(platform) || filterPlatform(exclude)) {
172 continue;
173 }
174 }
175
176 write('<script src="'+path+'"></'+'script>');
177 }
178 }
179
180})(this);