New Story Autofocus

New story modal now autofocuses on the title when it appears. This
required a small modification to the focus directive, as with DOM
manipulation like modals, the popup elements are linked _before_ they
are added to the DOM, rather than after. Adding a minor timeout
fixed that.

Change-Id: I5cb0001c2afd991544bc40c33c3fcd6b89f8b208
This commit is contained in:
Michael Krotscheck 2014-07-02 14:07:00 -07:00
parent 003c41fdc6
commit 1b354dd206
2 changed files with 6 additions and 3 deletions

View File

@ -15,6 +15,7 @@
<div class="col-sm-10">
<input id="name"
focus
type="text"
class="form-control"
ng-model="story.title"

View File

@ -20,7 +20,7 @@
* phase is run)
*/
angular.module('sb.util').directive('focus',
function () {
function ($timeout) {
'use strict';
return {
@ -29,8 +29,10 @@ angular.module('sb.util').directive('focus',
// Extract the element...
var e = $element[0];
if (!!e && e.hasOwnProperty('focus')) {
e.focus();
if (!!e && !!e.focus) {
$timeout(function () {
e.focus();
}, 10);
}
}
};