55* app this directive is contained in.
66*
77* Usage:
8- * <live-example [name="..."] [plnkr='...'] [noSource] [srcText="..."]>text</live-example>
8+ * <live-example [name="..."] [plnkr='...'] [noSource] [embedded] [ srcText="..."]>text</live-example>
99* Example:
1010* <p>Run <live-example>Try the live example</live-example></p>.
1111* // ~/resources/live-examples/{chapter}/ts/plnkr.html
1515*
1616* <p>Run <live-example plnkr="minimal"></live-example></p>.
1717* // ~/resources/live-examples/{chapter}/ts/minimal.plnkr.html
18+ *
19+ * <live-example embedded></live-example>
20+ * // ~/resources/live-examples/{chapter}/ts/eplnkr.html
21+ *
22+ * <live-example embedded plnkr="minimal"></live-example>
23+ * // ~/resources/live-examples/{chapter}/ts/minimal.eplnkr.html
1824*/
1925angularIO . directive ( 'liveExample' , [ '$location' , function ( $location ) {
2026
@@ -26,42 +32,60 @@ angularIO.directive('liveExample', ['$location', function ($location) {
2632
2733 function span ( text ) { return '<span>' + text + '</span>' ; }
2834
35+ function embeddedTemplate ( src , name ) {
36+ return '<div ng-if="embeddedShow">' +
37+ '<iframe frameborder="0" width="100%" height="100%" name="' + name + '" src="' + src + '"></iframe>' +
38+ '</div>' +
39+ '<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="/resources/images/plunker/placeholder.png" alt="plunker">' ;
40+ }
41+
2942 return {
3043 restrict : 'E' ,
31-
44+ scope : true ,
3245 compile : function ( tElement , attrs ) {
3346 var text = tElement . text ( ) || 'live example' ;
3447 var ex = attrs . name || NgIoUtil . getExampleName ( $location ) ;
35- var plnkr = '' ;
48+ var embedded = attrs . hasOwnProperty ( 'embedded' ) ;
49+ var plnkr = embedded ? 'eplnkr' : 'plnkr' ;
3650 var href , template ;
3751
3852 if ( attrs . plnkr ) {
39- plnkr = attrs . plnkr + '.' ;
53+ plnkr = attrs . plnkr + '.' + plnkr ;
4054 }
4155
4256 var isForDart = attrs . lang === 'dart' || NgIoUtil . isDoc ( $location , 'dart' ) ;
4357 var isForJs = attrs . lang === 'js' || NgIoUtil . isDoc ( $location , 'js' ) ;
4458 var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts' ;
45- var href = isForDart
46- ? 'http://angular-examples.github.io/' + ex
47- : '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + 'plnkr.html' ;
4859
49- // Link to live example.
50- var template = a ( text , { href : href , target : '_blank' } ) ;
60+ if ( attrs . hasOwnProperty ( 'embedded' ) && ! isForDart ) {
61+ href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
62+ template = embeddedTemplate ( href , plnkr ) ;
63+ } else {
64+ var href = isForDart
65+ ? 'http://angular-examples.github.io/' + ex
66+ : '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
67+
68+ // Link to live example.
69+ var template = a ( text , { href : href , target : '_blank' } ) ;
5170
52- // The hosted example and sources are in different locations for Dart.
53- // Also show link to sources for Dart, unless noSource is specified.
54- if ( isForDart && ! attrs . hasOwnProperty ( 'nosource' ) ) {
55- var srcText = attrs . srcText || 'view source' ;
56- var srcHref = 'http://github.com/angular-examples/' + ex ;
57- template = span ( template + ' (' + a ( srcText , { href : srcHref , target : '_blank' } ) + ')' ) ;
71+ // The hosted example and sources are in different locations for Dart.
72+ // Also show link to sources for Dart, unless noSource is specified.
73+ if ( isForDart && ! attrs . hasOwnProperty ( 'nosource' ) ) {
74+ var srcText = attrs . srcText || 'view source' ;
75+ var srcHref = 'http://github.com/angular-examples/' + ex ;
76+ template = span ( template + ' (' + a ( srcText , { href : srcHref , target : '_blank' } ) + ')' ) ;
77+ }
5878 }
5979
6080 // UPDATE ELEMENT WITH NEW TEMPLATE
6181 tElement . html ( template ) ;
6282
6383 // RETURN ELEMENT
64- return function ( scope , element , attrs ) { } ;
84+ return function ( scope , element , attrs ) {
85+ scope . toggleEmbedded = function ( ) {
86+ scope . embeddedShow = ! scope . embeddedShow ;
87+ }
88+ } ;
6589 }
6690 } ;
6791} ] ) ;
0 commit comments