PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.0.2
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / assets / lib / codemirror / addon / display / placeholder.js

placeholder.js in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.2, at assets/lib/codemirror/addon/display/placeholder.js

55 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 CodeMirror.defineOption("placeholder", "", function(cm, val, old) {
3 var prev = old && old != CodeMirror.Init;
4 if (val && !prev) {
5 cm.on("focus", onFocus);
6 cm.on("blur", onBlur);
7 cm.on("change", onChange);
8 onChange(cm);
9 } else if (!val && prev) {
10 cm.off("focus", onFocus);
11 cm.off("blur", onBlur);
12 cm.off("change", onChange);
13 clearPlaceholder(cm);
14 var wrapper = cm.getWrapperElement();
15 wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
16 }
17
18 if (val && !cm.hasFocus()) onBlur(cm);
19 });
20
21 function clearPlaceholder(cm) {
22 if (cm.state.placeholder) {
23 cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
24 cm.state.placeholder = null;
25 }
26 }
27 function setPlaceholder(cm) {
28 clearPlaceholder(cm);
29 var elt = cm.state.placeholder = document.createElement("pre");
30 elt.style.cssText = "height: 0; overflow: visible";
31 elt.className = "CodeMirror-placeholder";
32 elt.appendChild(document.createTextNode(cm.getOption("placeholder")));
33 cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
34 }
35
36 function onFocus(cm) {
37 clearPlaceholder(cm);
38 }
39 function onBlur(cm) {
40 if (isEmpty(cm)) setPlaceholder(cm);
41 }
42 function onChange(cm) {
43 var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
44 wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
45
46 if (cm.hasFocus()) return;
47 if (empty) setPlaceholder(cm);
48 else clearPlaceholder(cm);
49 }
50
51 function isEmpty(cm) {
52 return (cm.lineCount() === 1) && (cm.getLine(0) === "");
53 }
54 })();
55