socialforge/app/views/courses/show_comparecode.js.erb

101 lines
3.4 KiB
Plaintext

$("#ajax-modal").html('<%= escape_javascript( render :partial => 'courses/show_compare_code' ,:locals => {:src_code=> @src_code,:src_name=> @src_username,:dst_name=> @dst_username, :dst_code=> @dst_code, :simivalue=> @simi_value })%>');
showModal('ajax-modal', '1250px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 1235px; margin-top:-18px;' class='resourceClose'></a>");
$('#ajax-modal').parent().css("top","30%").css("left","20%").css("padding-top","20px").css("position","fixed");
//$('#ajax-modal').parent().addClass("resourceUploadPopup");
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
function closeModal(){
hideModal($(".program-compare-code"));
}
var program_name = "text/x-csrc";
var language = <%= @homework.language.to_i %>;
if (language == 1) {
program_name = 'text/x-csrc';
} else if(language==2){
program_name = 'text/x-c++src';
}else if(language==3){
program_name = 'text/x-cython';
} else if(language==4){
program_name = 'text/x-java';
}
//
//var editor_1 = CodeMirror(document.getElementById("program-code_1"), {
// mode: {name: program_name,
// version: 2,
// singleLineStringErrors: false},
// lineNumbers: true,
// indentUnit: 2,
// matchBrackets: true,
// readOnly: true,
// value: $("#program-src_1").text()
// }
//);
//
//var editor_2 = CodeMirror(document.getElementById("program-code_2"), {
// mode: {name: program_name,
// version: 2,
// singleLineStringErrors: false},
// lineNumbers: true,
// indentUnit: 2,
// matchBrackets: true,
// readOnly: true,
// value: $("#program-src_2").text()
// }
//);
var value, orig1, orig2, dv, panes = 2, highlight = true, connect = null, collapse = false;
function initUI() {
if (value == null) return;
var target = document.getElementById("program-compare-code");
target.innerHTML = "";
dv = CodeMirror.MergeView(target, {
value: value,
origLeft: panes == 3 ? orig1 : null,
orig: orig2,
lineNumbers: true,
mode: program_name,
highlightDifferences: highlight,
connect: connect,
collapseIdentical: collapse
});
}
function toggleDifferences() {
dv.setShowDifferences(highlight = !highlight);
}
value = $("#program-src_1").text();
orig1 = $("#program-src_1").text();
orig2 = $("#program-src_2").text();
initUI();
function mergeViewHeight(mergeView) {
function editorHeight(editor) {
if (!editor) return 0;
return editor.getScrollInfo().height;
}
return Math.max(editorHeight(mergeView.leftOriginal()),
editorHeight(mergeView.editor()),
editorHeight(mergeView.rightOriginal()));
}
function resize(mergeView) {
var height = mergeViewHeight(mergeView);
for(;;) {
if (mergeView.leftOriginal())
mergeView.leftOriginal().setSize(null, height);
mergeView.editor().setSize(null, height);
if (mergeView.rightOriginal())
mergeView.rightOriginal().setSize(null, height);
var newHeight = mergeViewHeight(mergeView);
if (newHeight >= height) break;
else height = newHeight;
}
mergeView.wrap.style.height = height + "px";
}