diff options
| -rw-r--r-- | public/assets/js/lib/views/details/editcomment.js | 1 | ||||
| -rw-r--r-- | public/assets/js/lib/views/mail/compose.js | 11 | ||||
| -rw-r--r-- | public/assets/js/vendor/util.js | 20 |
3 files changed, 30 insertions, 2 deletions
diff --git a/public/assets/js/lib/views/details/editcomment.js b/public/assets/js/lib/views/details/editcomment.js index 39d8a45..2f9a3b5 100644 --- a/public/assets/js/lib/views/details/editcomment.js +++ b/public/assets/js/lib/views/details/editcomment.js @@ -20,6 +20,7 @@ var EditCommentForm = FormView.extend({ this.action = "/api/comment/" + id $.get(this.action, function(data){ this.$comment.val(data.comment.comment).focus() + setCaretToPos(this.$comment.get(0), 0, 0) $("body").removeClass("loading") }.bind(this)) }, diff --git a/public/assets/js/lib/views/mail/compose.js b/public/assets/js/lib/views/mail/compose.js index f2592ea..3d75016 100644 --- a/public/assets/js/lib/views/mail/compose.js +++ b/public/assets/js/lib/views/mail/compose.js @@ -23,15 +23,22 @@ var ComposeView = FormView.extend({ .replace(/{{date}}/, date[0]) .replace(/{{time}}/, date[1]) .replace(/ /g, " ") - console.log(tmpl) + // console.log(tmpl) this.$("[name=username]").val(message.sender) this.$("[name=subject]").val(message.subject) - this.$("[name=body]").val(tmpl + message.body) + this.$("[name=body]").val(tmpl + message.body).focus() + setCaretToPos(this.$("[name=body]").get(0), 0, 0) $("body").removeClass('loading') }.bind(this)) return } this.$("[name=username]").val(username) + if (!username) { + this.$("[name=username]").focus() + } + else { + this.$("[name=body]").focus() + } $("body").removeClass('loading') }, diff --git a/public/assets/js/vendor/util.js b/public/assets/js/vendor/util.js index bcaa2d2..43ca81b 100644 --- a/public/assets/js/vendor/util.js +++ b/public/assets/js/vendor/util.js @@ -140,6 +140,26 @@ function range(m,n,s){ return a } +// manipulate text selection in an element +function setSelectionRange(input, selectionStart, selectionEnd) { + if (input.setSelectionRange) { + input.focus(); + input.setSelectionRange(selectionStart, selectionEnd); + } + else if (input.createTextRange) { + var range = input.createTextRange(); + range.collapse(true); + range.moveEnd('character', selectionEnd); + range.moveStart('character', selectionStart); + range.select(); + } +} + +// place cursor at a specific point (usually the beginning) +function setCaretToPos (input, pos) { + setSelectionRange(input, pos, pos); +} + var guid_syllables = "iz az ez or iv ex baz el lo lum ot un no".split(" ") var guid_n = 0 function guid(n){ |
