Created
July 10, 2015 16:37
-
-
Save orbeon/92bf7247d2fdb6308b95 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> | |
<style type="text/css"> | |
#hidden-input { visibility: hidden } | |
</style> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script> | |
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
$('#focus-hidden').click(function (event) { | |
event.preventDefault(); | |
$('#hidden-input').focus(); | |
}); | |
$('#focus-moved').click(function (event) { | |
event.preventDefault(); | |
var input = $('#moved-input'); | |
var parent = input.parent(); | |
$('.container').append(input); | |
parent.append(input); | |
if ($('.focus-version:checked').val() == 'default') { | |
input.focus(); | |
} else { | |
var focusable = $('#focus-moved'); | |
setFocus(focusable).then(function() { setFocus(input); }); | |
} | |
}); | |
function setFocus(element) { | |
var deferred, setFocusWorker; | |
deferred = $.Deferred(); | |
(setFocusWorker = function () { | |
element.focus(); | |
var focusSet = document.activeElement === element[0]; | |
focusSet ? deferred.resolve(): _.defer(setFocusWorker); | |
})(); | |
return deferred; | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<form> | |
<div class="container"> | |
<div class="page-header"><h1>Focus on IE</h1></div> | |
<div class="row"> | |
<div class="span4"><button class="btn" id="focus-hidden">Focus on hidden input</button></div> | |
<div class="span4"><input id="hidden-input"/></div> | |
</div> | |
<div class="row"> | |
<div class="span4"><button class="btn" id="focus-moved">Focus on moved input</button></div> | |
<div class="span4"><input id="moved-input"/></div> | |
<div class="span4"> | |
<label class="radio inline"> | |
<input type="radio" class="focus-version" name="focus-version" value="default" checked>Default | |
</label> | |
<label class="radio inline"> | |
<input type="radio" class="focus-version" name="focus-version" value="custom">Custom | |
</label> | |
</div> | |
</div> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment