Last active
August 29, 2015 14:05
-
-
Save leompeters/f743541353e7d4148852 to your computer and use it in GitHub Desktop.
JavaScript and CoffeeScript for focus on the first visible field of the first HTML form.
This file contains 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
/** | |
* Miscellaneous JavaScript for focus on the first visible field of the first form. | |
* | |
* @namespace Belanton.Codes.Scripts | |
* @see https://gist.github.com/leonardomarques/f743541353e7d4148852 | |
* @author Leonardo Marques <leonardo.marques@belanton.com> | |
* @license Licensed under the MIT license [http://www.opensource.org/licenses/mit-license.php] | |
* @copyright Copyright (c) 2013 Belanton, Inc. [http://www.belanton.com] | |
*/ | |
$(function () { | |
// A gift to you: | |
var $body = $("body"); | |
// Show a warning modal on IE. | |
if ($body.hasClass("js-show-ie-warning")) { | |
if ($.browser.msie && parseInt($.browser.version, 10) <= 7) { | |
$("#IeWarningModal").modal("show"); | |
} | |
} | |
// focus on the first visible field of the first form | |
$("form:first input[type!='hidden']:first").focus(); | |
}); |
This file contains 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
### | |
# Miscellaneous CoffeeScript for focus on the first visible field of the first form. | |
# | |
# @namespace Belanton.Codes.Scripts | |
# @see https://gist.github.com/leonardomarques/f743541353e7d4148852 | |
# @author Leonardo Marques <leonardo.marques@belanton.com> | |
# @license Licensed under the MIT license [http://www.opensource.org/licenses/mit-license.php] | |
# @copyright Copyright (c) 2013 Belanton, Inc. [http://www.belanton.com] | |
### | |
$ -> | |
# A gift to you: | |
$body = $("body") | |
# Show a warning modal on IE. | |
$("#IeWarningModal").modal "show" if $.browser.msie and parseInt($.browser.version, 10) <= 7 if $body.hasClass("js-show-ie-warning") | |
# focus on the first visible field of the first form | |
$("form:first input[type!='hidden']:first").focus() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment