Permalink
Browse files

Store the OS name in the app for use elsewhere

Signed-off-by: Jonathan Fielding <j.fielding@me.com>
  • Loading branch information...
1 parent 31bc1a0 commit 58a4cc0e7bc8b82041743a7d63d6b6730dce4236 @jonathan-fielding committed Mar 6, 2012
Showing with 23 additions and 32 deletions.
  1. +18 −0 assets/js/AppBoilerplate.js
  2. +2 −2 index.html
  3. +3 −30 plugins/theme_switcher/theme_switcher.js
@@ -6,6 +6,7 @@ var app = function(){
return {
'url_path': '',
'theme':'',
+ 'os':'',
init: function(event, eventData){
var module_name = $(eventData.toPage).attr('data-module');
var javascript_required = module_name +'.js'
@@ -14,6 +15,8 @@ var app = function(){
app.url_path = '../../';
}
+ app.getOS();
+
//Load the plugins into the app
require([app.url_path + 'plugins/add_plugins.js'],function(){
add_plugins.init();
@@ -41,6 +44,21 @@ var app = function(){
document.getElementsByTagName('head')[0].appendChild(stylesheet);
}
}
+ },
+ getOS: function(){
+ //Sniff the OS, (naughty but necessary for some functionality)
+ if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
+ app.os = 'iOS';
+ }
+
+ if((navigator.userAgent.match(/Android/i))) {
+ app.os = 'Android';
+ }
+
+ if((navigator.userAgent.match(/Windows Phone OS/i))) {
+ app.os = 'Windows Mobile';
+ }
+
}
};
View
@@ -10,11 +10,11 @@
<div data-role="page" data-module="bootstrap">
<div data-role="header" data-position="fixed">
- <h1>Loading</h1>
+ <h1>AppBoilerplate</h1>
</div>
<div data-role="content">
- <p>Loading...</p>
+ <p>AppBoilerplate is currently loading</p>
</div><!-- /content -->
<div data-role="footer" data-position="fixed">
@@ -6,32 +6,6 @@ app.theme_switcher = function(){
};
- var isIOS = function(){
- if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
- return true;
- }
- else{
- return false;
- }
- };
-
- var isAndroid = function(){
- if((navigator.userAgent.match(/Android/i))) {
- return true;
- }
- else{
- return false;
- }
- };
-
- var isWinMob = function(){
- if((navigator.userAgent.match(/Windows Phone OS/i))) {
- return true;
- }
- else{
- return false;
- }
- };
return {
'default_theme' : '',
@@ -40,24 +14,23 @@ app.theme_switcher = function(){
'winmob_theme' : '',
init: function(){
-
- if(isIOS()){
+ if(app.os === 'iOS'){
if(app.theme_switcher.iOS_theme != ''){
app.theme = app.theme_switcher.iOS_theme;
}
else{
app.theme = app.theme_switcher.default_theme;
}
}
- else if (isAndroid()) {
+ else if (app.os === 'Android') {
if(app.theme_switcher.android_theme != ''){
app.theme = app.theme_switcher.android_theme;
}
else{
app.theme = app.theme_switcher.default_theme;
}
}
- else if (isWinMob()) {
+ else if (app.os === 'Windows Mobile') {
if(app.theme_switcher.winmob_theme != ''){
app.theme = app.theme_switcher.winmob_theme;
}

0 comments on commit 58a4cc0

Please sign in to comment.