Last active
February 1, 2017 17:16
-
-
Save jordangray/5910582 to your computer and use it in GitHub Desktop.
A simple shim for the HTML5 formaction attribute.
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
# Test for formaction attribute support in Modernizer. | |
Modernizr.addTest 'formaction', 'formaction' of document.createElement('input') | |
# Shim for formaction attributes on buttons and inputs. | |
$.fn.shimFormAction = -> | |
return this if Modernizr.formaction | |
this.each -> | |
$(this).find 'input,button' | |
.filter '[formaction!=""][formaction]' | |
.on 'click', -> | |
$this = $ this | |
$this.closest('form').attr 'action', $this.attr('formaction') | |
true |
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
Modernizr.addTest('formaction', 'formaction' in document.createElement('input')); | |
$.fn.shimFormAction = function() { | |
if (Modernizr.formaction) { | |
return this; | |
} | |
return this.each(function() { | |
return $(this).find('input,button').filter('[formaction!=""][formaction]').on('click', function() { | |
var $this = $(this); | |
$this.closest('form').attr('action', $this.attr('formaction')); | |
return true; | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment