aboutsummaryrefslogtreecommitdiffstats
path: root/docs/doc_widgets.js
blob: f865548c530b9501d5668501470b270b6d37c3b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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; brush: xml;"></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();
    };
  });
})();