1 2 /** 3 * Exports the current runtime environment, by processing 4 * the query-params of the URL (<code>window.location.search</code> 5 * 6 * currently supported settings are 7 * <ul> 8 * <li>browser</li> 9 * <li>android</li> 10 * </ul> 11 * 12 * @exports {Object} a singleton object with information about the runtime setting: 13 * <pre>{ isBrowserEnv: [true|false] }</pre> 14 */ 15 define(['paramsParseFunc'], function(paramsParseFunc) { 16 17 var params = paramsParseFunc( window.location.search ); 18 19 var isBrowserEnv; 20 var isCordovaEnv; 21 var envSetting = ''; 22 23 if(params.has('env')){ 24 envSetting = params['env']; 25 26 if(envSetting === 'browser'){ 27 isBrowserEnv = true; 28 } 29 else { 30 isBrowserEnv = false; 31 } 32 33 if(envSetting === 'cordova' || envSetting === 'android' || envSetting === 'ios'){ 34 isCordovaEnv = true; 35 isBrowserEnv = false; 36 } 37 else { 38 isCordovaEnv = false; 39 } 40 } 41 else { 42 isBrowserEnv = true; 43 isCordovaEnv = false; 44 } 45 46 var env; 47 if(isBrowserEnv){ 48 env = 'browser'; 49 } else { 50 51 //if available, use plugin cordova-plugin-device for detecting specific env 52 if(typeof device !== 'undefined' && device.platform){ 53 54 var platform = device.platform; 55 if(/\bios\b/i.test(platform)){ 56 env = 'ios'; 57 } else if(/\bandroid\b/i.test(platform)){ 58 env = 'android'; 59 } else {//TODO handle other platforms 60 console.warn('Unknown platform "'+platform+'"'); 61 env = 'default'; 62 } 63 64 } else { 65 66 //fallback: use UserAgent for detecting env 67 var userAgent = navigator.userAgent; 68 if(/(iPad|iPhone|iPod)/ig.test(userAgent)){ 69 env = 'ios'; 70 } else if(/android/i.test(userAgent)){ 71 env = 'android'; 72 } else {//TODO handle other platforms 73 console.warn('Unknown platform for userAgent "'+userAgent+'"'); 74 env = 'default'; 75 } 76 77 } 78 79 } 80 81 return { 82 isBrowserEnv: isBrowserEnv, 83 isCordovaEnv: isCordovaEnv, 84 envSetting: envSetting, 85 platform: env 86 // , params : params 87 }; 88 }); 89