Add placeholder to code-mirror directives

This commit is contained in:
BoykoAlex
2016-09-09 12:55:29 -04:00
parent 609dddf82a
commit 80f5b0ff6b
4 changed files with 70 additions and 5 deletions

68
dist/spring-flo.js vendored
View File

@@ -9346,6 +9346,65 @@ define('codemirror', ['codemirror/lib/codemirror'], function (main) { return mai
CodeMirror.defineOption("hintOptions", null);
});
// 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("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define('codemirror/addon/display/placeholder',["../../lib/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";
elt.appendChild(document.createTextNode(cm.getOption("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) === "");
}
});
/*
* Copyright 2016 the original author or authors.
*
@@ -9363,7 +9422,7 @@ define('codemirror', ['codemirror/lib/codemirror'], function (main) { return mai
*/
define('controllers/dsl-editor',['require','angular','codemirror','codemirror/addon/lint/lint','codemirror/addon/hint/show-hint'],function(require) {
define('controllers/dsl-editor',['require','angular','codemirror','codemirror/addon/lint/lint','codemirror/addon/hint/show-hint','codemirror/addon/display/placeholder'],function(require) {
var angular = require('angular');
@@ -9377,8 +9436,10 @@ define('controllers/dsl-editor',['require','angular','codemirror','codemirror/ad
require('codemirror/addon/lint/lint');
require('codemirror/addon/hint/show-hint');
require('codemirror/addon/display/placeholder');
/**
/**
* Control graph-to-text syncing. When it is active the graph will be automatically
* updated as the text is modified.
*/
@@ -24741,7 +24802,7 @@ define("jshint", ["lodash"], function(){});
* benefit from the use of a real editor that can provide features like syntax highlighting and mark
* errors/warnings.
*/
define('controllers/code-editor',['require','angular','codemirror','codemirror/mode/meta','codemirror/addon/lint/lint','codemirror/addon/hint/show-hint','codemirror/addon/mode/loadmode','codemirror/addon/edit/matchbrackets','codemirror/addon/edit/closebrackets','codemirror/mode/groovy/groovy','codemirror/mode/javascript/javascript','codemirror/mode/python/python','codemirror/mode/ruby/ruby','codemirror/mode/clike/clike','jshint','codemirror/addon/lint/javascript-lint'],function(require) {
define('controllers/code-editor',['require','angular','codemirror','codemirror/mode/meta','codemirror/addon/lint/lint','codemirror/addon/hint/show-hint','codemirror/addon/mode/loadmode','codemirror/addon/edit/matchbrackets','codemirror/addon/edit/closebrackets','codemirror/addon/display/placeholder','codemirror/mode/groovy/groovy','codemirror/mode/javascript/javascript','codemirror/mode/python/python','codemirror/mode/ruby/ruby','codemirror/mode/clike/clike','jshint','codemirror/addon/lint/javascript-lint'],function(require) {
return ['$scope', function ($scope) {
@@ -24755,6 +24816,7 @@ define('controllers/code-editor',['require','angular','codemirror','codemirror/m
require('codemirror/addon/mode/loadmode');
require('codemirror/addon/edit/matchbrackets');
require('codemirror/addon/edit/closebrackets');
require('codemirror/addon/display/placeholder');
// languages
require('codemirror/mode/groovy/groovy');

File diff suppressed because one or more lines are too long

View File

@@ -40,6 +40,7 @@ define(function(require) {
require('codemirror/addon/mode/loadmode');
require('codemirror/addon/edit/matchbrackets');
require('codemirror/addon/edit/closebrackets');
require('codemirror/addon/display/placeholder');
// languages
require('codemirror/mode/groovy/groovy');

View File

@@ -29,8 +29,10 @@ define(function(require) {
require('codemirror/addon/lint/lint');
require('codemirror/addon/hint/show-hint');
require('codemirror/addon/display/placeholder');
/**
/**
* Control graph-to-text syncing. When it is active the graph will be automatically
* updated as the text is modified.
*/