2023-01-16 22:26:34 +00:00
|
|
|
ace.define("ace/ext/textarea",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/net","ace/ace"], function(require, exports, module){"use strict";
|
2013-12-30 15:00:16 +00:00
|
|
|
var event = require("../lib/event");
|
|
|
|
var UA = require("../lib/useragent");
|
|
|
|
var net = require("../lib/net");
|
|
|
|
var ace = require("../ace");
|
|
|
|
module.exports = exports = ace;
|
2023-01-16 22:26:34 +00:00
|
|
|
var getCSSProperty = function (element, container, property) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var ret = element.style[property];
|
|
|
|
if (!ret) {
|
|
|
|
if (window.getComputedStyle) {
|
|
|
|
ret = window.getComputedStyle(element, '').getPropertyValue(property);
|
2023-01-16 22:26:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-30 15:00:16 +00:00
|
|
|
ret = element.currentStyle[property];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ret || ret == 'auto' || ret == 'intrinsic') {
|
|
|
|
ret = container.style[property];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
function applyStyles(elm, styles) {
|
|
|
|
for (var style in styles) {
|
|
|
|
elm.style[style] = styles[style];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function setupContainer(element, getValue) {
|
|
|
|
if (element.type != 'textarea') {
|
|
|
|
throw new Error("Textarea required!");
|
|
|
|
}
|
|
|
|
var parentNode = element.parentNode;
|
|
|
|
var container = document.createElement('div');
|
2023-01-16 22:26:34 +00:00
|
|
|
var resizeEvent = function () {
|
2013-12-30 15:00:16 +00:00
|
|
|
var style = 'position:relative;';
|
|
|
|
[
|
|
|
|
'margin-top', 'margin-left', 'margin-right', 'margin-bottom'
|
2023-01-16 22:26:34 +00:00
|
|
|
].forEach(function (item) {
|
2013-12-30 15:00:16 +00:00
|
|
|
style += item + ':' +
|
2023-01-16 22:26:34 +00:00
|
|
|
getCSSProperty(element, container, item) + ';';
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
|
|
|
var width = getCSSProperty(element, container, 'width') || (element.clientWidth + "px");
|
2023-01-16 22:26:34 +00:00
|
|
|
var height = getCSSProperty(element, container, 'height') || (element.clientHeight + "px");
|
2013-12-30 15:00:16 +00:00
|
|
|
style += 'height:' + height + ';width:' + width + ';';
|
|
|
|
style += 'display:inline-block;';
|
|
|
|
container.setAttribute('style', style);
|
|
|
|
};
|
|
|
|
event.addListener(window, 'resize', resizeEvent);
|
|
|
|
resizeEvent();
|
|
|
|
parentNode.insertBefore(container, element.nextSibling);
|
|
|
|
while (parentNode !== document) {
|
|
|
|
if (parentNode.tagName.toUpperCase() === 'FORM') {
|
|
|
|
var oldSumit = parentNode.onsubmit;
|
2023-01-16 22:26:34 +00:00
|
|
|
parentNode.onsubmit = function (evt) {
|
2013-12-30 15:00:16 +00:00
|
|
|
element.value = getValue();
|
|
|
|
if (oldSumit) {
|
|
|
|
oldSumit.call(this, evt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parentNode = parentNode.parentNode;
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
2023-01-16 22:26:34 +00:00
|
|
|
exports.transformTextarea = function (element, options) {
|
2020-04-14 12:14:48 +00:00
|
|
|
var isFocused = element.autofocus || document.activeElement == element;
|
2013-12-30 15:00:16 +00:00
|
|
|
var session;
|
2023-01-16 22:26:34 +00:00
|
|
|
var container = setupContainer(element, function () {
|
2013-12-30 15:00:16 +00:00
|
|
|
return session.getValue();
|
|
|
|
});
|
|
|
|
element.style.display = 'none';
|
|
|
|
container.style.background = 'white';
|
|
|
|
var editorDiv = document.createElement("div");
|
|
|
|
applyStyles(editorDiv, {
|
|
|
|
top: "0px",
|
|
|
|
left: "0px",
|
|
|
|
right: "0px",
|
|
|
|
bottom: "0px",
|
|
|
|
border: "1px solid gray",
|
|
|
|
position: "absolute"
|
|
|
|
});
|
|
|
|
container.appendChild(editorDiv);
|
|
|
|
var settingOpener = document.createElement("div");
|
|
|
|
applyStyles(settingOpener, {
|
|
|
|
position: "absolute",
|
|
|
|
right: "0px",
|
|
|
|
bottom: "0px",
|
|
|
|
cursor: "nw-resize",
|
2020-04-14 12:14:48 +00:00
|
|
|
border: "solid 9px",
|
|
|
|
borderColor: "lightblue gray gray #ceade6",
|
2013-12-30 15:00:16 +00:00
|
|
|
zIndex: 101
|
|
|
|
});
|
|
|
|
var settingDiv = document.createElement("div");
|
|
|
|
var settingDivStyles = {
|
|
|
|
top: "0px",
|
|
|
|
left: "20%",
|
|
|
|
right: "0px",
|
|
|
|
bottom: "0px",
|
|
|
|
position: "absolute",
|
|
|
|
padding: "5px",
|
|
|
|
zIndex: 100,
|
|
|
|
color: "white",
|
|
|
|
display: "none",
|
|
|
|
overflow: "auto",
|
|
|
|
fontSize: "14px",
|
|
|
|
boxShadow: "-5px 2px 3px gray"
|
|
|
|
};
|
|
|
|
if (!UA.isOldIE) {
|
|
|
|
settingDivStyles.backgroundColor = "rgba(0, 0, 0, 0.6)";
|
2023-01-16 22:26:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-30 15:00:16 +00:00
|
|
|
settingDivStyles.backgroundColor = "#333";
|
|
|
|
}
|
|
|
|
applyStyles(settingDiv, settingDivStyles);
|
|
|
|
container.appendChild(settingDiv);
|
2014-07-08 20:15:22 +00:00
|
|
|
options = options || exports.defaultOptions;
|
2013-12-30 15:00:16 +00:00
|
|
|
var editor = ace.edit(editorDiv);
|
|
|
|
session = editor.getSession();
|
|
|
|
session.setValue(element.value || element.innerHTML);
|
2020-04-14 12:14:48 +00:00
|
|
|
if (isFocused)
|
|
|
|
editor.focus();
|
2013-12-30 15:00:16 +00:00
|
|
|
container.appendChild(settingOpener);
|
2020-04-14 12:14:48 +00:00
|
|
|
setupApi(editor, editorDiv, settingDiv, ace, options);
|
2014-07-08 20:15:22 +00:00
|
|
|
setupSettingPanel(settingDiv, settingOpener, editor);
|
2013-12-30 15:00:16 +00:00
|
|
|
var state = "";
|
2023-01-16 22:26:34 +00:00
|
|
|
event.addListener(settingOpener, "mousemove", function (e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var rect = this.getBoundingClientRect();
|
|
|
|
var x = e.clientX - rect.left, y = e.clientY - rect.top;
|
2023-01-16 22:26:34 +00:00
|
|
|
if (x + y < (rect.width + rect.height) / 2) {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.style.cursor = "pointer";
|
|
|
|
state = "toggle";
|
2023-01-16 22:26:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-30 15:00:16 +00:00
|
|
|
state = "resize";
|
|
|
|
this.style.cursor = "nw-resize";
|
|
|
|
}
|
|
|
|
});
|
2023-01-16 22:26:34 +00:00
|
|
|
event.addListener(settingOpener, "mousedown", function (e) {
|
2020-04-14 12:14:48 +00:00
|
|
|
e.preventDefault();
|
2013-12-30 15:00:16 +00:00
|
|
|
if (state == "toggle") {
|
|
|
|
editor.setDisplaySettings();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
container.style.zIndex = 100000;
|
|
|
|
var rect = container.getBoundingClientRect();
|
2023-01-16 22:26:34 +00:00
|
|
|
var startX = rect.width + rect.left - e.clientX;
|
|
|
|
var startY = rect.height + rect.top - e.clientY;
|
|
|
|
event.capture(settingOpener, function (e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
container.style.width = e.clientX - rect.left + startX + "px";
|
|
|
|
container.style.height = e.clientY - rect.top + startY + "px";
|
|
|
|
editor.resize();
|
2023-01-16 22:26:34 +00:00
|
|
|
}, function () { });
|
2013-12-30 15:00:16 +00:00
|
|
|
});
|
|
|
|
return editor;
|
|
|
|
};
|
|
|
|
function load(url, module, callback) {
|
2023-01-16 22:26:34 +00:00
|
|
|
net.loadScript(url, function () {
|
2013-12-30 15:00:16 +00:00
|
|
|
require([module], callback);
|
|
|
|
});
|
|
|
|
}
|
2020-04-14 12:14:48 +00:00
|
|
|
function setupApi(editor, editorDiv, settingDiv, ace, options) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var session = editor.getSession();
|
|
|
|
var renderer = editor.renderer;
|
|
|
|
function toBool(value) {
|
|
|
|
return value === "true" || value == true;
|
|
|
|
}
|
2023-01-16 22:26:34 +00:00
|
|
|
editor.setDisplaySettings = function (display) {
|
2013-12-30 15:00:16 +00:00
|
|
|
if (display == null)
|
|
|
|
display = settingDiv.style.display == "none";
|
|
|
|
if (display) {
|
|
|
|
settingDiv.style.display = "block";
|
|
|
|
settingDiv.hideButton.focus();
|
|
|
|
editor.on("focus", function onFocus() {
|
|
|
|
editor.removeListener("focus", onFocus);
|
|
|
|
settingDiv.style.display = "none";
|
|
|
|
});
|
2023-01-16 22:26:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-12-30 15:00:16 +00:00
|
|
|
editor.focus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
editor.$setOption = editor.setOption;
|
2014-07-08 20:15:22 +00:00
|
|
|
editor.$getOption = editor.getOption;
|
2023-01-16 22:26:34 +00:00
|
|
|
editor.setOption = function (key, value) {
|
2013-12-30 15:00:16 +00:00
|
|
|
switch (key) {
|
|
|
|
case "mode":
|
2020-04-14 12:14:48 +00:00
|
|
|
editor.$setOption("mode", "ace/mode/" + value);
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case "theme":
|
2020-04-14 12:14:48 +00:00
|
|
|
editor.$setOption("theme", "ace/theme/" + value);
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
case "keybindings":
|
|
|
|
switch (value) {
|
|
|
|
case "vim":
|
|
|
|
editor.setKeyboardHandler("ace/keyboard/vim");
|
|
|
|
break;
|
|
|
|
case "emacs":
|
|
|
|
editor.setKeyboardHandler("ace/keyboard/emacs");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
editor.setKeyboardHandler(null);
|
|
|
|
}
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2020-04-14 12:14:48 +00:00
|
|
|
case "wrap":
|
2014-07-08 20:15:22 +00:00
|
|
|
case "fontSize":
|
|
|
|
editor.$setOption(key, value);
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2013-12-30 15:00:16 +00:00
|
|
|
default:
|
|
|
|
editor.$setOption(key, toBool(value));
|
|
|
|
}
|
|
|
|
};
|
2023-01-16 22:26:34 +00:00
|
|
|
editor.getOption = function (key) {
|
2014-07-08 20:15:22 +00:00
|
|
|
switch (key) {
|
|
|
|
case "mode":
|
2020-04-14 12:14:48 +00:00
|
|
|
return editor.$getOption("mode").substr("ace/mode/".length);
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2014-07-08 20:15:22 +00:00
|
|
|
case "theme":
|
2020-04-14 12:14:48 +00:00
|
|
|
return editor.$getOption("theme").substr("ace/theme/".length);
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2014-07-08 20:15:22 +00:00
|
|
|
case "keybindings":
|
2020-04-14 12:14:48 +00:00
|
|
|
var value = editor.getKeyboardHandler();
|
2014-07-08 20:15:22 +00:00
|
|
|
switch (value && value.$id) {
|
|
|
|
case "ace/keyboard/vim":
|
|
|
|
return "vim";
|
|
|
|
case "ace/keyboard/emacs":
|
|
|
|
return "emacs";
|
|
|
|
default:
|
|
|
|
return "ace";
|
|
|
|
}
|
2023-01-16 22:26:34 +00:00
|
|
|
break;
|
2014-07-08 20:15:22 +00:00
|
|
|
default:
|
|
|
|
return editor.$getOption(key);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
editor.setOptions(options);
|
2013-12-30 15:00:16 +00:00
|
|
|
return editor;
|
|
|
|
}
|
2014-07-08 20:15:22 +00:00
|
|
|
function setupSettingPanel(settingDiv, settingOpener, editor) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var BOOL = null;
|
|
|
|
var desc = {
|
2023-01-16 22:26:34 +00:00
|
|
|
mode: "Mode:",
|
|
|
|
wrap: "Soft Wrap:",
|
|
|
|
theme: "Theme:",
|
|
|
|
fontSize: "Font Size:",
|
|
|
|
showGutter: "Display Gutter:",
|
|
|
|
keybindings: "Keyboard",
|
2013-12-30 15:00:16 +00:00
|
|
|
showPrintMargin: "Show Print Margin:",
|
2023-01-16 22:26:34 +00:00
|
|
|
useSoftTabs: "Use Soft Tabs:",
|
|
|
|
showInvisibles: "Show Invisibles"
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
|
|
|
var optionValues = {
|
|
|
|
mode: {
|
2023-01-16 22:26:34 +00:00
|
|
|
text: "Plain",
|
2013-12-30 15:00:16 +00:00
|
|
|
javascript: "JavaScript",
|
2023-01-16 22:26:34 +00:00
|
|
|
xml: "XML",
|
|
|
|
html: "HTML",
|
|
|
|
css: "CSS",
|
|
|
|
scss: "SCSS",
|
|
|
|
python: "Python",
|
|
|
|
php: "PHP",
|
|
|
|
java: "Java",
|
|
|
|
ruby: "Ruby",
|
|
|
|
c_cpp: "C/C++",
|
|
|
|
coffee: "CoffeeScript",
|
|
|
|
json: "json",
|
|
|
|
perl: "Perl",
|
|
|
|
clojure: "Clojure",
|
|
|
|
ocaml: "OCaml",
|
|
|
|
csharp: "C#",
|
|
|
|
haxe: "haXe",
|
|
|
|
svg: "SVG",
|
|
|
|
textile: "Textile",
|
|
|
|
groovy: "Groovy",
|
|
|
|
liquid: "Liquid",
|
|
|
|
Scala: "Scala"
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
|
|
|
theme: {
|
2023-01-16 22:26:34 +00:00
|
|
|
clouds: "Clouds",
|
|
|
|
clouds_midnight: "Clouds Midnight",
|
|
|
|
cobalt: "Cobalt",
|
|
|
|
crimson_editor: "Crimson Editor",
|
|
|
|
dawn: "Dawn",
|
|
|
|
gob: "Green on Black",
|
|
|
|
eclipse: "Eclipse",
|
|
|
|
idle_fingers: "Idle Fingers",
|
|
|
|
kr_theme: "Kr Theme",
|
|
|
|
merbivore: "Merbivore",
|
|
|
|
merbivore_soft: "Merbivore Soft",
|
|
|
|
mono_industrial: "Mono Industrial",
|
|
|
|
monokai: "Monokai",
|
|
|
|
pastel_on_dark: "Pastel On Dark",
|
|
|
|
solarized_dark: "Solarized Dark",
|
|
|
|
solarized_light: "Solarized Light",
|
|
|
|
textmate: "Textmate",
|
|
|
|
twilight: "Twilight",
|
|
|
|
vibrant_ink: "Vibrant Ink"
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
2014-07-08 20:15:22 +00:00
|
|
|
showGutter: BOOL,
|
2013-12-30 15:00:16 +00:00
|
|
|
fontSize: {
|
|
|
|
"10px": "10px",
|
|
|
|
"11px": "11px",
|
|
|
|
"12px": "12px",
|
|
|
|
"14px": "14px",
|
|
|
|
"16px": "16px"
|
|
|
|
},
|
2014-07-08 20:15:22 +00:00
|
|
|
wrap: {
|
2023-01-16 22:26:34 +00:00
|
|
|
off: "Off",
|
|
|
|
40: "40",
|
|
|
|
80: "80",
|
|
|
|
free: "Free"
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
|
|
|
keybindings: {
|
|
|
|
ace: "ace",
|
|
|
|
vim: "vim",
|
|
|
|
emacs: "emacs"
|
|
|
|
},
|
2023-01-16 22:26:34 +00:00
|
|
|
showPrintMargin: BOOL,
|
|
|
|
useSoftTabs: BOOL,
|
|
|
|
showInvisibles: BOOL
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
|
|
|
var table = [];
|
|
|
|
table.push("<table><tr><th>Setting</th><th>Value</th></tr>");
|
|
|
|
function renderOption(builder, option, obj, cValue) {
|
|
|
|
if (!obj) {
|
2023-01-16 22:26:34 +00:00
|
|
|
builder.push("<input type='checkbox' title='", option, "' ", cValue + "" == "true" ? "checked='true'" : "", "'></input>");
|
2013-12-30 15:00:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
builder.push("<select title='" + option + "'>");
|
|
|
|
for (var value in obj) {
|
|
|
|
builder.push("<option value='" + value + "' ");
|
|
|
|
if (cValue == value) {
|
|
|
|
builder.push(" selected ");
|
|
|
|
}
|
2023-01-16 22:26:34 +00:00
|
|
|
builder.push(">", obj[value], "</option>");
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
|
|
|
builder.push("</select>");
|
|
|
|
}
|
2014-07-08 20:15:22 +00:00
|
|
|
for (var option in exports.defaultOptions) {
|
2013-12-30 15:00:16 +00:00
|
|
|
table.push("<tr><td>", desc[option], "</td>");
|
|
|
|
table.push("<td>");
|
2014-07-08 20:15:22 +00:00
|
|
|
renderOption(table, option, optionValues[option], editor.getOption(option));
|
2013-12-30 15:00:16 +00:00
|
|
|
table.push("</td></tr>");
|
|
|
|
}
|
|
|
|
table.push("</table>");
|
|
|
|
settingDiv.innerHTML = table.join("");
|
2023-01-16 22:26:34 +00:00
|
|
|
var onChange = function (e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var select = e.currentTarget;
|
|
|
|
editor.setOption(select.title, select.value);
|
|
|
|
};
|
2023-01-16 22:26:34 +00:00
|
|
|
var onClick = function (e) {
|
2013-12-30 15:00:16 +00:00
|
|
|
var cb = e.currentTarget;
|
|
|
|
editor.setOption(cb.title, cb.checked);
|
|
|
|
};
|
|
|
|
var selects = settingDiv.getElementsByTagName("select");
|
|
|
|
for (var i = 0; i < selects.length; i++)
|
|
|
|
selects[i].onchange = onChange;
|
|
|
|
var cbs = settingDiv.getElementsByTagName("input");
|
|
|
|
for (var i = 0; i < cbs.length; i++)
|
|
|
|
cbs[i].onclick = onClick;
|
|
|
|
var button = document.createElement("input");
|
|
|
|
button.type = "button";
|
|
|
|
button.value = "Hide";
|
2023-01-16 22:26:34 +00:00
|
|
|
event.addListener(button, "click", function () {
|
2013-12-30 15:00:16 +00:00
|
|
|
editor.setDisplaySettings(false);
|
|
|
|
});
|
|
|
|
settingDiv.appendChild(button);
|
|
|
|
settingDiv.hideButton = button;
|
|
|
|
}
|
2014-07-08 20:15:22 +00:00
|
|
|
exports.defaultOptions = {
|
2023-01-16 22:26:34 +00:00
|
|
|
mode: "javascript",
|
|
|
|
theme: "textmate",
|
|
|
|
wrap: "off",
|
|
|
|
fontSize: "12px",
|
|
|
|
showGutter: "false",
|
|
|
|
keybindings: "ace",
|
|
|
|
showPrintMargin: "false",
|
|
|
|
useSoftTabs: "true",
|
|
|
|
showInvisibles: "false"
|
2013-12-30 15:00:16 +00:00
|
|
|
};
|
|
|
|
|
2020-04-14 12:14:48 +00:00
|
|
|
}); (function() {
|
|
|
|
ace.require(["ace/ext/textarea"], function(m) {
|
|
|
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
|
|
|
module.exports = m;
|
|
|
|
}
|
|
|
|
});
|
2014-07-08 20:15:22 +00:00
|
|
|
})();
|
|
|
|
|