allow for passing file to Ox.SyntaxHighlighter

This commit is contained in:
rolux 2012-06-23 20:24:06 +02:00
parent 6fcac07ee9
commit f473100875

View file

@ -4,6 +4,7 @@
Ox.SyntaxHighlighter <f> Syntax Highlighter Ox.SyntaxHighlighter <f> Syntax Highlighter
([options[, self]]) -> <o:Ox.Element> Syntax Highlighter ([options[, self]]) -> <o:Ox.Element> Syntax Highlighter
options <o> Options options <o> Options
file <s|''> JavaScript file (alternative to `source` option)
lineLength <n|0> If larger than zero, show edge of page lineLength <n|0> If larger than zero, show edge of page
offset <n|1> First line number offset <n|1> First line number
replace <[[]]|[]> Array of replacements replace <[[]]|[]> Array of replacements
@ -24,6 +25,7 @@ Ox.SyntaxHighlighter = function(options, self) {
self = self || {}; self = self || {};
var that = Ox.Element({}, self) var that = Ox.Element({}, self)
.defaults({ .defaults({
file: '',
lineLength: 0, lineLength: 0,
offset: 1, offset: 1,
replace: [], replace: [],
@ -39,7 +41,14 @@ Ox.SyntaxHighlighter = function(options, self) {
.update(renderSource) .update(renderSource)
.addClass('OxSyntaxHighlighter'); .addClass('OxSyntaxHighlighter');
renderSource(); if (self.options.file) {
Ox.get(self.options.file, function(source) {
self.options.source = source;
renderSource();
});
} else {
renderSource();
}
function renderSource() { function renderSource() {
var $lineNumbers, $line, $source, width, var $lineNumbers, $line, $source, width,