Skip to content
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

Request: Standalone Code #4

Open
Twipped opened this issue Dec 5, 2011 · 6 comments
Open

Request: Standalone Code #4

Twipped opened this issue Dec 5, 2011 · 6 comments

Comments

@Twipped
Copy link

Twipped commented Dec 5, 2011

I'd love to use this on all my sites, but we don't use jQuery or Modernizr and that's a lot of extra code (and page memory) to include just to get this functionality.

Please consider creating a standalone version.

@BaylorRae
Copy link
Contributor

I think I've figured out how to check browser support. I've only tested this in Safari 5.1.1, Firefox 7.0.1, Chrome 15.0.874.121 and Opera 11.60 on my mac. So someone will need to see how this works in browsers on Windows.

var search = $('#search')[0];
if( search.list !== null || search.list !== undefined )
  console.log('supported!'); // Firefox and Opera pass

@ruanmer
Copy link
Contributor

ruanmer commented Dec 6, 2011

what about safari?? coz safari has partial support

@BaylorRae
Copy link
Contributor

@ruanmer The code I included doesn't include Safari. Safari acts kind of weird because it finds the datalist, but it doesn't create the drop down.

@chriscoyier
Copy link
Contributor

Yeah the majority of the suckness of testing for this is that Safari reports success but should not. Ideally we think of a fancy test we can perform (beyond just checking for the list attribute) that gives correct results in all browsers. I'm fairly stumped at the moment.

Ideally, that test would be baked into Modernizr.

@chrisabrams
Copy link

Any updates? +1 for stand alone.

@AlgyTaylor
Copy link

This will check for browser support then load the library w/o modernizr. Then

<script type="text/javascript">
            (function () {
                /**
                 * Loads a new javascript then performs a function
                 */
                function loadScript (url, then) {
                    var script = document.createElement('script');

                    script.addEventListener('load', then);
                    script.setAttribute('type', 'text/javascript');
                    script.setAttribute('src', url);

                    document.head.appendChild(script);
                }

                if (!('options' in document.createElement('datalist'))) {
                    loadScript('/path/to/jquery.relevant-dropdown.js', function () {
                        $('input[list]').relevantDropdown();
                    });
                }
            })();
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants