UNPKG

7.37 kBJavaScriptView Raw
1import { InjectionToken } from '@angular/core';
2import { isCordova, isElectron, isIos, isIosUIWebView } from './platform-utils';
3export var PLATFORM_CONFIGS = {
4 /**
5 * core
6 */
7 'core': {
8 settings: {
9 mode: 'md',
10 keyboardHeight: 290
11 }
12 },
13 /**
14 * mobile
15 */
16 'mobile': {},
17 /**
18 * phablet
19 */
20 'phablet': {
21 isMatch: function (plt) {
22 var smallest = Math.min(plt.width(), plt.height());
23 var largest = Math.max(plt.width(), plt.height());
24 return (smallest > 390 && smallest < 520) &&
25 (largest > 620 && largest < 800);
26 }
27 },
28 /**
29 * tablet
30 */
31 'tablet': {
32 isMatch: function (plt) {
33 var smallest = Math.min(plt.width(), plt.height());
34 var largest = Math.max(plt.width(), plt.height());
35 return (smallest > 460 && smallest < 820) &&
36 (largest > 780 && largest < 1400);
37 }
38 },
39 /**
40 * android
41 */
42 'android': {
43 superset: 'mobile',
44 subsets: [
45 'phablet',
46 'tablet'
47 ],
48 settings: {
49 activator: function (plt) {
50 // md mode defaults to use ripple activator
51 // however, under-powered devices shouldn't use ripple
52 // if this a linux device, and is using Android Chrome v36 (Android 5.0)
53 // or above then use ripple, otherwise do not use a ripple effect
54 if (plt.testNavigatorPlatform('linux')) {
55 var chromeVersion = plt.matchUserAgentVersion(/Chrome\/(\d+).(\d+)?/);
56 if (chromeVersion) {
57 // linux android device using modern android chrome browser gets ripple
58 if (parseInt(chromeVersion.major, 10) < 36 || plt.version().major < 5) {
59 return 'none';
60 }
61 else {
62 return 'ripple';
63 }
64 }
65 // linux android device not using chrome browser checks just android's version
66 if (plt.version().major < 5) {
67 return 'none';
68 }
69 }
70 // fallback to always use ripple
71 return 'ripple';
72 },
73 autoFocusAssist: 'immediate',
74 inputCloning: true,
75 scrollAssist: true,
76 hoverCSS: false,
77 keyboardHeight: 300,
78 mode: 'md',
79 },
80 isMatch: function (plt) {
81 return plt.isPlatformMatch('android', ['android', 'silk'], ['windows phone']);
82 },
83 versionParser: function (plt) {
84 return plt.matchUserAgentVersion(/Android (\d+).(\d+)?/);
85 }
86 },
87 /**
88 * ios
89 */
90 'ios': {
91 superset: 'mobile',
92 subsets: [
93 'ipad',
94 'iphone'
95 ],
96 settings: {
97 autoFocusAssist: 'delay',
98 hideCaretOnScroll: true,
99 hoverCSS: false,
100 inputBlurring: isIos,
101 inputCloning: isIos,
102 keyboardHeight: 250,
103 mode: 'ios',
104 statusbarPadding: isCordova,
105 swipeBackEnabled: isIos,
106 tapPolyfill: isIosUIWebView,
107 virtualScrollEventAssist: isIosUIWebView,
108 disableScrollAssist: isIos,
109 scrollAssist: isIos,
110 keyboardResizes: keyboardResizes,
111 },
112 isMatch: function (plt) {
113 return plt.isPlatformMatch('ios', ['iphone', 'ipad', 'ipod'], ['windows phone']);
114 },
115 versionParser: function (plt) {
116 return plt.matchUserAgentVersion(/OS (\d+)_(\d+)?/);
117 }
118 },
119 /**
120 * ipad
121 */
122 'ipad': {
123 superset: 'tablet',
124 settings: {
125 keyboardHeight: 500,
126 },
127 isMatch: function (plt) {
128 return plt.isPlatformMatch('ipad');
129 }
130 },
131 /**
132 * iphone
133 */
134 'iphone': {
135 subsets: [
136 'phablet'
137 ],
138 isMatch: function (plt) {
139 return plt.isPlatformMatch('iphone');
140 }
141 },
142 /**
143 * Windows
144 */
145 'windows': {
146 superset: 'mobile',
147 subsets: [
148 'phablet',
149 'tablet'
150 ],
151 settings: {
152 mode: 'wp',
153 autoFocusAssist: 'immediate',
154 hoverCSS: false
155 },
156 isMatch: function (plt) {
157 return plt.isPlatformMatch('windows', ['windows phone']);
158 },
159 versionParser: function (plt) {
160 return plt.matchUserAgentVersion(/Windows Phone (\d+).(\d+)?/);
161 }
162 },
163 /**
164 * cordova
165 */
166 'cordova': {
167 isEngine: true,
168 initialize: function (plt) {
169 // prepare a custom "ready" for cordova "deviceready"
170 plt.prepareReady = function () {
171 // 1) ionic bootstrapped
172 plt.windowLoad(function (win, doc) {
173 // 2) window onload triggered or completed
174 doc.addEventListener('deviceready', function () {
175 // 3) cordova deviceready event triggered
176 // add cordova listeners to emit platform events
177 doc.addEventListener('backbutton', function (ev) {
178 plt.zone.run(function () {
179 plt.backButton.emit(ev);
180 });
181 });
182 doc.addEventListener('pause', function (ev) {
183 plt.zone.run(function () {
184 plt.pause.emit(ev);
185 });
186 });
187 doc.addEventListener('resume', function (ev) {
188 plt.zone.run(function () {
189 plt.resume.emit(ev);
190 });
191 });
192 // cordova has its own exitApp method
193 plt.exitApp = function () {
194 win['navigator']['app'].exitApp();
195 };
196 // cordova has fully loaded and we've added listeners
197 plt.triggerReady('cordova');
198 });
199 });
200 };
201 },
202 isMatch: function (plt) {
203 return isCordova(plt);
204 }
205 },
206 /**
207 * electron
208 */
209 'electron': {
210 superset: 'core',
211 initialize: function (plt) {
212 plt.prepareReady = function () {
213 // 1) ionic bootstrapped
214 plt.windowLoad(function () {
215 plt.triggerReady('electron');
216 });
217 };
218 },
219 isMatch: function (plt) {
220 return isElectron(plt);
221 }
222 }
223};
224function keyboardResizes(plt) {
225 var win = plt.win();
226 if (win.Ionic && win.Ionic.keyboardResizes === true) {
227 return true;
228 }
229 return false;
230}
231export var PlatformConfigToken = new InjectionToken('PLTCONFIG');
232export function providePlatformConfigs() {
233 return PLATFORM_CONFIGS;
234}
235//# sourceMappingURL=platform-registry.js.map
\No newline at end of file