Skip to content

Instantly share code, notes, and snippets.

@leompeters
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leompeters/f743541353e7d4148852 to your computer and use it in GitHub Desktop.
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.
/**
* 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();
});
###
# 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