|
22 | 22 | ' </body>\n' + |
23 | 23 | '</html>'; |
24 | 24 |
|
25 | | - angular.widget('doc:example', ['$injector', '$element', function($injector, element){ |
26 | | - this.descend(true); //compile the example code |
| 25 | + angular.widget('doc:example', ['$injector', '$browser', '$location', '$element', |
| 26 | + function($injector, $browser, $location, element){ |
| 27 | + this.descend(false); // do not compile the example code |
27 | 28 | var module = element.attr('module') || ''; |
28 | 29 |
|
29 | 30 | //jQuery find() methods in this widget contain primitive selectors on purpose so that we can use |
|
38 | 39 | jsfiddle = example.attr('jsfiddle') || true, |
39 | 40 | scenario = element.find('pre').eq(1); //doc-scenario |
40 | 41 |
|
41 | | - var tabHtml = |
42 | | - '<ul class="doc-example">'; |
| 42 | + var tabs = angular.element('<ul class="doc-example">'); |
43 | 43 |
|
44 | 44 | // show source tab, if not disabled |
45 | 45 | if (showSource) { |
46 | | - tabHtml += |
| 46 | + tabs.append( |
47 | 47 | '<li class="doc-example-heading"><h3>Source</h3></li>' + |
48 | 48 | '<li class="doc-example-source" ng:non-bindable>' + |
49 | 49 | jsFiddleButton(jsfiddle) + // may or may not have value |
50 | | - '<pre class="brush: js; html-script: true; toolbar: false;"></pre></li>'; |
| 50 | + '<pre class="brush: js; html-script: true; toolbar: false;"></pre></li>'); |
51 | 51 | } |
52 | 52 | // show live preview tab |
53 | | - tabHtml += |
54 | | - '<li class="doc-example-heading"><h3>Live Preview</h3></li>' + |
55 | | - '<li class="doc-example-live">' + htmlSrc +'</li>'; |
| 53 | + var livePreviewTab; |
| 54 | + tabs.append('<li class="doc-example-heading"><h3>Live Preview</h3></li>'); |
| 55 | + tabs.append(livePreviewTab = angular.element('<li class="doc-example-live">' + htmlSrc +'</li>')); |
56 | 56 | // show scenario tab, if present |
57 | 57 | if (scenario.text()) { |
58 | | - tabHtml += |
| 58 | + tabs.append( |
59 | 59 | '<li class="doc-example-heading"><h3>Scenario Test</h3></li>' + |
60 | | - '<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>'; |
| 60 | + '<li class="doc-example-scenario"><pre class="brush: js">' + scenario.text() + '</pre></li>'); |
61 | 61 | } |
62 | | - tabHtml += |
63 | | - '</ul>'; |
64 | | - var tabs = angular.element(tabHtml); |
65 | 62 |
|
66 | 63 | tabs.find('li').eq(1).find('pre').text( |
67 | 64 | HTML_TEMPLATE. |
|
82 | 79 | alert(e); |
83 | 80 | } |
84 | 81 |
|
85 | | - if (module) { |
86 | | - $injector.invoke(null, angular.module[module]); |
87 | | - } |
| 82 | + return function() { |
| 83 | + var scope = this; |
| 84 | + var modules = [ |
| 85 | + 'ng', |
| 86 | + function($provide) { |
| 87 | + $provide.value('$browser', $browser); |
| 88 | + $provide.value('$location', $location); |
| 89 | + } |
| 90 | + ]; |
| 91 | + module && modules.push(module); |
88 | 92 |
|
| 93 | + angular.bootstrap(livePreviewTab, modules).invoke(function($rootScope) { |
| 94 | + element.bind('$destroy', scope.$root.$watch(function() { |
| 95 | + $rootScope.$digest(); |
| 96 | + })); |
| 97 | + }); |
| 98 | + }; |
89 | 99 |
|
90 | 100 | function jsFiddleButton(jsfiddle) { |
91 | 101 | var fixJsFiddleIssue132 = true; |
|
0 commit comments