aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorMisko Hevery2010-11-10 15:31:15 -0800
committerMisko Hevery2010-11-10 21:01:05 -0800
commit43a4ff4cdf4100ded15b90d49a514648a88b87b4 (patch)
treef53adbe5fe7c5257877b9c1e709a618323f95125 /docs
parent6b8ed42670039f53d2b20dc1079f742840f62ae9 (diff)
downloadangular.js-43a4ff4cdf4100ded15b90d49a514648a88b87b4.tar.bz2
Example snippets now have full html snippets
Diffstat (limited to 'docs')
-rw-r--r--docs/doc_widgets.js46
1 files changed, 36 insertions, 10 deletions
diff --git a/docs/doc_widgets.js b/docs/doc_widgets.js
index f865548c..ed1dad8d 100644
--- a/docs/doc_widgets.js
+++ b/docs/doc_widgets.js
@@ -1,15 +1,24 @@
(function(){
+
+ var angularJsUrl;
+ var scripts = document.getElementsByTagName("script");
+ var filename = /(.*\/)angular([^\/]*)/;
+ for(var j = 0; j < scripts.length; j++) {
+ var src = scripts[j].src;
+ if (src && src.match(filename)) {
+ angularJsUrl = src;
+ }
+ }
+
+
var HTML_TEMPLATE =
- '<!DOCTYPE HTML>\n' +
+ '<!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' +
+ ' <script type="text/javascript" ng:autobind\n' +
+ ' src="' + angularJsUrl + '"></script>\n' +
+ ' <body>\n' +
'_HTML_SOURCE_\n' +
- ' </body>\n' +
+ ' </body>\n' +
'</html>';
angular.widget('doc:example', function(element){
@@ -20,16 +29,20 @@
exampleSrc = example.text(),
scenario = element.find('doc\\:scenario').eq(0);
+ var code = indent(exampleSrc);
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; brush: xml;"></pre></li>' +
+ '<li class="doc-example-source" ng:non-bindable>' +
+ '<pre class="brush: js; html-script: true; highlight: [' +
+ code.hilite + ']; toolbar: false;"></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);
+
+ tabs.find('li.doc-example-source > pre').text(HTML_TEMPLATE.replace('_HTML_SOURCE_', code.html));
element.html('');
element.append(tabs);
@@ -46,4 +59,17 @@
SyntaxHighlighter.highlight();
};
});
+
+ function indent(text) {
+ var lines = text.split(/\n/);
+ var lineNo = [];
+ while (lines[0].match(/^\s*$/)) lines.shift();
+ while (lines[lines.length - 1].match(/^\s*$/)) lines.pop();
+ for ( var i = 0; i < lines.length; i++) {
+ lines[i] = ' ' + lines[i];
+ lineNo.push(6 + i);
+ }
+ return {html: lines.join('\n'), hilite: lineNo.join(',') };
+ };
+
})(); \ No newline at end of file