Skip to content

Commit

Permalink
Mobile, now with actual mobile platform detection (bug 637778)
Browse files Browse the repository at this point in the history
  • Loading branch information
potch committed Mar 1, 2011
1 parent 641ba55 commit e6130a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
20 changes: 13 additions & 7 deletions media/js/zamboni/browser.js
Expand Up @@ -12,9 +12,11 @@ function BrowserUtils() {
'thunderbird': /Mozilla.*(Thunderbird|Shredder|Lanikai)\/([^\s*]*).*$/
},
osStrings = {
'windows': 'Win32',
'windows': 'Windows',
'mac': 'Mac',
'linux': 'Linux'
'linux': 'Linux',
'android': 'Android',
'maemo': 'Maemo'
};

// browser detection
Expand All @@ -37,19 +39,23 @@ function BrowserUtils() {
for (i in osStrings) {
if (osStrings.hasOwnProperty(i)) {
pattern = osStrings[i];
os[i] = navigator.platform.indexOf(pattern) != -1;
os[i] = navigator.userAgent.indexOf(pattern) != -1;
if (os[i]) {
platform = i;
}
}
}
os['other'] = !platform;
if (!platform) {
os['other'] = !platform;
platform = "other";
}

return {
"browser": browser,
"browserVersion": browserVersion,
"os": os,
"platform": platform
"platform": platform,
"platformName": gettext(osStrings[platform])
};
}

Expand Down Expand Up @@ -103,9 +109,9 @@ var VersionCompare = {
var pattern = /^([-\d]*)([^-\d]*)([-\d]*)(.*)$/,
m = pattern.exec(p),
r = {
'numA' : parseInt(m[1]),
'numA' : parseInt(m[1], 10),
'strB' : m[2],
'numC' : parseInt(m[3]),
'numC' : parseInt(m[3], 10),
'extraD' : m[4]
};
if (r['strB'] == '+') {
Expand Down
18 changes: 9 additions & 9 deletions media/js/zamboni/mobile_buttons.js
Expand Up @@ -45,7 +45,7 @@
'tooOld': format(gettext("Requires Newer Version of {0}"), z.appName),
'unreviewed': gettext("Unreviewed"),
'badApp': format(gettext("Not Available for {0}"), z.appName),
'badPlatform': format(gettext("Not Available for {0}"), z.platform),
'badPlatform': format(gettext("Not Available for {0}"), z.platformName),
'experimental': gettext("Experimental")
};

Expand Down Expand Up @@ -85,7 +85,7 @@
versionPlatformCheck();

this.actionQueue.push([0, function() {
var href = activeInstaller.attr('href');
var href = activeInstaller.attr('href'),
hash = hashes[href],
attr = self.attr,
install = attr.search ? z.installSearch : z.installAddon;
Expand All @@ -101,7 +101,7 @@
}

// sort the actionQueue by priority
this.actionQueue.sort(function (a, b) {return b[0]-a[0]});
this.actionQueue.sort(function (a, b) {return b[0]-a[0];});
};

function collectHashes() {
Expand All @@ -126,7 +126,7 @@
// execute the next action if the current action returns true.
if (result === true) {
self.resumeInstall();
};
}
}
this.resumeInstall = function() {
// moving on.
Expand Down Expand Up @@ -166,8 +166,8 @@
var b = dom.self,
attr = self.attr,
classes = self.classes,
platformer = b.find('.platform').length,
platformSupported = (platformer && dom.buttons.filter("." + z.platform).length),
platformer = !!b.find('.platform').length,
platformSupported = !platformer || dom.buttons.filter("." + z.platform).length,
appSupported = z.appMatchesUserAgent && attr.min && attr.max,
olderBrowser, newerBrowser,
canInstall = true;
Expand All @@ -185,7 +185,7 @@
} else {
if (!appSupported) errors.push("badApp");
if (!platformSupported) {
errors.push("badApp");
errors.push("badPlatform");
dom.buttons.hide().eq(0).show();
}
canInstall = false;
Expand Down Expand Up @@ -215,15 +215,15 @@
} else {
dom.buttons.click(startInstall);
}
};
}

//and of course, initialize the button.
this.init();
}

z.b = function() {
new Button(this);
}
};

jQuery.fn.installButton = function() {
return this.each(z.b);
Expand Down

0 comments on commit e6130a8

Please sign in to comment.