-
Notifications
You must be signed in to change notification settings - Fork 1
/
instruktor.js
35 lines (31 loc) · 907 Bytes
/
instruktor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(function ($) {
var getDisplayType = function(el) {
switch (el.tagName.toUpperCase()) {
case 'SCRIPT':
return 'js';
case 'STYLE':
case 'LINK':
return 'css';
default:
return 'html';
}
},
repeatUntil = function(isOkayFn, delay, counter) {
if (!!counter) clearTimeout(counter);
if (!isOkayFn()) {
var c = setTimeout(function() {
repeatUntil(isOkayFn, delay, c);
}, delay || 1000);
}
};
$.fn.Instruktor = function () {
var $return = this.each(function(i, v) {
var $me = $(v), target = $me.data('target') || '.example', $targets = $me.nextUntil(':not(' + target + ')'), result = '';
$targets.each(function(j, t) {
result += '<pre class="brush: ' + getDisplayType(t) + '">' + $('<div/>').text(t.outerHTML).html() + '</pre>';
});
$me.append('<div class="code-sample">' + result + '</div>');
});
return $return;
};
})(jQuery);