Add visual display

This commit is contained in:
Faisal Salman 2012-09-11 02:40:53 +07:00
parent be7e60a0b1
commit 6ef48fbc69
34 changed files with 240 additions and 212 deletions

BIN
images/android.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

BIN
images/arch.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
images/bada.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
images/blackberry.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
images/bsd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

BIN
images/check.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/chrom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
images/chromium.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/debian.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
images/fedora.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
images/firefox.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

BIN
images/freebsd.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
images/gentoo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
images/ie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
images/ipad.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
images/konqueror.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
images/linux.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
images/mac.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/mandriva.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
images/meego.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/mozilla.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
images/opera.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
images/pc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
images/phone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

BIN
images/redhat.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
images/safari.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
images/slackware.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
images/solaris.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
images/suse.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
images/symbian.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
images/ubuntu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
images/undefined.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
images/windows.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -121,6 +121,12 @@
<th>OS</th> <th>OS</th>
<th>Device</th> <th>Device</th>
</tr> </tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr> <tr>
<td></td> <td></td>
<td></td> <td></td>
@ -135,11 +141,11 @@
</table> </table>
</section> </section>
<section> <section>
<p>Wanna test other UA string? Select a user-agent string to be tested:</p> <p>How well this parse other user-agent string? try select a string to be parsed:</p>
<select> <select>
<option>Pick one</option> <option>Pick one</option>
</select> </select>
<p>Wanna test more? Enter any user-agent string you want to test here:</p> <p>Want more? try enter any user-agent string you want to parse here:</p>
<input type="text" /> <input type="text" />
</section> </section>
<footer> <footer>
@ -157,14 +163,34 @@
var txt = document.getElementsByTagName('input')[0]; var txt = document.getElementsByTagName('input')[0];
var parser = new UAParser(); var parser = new UAParser();
var fill = function(el, prop){ var fill = function(el, prop){
if(prop !== undefined){ if(typeof prop === 'object'){
el.innerHTML = '';
el.appendChild(prop);
} else if(typeof prop === 'string'){
el.innerHTML = prop; el.innerHTML = prop;
el.style.color = "red"; el.style.color = "red";
} else { } else {
el.innerHTML = "No data"; el.innerHTML = "No data";
el.style.color = "#aaa"; el.style.color = "#aaa";
} }
} };
var imgMap = function(prop, arr){
var img = document.createElement('img');
img.src = 'images/undefined.png';
for(var i in arr){
if(arr.hasOwnProperty(i)){
var isobj = typeof arr[i] === 'object';
var r = isobj ? new RegExp(arr[i][0], 'i') : new RegExp(arr[i], 'i');
if(r.test(prop['name'])){
img.src = 'images/'+(isobj?arr[i][1]:arr[i])+'.png';
return img;
} else if(prop['name'] !== undefined){
img.src = 'images/check.png';
}
}
}
return img;
};
for(var i = 0; i < uaExampleList.length; i++){ for(var i = 0; i < uaExampleList.length; i++){
var opt = document.createElement('option'); var opt = document.createElement('option');
opt.innerHTML = uaExampleList[i]; opt.innerHTML = uaExampleList[i];
@ -177,14 +203,16 @@
var os = parser.getOS(); var os = parser.getOS();
var device = parser.getDevice(); var device = parser.getDevice();
var tbl = document.getElementsByTagName('td'); var tbl = document.getElementsByTagName('td');
fill(tbl[0], browser.name); var prop = [
fill(tbl[1], engine.name); imgMap(browser, ['ie', 'chrom', 'konqueror', 'safari', 'opera', 'firefox', ['fennec', 'firefox'], 'mozilla']),
fill(tbl[2], os.name); imgMap(engine, [['trident', 'ie'], ['webkit', 'safari'], ['khtml', 'konqueror'], ['presto', 'opera'], ['gecko', 'mozilla']]),
fill(tbl[3], device.name); imgMap(os, ['meego', 'symbian', 'android', 'blackberry', 'bada', 'windows', 'chromium', 'mac', 'freebsd', 'bsd', 'ubuntu', 'gentoo', 'fedora', 'mandriva', 'redhat', 'suse', 'debian', 'slackware', 'arch', 'linux', 'solaris', ['ios', 'mac'], ['rim', 'blackberry']]),
fill(tbl[4], browser.version); imgMap(device, [['undefined', 'pc'], 'ipad', ['tablet', 'ipad'], ['playbook', 'ipad'], ['\\w+', 'phone']]),
fill(tbl[5], engine.version); browser.name, engine.name, os.name, device.name,
fill(tbl[6], os.version); browser.version, engine.version, os.version, device.version];
fill(tbl[7], device.version); for(var i = 0; i < prop.length; i++){
fill(tbl[i], prop[i]);
}
pre.innerHTML = 'Result for <span style="color:red">' + (uastring ? uastring.replace(/</g,'&lt;') : 'your browser\'s user-agent string') + ' :</span>'; pre.innerHTML = 'Result for <span style="color:red">' + (uastring ? uastring.replace(/</g,'&lt;') : 'your browser\'s user-agent string') + ' :</span>';
} }
fillTable(); fillTable();