page.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var onDocumentLoad = function ( event ) {
  2. var name = /[A-z0-9]+\.html/.exec( window.location.pathname ).toString().split( '.html' )[ 0 ];
  3. var path = /\/api\/[A-z0-9\/]+/.exec( window.location.pathname ).toString().substr( 5 );
  4. var text = document.body.innerHTML;
  5. text = text.replace(/\[name\]/gi, name);
  6. text = text.replace(/\[path\]/gi, path);
  7. text = text.replace(/\[page:(\w+)\]/gi, "[page:$1 $1]" ); // [page:name] to [page:name title]
  8. text = text.replace(/\[page:(\w+) ([\w|\.]+)\]/gi, "<a href=\"javascript:window.parent.goTo('$1')\" title=\"$1\">$2</a>" ); // [page:name title]
  9. text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_]+)\]/gi, "[link:$1 $1]" ); // [link:url] to [link:url title]
  10. text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_]+) ([\w|\:|\/|\.|\-|\_]+)\]/gi, "<a href=\"$1\" target=\"_blank\">$2</a>" ); // [link:url title]
  11. text = text.replace(/\*([\w|\"][\w|\ |\-|\/|\+|\-|\(|\)|\=|\,|\.\"]+[\w|\"]|\w)\*/gi, "<strong>$1</strong>" ); // *
  12. document.body.innerHTML = text;
  13. // Edit button
  14. var button = document.createElement( 'div' );
  15. button.id = 'button';
  16. button.textContent = 'Edit this page';
  17. button.addEventListener( 'click', function ( event ) {
  18. window.open( 'https://github.com/mrdoob/three.js/blob/dev/docs/api/' + path + '.html' );
  19. }, false );
  20. document.body.appendChild( button );
  21. // Syntax highlighting
  22. var styleBase = document.createElement( 'link' );
  23. styleBase.href = '../../prettify/prettify.css';
  24. styleBase.rel = 'stylesheet';
  25. var styleCustom = document.createElement( 'link' );
  26. styleCustom.href = '../../prettify/threejs.css';
  27. styleCustom.rel = 'stylesheet';
  28. document.head.appendChild( styleBase );
  29. document.head.appendChild( styleCustom );
  30. var prettify = document.createElement( 'script' );
  31. prettify.src = '../../prettify/prettify.js';
  32. prettify.onload = function () {
  33. var elements = document.getElementsByTagName( 'code' );
  34. for ( var i = 0; i < elements.length; i ++ ) {
  35. var e = elements[ i ];
  36. e.className += ' prettyprint';
  37. }
  38. prettyPrint();
  39. }
  40. document.head.appendChild( prettify );
  41. };
  42. document.addEventListener( 'DOMContentLoaded', onDocumentLoad, false );