page.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  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|\ |\-|\/|\+|\-|\(|\)|\=|\,|\.\"]+)\*/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. };
  22. document.addEventListener( 'DOMContentLoaded', onDocumentLoad, false );