source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/docs/page.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 2.7 KB
Line 
1var onDocumentLoad = function ( event ) {
2
3 var path;
4 var pathname = window.location.pathname;
5 var section = /\/(manual|api)\//.exec( pathname )[ 1 ].toString().split( '.html' )[ 0 ];
6 var name = /[\-A-z0-9]+\.html/.exec( pathname ).toString().split( '.html' )[ 0 ];
7
8 if ( section == 'manual' ) {
9
10 name = name.replace(/\-/g, ' ');
11
12 path = pathname.replace( /\ /g, '-' );
13 path = /\/manual\/[-A-z0-9\/]+/.exec( path ).toString().substr( 8 );
14
15 } else {
16
17 path = /\/api\/[A-z0-9\/]+/.exec( pathname ).toString().substr( 5 );
18
19 }
20
21 var text = document.body.innerHTML;
22
23 text = text.replace(/\[name\]/gi, name);
24 text = text.replace(/\[path\]/gi, path);
25 text = text.replace(/\[page:(\w+)\]/gi, "[page:$1 $1]" ); // [page:name] to [page:name title]
26 text = text.replace(/\[page:(\w+) ([\w|\.]+)\]/gi, "<a href=\"javascript:window.parent.goTo('$1')\" title=\"$1\">$2</a>" ); // [page:name title]
27 text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_]+)\]/gi, "[link:$1 $1]" ); // [link:url] to [link:url title]
28 text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_|\(|\)]+) ([\w|\:|\/|\.|\-|\_ ]+)\]/gi, "<a href=\"$1\" target=\"_blank\">$2</a>" ); // [link:url title]
29 text = text.replace(/\*([\w|\d|\"|\-|\(][\w|\d|\ |\-|\/|\+|\-|\(|\)|\=|\,|\.\"]*[\w|\d|\"|\)]|\w)\*/gi, "<strong>$1</strong>" ); // *
30
31 document.body.innerHTML = text;
32
33 // handle code snippets formatting
34
35 var elements = document.getElementsByTagName( 'code' );
36
37 for ( var i = 0; i < elements.length; i ++ ) {
38
39 var element = elements[ i ];
40
41 text = element.textContent.trim();
42 text = text.replace( /^\t\t/gm, '' );
43
44 element.textContent = text;
45
46 }
47
48 // Edit button
49
50 var button = document.createElement( 'div' );
51 button.id = 'button';
52 button.textContent = 'Edit this page';
53
54 button.addEventListener( 'click', function ( event ) {
55
56 window.open( 'https://github.com/mrdoob/three.js/blob/dev/docs/' + section + '/' + path + '.html' );
57
58 }, false );
59
60 document.body.appendChild( button );
61
62 // Syntax highlighting
63
64 var styleBase = document.createElement( 'link' );
65 styleBase.href = '../../prettify/prettify.css';
66 styleBase.rel = 'stylesheet';
67
68 var styleCustom = document.createElement( 'link' );
69 styleCustom.href = '../../prettify/threejs.css';
70 styleCustom.rel = 'stylesheet';
71
72 document.head.appendChild( styleBase );
73 document.head.appendChild( styleCustom );
74
75 var prettify = document.createElement( 'script' );
76 prettify.src = '../../prettify/prettify.js';
77
78 prettify.onload = function () {
79
80 var elements = document.getElementsByTagName( 'code' );
81
82 for ( var i = 0; i < elements.length; i ++ ) {
83
84 var e = elements[ i ];
85 e.className += ' prettyprint';
86
87 }
88
89 prettyPrint();
90
91 }
92
93 document.head.appendChild( prettify );
94
95};
96
97document.addEventListener( 'DOMContentLoaded', onDocumentLoad, false );
Note: See TracBrowser for help on using the repository browser.