You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2016/02/08 12:12:01 UTC
[05/11] brooklyn-ui git commit: Replace existing textareas for
editing YAML with Composer Tab + Codemirror
Replace existing textareas for editing YAML with Composer Tab + Codemirror
Continuatiion of work started in https://github.com/apache/incubator-brooklyn/pull/865 for BROOKLYN-166
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/commit/4174bdb2
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/tree/4174bdb2
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-ui/diff/4174bdb2
Branch: refs/heads/master
Commit: 4174bdb2b61e60216b48a3a0e6aa71a8e0a458a8
Parents: 18b073a
Author: Mark McKenna <m4...@gmail.com>
Authored: Tue Feb 2 16:12:29 2016 +0000
Committer: Mark McKenna <m4...@gmail.com>
Committed: Tue Feb 2 16:59:37 2016 +0000
----------------------------------------------------------------------
src/build/optimize-js.json | 1 +
src/main/license/files/LICENSE | 70 +-
src/main/license/source-inclusions.yaml | 8 +-
src/main/webapp/assets/css/brooklyn.css | 13 +-
src/main/webapp/assets/css/codemirror.css | 334 +
src/main/webapp/assets/css/show-hint.css | 38 +
.../assets/js/addon/display/placeholder.js | 60 +
.../webapp/assets/js/addon/hint/anyword-hint.js | 41 +
.../webapp/assets/js/addon/hint/show-hint.js | 386 +
src/main/webapp/assets/js/config.js | 22 +-
src/main/webapp/assets/js/lib/codemirror.js | 8835 ++++++++++++++++++
src/main/webapp/assets/js/libs/bootstrap.js | 1 +
src/main/webapp/assets/js/libs/js-yaml.js | 5461 ++++++-----
src/main/webapp/assets/js/mode/yaml/yaml.js | 117 +
.../assets/js/model/catalog-application.js | 6 +
src/main/webapp/assets/js/router.js | 19 +-
.../webapp/assets/js/util/brooklyn-utils.js | 1 +
.../assets/js/view/application-add-wizard.js | 83 +-
src/main/webapp/assets/js/view/catalog.js | 51 +-
src/main/webapp/assets/js/view/editor.js | 186 +
.../assets/tpl/app-add-wizard/create.html | 9 +-
src/main/webapp/assets/tpl/editor/page.html | 45 +
src/main/webapp/index.html | 7 +
src/test/javascript/config.txt | 5 +
.../specs/view/application-add-wizard-spec.js | 5 +-
25 files changed, 13137 insertions(+), 2667 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/build/optimize-js.json
----------------------------------------------------------------------
diff --git a/src/build/optimize-js.json b/src/build/optimize-js.json
index 60855d9..9cca776 100644
--- a/src/build/optimize-js.json
+++ b/src/build/optimize-js.json
@@ -16,3 +16,4 @@
// Set to "none" to skip minification
optimize: "uglify"
})
+
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/license/files/LICENSE
----------------------------------------------------------------------
diff --git a/src/main/license/files/LICENSE b/src/main/license/files/LICENSE
index 58c78f1..2a6ca8d 100644
--- a/src/main/license/files/LICENSE
+++ b/src/main/license/files/LICENSE
@@ -208,6 +208,13 @@ This project includes the software: backbone.js
Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
Copyright (c) Jeremy Ashkenas, DocumentCloud Inc. (2010-2013)
+This project includes the software: backbone.js
+ Available at: http://backbonejs.org
+ Developed by: DocumentCloud Inc. (http://www.documentcloud.org/)
+ Version used: 1.1.2
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (c) Jeremy Ashkenas, DocumentCloud (2010-2014)
+
This project includes the software: bootstrap.js
Available at: http://twitter.github.com/bootstrap/javascript.html#transitions
Version used: 2.0.4
@@ -222,6 +229,14 @@ This project includes the software: handlebars.js
Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
Copyright (c) Yehuda Katz (2012)
+This project includes the software: handlebars.js
+ Available at: https://github.com/wycats/handlebars.js
+ Developed by: Yehuda Katz (https://github.com/wycats/)
+ Inclusive of: handlebars*.js
+ Version used: 2.0.0
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (C) by Yehuda Katz (2011-2014)
+
This project includes the software: jQuery JavaScript Library
Available at: http://jquery.com/
Developed by: The jQuery Foundation (http://jquery.org/)
@@ -234,6 +249,18 @@ This project includes the software: jQuery JavaScript Library
Available at http://sizzlejs.com
Used under the MIT license
+This project includes the software: jQuery JavaScript Library
+ Available at: http://jquery.com/
+ Developed by: The jQuery Foundation (http://jquery.org/)
+ Inclusive of: jquery.js
+ Version used: 1.8.0
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (c) jQuery Foundation and other contributors (2012)
+ Includes code fragments from sizzle.js:
+ Copyright (c) The Dojo Foundation
+ Available at http://sizzlejs.com
+ Used under the MIT license
+
This project includes the software: jQuery BBQ: Back Button & Query Library
Available at: http://benalman.com/projects/jquery-bbq-plugin/
Developed by: "Cowboy" Ben Alman (http://benalman.com/)
@@ -282,13 +309,6 @@ This project includes the software: js-yaml.js
Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
Copyright (c) Vitaly Puzrin (2011-2015)
-This project includes the software: marked.js
- Available at: https://github.com/chjj/marked
- Developed by: Christopher Jeffrey (https://github.com/chjj)
- Version used: 0.3.1
- Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
- Copyright (c) Christopher Jeffrey (2011-2014)
-
This project includes the software: moment.js
Available at: http://momentjs.com
Developed by: Tim Wood (http://momentjs.com)
@@ -330,12 +350,19 @@ This project includes the software: RequireJS (r.js maven plugin)
Arpad Borsos (2012)
Used under the BSD 2-Clause license.
+This project includes the software: Swagger JS
+ Available at: https://github.com/swagger-api/swagger-js
+ Inclusive of: swagger.js
+ Version used: 2.1.6
+ Used under the following license: Apache License, version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
+ Copyright (c) SmartBear Software (2015)
+
This project includes the software: Swagger UI
Available at: https://github.com/swagger-api/swagger-ui
- Inclusive of: swagger*.{js,css,html}
- Version used: 2.1.4
+ Inclusive of: swagger-ui.js
+ Version used: 2.1.3
Used under the following license: Apache License, version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
- Copyright (c) SmartBear Software (2011-2015)
+ Copyright (c) SmartBear Software (2015)
This project includes the software: underscore.js
Available at: http://underscorejs.org
@@ -345,6 +372,14 @@ This project includes the software: underscore.js
Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
Copyright (c) Jeremy Ashkenas, DocumentCloud Inc. (2009-2013)
+This project includes the software: underscore.js
+ Available at: http://underscorejs.org
+ Developed by: DocumentCloud Inc. (http://www.documentcloud.org/)
+ Inclusive of: underscore*.{js,map}
+ Version used: 1.7.0
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (c) Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors (2009-2014)
+
This project includes the software: ZeroClipboard
Available at: http://zeroclipboard.org/
Developed by: ZeroClipboard contributors (https://github.com/zeroclipboard)
@@ -353,6 +388,21 @@ This project includes the software: ZeroClipboard
Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
Copyright (c) Jon Rohan, James M. Greene (2014)
+This project includes the software: marked.js
+ Available at: https://github.com/chjj/marked
+ Developed by: Christopher Jeffrey (https://github.com/chjj)
+ Inclusive of: marked.js
+ Version used: 0.3.1
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (c) Christopher Jeffrey (2011-2014)
+
+This project includes the software: CodeMirror
+ Available at: https://codemirror.net/
+ Developed by: CodeMirror (https://codemirror.net)
+ Inclusive of: codemirror*.{js,css}
+ Version used: 5.7.0
+ Used under the following license: The MIT License (http://opensource.org/licenses/MIT)
+ Copyright (c) Marijn Haverbeke (2015)
---------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/license/source-inclusions.yaml
----------------------------------------------------------------------
diff --git a/src/main/license/source-inclusions.yaml b/src/main/license/source-inclusions.yaml
index 8c1945c..32476f4 100644
--- a/src/main/license/source-inclusions.yaml
+++ b/src/main/license/source-inclusions.yaml
@@ -20,10 +20,9 @@
# extras file for org.heneveld.license-audit-maven-plugin
# listing projects from which *source* files are included
-- id: jquery-core:1.7.2
-- id: swagger-ui:2.1.4
-# we use other versions of the above in other projs
-
+- id: jquery-core
+- id: swagger
+- id: swagger-ui
- id: jquery.wiggle.min.js
- id: require.js
- id: require.js/r.js
@@ -40,3 +39,4 @@
- id: js-yaml.js
- id: jquery.form.js
- id: marked.js
+- id: codemirror.js
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/css/brooklyn.css
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/css/brooklyn.css b/src/main/webapp/assets/css/brooklyn.css
index fde2a3c..c2ad673 100644
--- a/src/main/webapp/assets/css/brooklyn.css
+++ b/src/main/webapp/assets/css/brooklyn.css
@@ -25,7 +25,6 @@ BODY {
textarea {
white-space: pre;
word-wrap: normal;
- overflow-x: scroll;
}
/* HEADER */
@@ -269,3 +268,15 @@ textarea {
content: 'Not Available';
*/
}
+
+button.catalog-submit-button.btn {
+ margin-top: 10px;
+}
+
+.CodeMirror .cm-s-default {
+ height: 560px;
+}
+
+.CodeMirror .CodeMirror-placeholder {
+ color: #999;
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/css/codemirror.css
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/css/codemirror.css b/src/main/webapp/assets/css/codemirror.css
new file mode 100644
index 0000000..3543523
--- /dev/null
+++ b/src/main/webapp/assets/css/codemirror.css
@@ -0,0 +1,334 @@
+/* BASICS */
+
+.CodeMirror {
+ /* Set height, width, borders, and global font properties here */
+ font-family: monospace;
+ height: 300px;
+ color: black;
+}
+
+/* PADDING */
+
+.CodeMirror-lines {
+ padding: 4px 0; /* Vertical padding around content */
+}
+.CodeMirror pre {
+ padding: 0 4px; /* Horizontal padding of content */
+}
+
+.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
+ background-color: white; /* The little square between H and V scrollbars */
+}
+
+/* GUTTER */
+
+.CodeMirror-gutters {
+ border-right: 1px solid #ddd;
+ background-color: #f7f7f7;
+ white-space: nowrap;
+}
+.CodeMirror-linenumbers {}
+.CodeMirror-linenumber {
+ padding: 0 3px 0 5px;
+ min-width: 20px;
+ text-align: right;
+ color: #999;
+ white-space: nowrap;
+}
+
+.CodeMirror-guttermarker { color: black; }
+.CodeMirror-guttermarker-subtle { color: #999; }
+
+/* CURSOR */
+
+.CodeMirror-cursor {
+ border-left: 1px solid black;
+ border-right: none;
+ width: 0;
+}
+/* Shown when moving in bi-directional text */
+.CodeMirror div.CodeMirror-secondarycursor {
+ border-left: 1px solid silver;
+}
+.cm-fat-cursor .CodeMirror-cursor {
+ width: auto;
+ border: 0;
+ background: #7e7;
+}
+.cm-fat-cursor div.CodeMirror-cursors {
+ z-index: 1;
+}
+
+.cm-animate-fat-cursor {
+ width: auto;
+ border: 0;
+ -webkit-animation: blink 1.06s steps(1) infinite;
+ -moz-animation: blink 1.06s steps(1) infinite;
+ animation: blink 1.06s steps(1) infinite;
+ background-color: #7e7;
+}
+@-moz-keyframes blink {
+ 0% {}
+ 50% { background-color: transparent; }
+ 100% {}
+}
+@-webkit-keyframes blink {
+ 0% {}
+ 50% { background-color: transparent; }
+ 100% {}
+}
+@keyframes blink {
+ 0% {}
+ 50% { background-color: transparent; }
+ 100% {}
+}
+
+/* Can style cursor different in overwrite (non-insert) mode */
+.CodeMirror-overwrite .CodeMirror-cursor {}
+
+.cm-tab { display: inline-block; text-decoration: inherit; }
+
+.CodeMirror-ruler {
+ border-left: 1px solid #ccc;
+ position: absolute;
+}
+
+/* DEFAULT THEME */
+
+.cm-s-default .cm-header {color: blue;}
+.cm-s-default .cm-quote {color: #090;}
+.cm-negative {color: #d44;}
+.cm-positive {color: #292;}
+.cm-header, .cm-strong {font-weight: bold;}
+.cm-em {font-style: italic;}
+.cm-link {text-decoration: underline;}
+.cm-strikethrough {text-decoration: line-through;}
+
+.cm-s-default .cm-keyword {color: #708;}
+.cm-s-default .cm-atom {color: #219;}
+.cm-s-default .cm-number {color: #164;}
+.cm-s-default .cm-def {color: #00f;}
+.cm-s-default .cm-variable,
+.cm-s-default .cm-punctuation,
+.cm-s-default .cm-property,
+.cm-s-default .cm-operator {}
+.cm-s-default .cm-variable-2 {color: #05a;}
+.cm-s-default .cm-variable-3 {color: #085;}
+.cm-s-default .cm-comment {color: #a50;}
+.cm-s-default .cm-string {color: #a11;}
+.cm-s-default .cm-string-2 {color: #f50;}
+.cm-s-default .cm-meta {color: #555;}
+.cm-s-default .cm-qualifier {color: #555;}
+.cm-s-default .cm-builtin {color: #30a;}
+.cm-s-default .cm-bracket {color: #997;}
+.cm-s-default .cm-tag {color: #170;}
+.cm-s-default .cm-attribute {color: #00c;}
+.cm-s-default .cm-hr {color: #999;}
+.cm-s-default .cm-link {color: #00c;}
+
+.cm-s-default .cm-error {color: #f00;}
+.cm-invalidchar {color: #f00;}
+
+.CodeMirror-composing { border-bottom: 2px solid; }
+
+/* Default styles for common addons */
+
+div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
+div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
+.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
+.CodeMirror-activeline-background {background: #e8f2ff;}
+
+/* STOP */
+
+/* The rest of this file contains styles related to the mechanics of
+ the editor. You probably shouldn't touch them. */
+
+.CodeMirror {
+ position: relative;
+ overflow: hidden;
+ background: white;
+}
+
+.CodeMirror-scroll {
+ overflow: scroll !important; /* Things will break if this is overridden */
+ /* 30px is the magic margin used to hide the element's real scrollbars */
+ /* See overflow: hidden in .CodeMirror */
+ margin-bottom: -30px; margin-right: -30px;
+ padding-bottom: 30px;
+ height: 100%;
+ outline: none; /* Prevent dragging from highlighting the element */
+ position: relative;
+}
+.CodeMirror-sizer {
+ position: relative;
+ border-right: 30px solid transparent;
+}
+
+/* The fake, visible scrollbars. Used to force redraw during scrolling
+ before actuall scrolling happens, thus preventing shaking and
+ flickering artifacts. */
+.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
+ position: absolute;
+ z-index: 6;
+ display: none;
+}
+.CodeMirror-vscrollbar {
+ right: 0; top: 0;
+ overflow-x: hidden;
+ overflow-y: scroll;
+}
+.CodeMirror-hscrollbar {
+ bottom: 0; left: 0;
+ overflow-y: hidden;
+ overflow-x: scroll;
+}
+.CodeMirror-scrollbar-filler {
+ right: 0; bottom: 0;
+}
+.CodeMirror-gutter-filler {
+ left: 0; bottom: 0;
+}
+
+.CodeMirror-gutters {
+ position: absolute; left: 0; top: 0;
+ z-index: 3;
+}
+.CodeMirror-gutter {
+ white-space: normal;
+ height: 100%;
+ display: inline-block;
+ margin-bottom: -30px;
+ /* Hack to make IE7 behave */
+ *zoom:1;
+ *display:inline;
+}
+.CodeMirror-gutter-wrapper {
+ position: absolute;
+ z-index: 4;
+ background: none !important;
+ border: none !important;
+}
+.CodeMirror-gutter-background {
+ position: absolute;
+ top: 0; bottom: 0;
+ z-index: 4;
+}
+.CodeMirror-gutter-elt {
+ position: absolute;
+ cursor: default;
+ z-index: 4;
+}
+.CodeMirror-gutter-wrapper {
+ -webkit-user-select: none;
+ -moz-user-select: none;
+ user-select: none;
+}
+
+.CodeMirror-lines {
+ cursor: text;
+ min-height: 1px; /* prevents collapsing before first draw */
+}
+.CodeMirror pre {
+ /* Reset some styles that the rest of the page might have set */
+ -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
+ border-width: 0;
+ background: transparent;
+ font-family: inherit;
+ font-size: inherit;
+ margin: 0;
+ white-space: pre;
+ word-wrap: normal;
+ line-height: inherit;
+ color: inherit;
+ z-index: 2;
+ position: relative;
+ overflow: visible;
+ -webkit-tap-highlight-color: transparent;
+}
+.CodeMirror-wrap pre {
+ word-wrap: break-word;
+ white-space: pre-wrap;
+ word-break: normal;
+}
+
+.CodeMirror-linebackground {
+ position: absolute;
+ left: 0; right: 0; top: 0; bottom: 0;
+ z-index: 0;
+}
+
+.CodeMirror-linewidget {
+ position: relative;
+ z-index: 2;
+ overflow: auto;
+}
+
+.CodeMirror-widget {}
+
+.CodeMirror-code {
+ outline: none;
+}
+
+/* Force content-box sizing for the elements where we expect it */
+.CodeMirror-scroll,
+.CodeMirror-sizer,
+.CodeMirror-gutter,
+.CodeMirror-gutters,
+.CodeMirror-linenumber {
+ -moz-box-sizing: content-box;
+ box-sizing: content-box;
+}
+
+.CodeMirror-measure {
+ position: absolute;
+ width: 100%;
+ height: 0;
+ overflow: hidden;
+ visibility: hidden;
+}
+
+.CodeMirror-cursor { position: absolute; }
+.CodeMirror-measure pre { position: static; }
+
+div.CodeMirror-cursors {
+ visibility: hidden;
+ position: relative;
+ z-index: 3;
+}
+div.CodeMirror-dragcursors {
+ visibility: visible;
+}
+
+.CodeMirror-focused div.CodeMirror-cursors {
+ visibility: visible;
+}
+
+.CodeMirror-selected { background: #d9d9d9; }
+.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
+.CodeMirror-crosshair { cursor: crosshair; }
+.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
+.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
+
+.cm-searching {
+ background: #ffa;
+ background: rgba(255, 255, 0, .4);
+}
+
+/* IE7 hack to prevent it from returning funny offsetTops on the spans */
+.CodeMirror span { *vertical-align: text-bottom; }
+
+/* Used to force a border model for a node */
+.cm-force-border { padding-right: .1px; }
+
+@media print {
+ /* Hide the cursor when printing */
+ .CodeMirror div.CodeMirror-cursors {
+ visibility: hidden;
+ }
+}
+
+/* See issue #2901 */
+.cm-tab-wrap-hack:after { content: ''; }
+
+/* Help users use markselection to safely style text background */
+span.CodeMirror-selectedtext { background: none; }
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/css/show-hint.css
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/css/show-hint.css b/src/main/webapp/assets/css/show-hint.css
new file mode 100644
index 0000000..d2033ba
--- /dev/null
+++ b/src/main/webapp/assets/css/show-hint.css
@@ -0,0 +1,38 @@
+.CodeMirror-hints {
+ position: absolute;
+ z-index: 10;
+ overflow: hidden;
+ list-style: none;
+
+ margin: 0;
+ padding: 2px;
+
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
+ border-radius: 3px;
+ border: 1px solid silver;
+
+ background: white;
+ font-size: 90%;
+ font-family: monospace;
+
+ max-height: 20em;
+ overflow-y: auto;
+}
+
+.CodeMirror-hint {
+ margin: 0;
+ padding: 0 4px;
+ border-radius: 2px;
+ max-width: 19em;
+ overflow: hidden;
+ white-space: pre;
+ color: black;
+ cursor: pointer;
+}
+
+li.CodeMirror-hint-active {
+ background: #08f;
+ color: white;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/js/addon/display/placeholder.js
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/js/addon/display/placeholder.js b/src/main/webapp/assets/js/addon/display/placeholder.js
new file mode 100644
index 0000000..ba6c096
--- /dev/null
+++ b/src/main/webapp/assets/js/addon/display/placeholder.js
@@ -0,0 +1,60 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
+ var prev = old && old != CodeMirror.Init;
+ if (val && !prev) {
+ cm.on("blur", onBlur);
+ cm.on("change", onChange);
+ onChange(cm);
+ } else if (!val && prev) {
+ cm.off("blur", onBlur);
+ cm.off("change", onChange);
+ clearPlaceholder(cm);
+ var wrapper = cm.getWrapperElement();
+ wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
+ }
+
+ if (val && !cm.hasFocus()) onBlur(cm);
+ });
+
+ function clearPlaceholder(cm) {
+ if (cm.state.placeholder) {
+ cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
+ cm.state.placeholder = null;
+ }
+ }
+ function setPlaceholder(cm) {
+ clearPlaceholder(cm);
+ var elt = cm.state.placeholder = document.createElement("pre");
+ elt.style.cssText = "height: 0; overflow: visible";
+ elt.className = "CodeMirror-placeholder";
+ var placeHolder = cm.getOption("placeholder")
+ if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
+ elt.appendChild(placeHolder)
+ cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
+ }
+
+ function onBlur(cm) {
+ if (isEmpty(cm)) setPlaceholder(cm);
+ }
+ function onChange(cm) {
+ var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
+ wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
+
+ if (empty) setPlaceholder(cm);
+ else clearPlaceholder(cm);
+ }
+
+ function isEmpty(cm) {
+ return (cm.lineCount() === 1) && (cm.getLine(0) === "");
+ }
+});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/js/addon/hint/anyword-hint.js
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/js/addon/hint/anyword-hint.js b/src/main/webapp/assets/js/addon/hint/anyword-hint.js
new file mode 100644
index 0000000..ade4274
--- /dev/null
+++ b/src/main/webapp/assets/js/addon/hint/anyword-hint.js
@@ -0,0 +1,41 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+
+ var WORD = /[\w$]+/, RANGE = 500;
+
+ CodeMirror.registerHelper("hint", "anyword", function(editor, options) {
+ var word = options && options.word || WORD;
+ var range = options && options.range || RANGE;
+ var cur = editor.getCursor(), curLine = editor.getLine(cur.line);
+ var end = cur.ch, start = end;
+ while (start && word.test(curLine.charAt(start - 1))) --start;
+ var curWord = start != end && curLine.slice(start, end);
+
+ var list = options && options.list || [], seen = {};
+ var re = new RegExp(word.source, "g");
+ for (var dir = -1; dir <= 1; dir += 2) {
+ var line = cur.line, endLine = Math.min(Math.max(line + dir * range, editor.firstLine()), editor.lastLine()) + dir;
+ for (; line != endLine; line += dir) {
+ var text = editor.getLine(line), m;
+ while (m = re.exec(text)) {
+ if (line == cur.line && m[0] === curWord) continue;
+ if ((!curWord || m[0].lastIndexOf(curWord, 0) == 0) && !Object.prototype.hasOwnProperty.call(seen, m[0])) {
+ seen[m[0]] = true;
+ list.push(m[0]);
+ }
+ }
+ }
+ }
+ return {list: list, from: CodeMirror.Pos(cur.line, start), to: CodeMirror.Pos(cur.line, end)};
+ });
+});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/js/addon/hint/show-hint.js
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/js/addon/hint/show-hint.js b/src/main/webapp/assets/js/addon/hint/show-hint.js
new file mode 100644
index 0000000..fa27867
--- /dev/null
+++ b/src/main/webapp/assets/js/addon/hint/show-hint.js
@@ -0,0 +1,386 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+
+ var HINT_ELEMENT_CLASS = "CodeMirror-hint";
+ var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
+
+ // This is the old interface, kept around for now to stay
+ // backwards-compatible.
+ CodeMirror.showHint = function(cm, getHints, options) {
+ if (!getHints) return cm.showHint(options);
+ if (options && options.async) getHints.async = true;
+ var newOpts = {hint: getHints};
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
+ return cm.showHint(newOpts);
+ };
+
+ CodeMirror.defineExtension("showHint", function(options) {
+ // We want a single cursor position.
+ if (this.listSelections().length > 1 || this.somethingSelected()) return;
+
+ if (this.state.completionActive) this.state.completionActive.close();
+ var completion = this.state.completionActive = new Completion(this, options);
+ if (!completion.options.hint) return;
+
+ CodeMirror.signal(this, "startCompletion", this);
+ completion.update(true);
+ });
+
+ function Completion(cm, options) {
+ this.cm = cm;
+ this.options = this.buildOptions(options);
+ this.widget = null;
+ this.debounce = 0;
+ this.tick = 0;
+ this.startPos = this.cm.getCursor();
+ this.startLen = this.cm.getLine(this.startPos.line).length;
+
+ var self = this;
+ cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
+ }
+
+ var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
+ return setTimeout(fn, 1000/60);
+ };
+ var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
+
+ Completion.prototype = {
+ close: function() {
+ if (!this.active()) return;
+ this.cm.state.completionActive = null;
+ this.tick = null;
+ this.cm.off("cursorActivity", this.activityFunc);
+
+ if (this.widget && this.data) CodeMirror.signal(this.data, "close");
+ if (this.widget) this.widget.close();
+ CodeMirror.signal(this.cm, "endCompletion", this.cm);
+ },
+
+ active: function() {
+ return this.cm.state.completionActive == this;
+ },
+
+ pick: function(data, i) {
+ var completion = data.list[i];
+ if (completion.hint) completion.hint(this.cm, data, completion);
+ else this.cm.replaceRange(getText(completion), completion.from || data.from,
+ completion.to || data.to, "complete");
+ CodeMirror.signal(data, "pick", completion);
+ this.close();
+ },
+
+ cursorActivity: function() {
+ if (this.debounce) {
+ cancelAnimationFrame(this.debounce);
+ this.debounce = 0;
+ }
+
+ var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
+ if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
+ pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
+ (pos.ch && this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
+ this.close();
+ } else {
+ var self = this;
+ this.debounce = requestAnimationFrame(function() {self.update();});
+ if (this.widget) this.widget.disable();
+ }
+ },
+
+ update: function(first) {
+ if (this.tick == null) return;
+ if (!this.options.hint.async) {
+ this.finishUpdate(this.options.hint(this.cm, this.options), first);
+ } else {
+ var myTick = ++this.tick, self = this;
+ this.options.hint(this.cm, function(data) {
+ if (self.tick == myTick) self.finishUpdate(data, first);
+ }, this.options);
+ }
+ },
+
+ finishUpdate: function(data, first) {
+ if (this.data) CodeMirror.signal(this.data, "update");
+ if (data && this.data && CodeMirror.cmpPos(data.from, this.data.from)) data = null;
+ this.data = data;
+
+ var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
+ if (this.widget) this.widget.close();
+ if (data && data.list.length) {
+ if (picked && data.list.length == 1) {
+ this.pick(data, 0);
+ } else {
+ this.widget = new Widget(this, data);
+ CodeMirror.signal(data, "shown");
+ }
+ }
+ },
+
+ buildOptions: function(options) {
+ var editor = this.cm.options.hintOptions;
+ var out = {};
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
+ if (editor) for (var prop in editor)
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
+ if (options) for (var prop in options)
+ if (options[prop] !== undefined) out[prop] = options[prop];
+ return out;
+ }
+ };
+
+ function getText(completion) {
+ if (typeof completion == "string") return completion;
+ else return completion.text;
+ }
+
+ function buildKeyMap(completion, handle) {
+ var baseMap = {
+ Up: function() {handle.moveFocus(-1);},
+ Down: function() {handle.moveFocus(1);},
+ PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
+ PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
+ Home: function() {handle.setFocus(0);},
+ End: function() {handle.setFocus(handle.length - 1);},
+ Enter: handle.pick,
+ Tab: handle.pick,
+ Esc: handle.close
+ };
+ var custom = completion.options.customKeys;
+ var ourMap = custom ? {} : baseMap;
+ function addBinding(key, val) {
+ var bound;
+ if (typeof val != "string")
+ bound = function(cm) { return val(cm, handle); };
+ // This mechanism is deprecated
+ else if (baseMap.hasOwnProperty(val))
+ bound = baseMap[val];
+ else
+ bound = val;
+ ourMap[key] = bound;
+ }
+ if (custom)
+ for (var key in custom) if (custom.hasOwnProperty(key))
+ addBinding(key, custom[key]);
+ var extra = completion.options.extraKeys;
+ if (extra)
+ for (var key in extra) if (extra.hasOwnProperty(key))
+ addBinding(key, extra[key]);
+ return ourMap;
+ }
+
+ function getHintElement(hintsElement, el) {
+ while (el && el != hintsElement) {
+ if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
+ el = el.parentNode;
+ }
+ }
+
+ function Widget(completion, data) {
+ this.completion = completion;
+ this.data = data;
+ this.picked = false;
+ var widget = this, cm = completion.cm;
+
+ var hints = this.hints = document.createElement("ul");
+ hints.className = "CodeMirror-hints";
+ this.selectedHint = data.selectedHint || 0;
+
+ var completions = data.list;
+ for (var i = 0; i < completions.length; ++i) {
+ var elt = hints.appendChild(document.createElement("li")), cur = completions[i];
+ var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
+ if (cur.className != null) className = cur.className + " " + className;
+ elt.className = className;
+ if (cur.render) cur.render(elt, data, cur);
+ else elt.appendChild(document.createTextNode(cur.displayText || getText(cur)));
+ elt.hintId = i;
+ }
+
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
+ var left = pos.left, top = pos.bottom, below = true;
+ hints.style.left = left + "px";
+ hints.style.top = top + "px";
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
+ var winW = window.innerWidth || Math.max(document.body.offsetWidth, document.documentElement.offsetWidth);
+ var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
+ (completion.options.container || document.body).appendChild(hints);
+ var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
+ if (overlapY > 0) {
+ var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
+ if (curTop - height > 0) { // Fits above cursor
+ hints.style.top = (top = pos.top - height) + "px";
+ below = false;
+ } else if (height > winH) {
+ hints.style.height = (winH - 5) + "px";
+ hints.style.top = (top = pos.bottom - box.top) + "px";
+ var cursor = cm.getCursor();
+ if (data.from.ch != cursor.ch) {
+ pos = cm.cursorCoords(cursor);
+ hints.style.left = (left = pos.left) + "px";
+ box = hints.getBoundingClientRect();
+ }
+ }
+ }
+ var overlapX = box.right - winW;
+ if (overlapX > 0) {
+ if (box.right - box.left > winW) {
+ hints.style.width = (winW - 5) + "px";
+ overlapX -= (box.right - box.left) - winW;
+ }
+ hints.style.left = (left = pos.left - overlapX) + "px";
+ }
+
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
+ moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
+ setFocus: function(n) { widget.changeActive(n); },
+ menuSize: function() { return widget.screenAmount(); },
+ length: completions.length,
+ close: function() { completion.close(); },
+ pick: function() { widget.pick(); },
+ data: data
+ }));
+
+ if (completion.options.closeOnUnfocus) {
+ var closingOnBlur;
+ cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
+ cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
+ }
+
+ var startScroll = cm.getScrollInfo();
+ cm.on("scroll", this.onScroll = function() {
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
+ var newTop = top + startScroll.top - curScroll.top;
+ var point = newTop - (window.pageYOffset || (document.documentElement || document.body).scrollTop);
+ if (!below) point += hints.offsetHeight;
+ if (point <= editor.top || point >= editor.bottom) return completion.close();
+ hints.style.top = newTop + "px";
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
+ });
+
+ CodeMirror.on(hints, "dblclick", function(e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
+ });
+
+ CodeMirror.on(hints, "click", function(e) {
+ var t = getHintElement(hints, e.target || e.srcElement);
+ if (t && t.hintId != null) {
+ widget.changeActive(t.hintId);
+ if (completion.options.completeOnSingleClick) widget.pick();
+ }
+ });
+
+ CodeMirror.on(hints, "mousedown", function() {
+ setTimeout(function(){cm.focus();}, 20);
+ });
+
+ CodeMirror.signal(data, "select", completions[0], hints.firstChild);
+ return true;
+ }
+
+ Widget.prototype = {
+ close: function() {
+ if (this.completion.widget != this) return;
+ this.completion.widget = null;
+ this.hints.parentNode.removeChild(this.hints);
+ this.completion.cm.removeKeyMap(this.keyMap);
+
+ var cm = this.completion.cm;
+ if (this.completion.options.closeOnUnfocus) {
+ cm.off("blur", this.onBlur);
+ cm.off("focus", this.onFocus);
+ }
+ cm.off("scroll", this.onScroll);
+ },
+
+ disable: function() {
+ this.completion.cm.removeKeyMap(this.keyMap);
+ var widget = this;
+ this.keyMap = {Enter: function() { widget.picked = true; }};
+ this.completion.cm.addKeyMap(this.keyMap);
+ },
+
+ pick: function() {
+ this.completion.pick(this.data, this.selectedHint);
+ },
+
+ changeActive: function(i, avoidWrap) {
+ if (i >= this.data.list.length)
+ i = avoidWrap ? this.data.list.length - 1 : 0;
+ else if (i < 0)
+ i = avoidWrap ? 0 : this.data.list.length - 1;
+ if (this.selectedHint == i) return;
+ var node = this.hints.childNodes[this.selectedHint];
+ node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
+ node = this.hints.childNodes[this.selectedHint = i];
+ node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
+ if (node.offsetTop < this.hints.scrollTop)
+ this.hints.scrollTop = node.offsetTop - 3;
+ else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
+ this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
+ CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
+ },
+
+ screenAmount: function() {
+ return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
+ }
+ };
+
+ CodeMirror.registerHelper("hint", "auto", function(cm, options) {
+ var helpers = cm.getHelpers(cm.getCursor(), "hint"), words;
+ if (helpers.length) {
+ for (var i = 0; i < helpers.length; i++) {
+ var cur = helpers[i](cm, options);
+ if (cur && cur.list.length) return cur;
+ }
+ } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
+ if (words) return CodeMirror.hint.fromList(cm, {words: words});
+ } else if (CodeMirror.hint.anyword) {
+ return CodeMirror.hint.anyword(cm, options);
+ }
+ });
+
+ CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur);
+ var to = CodeMirror.Pos(cur.line, token.end);
+ if (token.string && /\w/.test(token.string[token.string.length - 1])) {
+ var term = token.string, from = CodeMirror.Pos(cur.line, token.start);
+ } else {
+ var term = "", from = to;
+ }
+ var found = [];
+ for (var i = 0; i < options.words.length; i++) {
+ var word = options.words[i];
+ if (word.slice(0, term.length) == term)
+ found.push(word);
+ }
+
+ if (found.length) return {list: found, from: from, to: to};
+ });
+
+ CodeMirror.commands.autocomplete = CodeMirror.showHint;
+
+ var defaultOptions = {
+ hint: CodeMirror.hint.auto,
+ completeSingle: true,
+ alignWithWord: true,
+ closeCharacters: /[\s()\[\]{};:>,]/,
+ closeOnUnfocus: true,
+ completeOnSingleClick: false,
+ container: null,
+ customKeys: null,
+ extraKeys: null
+ };
+
+ CodeMirror.defineOption("hintOptions", null);
+});
http://git-wip-us.apache.org/repos/asf/brooklyn-ui/blob/4174bdb2/src/main/webapp/assets/js/config.js
----------------------------------------------------------------------
diff --git a/src/main/webapp/assets/js/config.js b/src/main/webapp/assets/js/config.js
index 6710ff1..24965a8 100644
--- a/src/main/webapp/assets/js/config.js
+++ b/src/main/webapp/assets/js/config.js
@@ -30,11 +30,13 @@ require.config({
"underscore":"libs/underscore",
"backbone":"libs/backbone",
"bootstrap":"libs/bootstrap",
+
"jquery-form":"libs/jquery.form",
"jquery-datatables":"libs/jquery.dataTables",
"jquery-slideto":"util/jquery.slideto",
"jquery-wiggle":"libs/jquery.wiggle.min",
"jquery-ba-bbq":"libs/jquery.ba-bbq.min",
+
"moment":"libs/moment",
"handlebars":"libs/handlebars-1.0.rc.1",
"brooklyn":"util/brooklyn",
@@ -47,7 +49,17 @@ require.config({
"uri":"libs/URI",
"zeroclipboard":"libs/ZeroClipboard",
"js-yaml":"libs/js-yaml",
-
+
+ "codemirror":"lib/codemirror",
+
+ "mode":"mode",
+ "addon":"addon",
+
+ "codemirror-mode-yaml":"mode/yaml/yaml",
+ "codemirror-addon-show-hint":"addon/hint/show-hint",
+ "codemirror-addon-anyword-hint":"addon/hint/anyword-hint",
+ "codemirror-addon-display-placeholder":"addon/display/placeholder",
+
"tpl":"../tpl"
},
@@ -70,6 +82,14 @@ require.config({
"jquery-wiggle": { deps: [ "jquery" ] },
"jquery-ba-bbq": { deps: [ "jquery" ] },
"handlebars": { deps: [ "jquery" ] },
+ "codemirror":{
+ exports:"CodeMirror"
+ },
+ "codemirror-mode-yaml":{ deps: ["codemirror"] },
+ "codemirror-addon-show-hint":{ deps: ["codemirror"] },
+ "codemirror-addon-anyword-hint":{ deps: ["codemirror"] },
+ "codemirror-addon-display-placeholder":{ deps: ["codemirror"] },
+
"bootstrap": { deps: [ "jquery" ] /* http://stackoverflow.com/questions/9227406/bootstrap-typeerror-undefined-is-not-a-function-has-no-method-tab-when-us */ }
}
});