Created
May 14, 2013 06:54
-
-
Save NTaylorMullen/5574159 to your computer and use it in GitHub Desktop.
Auto typescript codemirror loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../Scripts/jquery-2.0.0.js" /> | |
/// <reference path="codemirror.js" /> | |
(function () { | |
var fileCache = {}, | |
fileListTemplate = $("<li class='fileNav'><a href='#'></a></li>"), | |
fileList = $("#_fileList"), | |
fileContent = $("#_fileContent"), | |
jsScriptHolder = $("#_scripts"), | |
newFileListNav = function (name) { | |
var ele = fileListTemplate.clone(); | |
ele.find("a").html(name); | |
return ele; | |
}, | |
editor = CodeMirror(fileContent[0], { | |
lineNumbers: true, | |
matchBrackets: true, | |
mode: "text/typescript", | |
readOnly: true, | |
theme: "solarized light" | |
}); | |
$.each($("typescript"), function (i, ele) { | |
var $ele = $(ele), | |
tsSrc = $ele.attr("src"), | |
jsSrc = tsSrc.substr(0, tsSrc.length - 2) + "js", | |
split = tsSrc.split('.'), | |
fileName = split[split.length - 2], | |
fileNav = newFileListNav(fileName + ".ts"), | |
text; | |
// Load JS dynamically | |
$.getScript(jsSrc); | |
// Build TS cache | |
$.get(tsSrc, function (code) { | |
fileCache[fileName] = code; | |
// Bind click after we've received the typescript cache | |
fileNav.click(function (e) { | |
editor.setOption("value", fileCache[fileName]); | |
$("li.fileNav").removeClass("active"); | |
fileNav.addClass("active"); | |
e.preventDefault(); | |
return false; | |
}); | |
}); | |
fileList.append(fileNav); | |
$ele.remove(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment