Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / display / placeholder.js
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 })();