Open ghost opened 8 years ago
That's pretty cool, and I will add the search function later Thanks.
I'm glad that you liked it. If you want to detect the visitor operating system, here's the code and working demo - https://jsfiddle.net/3mqtuy0r/
Add the following span
in any html page.
<span id='detect-os'></span>
The script:
(function() {
'use strict';
var detect =
{
mobile: ['Android', 'iPhone', 'iPod', 'iPad', 'Symbian', 'Windows Phone', 'BlackBerry'],
shorter: ['Linux', 'Free', 'Open', 'NetBSD', 'BSD', 'Mac',
'Win', 'Sun', 'HP', 'Play', 'Web', 'QNX', 'BeOS', 'X11', 'OS/2'],
longer: ['Linux', 'FreeBSD', 'OpenBSD', 'NetBSD', 'BSD', 'Macintosh',
'Windows', 'SunOS', 'Hewlett-Packard', 'PlayStation',
'WebTV OS', 'QNX', 'BeOS', 'UNIX', 'OS/2'],
foundOS: 'unknown',
itsmobile: navigator.userAgent.match(/(Android)|(iPod)|(iPad)|(Symbian)|(Phone)|(BlackBerry)/i),
findOS: function(arr, os, mobile_bool) {
var x = arr.length;
while (x--) {
if (os.indexOf(arr[x]) !== -1)
{
detect.foundOS = (mobile_bool ? arr[x] : detect.longer[x]);
break;
}
}
}
};
if (detect.itsmobile) {
detect.findOS(detect.mobile, navigator.userAgent, true);
} else {
detect.findOS(detect.shorter, navigator.platform, false);
}
document.getElementById('detect-os').textContent = detect.foundOS;
}());
You can combine both javascripts in one file instead. Copy search.js and add it above/below this example.
Hello,
Saw that you wanted to add searching function to your project and decided to contribute a code that I use in my blog.
Test page (index.html), online demo here or just type something in my blog search form.
You must have https://github.com/blueimp/JavaScript-Templates installed (npm install; npm run build)
search.js
Every key stroke will trigger the search function, thus making it interactive without the need from the user to click any submit buttons (especially useful on mobile devices).
3 days later: replaced the entries objects with arrays instead.