PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.10
Smart Grid-Layout Design for Contact Form 7 v4.10
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
cf7-grid-layout / assets / codemirror / addon / display / placeholder.js

placeholder.js in Smart Grid-Layout Design for Contact Form 7 4.10, at assets/codemirror/addon/display/placeholder.js

63 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3
4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env
10 mod(CodeMirror);
11 })(function(CodeMirror) {
12 CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
13 var prev = old && old != CodeMirror.Init;
14 if (val && !prev) {
15 cm.on("blur", onBlur);
16 cm.on("change", onChange);
17 cm.on("swapDoc", onChange);
18 onChange(cm);
19 } else if (!val && prev) {
20 cm.off("blur", onBlur);
21 cm.off("change", onChange);
22 cm.off("swapDoc", onChange);
23 clearPlaceholder(cm);
24 var wrapper = cm.getWrapperElement();
25 wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
26 }
27
28 if (val && !cm.hasFocus()) onBlur(cm);
29 });
30
31 function clearPlaceholder(cm) {
32 if (cm.state.placeholder) {
33 cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
34 cm.state.placeholder = null;
35 }
36 }
37 function setPlaceholder(cm) {
38 clearPlaceholder(cm);
39 var elt = cm.state.placeholder = document.createElement("pre");
40 elt.style.cssText = "height: 0; overflow: visible";
41 elt.className = "CodeMirror-placeholder";
42 var placeHolder = cm.getOption("placeholder")
43 if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
44 elt.appendChild(placeHolder)
45 cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
46 }
47
48 function onBlur(cm) {
49 if (isEmpty(cm)) setPlaceholder(cm);
50 }
51 function onChange(cm) {
52 var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
53 wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
54
55 if (empty) setPlaceholder(cm);
56 else clearPlaceholder(cm);
57 }
58
59 function isEmpty(cm) {
60 return (cm.lineCount() === 1) && (cm.getLine(0) === "");
61 }
62 });
63