Permalink
Browse files

fixing formfactor detection

  • Loading branch information...
1 parent 9854cc0 commit 18b6d3de24a8a27abf1ebcc032330a4974a9717b @yonromai yonromai committed May 3, 2012
Showing with 36 additions and 47 deletions.
  1. +35 −7 snapapp/common/js/formfactor.indicators.js
  2. +1 −40 snapapp/index.html
@@ -14,20 +14,44 @@
limitations under the License.
*/
+function handleFormfactorDetection(){
+ if(commonScriptsLoaded && specificScriptsLoaded){
+ doDeviceRouting();
+ } else {
+ setTimeout("handleFormfactorDetection()",1000);
+ }
+};
+
+function commonScriptsLoaded(){
+ var commonScriptsLoaded = true;
+};
+
+function specificScriptsLoaded(){
+ var specificScriptsLoaded = true;
+ return factor;
+};
+
+function doDeviceRouting(){
+ $("#loadingLbl").text(device);
+};
+
formfactor.register({
'desktop': [
- 'screen'
+ 'desktop',
+ function() { return navigator.userAgent.toLowerCase().indexOf("macintosh") > 0 }
],
/* 'handheld': [ //One day maybe :)
'handheld',
function() { return navigator.userAgent.indexOf("Opera Mini") > 0; },
function() { return navigator.userAgent.indexOf("Opera Mobi") > 0; }
],*/
'phone': [
+ 'phone',
function() { return navigator.userAgent.toLowerCase().indexOf("mobile") > 0 } ,
function() { return navigator.userAgent.toLowerCase().indexOf("phone") > 0 },
],
'tablet': [
+ 'tablet',
function () { return navigator.userAgent.toLowerCase().indexOf("android") > 0 && !(navigator.userAgent.toLowerCase().indexOf("mobile") > 0) },
function () { return navigator.userAgent.indexOf("iPad") > 0 },
function() { return navigator.userAgent.indexOf("Xoom") > 0 }
@@ -42,17 +66,17 @@ var factor = formfactor.detect([ //TODO: Look for ressources neededà
{
"formfactor": "phone",
//"resources": ["/scripts/phone/jquery.touch.js", "/scripts/tablet/css-beziers.js", "/scripts/tablet/touchscroll.js", "/scripts/phone/controller.js", "/css/phone.css"]
- "callbacks": specificScriptsLoaded()
+ //"callbacks": specificScriptsLoaded()
},
{
"formfactor": "tv",
//"resources": ["/scripts/tv/controller.js", "/css/tv.css"]
- "callbacks": specificScriptsLoaded()
+ //"callbacks": specificScriptsLoaded()
},
{
"formfactor": "tablet",
//"resources": ["/css/tablet.css", '/css/tablet/touchscroll.css', "/scripts/tablet/jquery.touch.tablet.js", "/scripts/tablet/css-beziers.js", "/scripts/tablet/touchscroll.js", "/scripts/tablet/controller.js"]
- "callbacks": specificScriptsLoaded()
+ //"//callbacks": specificScriptsLoaded()
},
/* {
"formfactor": "handheld",
@@ -61,16 +85,18 @@ var factor = formfactor.detect([ //TODO: Look for ressources neededà
},*/
{
"formfactor": "desktop",
- //"resources": ["/scripts/desktop/controller.js", "/css/desktop.css"]
- "callbacks": specificScriptsLoaded()
+ "resources": ["/scripts/desktop/controller.js"]
+ //"callbacks": specificScriptsLoaded()
}
],
{
"formfactor": "default",
//"resources": ["/css/default.css"]
- "callbacks": specificScriptsLoaded()
+ //"callbacks": specificScriptsLoaded()
}
);
+var device = specificScriptsLoaded();
+
/*
if(!!factor) {
$(document).ready(function() {
@@ -85,3 +111,5 @@ if(!!factor) {
}
*/
+
+
View
@@ -4,50 +4,11 @@
<meta charset="utf-8">
<title>SNAP Device detection</title>
<script src="./common/lib/jquery/jquery-1.7.2.min.js"></script>
+
</head>
<body>
<script>
setTimeout("handleFormfactorDetection()",4000);
- function handleFormfactorDetection(){
- if(commonScriptsLoaded && specificScriptsLoaded){
- doDeviceRouting();
- } else {
- setTimeout("handleFormfactorDetection()",1000);
- }
- };
-
- function commonScriptsLoaded(){
- var commonScriptsLoaded = true;
- };
-
- function specificScriptsLoaded(){
- var specificScriptsLoaded = true;
-
- var device = getDevice();
-
- $("#loadingLbl").text(device);
- };
-
- function doDeviceRouting(){
-
- };
-
- function getDevice(){
- if(formfactor.is("phone")) {
- return "tv";
- };
- if(formfactor.is("tablet")) {
- return "tv";
- };
- if(formfactor.is("tv")) {
- return "tv";
- };
- if(formfactor.is("desktop")) {
- return "tv";
- };
- return "default";
- }
-
</script>
<p id="loadingLbl">Loading Scripts...</p>

0 comments on commit 18b6d3d

Please sign in to comment.