(placeholder, getcompletionsfunction, cssclass, initialText, allowAlternative, blur)
| 1 | var currentmodal = null; |
| 2 | |
| 3 | function 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 = "↵" |
| 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' > </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() |
no test coverage detected