Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
53d5a335
Commit
53d5a335
authored
Feb 26, 2012
by
Ryan Niemeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apply focus() asynchronously to prevent issues with element not being visible yet.
parent
66e495cb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
architecture-examples/knockoutjs/index.html
architecture-examples/knockoutjs/index.html
+1
-1
architecture-examples/knockoutjs/js/app.js
architecture-examples/knockoutjs/js/app.js
+13
-7
No files found.
architecture-examples/knockoutjs/index.html
View file @
53d5a335
...
...
@@ -23,7 +23,7 @@
<a
class=
"destroy"
href=
"#"
data-bind=
"click: $root.remove"
></a>
</div>
<input
class=
"edit"
type=
"text"
data-bind=
"value: content, valueUpdate: 'afterkeydown', enterKey: stopEditing,
hasfocus: editing, select: true
, event: { blur: stopEditing }"
/>
data-bind=
"value: content, valueUpdate: 'afterkeydown', enterKey: stopEditing,
selectAndFocus: editing
, event: { blur: stopEditing }"
/>
</li>
</ul>
</section>
...
...
architecture-examples/knockoutjs/js/app.js
View file @
53d5a335
...
...
@@ -28,14 +28,20 @@
}
};
//select text when element is focused
ko
.
bindingHandlers
.
select
=
{
init
:
function
(
element
)
{
var
handler
=
function
()
{
//wrapper to hasfocus that also selects text and applies focus async
ko
.
bindingHandlers
.
selectAndFocus
=
{
init
:
function
(
element
,
valueAccessor
,
allBindingsAccessor
)
{
ko
.
bindingHandlers
.
hasfocus
.
init
(
element
,
valueAccessor
,
allBindingsAccessor
);
ko
.
utils
.
registerEventHandler
(
element
,
"
focus
"
,
function
()
{
element
.
select
();
};
ko
.
utils
.
registerEventHandler
(
element
,
"
focus
"
,
handler
);
});
},
update
:
function
(
element
,
valueAccessor
)
{
ko
.
utils
.
unwrapObservable
(
valueAccessor
());
//for dependency
//ensure that element is visible before trying to focus
setTimeout
(
function
()
{
ko
.
bindingHandlers
.
hasfocus
.
update
(
element
,
valueAccessor
);
},
0
);
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment