diff options
| author | Igor Minar | 2010-11-05 21:12:37 -0700 |
|---|---|---|
| committer | Igor Minar | 2010-11-09 22:27:31 -0800 |
| commit | 324694a58b6d0ed33e05b511be4767573d9187dd (patch) | |
| tree | 0b7243e721da17e9b5c5a1111ed9c0d28829b309 /docs/doc_widgets.js | |
| parent | effcd340e9d41a2ab8368e4de06a1a83a206ac32 (diff) | |
| download | angular.js-324694a58b6d0ed33e05b511be4767573d9187dd.tar.bz2 | |
Better example widget
- syntax highlighting
- tabless design
- rename widget to doc:example
- rename widget files (wiki_widget.* -> doc_widget.*)
- example section is now optional
Diffstat (limited to 'docs/doc_widgets.js')
| -rw-r--r-- | docs/doc_widgets.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/doc_widgets.js b/docs/doc_widgets.js new file mode 100644 index 00000000..7d723bb3 --- /dev/null +++ b/docs/doc_widgets.js @@ -0,0 +1,49 @@ +(function(){ + var HTML_TEMPLATE = + '<!DOCTYPE HTML>\n' + + '<html xmlns:ng="http://angularjs.org">\n' + + ' <head>\n' + + ' <title>Angular Example</title>\n' + + ' <script type="text/javascript"\n' + + ' src="../angular.js" ng:autobind></script>\n' + + ' </head>\n' + + ' <body>\n' + + '_HTML_SOURCE_\n' + + ' </body>\n' + + '</html>'; + + angular.widget('doc:example', function(element){ + this.descend(true); //compile the example code + element.hide(); + + var example = element.find('doc\\:source').eq(0), + exampleSrc = example.text(), + scenario = element.find('doc\\:scenario').eq(0); + + var tabs = angular.element( + '<ul class="doc-example">' + + '<li class="doc-example-heading"><h3>Source</h3></li>' + + '<li class="doc-example-source" ng:non-bindable><pre class="brush: js"></pre></li>' + + '<li class="doc-example-heading"><h3>Live Preview</h3></li>' + + '<li class="doc-example-live">' + exampleSrc +'</li>' + + '<li class="doc-example-heading"><h3>Scenario Test</h3></li>' + + '<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>' + + '</ul>'); + tabs.find('li.doc-example-source > pre').text(exampleSrc); + + element.html(''); + element.append(tabs); + element.show(); + + var script = (exampleSrc.match(/<script[^\>]*>([\s\S]*)<\/script>/) || [])[1] || ''; + try { + eval(script); + } catch (e) { + alert(e); + } + + return function() { + SyntaxHighlighter.highlight(); + } + }); +})();
\ No newline at end of file |
