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