-
Notifications
You must be signed in to change notification settings - Fork 665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contribution: Searching function #21
Comments
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 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: