forked from isobar-us/code-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (75 loc) · 2.41 KB
/
script.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//"use strict";
/**
* Author: Isobar North America
*/
var ISOBAR = {
common : {
init: function(){
this.toc();
this.syntax();
this.stuff();
},
// generate table of contents
toc : function(){
var main = document.getElementById('main'),
toc = document.getElementById('toc'),
hx = $('section h1, section h2, section h3, section h4, section h5, #revisions h1'),
frag = document.createDocumentFragment(),
hx_len = hx.length,
anchor, tag, the_text;
for (var i = 0, j = hx_len; i < j; i++) {
tag = hx[i].tagName.toLowerCase();
if (tag === 'h1' || tag == 'h2' || tag == 'h3' || tag == 'h4' || tag == 'h5') {
the_text = $.trim( hx[i].innerHTML );
anchor = '_' + the_text.replace(/\s+|\-/g, '_').replace(/[^A-Z0-9_]/gi, '').replace(/_+/g, '_').toLowerCase();
hx[i].id = anchor;
hx[i].innerHTML += '<a href="#' + anchor + '" class="anchor_link" title="Permalink">◊</a>';
toc.innerHTML += '<li class="' + tag + '"><a href="#' + anchor + '">' + the_text + '</a></li>';
}
///*console.log({ 'a': anchor, 'tag': tag, 'hx': hx[i] })*/;
if (tag === 'h1') {
hx[i].innerHTML += '<a href="#" class="backAnchor" title="Top">Back to Top</a>';
}
}
toc.style.display = 'block';
},
// just hooking up back to top
stuff : function(){
$('a.backAnchor').live('click',function(){
window.scrollTo(0, 0);
return false;
});
},
// set up syntax highlighter
syntax : function(){
SyntaxHighlighter.config.tagName = 'textarea';
SyntaxHighlighter.defaults['wrap-lines'] = false;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.defaults['tab-size'] = 4;
SyntaxHighlighter.all();
}
}
};
var UTIL = {
fire : function(func,funcname, args){
var namespace = ISOBAR; // indicate your obj literal namespace here
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && namespace[func] && typeof namespace[func][funcname] == 'function'){
namespace[func][funcname](args);
}
},
loadEvents : function(){
var bodyId = document.body.id;
// hit up common first.
UTIL.fire('common');
// do all the classes too.
$.each(document.body.className.split(/\s+/),function(i,classnm){
UTIL.fire(classnm);
UTIL.fire(classnm,bodyId);
});
UTIL.fire('common','finalize');
}
};
// kick it all off here
$(document).ready(UTIL.loadEvents);