/*
Ajax Code Display
written by Christian Heilmann (http://wait-till-i.com)
license:http://creativecommons.org/licenses/by/3.0/
requires on jQuery 1.2.2 or newer
*/
// when the web page is ready
$(document).ready(
function(){
// get all links with the class codeexample and apply a function
$('a.codeexample').each(
function(){
// if the class 'dodisplay' is present
if(this.className.indexOf('dodisplay') !==- 1){
// add functionality to toggle the display of the output
$(this).toggle(
// on the first click and subsequent odd clicks
function(){
// create an IFRAME after the element that shows the document
// the original link points to
$(this).after('');
// store the original text in the link and change it to 'close'
this.oldhtml = this.innerHTML;
this.innerHTML = 'close';
},
// on the second and subsequent even clicks
function(){
// remove the IFRAME and change the link text back to the old text
this.parentNode.removeChild(this.nextSibling);
this.innerHTML = this.oldhtml;
}
);
}
// store the link reference in 'link'
var link = this;
// are there any highlights to be done?
var highlights = this.className.match(/highlight\[([^\]]+)/);
// shall I only display a range of lines?
var boundaries = this.className.match(/lines\[([^\]]+)/);
// convert the ranges defined in classes to arrays
// [1,5-7,12-15] => [1,5,6,7,12,13,14,15]
var getrange = function(range){
var elms = range.split(',');
var range = [];
for(var i=0,j=elms.length;i' + line + '';
};
};
};
// if there are only a few lines to be displayed
if(boundaries){
// get all the needed lines and loop over them
var chunk = getrange(boundaries[1]);
for(var i=0,j=chunk.length;i0 && chunk[i] !== (chunk[i-1])+1){
codeout.push('[...]');
};
// add a span with the line number, followed by a tab
if(line){
var html = ''+(chunk[i])+'\t'+line;
codeout.push(html);
};
};
// if there are no boundaries just add line numbers to each line
} else {
for(var i=0,j=lines.length;i' +
codeout.join('\n') +
''
);
};
// do the ajax, timeout after 100 milliseconds if the
// document is not available
$.ajax({
url:this.href,
timeout:500,
success:convert
});
}
);
}
);