Skip to content

Commit abb7029

Browse files
author
minjk-bl
committed
CHROME: add lib files(codemirror, jquery, require)
1 parent 9fea57b commit abb7029

File tree

13 files changed

+13593
-0
lines changed

13 files changed

+13593
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/5/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+
"use strict"
13+
14+
CodeMirror.defineOption("autoRefresh", false, function(cm, val) {
15+
if (cm.state.autoRefresh) {
16+
stopListening(cm, cm.state.autoRefresh)
17+
cm.state.autoRefresh = null
18+
}
19+
if (val && cm.display.wrapper.offsetHeight == 0)
20+
startListening(cm, cm.state.autoRefresh = {delay: val.delay || 250})
21+
})
22+
23+
function startListening(cm, state) {
24+
function check() {
25+
if (cm.display.wrapper.offsetHeight) {
26+
stopListening(cm, state)
27+
if (cm.display.lastWrapHeight != cm.display.wrapper.clientHeight)
28+
cm.refresh()
29+
} else {
30+
state.timeout = setTimeout(check, state.delay)
31+
}
32+
}
33+
state.timeout = setTimeout(check, state.delay)
34+
state.hurry = function() {
35+
clearTimeout(state.timeout)
36+
state.timeout = setTimeout(check, 50)
37+
}
38+
CodeMirror.on(window, "mouseup", state.hurry)
39+
CodeMirror.on(window, "keyup", state.hurry)
40+
}
41+
42+
function stopListening(_cm, state) {
43+
clearTimeout(state.timeout)
44+
CodeMirror.off(window, "mouseup", state.hurry)
45+
CodeMirror.off(window, "keyup", state.hurry)
46+
}
47+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/5/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+
CodeMirror.on(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose = function() { onComposition(cm) })
19+
onChange(cm);
20+
} else if (!val && prev) {
21+
cm.off("blur", onBlur);
22+
cm.off("change", onChange);
23+
cm.off("swapDoc", onChange);
24+
CodeMirror.off(cm.getInputField(), "compositionupdate", cm.state.placeholderCompose)
25+
clearPlaceholder(cm);
26+
var wrapper = cm.getWrapperElement();
27+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "");
28+
}
29+
30+
if (val && !cm.hasFocus()) onBlur(cm);
31+
});
32+
33+
function clearPlaceholder(cm) {
34+
if (cm.state.placeholder) {
35+
cm.state.placeholder.parentNode.removeChild(cm.state.placeholder);
36+
cm.state.placeholder = null;
37+
}
38+
}
39+
function setPlaceholder(cm) {
40+
clearPlaceholder(cm);
41+
var elt = cm.state.placeholder = document.createElement("pre");
42+
elt.style.cssText = "height: 0; overflow: visible";
43+
elt.style.direction = cm.getOption("direction");
44+
elt.className = "CodeMirror-placeholder CodeMirror-line-like";
45+
var placeHolder = cm.getOption("placeholder")
46+
if (typeof placeHolder == "string") placeHolder = document.createTextNode(placeHolder)
47+
elt.appendChild(placeHolder)
48+
cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild);
49+
}
50+
51+
function onComposition(cm) {
52+
setTimeout(function() {
53+
var empty = false
54+
if (cm.lineCount() == 1) {
55+
var input = cm.getInputField()
56+
empty = input.nodeName == "TEXTAREA" ? !cm.getLine(0).length
57+
: !/[^\u200b]/.test(input.querySelector(".CodeMirror-line").textContent)
58+
}
59+
if (empty) setPlaceholder(cm)
60+
else clearPlaceholder(cm)
61+
}, 20)
62+
}
63+
64+
function onBlur(cm) {
65+
if (isEmpty(cm)) setPlaceholder(cm);
66+
}
67+
function onChange(cm) {
68+
var wrapper = cm.getWrapperElement(), empty = isEmpty(cm);
69+
wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : "");
70+
71+
if (empty) setPlaceholder(cm);
72+
else clearPlaceholder(cm);
73+
}
74+
75+
function isEmpty(cm) {
76+
return (cm.lineCount() === 1) && (cm.getLine(0) === "");
77+
}
78+
});

0 commit comments

Comments
 (0)