MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / runModal

Function runModal

lib/web/modal.js:3–145  ·  view source on GitHub ↗
(placeholder, getcompletionsfunction, cssclass, initialText, allowAlternative, blur)

Source from the content-addressed store, hash-verified

1var currentmodal = null;
2
3function runModal(placeholder, getcompletionsfunction, cssclass, initialText, allowAlternative, blur) {
4
5 var w = $(".CodeMirror").width();
6 var h = $(".CodeMirror").height();
7
8 var mx = 450;
9
10 var shift = ($(window).height() - h)/2;
11 var shiftx = ($(window).width() - w);
12
13 if (shiftx<0) shiftx = 0;
14
15 // shift = 0;
16 // shiftx = 500;
17
18 var modal = $("<dialog style='max-height:"+mx+"!important;' class='" + cssclass + "'><input spellcheck='false' data-autosize-input='{ \"space\": 10 }' autocomplete='off' placeholder='" + placeholder + "' class='Field-textBox' type='text' name='main'></input><ol style='max-height:" + (mx-40) + "'></ol></dialog>");
19
20 $("dialog").remove();
21
22 modal.appendTo($("body"));
23
24 modal.width(400);
25 modal.height(450);
26
27
28 var inputBox = modal.find("input");
29 var ol = modal.find("ol");
30
31 if (initialText)
32 inputBox.val(initialText);
33
34
35 function updateCompletions() {
36 $(ol).empty();
37 var completions = getcompletionsfunction(inputBox.val());
38
39 for (var i = 0; i < completions.length; i++) {
40 var num = "";
41 if (i == 0) {
42 num = "&crarr;"
43 } else if (i < 10) {
44 num = "^" + i
45 }
46 var label = $("<li><span class='Field-number'>" + num + "</span>" + completions[i].text + "</li>");
47 if (num == "")
48 label = $("<li><span class='Field-number' style='opacity:0.0' >&nbsp;</span>" + completions[i].text + "</li>");
49 label.hover(function () {
50 $(this).css("background", "#444")
51 }
52 , function () {
53 $(this).css("background", "")
54 });
55 label.click(function () {
56 this.callback(inputBox.val());
57 setTimeout(function () {
58 modal[0].close();
59 modal.detach();
60 cm.focus()

Callers 4

preamble2.jsFile · 0.85
instantiate.jsFile · 0.85
runModalAtCursorFunction · 0.85
preamble.jsFile · 0.85

Calls 9

updateCompletionsFunction · 0.85
highlightRunAndCloseFunction · 0.85
widthMethod · 0.80
$Function · 0.70
appendToMethod · 0.65
removeMethod · 0.45
findMethod · 0.45
onMethod · 0.45
focusMethod · 0.45

Tested by

no test coverage detected