Last active
          August 29, 2015 13:56 
        
      - 
      
- 
        Save magnobiet/8933752 to your computer and use it in GitHub Desktop. 
    jQuery Auto Focus Polyfill
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | /*! | |
| * jQuery Auto Focus Polyfill v0.1.0 | |
| * https://gist.github.com/magnobiet/8933752/edit | |
| * | |
| * Made by Magno Biét | |
| * Under MIT License | |
| */ | |
| ;(function($, window, document, undefined) { | |
| var pluginName = 'autoFocusPolyfill', | |
| defaults = {}; | |
| function Plugin(element, options) { | |
| this.element = element; | |
| this.settings = $.extend({}, defaults, options); | |
| this._defaults = defaults; | |
| this._name = pluginName; | |
| this.init(); | |
| } | |
| Plugin.prototype = { | |
| init: function() { | |
| if (!this.supportsInputAttribute('autofocus')) { | |
| $(this.element).focus(); | |
| } | |
| }, | |
| supportsInputAttribute: function(attr) { | |
| var input = document.createElement('input'); | |
| return attr in input; | |
| } | |
| }; | |
| $.fn[pluginName] = function(options) { | |
| this.each(function() { | |
| if (!$.data(this, 'plugin_' + pluginName)) { | |
| $.data(this, 'plugin_' + pluginName, new Plugin(this, options)); | |
| } | |
| }); | |
| return this; | |
| }; | |
| }(jQuery, window, document)); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $(function() { | |
| $('[autofocus]').autoFocusPolyfill(); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment