$(
function
() {
$(document).keydown(
function
(e) {
if
(e.altKey && e.keyCode == 65) {
$(
".actions-button"
).click();
e.preventDefault();
}
});
var
showHelp =
function
(cm, showDocTab) {
var
selection = cm.getSelection();
var
topic;
if
(selection) {
topic = selection;
}
else
{
var
cursor = cm.getCursor();
var
c = {
line: cursor.line,
ch: cursor.ch + 1
};
var
token = cm.getTokenAt(c);
if
(token.string) {
topic = $.trim(token.string);
}
else
{
topic =
''
;
}
}
$.post(
"/help"
, {
topic : topic,
style : $(
"#pod_style_selector"
, $(
'#options-dialog'
)).val()
},
function
(html) {
var
$iframe = $(
"#doc"
);
var
scrollTop = $iframe.contents().scrollTop();
var
doc = $iframe[0].contentDocument;
doc.open();
doc.write(html);
doc.close();
$iframe.contents().scrollTop(scrollTop);
if
(showDocTab) {
$(
'a[href="#doc-tab"]'
).click();
}
}
);
};
var
editors = {};
var
currentEditorId;
var
problemCount = 0;
var
$helpDialog = $(
"#help-dialog"
);
var
$perlDocDialog = $(
"#perl-doc-dialog"
);
window.whitespaceOverlay = {
showTabs :
false
,
showSpaces :
false
,
token :
function
(stream) {
if
(stream.eatWhile(/\S/)) {
return
null
;
}
ch = stream.next();
if
(ch ==
'\t'
) {
return
this
.showTabs ?
"whitespace-tab"
:
null
;
}
else
{
return
this
.showSpaces ?
"whitespace-space"
:
null
;
}
}
};
window.showWhitespace =
function
(editor) {
whitespaceOverlay.showSpaces = $(
"#show_spaces_checkbox"
).is(
':checked'
);
whitespaceOverlay.showTabs = $(
"#show_tabs_checkbox"
).is(
':checked'
);
editor.removeOverlay(window.whitespaceOverlay);
editor.addOverlay(window.whitespaceOverlay);
diffEditor.removeOverlay(window.whitespaceOverlay);
diffEditor.addOverlay(window.whitespaceOverlay);
};
var
inputEditor = CodeMirror.fromTextArea(document.getElementById(
'input'
), {
tabSize: 4,
indentUnit: 4,
indentWithTabs:
true
});
inputEditor.setValue(
"The following input will be sent to the process that is run"
);
var
outputEditor = CodeMirror.fromTextArea(document.getElementById(
'output'
), {
tabSize: 4,
indentUnit: 4,
indentWithTabs:
true
,
readOnly:
true
});
outputEditor.setValue(
"Output from running processes is shown here.\nPlease run a script to show something useful"
);
var
diffEditor = CodeMirror.fromTextArea(document.getElementById(
'diff'
), {
tabSize: 4,
indentUnit: 4,
indentWithTabs:
true
,
readOnly:
true
,
flattenSpans:
false
});
diffEditor.setValue(
"This will contain commit changes.\nPlease use Git Diff to show something useful"
);
var
searchEditor = CodeMirror.fromTextArea(document.getElementById(
'search'
), {
tabSize: 4,
indentUnit: 4,
indentWithTabs:
true
,
readOnly:
true
});
$(
'a[href="#input-tab"]'
).click(
function
() {
setTimeout(
function
() {
inputEditor.refresh();
}, 0);
});
$(
'a[href="#output-tab"]'
).click(
function
() {
setTimeout(
function
() {
outputEditor.refresh();
}, 0);
});
$(
'a[href="#search-tab"]'
).click(
function
() {
setTimeout(
function
() {
searchEditor.refresh();
}, 0);
});
$(
'a[href="#diff-tab"]'
).click(
function
() {
$(document).trigger(
"action-git-diff"
);
setTimeout(
function
() {
diffEditor.refresh();
}, 0);
});
var
firstTime =
true
;
setInterval(
function
() {
$.post(
"/ping"
, {},
function
() {
$(
"#connection-status"
)
.text(
"Connected"
)
.addClass(
"btn-success"
)
.removeClass(
"btn-danger"
);
if
(firstTime) {
AddEditorTab();
window.ChangeMode(diffEditor,
'diff'
);
firstTime =
false
;
}
}).fail(
function
() {
$(
"#connection-status"
)
.text(
"Closed"
)
.addClass(
"btn-danger"
)
.removeClass(
"btn-success"
);
});
}, 5000);
var
showStarAfterNameIfModified =
function
(editor) {
if
(editor.isClean()) {
$(
"#myTab > li.active > a > span"
).text(
''
);
}
else
{
$(
"#myTab > li.active > a > span"
).text(
" *"
);
}
};
var
tabId = 1;
window.AddEditorTab =
function
(tabName, filename, mode, contents) {
if
(!tabName) {
tabName =
"Untitled "
+ tabId;
}
var
editorId =
"editor"
+ tabId;
$(
"#myTab"
).append(
'<li><a href="#'
+ tabId +
'" data-toggle="tab">'
+ tabName +
' <span></span> <i class="icon-remove"></i></a></li>'
);
$(
"#myTab li.farabi-add-tab"
).remove();
$(
"#myTab"
).append(
'<li class="farabi-add-tab"> <i class="icon-plus-sign"></i></li>'
);
$(
".farabi-add-tab"
).click(
function
() {
$(document).trigger(
'action-new-file'
);
});
$(
"#myTabContent"
).append(
'<div class="tab-pane" id="'
+ tabId +
'">'
+
'<div class="farabi-bordered" id="editor-border">'
+
'<textarea id="'
+editorId+
'" name="'
+ editorId +
'" class="editor"></textarea>'
+
'<div class="editor-stats pull-right"></div>'
+
'</div>'
+
'</div>'
);
$(
"i"
,
"#myTab"
).mouseover(
function
() {
$(
this
).addClass(
"farabi-icon-selected"
);
});
$(
"i"
,
"#myTab"
).mouseout(
function
() {
$(
this
).removeClass(
"farabi-icon-selected"
);
});
$(
"i.icon-remove"
,
"#myTab"
).click(
function
(e) {
var
$tab = $(
this
).parent();
var
href = $tab.attr(
"href"
);
currentEditorId =
"editor"
+ href.substring(1);
currentEditor = editors[currentEditorId].editor;
e.stopImmediatePropagation();
$(document).trigger(
'action-close-file'
);
});
var
show_cmd_output =
function
(data) {
var
outputEditor = GetOutputEditor();
outputEditor.setValue(
''
);
if
(
typeof
data.stderr ==
"undefined"
) {
outputEditor.setValue(
"Invalid response.. Please run it again. Hopefully will fix it soon :)"
);
$(
'a[href="#output-tab"]'
).tab(
'show'
);
setTimeout(
function
() {
outputEditor.refresh();
}, 0);
return
;
}
if
(data.stderr && data.stderr.length) {
outputEditor.setValue(data.stderr +
"\n"
);
}
outputEditor.setValue(outputEditor.getValue() + data.stdout +
"\nExit code: "
+ data.exit);
$(
'a[href="#output-tab"]'
).tab(
'show'
);
setTimeout(
function
() {
outputEditor.refresh();
}, 0);
};
var
editor = CodeMirror.fromTextArea(document.getElementById(editorId), {
lineNumbers:
true
,
matchBrackets:
true
,
tabSize: 4,
indentUnit: 4,
indentWithTabs:
true
,
highlightSelectionMatches:
true
,
styleSelectedText:
true
,
styleActiveLine:
true
,
flattenSpans:
false
,
extraKeys: {
"F1"
:
function
(cm) {
showHelp(cm,
true
);
},
'Ctrl-Alt-F'
:
function
(cm) {
$(document).trigger(
'action-ack'
);
},
'Alt-A'
:
function
(cm) {
$(
".actions-button"
).click();
},
'Alt-N'
:
function
(cm) {
$(document).trigger(
'action-new-file'
);
},
'Alt-O'
:
function
(cm) {
$(document).trigger(
'action-open-file'
);
},
'Alt-S'
:
function
(cm) {
$(document).trigger(
'action-save-file'
);
},
'Alt-W'
:
function
(cm) {
$(document).trigger(
'action-close-file'
);
},
"Alt-L"
:
function
(cm) {
$(document).trigger(
'action-goto-line'
);
},
'Alt-Enter'
:
function
(cm) {
var
mode = cm.getOption(
"mode"
);
if
(mode ==
"perl"
) {
$.post(
'run_perl'
,
{
"source"
: cm.getValue(),
"input"
: GetInputEditor().getValue()
},
function
(result) {
show_cmd_output(result);
}
);
}
else
{
$(
"#action-run"
).click();
}
},
"F10"
:
function
(cm) {
cm.setOption(
"fullScreen"
, !cm.getOption(
"fullScreen"
));
},
"F11"
:
function
(cm) {
cm.setOption(
"fullScreen"
, !cm.getOption(
"fullScreen"
));
},
"Esc"
:
function
(cm) {
if
(cm.getOption(
"fullScreen"
)) {
cm.setOption(
"fullScreen"
,
false
);
}
}
}
});
if
(contents) {
editor.setValue(contents);
editor.clearHistory();
editor.markClean();
}
if
( !mode ) {
window.ChangeMode(editor,
'perl'
);
}
else
{
window.ChangeMode(editor, mode);
}
editor.on(
"cursorActivity"
,
function
(cm) {
window.showEditorStats(cm);
});
var
timeoutId;
var
onChange =
function
(cm) {
clearInterval(timeoutId);
timeoutId = setTimeout(
function
() {
var
mode = cm.getOption(
"mode"
);
if
(mode ==
"perl"
) {
syntaxCheck(cm);
if
($(
"#preview-tab"
).is(
":visible"
)) {
$(
'a[href="#preview-tab"]'
).click();
}
}
else
if
(mode ==
"markdown"
) {
if
($(
"#preview-tab"
).is(
":visible"
)) {
$(
'a[href="#preview-tab"]'
).click();
}
}
else
if
(mode ==
"javascript"
) {
$(document).trigger(
'action-jshint'
);
}
else
{
$(
"#pod"
).html(
'Only supported for Perl files'
);
}
}, 250);
showStarAfterNameIfModified(cm);
};
editor.on(
"change"
, onChange);
editor.on(
"focus"
, onChange);
editors[editorId] = {
editor : editor,
filename : filename,
tabName : tabName,
tabId : tabId
};
currentEditorId = editorId;
var
$lastTab = $(
"#myTab a:last"
);
$lastTab.tab(
'show'
);
$lastTab.on(
'shown'
,
function
(e) {
editor.refresh();
});
$(
"#myTab a"
).on(
'shown'
,
function
() {
currentEditorId =
"editor"
+ $(
this
).attr(
"href"
).substring(1);
});
setTimeout(
function
() {
editor.focus();
window.showEditorStats(editor);
$(
"#theme_selector"
).change();
var
mode = editor.getOption(
"mode"
);
if
(mode ==
"perl"
) {
syntaxCheck(editor);
if
($(
"#preview-tab"
).is(
":visible"
)) {
$(
'a[href="#preview-tab"]'
).click();
}
}
else
if
(mode ==
"markdown"
) {
if
($(
"#preview-tab"
).is(
":visible"
)) {
$(
'a[href="#preview-tab"]'
).click();
}
}
else
if
(mode ==
"javascript"
) {
$(document).trigger(
'action-jshint'
);
}
else
{
$(
"#pod"
).html(
'Not supported for mode "'
+ mode +
'"'
);
}
if
($(
"#diff-tab"
).is(
":visible"
)) {
$(document).trigger(
"action-git-diff"
);
}
window.showWhitespace(editor);
editor.refresh();
}, 0);
tabId++;
};
$(
"form"
).submit(
function
() {
return
false
;
});
window.ChangeMode =
function
(cm, modeFile, mode) {
if
(
typeof
mode ==
'undefined'
) {
mode = modeFile;
}
CodeMirror.modeURL =
"assets/codemirror/mode/%N/%N.js"
;
cm.setOption(
"mode"
, mode);
CodeMirror.autoLoadMode(cm, modeFile);
};
window.showEditorStats =
function
(cm) {
var
cursor = cm.getCursor();
var
selection = cm.getSelection();
var
line_number = cursor.line + 1;
var
column_number = cursor.ch + 1;
var
$editorStats = $(
'.editor-stats'
);
$editorStats.html(
'<span class="badge badge-info"><strong>Line: '
+ line_number +
'</strong></span>'
+
' <span class="badge badge-info"><strong>Column: '
+ column_number +
'</strong></span>'
+
' <span class="badge badge-info"><strong>Lines: '
+ cm.lineCount() +
'</strong></span>'
+
(selection ?
' <span class="badge badge-info"><strong>Selected: '
+ selection.length +
'</strong></span>'
:
''
) +
' <span class="badge badge-info"><strong>Characters: '
+ cm.getValue().length +
'</strong></span> '
+
((problemCount > 0) ?
'<span id="problems-button" class="badge badge-important"><strong>Problems: '
+ problemCount +
'</strong></span>'
:
'<span id="problems-button" class="badge badge-success"><strong>No Problems</span>'
)
);
$(
"#problems-button"
, $editorStats).click(
function
() {
$(
'a[href="#problems-tab"]'
).tab(
'show'
);
});
};
var
previewTabChanged =
function
(editor) {
var
mode = editor.getOption(
"mode"
);
if
(mode ==
"perl"
) {
$.post(
"/pod2html"
,
{
"source"
: editor.getValue(),
"style"
: $(
"#pod_style_selector"
, $(
'#options-dialog'
)).val()
},
function
(html) {
var
$iframe = $(
"#pod"
);
var
scrollTop = $iframe.contents().scrollTop();
var
doc = $iframe[0].contentDocument;
doc.open();
doc.write(html);
doc.close();
$iframe.contents().scrollTop(scrollTop);
}
);
}
else
if
(mode ==
"markdown"
) {
$.post(
"/md2html"
,
{
"text"
: editor.getValue()
},
function
(html) {
var
$iframe = $(
"#pod"
);
var
scrollTop = $iframe.contents().scrollTop();
var
doc = $iframe[0].contentDocument;
doc.open();
doc.write(html);
doc.close();
$iframe.contents().scrollTop(scrollTop);
}
);
}
};
$(
'a[href="#preview-tab"]'
).click(
function
() {
previewTabChanged(GetCurrentEditor());
});
window.GetCurrentEditor =
function
() {
return
editors[currentEditorId].editor;
};
window.GetCurrentFilename =
function
() {
return
editors[currentEditorId].filename;
};
window.GetOutputEditor =
function
() {
return
outputEditor;
};
window.GetInputEditor =
function
() {
return
inputEditor;
};
window.GetSearchEditor =
function
() {
return
searchEditor;
};
window.GetEditors =
function
() {
var
results = [];
for
(
var
editorId
in
editors) {
results.push(editors[editorId].editor);
}
return
results;
};
$(
".results"
).hide();
$(document).on(
'action-perl-doc'
,
function
() {
$perlDocDialog.modal(
'show'
);
});
$(document).on(
'action-perl-tidy'
,
function
() {
var
editor = GetCurrentEditor();
var
outputEditor = GetOutputEditor();
var
source = editor.getValue();
$.post(
'perl_tidy'
, {
"source"
: source},
function
(data) {
if
(data.error ===
''
) {
if
(source != data.source) {
var
cursor = editor.getCursor();
editor.setValue(data.source);
editor.setCursor(cursor);
}
}
else
{
outputEditor.setValue(
'Error:\n'
+ data.error);
}
});
});
var
syntaxCheckerWidgets = [];
var
syntaxCheck =
function
(editor) {
$.post(
'/syntax_check'
, {
"source"
: editor.getValue()},
function
(problems) {
editor.operation(
function
(){
var
i;
for
(i = 0; i < syntaxCheckerWidgets.length; i++) {
editor.removeLineWidget(syntaxCheckerWidgets[i]);
}
syntaxCheckerWidgets.length = 0;
$(
".farabi-error-icon"
).remove();
problemCount = problems.length;
var
html =
''
;
if
(problems.length > 0) {
html +=
"<thead>"
+
"<th>Line</th>"
+
"<th>Message</th>"
+
"<th>File</th>"
+
"<th>Source</th>"
+
"</thead>"
;
html +=
"<tbody>"
;
var
showProblemsTab =
function
() {
$(
'a[href="#problems-tab"]'
).tab(
'show'
);
};
for
(i = 0; i < problems.length; i++) {
var
problem = problems[i];
var
msg = document.createElement(
"div"
);
var
icon = msg.appendChild(document.createElement(
"span"
));
icon.innerHTML =
"!!"
;
icon.className =
"farabi-error-icon"
;
msg.appendChild(document.createTextNode(problem.message));
msg.className =
"farabi-error"
;
syntaxCheckerWidgets.push(
editor.addLineWidget(
problem.line - 1,
msg,
{coverGutter:
true
, noHScroll:
true
}
)
);
$(msg).click(showProblemsTab);
html +=
"<tr>"
+
'<td class="problem-line">'
+ problem.line +
"</td>"
+
"<td>"
+ problem.message +
"</td>"
+
"<td>"
+ problem.file +
"</td>"
+
"<td>Syntax Check</td>"
+
"</tr>"
;
}
html +=
"</tbody>"
;
}
else
{
html =
'<tr>'
+
'<td><span class="badge badge-success">No problems found</span></td>'
+
'</tr>'
;
}
$(
"#problems > table"
).html(html);
$(
"#problems> table > tbody > tr"
).click(
function
() {
var
line = parseInt($(
".problem-line"
,
this
).text(), 10);
var
editor = GetCurrentEditor();
editor.setCursor({line: line - 1, ch: 0});
});
window.showEditorStats(editor);
});
});
};
var
jsHintWidgets = [];
var
jsHint =
function
(editor) {
editor.operation(
function
(){
var
i;
for
(i = 0; i < jsHintWidgets.length; i++) {
editor.removeLineWidget(jsHintWidgets[i]);
}
jsHintWidgets.length = 0;
$(
".farabi-error-icon"
).remove();
JSHINT(editor.getValue());
problemCount = JSHINT.errors.length;
var
html =
''
;
if
(JSHINT.errors.length > 0) {
html +=
"<thead>"
+
"<th>Line</th>"
+
"<th>Message</th>"
+
"<th>File</th>"
+
"<th>Source</th>"
+
"</thead>"
;
html +=
"<tbody>"
;
var
showProblemsTab =
function
() {
$(
'a[href="#problems-tab"]'
).tab(
'show'
);
};
for
(i = 0; i < JSHINT.errors.length; ++i) {
var
problem = JSHINT.errors[i];
if
(!problem) {
continue
;
}
var
msg = document.createElement(
"div"
);
var
icon = msg.appendChild(document.createElement(
"span"
));
icon.innerHTML =
"!!"
;
icon.className =
"farabi-error-icon"
;
msg.appendChild(document.createTextNode(problem.reason));
msg.className =
"farabi-error"
;
jsHintWidgets.push(
editor.addLineWidget(
problem.line - 1,
msg,
{coverGutter:
true
, noHScroll:
true
}
)
);
$(msg).click(showProblemsTab);
html +=
"<tr>"
+
'<td class="problem-line">'
+ problem.line +
"</td>"
+
"<td>"
+ problem.reason +
"</td>"
+
"<td></td>"
+
"<td>JSHint</td>"
+
"</tr>"
;
}
html +=
"</tbody>"
;
}
else
{
html =
'<tr>'
+
'<td><span class="badge badge-success">No problems found</span></td>'
+
'</tr>'
;
}
$(
"#problems > table"
).html(html);
$(
"#problems> table > tbody > tr"
).click(
function
() {
var
line = parseInt($(
".problem-line"
,
this
).text(), 10);
var
editor = GetCurrentEditor();
editor.setCursor({line: line - 1, ch: 0});
});
window.showEditorStats(editor);
});
};
$(document).on(
'action-jshint'
,
function
() {
var
editor = GetCurrentEditor();
if
(
"JSHint"
in
window) {
jsHint(editor);
}
else
{
$.ajax({
url:
'assets/jshint/jshint-1.1.0.js'
,
dataType:
"script"
,
success:
function
() {
jsHint(editor);
}
});
}
});
$(document).on(
'action-help'
,
function
() {
$helpDialog.modal(
"show"
);
});
var
onCloseFocusEditor =
function
() {
var
editor = GetCurrentEditor();
if
(editor) {
editor.focus();
}
};
$(
".modal"
).hide().on(
'hidden'
, onCloseFocusEditor);
$(document).on(
'action-new-file'
,
function
() {
AddEditorTab();
});
$(
".navbar .dropdown-menu li > a"
).click(
function
() {
var
action = $(
this
).attr(
"id"
);
if
(action) {
$(document).trigger(action);
}
else
{
alert(
"Undefined action. Please specify it as an id attribute!"
);
}
});
$(document).on(
'action-close-file'
,
function
() {
var
o = editors[currentEditorId];
if
(!o.editor.isClean()) {
$(
"#save-question-dialog"
).modal(
'show'
);
return
;
}
var
isEmpty =
function
(obj) {
for
(
var
key
in
obj) {
return
false
;
}
return
true
;
};
var
currentTabId = editors[currentEditorId].tabId;
$(
"#myTab > li > a[href=#"
+ currentTabId +
"]"
).remove();
$(
"#myTabContent > div[id="
+ currentTabId +
"]"
).remove();
delete
editors[currentEditorId];
if
(isEmpty(editors)) {
AddEditorTab();
}
else
{
var
$lastTab = $(
"#myTab a:last"
);
$lastTab.tab(
'show'
);
currentEditorId =
"editor"
+ $lastTab.attr(
"href"
).substring(1);
GetCurrentEditor().focus();
}
});
$(document).on(
'action-close-all-files'
,
function
() {
$(
"#myTab > li"
).remove();
$(
"#myTabContent > div"
).remove();
editors = {};
AddEditorTab();
});
$(document).on(
'action-save-file'
,
function
() {
var
editor = GetCurrentEditor();
var
filename = GetCurrentFilename();
$.post(
'/save_file'
, {
"filename"
: filename,
"source"
: editor.getValue()},
function
(data) {
if
(data.err ===
''
) {
editor.markClean();
showStarAfterNameIfModified(editor);
if
($(
"#diff-tab"
).is(
":visible"
)) {
$(document).trigger(
"action-git-diff"
);
}
}
else
{
alert(
'Error:\n'
+ data.err);
}
});
});
$(document).on(
'action-dump-ppi-tree'
,
function
() {
var
editor = GetCurrentEditor();
var
outputEditor = GetOutputEditor();
outputEditor.setValue(
"'"
+ editor.getSelection() +
"'"
);
var
source = editor.getSelection();
if
(source ===
''
) {
source = editor.getValue();
}
$.post(
'/dump_ppi_tree'
, {
"source"
: source},
function
(data) {
if
(data.error ===
''
) {
outputEditor.setValue(data.output);
}
else
{
outputEditor.setValue(data.error);
}
$(
'a[href="#output-tab"]'
).tab(
'show'
);
outputEditor.refresh();
});
});
$(
".navbar .brand"
).click(
function
() {
$(document).trigger(
"action-about"
);
});
var
git =
function
(cmd) {
$.post(
'/git'
, {cmd: cmd},
function
(result) {
diffEditor.setValue(
''
);
if
(result.stderr.length) {
diffEditor.setValue(result.stderr +
"\n"
);
}
diffEditor.setValue(diffEditor.getValue() + result.stdout);
$(
'a[href="#diff-tab"]'
).tab(
'show'
);
diffEditor.refresh();
});
};
$(document).on(
'action-git-diff'
,
function
() {
git(
'diff'
);
});
$(document).on(
'action-git-log'
,
function
() {
git(
'log'
);
});
$(document).on(
'action-git-status'
,
function
() {
git(
'status'
);
});
$(document).on(
'action-perl-strip'
,
function
() {
var
editor = GetCurrentEditor();
$.post(
'/perl_strip'
, {source: editor.getValue()},
function
(result) {
if
(result.error) {
editor.setValue(result.source);
}
else
{
alert(
"No result"
);
}
});
});
$(document).on(
'action-spellunker'
,
function
() {
var
editor = GetCurrentEditor();
$.post(
'/spellunker'
, {text: editor.getValue()},
function
(result) {
spellunker(editor);
});
});
var
spellunkerWidgets = [];
var
spellunker =
function
(editor) {
$.post(
'/spellunker'
, {
"text"
: editor.getValue()},
function
(problems) {
editor.operation(
function
(){
var
i;
for
(i = 0; i < spellunkerWidgets.length; i++) {
editor.removeLineWidget(spellunkerWidgets[i]);
}
spellunkerWidgets.length = 0;
$(
".farabi-error-icon"
).remove();
problemCount = problems.length;
var
html =
''
;
if
(problems.length > 0) {
html +=
"<thead>"
+
"<th>Line</th>"
+
"<th>Message</th>"
+
"<th>File</th>"
+
"<th>Source</th>"
+
"</thead>"
;
html +=
"<tbody>"
;
var
showProblemsTab =
function
() {
$(
'a[href="#problems-tab"]'
).tab(
'show'
);
};
for
(i = 0; i < problems.length; i++) {
var
problem = problems[i];
var
msg = document.createElement(
"div"
);
var
icon = msg.appendChild(document.createElement(
"span"
));
icon.innerHTML =
"!!"
;
icon.className =
"farabi-error-icon"
;
msg.appendChild(document.createTextNode(problem.message));
msg.className =
"farabi-error"
;
spellunkerWidgets.push(
editor.addLineWidget(
problem.line - 1,
msg,
{coverGutter:
true
, noHScroll:
true
}
)
);
$(msg).click(showProblemsTab);
html +=
"<tr>"
+
'<td class="problem-line">'
+ problem.line +
"</td>"
+
"<td>"
+ problem.message +
"</td>"
+
"<td>"
+ problem.file +
"</td>"
+
"<td>Spellunker</td>"
+
"</tr>"
;
}
html +=
"</tbody>"
;
}
else
{
html =
'<tr>'
+
'<td><span class="badge badge-success">No problems found</span></td>'
+
'</tr>'
;
}
$(
"#problems > table"
).html(html);
$(
"#problems> table > tbody > tr"
).click(
function
() {
var
line = parseInt($(
".problem-line"
,
this
).text(), 10);
var
editor = GetCurrentEditor();
editor.setCursor({line: line - 1, ch: 0});
});
window.showEditorStats(editor);
});
});
};
$(document).on(
'action-ack'
,
function
() {
var
editor = GetCurrentEditor();
var
selection = editor.getSelection();
if
(!selection) {
setTimeout(
function
() {
alert(
"Please select some text to search for it in your current project folder"
);
}, 0);
return
;
}
$.post(
'/ack'
, {text: selection},
function
(result) {
var
searchEditor = GetSearchEditor();
searchEditor.setValue(
''
);
if
(result.stderr.length) {
searchEditor.setValue(result.stderr +
"\n"
);
}
searchEditor.setValue(searchEditor.getValue() + result.stdout);
$(
'a[href="#search-tab"]'
).tab(
'show'
);
searchEditor.refresh();
});
});
var
showCmdOutput =
function
(result) {
var
outputEditor = GetOutputEditor();
outputEditor.setValue(
''
);
if
(result.stderr.length) {
outputEditor.setValue(result.stderr +
"\n"
);
}
outputEditor.setValue(outputEditor.getValue() + result.stdout);
$(
'a[href="#output-tab"]'
).tab(
'show'
);
outputEditor.refresh();
};
$(document).on(
'action-midgen'
,
function
() {
$.post(
'/midgen'
, {}, showCmdOutput);
});
$(document).on(
'action-build'
,
function
() {
$.post(
'/project'
, {cmd:
'build'
}, showCmdOutput);
});
$(document).on(
'action-build-test'
,
function
() {
$.post(
'/project'
, {cmd:
'test'
}, showCmdOutput);
});
$(document).on(
'action-build-clean'
,
function
() {
$.post(
'/project'
, {cmd:
'clean'
}, showCmdOutput);
});
$(document).on(
'action-cpanm'
,
function
() {
var
editor = GetCurrentEditor();
var
selection = editor.getSelection();
if
(!selection) {
setTimeout(
function
() {
alert(
"Please select some text to search for it in your current project folder"
);
}, 0);
return
;
}
$.post(
'/cpanm'
, {module: selection}, showCmdOutput);
});
});