Repository: incubator-brooklyn Updated Branches: refs/heads/master 3650dfa23 -> d2beaa7de
in yaml preview window, scroll to top after setting contents Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f439cefe Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f439cefe Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f439cefe Branch: refs/heads/master Commit: f439cefe681528e577f2111af921d7296e22436c Parents: 4d6fb47 Author: Alex Heneveld <[email protected]> Authored: Sat Jun 20 10:13:28 2015 -0700 Committer: Alex Heneveld <[email protected]> Committed: Sun Jun 21 12:22:11 2015 -0700 ---------------------------------------------------------------------- .../webapp/assets/js/util/brooklyn-utils.js | 26 ++++++++++++++++++++ .../assets/js/view/application-add-wizard.js | 4 +-- 2 files changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f439cefe/usage/jsgui/src/main/webapp/assets/js/util/brooklyn-utils.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/util/brooklyn-utils.js b/usage/jsgui/src/main/webapp/assets/js/util/brooklyn-utils.js index 318a734..5f3915c 100644 --- a/usage/jsgui/src/main/webapp/assets/js/util/brooklyn-utils.js +++ b/usage/jsgui/src/main/webapp/assets/js/util/brooklyn-utils.js @@ -188,6 +188,32 @@ define([ }); } + Util.setSelectionRange = function (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(); + } + }; + + Util.setCaretToPos = function (input, pos) { + Util.setSelectionRange(input, pos, pos); + }; + + $.fn.setCaretToStart = function() { + this.each(function(index, elem) { + Util.setCaretToPos(elem, 0); + $(elem).scrollTop(0); + }); + return this; + }; + $("#logout-link").on("click", function (e) { e.preventDefault(); Util.logout() http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f439cefe/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js ---------------------------------------------------------------------- diff --git a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js index e9427dd..09fd1c4 100644 --- a/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js +++ b/usage/jsgui/src/main/webapp/assets/js/view/application-add-wizard.js @@ -280,7 +280,7 @@ define([ if (yaml) { // it's a yaml catalog template which includes a location, show the yaml tab $("ul#app-add-wizard-create-tab").find("a[href='#yamlTab']").tab('show'); - $("#yaml_code").focus(); + $("#yaml_code").setCaretToStart(); } else { // it's a java catalog template or yaml template without a location, go to wizard this.currentStep += 1; @@ -302,7 +302,7 @@ define([ that.model.spec.pruneLocations(); $("textarea#yaml_code").val(JsYaml.safeDump(oldSpecToCamp(that.model.spec.toJSON()))); $("ul#app-add-wizard-create-tab").find("a[href='#yamlTab']").tab('show'); - $("#yaml_code").focus(); + $("#yaml_code").setCaretToStart(); }); } else { // call to validate should showFailure
