2121*
2222* <live-example embedded plnkr="minimal"></live-example>
2323* // ~/resources/live-examples/{chapter}/ts/minimal.eplnkr.html
24+ *
25+ * <live-example api="core/animation/ts/dsl"></live-example>
26+ * // ~/resources/api-live-examples/core/animation/ts/dsl/plnkr.html
27+ *
28+ * <live-example api="core/animation/ts/dsl" embedded></live-example>
29+ * // ~/resources/api-live-examples/core/animation/ts/dsl/eplnkr.html
30+ *
31+ * <live-example api="core/animation/ts/dsl" noimg></live-example>
32+ * // ~/resources/api-live-examples/core/animation/ts/dsl/plnkr.html
2433*/
2534angularIO . directive ( 'liveExample' , [ '$location' , function ( $location ) {
2635
@@ -30,7 +39,18 @@ angularIO.directive('liveExample', ['$location', function ($location) {
3039 return '<a' + attr + '>' + text + '</a>' ;
3140 }
3241
33- function span ( text ) { return '<span>' + text + '</span>' ; }
42+ function embeddedNoImgTemplate ( src ) {
43+ return '<div ng-if="embeddedShow">' +
44+ '<div class="api-live-example" ng-click="toggleEmbedded()" ng-if="embeddedShow">' +
45+ '<img src="/resources/images/icons/ic_keyboard_arrow_down_black_24px.svg"><span>Live example</span>' +
46+ '</div>' +
47+ '<iframe frameborder="0" width="100%" height="100%" src="' + src + '"></iframe>' +
48+ '</div>' +
49+ '<div class="api-live-example" ng-click="toggleEmbedded()" ng-if="!embeddedShow">' +
50+ '<img src="/resources/images/icons/ic_keyboard_arrow_right_black_24px.svg"><span>Live example</span>' +
51+ '</div>'
52+
53+ }
3454
3555 function embeddedTemplate ( src , img ) {
3656 return '<div ng-if="embeddedShow">' +
@@ -39,6 +59,24 @@ angularIO.directive('liveExample', ['$location', function ($location) {
3959 '<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="' + img + '" alt="plunker">' ;
4060 }
4161
62+ function getHref ( langOrApi , example , plnkr ) {
63+ var href ;
64+ switch ( langOrApi ) {
65+ case 'ts' :
66+ case 'js' :
67+ href = '/resources/live-examples/' + example + '/' + langOrApi + '/' + plnkr + '.html' ;
68+ break ;
69+ case 'dart' :
70+ href = 'http://angular-examples.github.io/' + example ;
71+ break ;
72+ case 'api' :
73+ href = '/resources/api-live-examples/' + example + '/' + plnkr + '.html' ;
74+ }
75+ return href ;
76+ }
77+
78+ function span ( text ) { return '<span>' + text + '</span>' ; }
79+
4280 return {
4381 restrict : 'E' ,
4482 scope : true ,
@@ -47,35 +85,41 @@ angularIO.directive('liveExample', ['$location', function ($location) {
4785 var ex = attrs . name || NgIoUtil . getExampleName ( $location ) ;
4886 var embedded = attrs . hasOwnProperty ( 'embedded' ) ;
4987 var plnkr = embedded ? 'eplnkr' : 'plnkr' ;
50- var href , template ;
88+ var href , template , exLang ;
5189 var imageBase = '/resources/images/' ;
5290 var defaultImg = 'plunker/placeholder.png' ;
53-
91+ var noImg = angular . isDefined ( attrs . noimg ) ;
92+ var isApi = ! ! attrs . api ;
93+ console . log ( noImg ) ;
5494 if ( attrs . plnkr ) {
5595 plnkr = attrs . plnkr + '.' + plnkr ;
5696 }
5797
98+ if ( isApi ) {
99+ ex = attrs . api ;
100+ exLang = 'api' ;
101+ } else {
102+ exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts' ;
103+ }
104+
58105 var isForDart = attrs . lang === 'dart' || NgIoUtil . isDoc ( $location , 'dart' ) ;
59106 var isForJs = attrs . lang === 'js' || NgIoUtil . isDoc ( $location , 'js' ) ;
60- var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts' ;
61107
62108 if ( embedded && ! isForDart ) {
63- href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html' ;
109+ href = getHref ( exLang , ex , plnkr ) ;
64110 img = imageBase + ( attrs . img || defaultImg ) ;
65- template = embeddedTemplate ( href , img ) ;
111+ template = noImg ? embeddedNoImgTemplate ( href ) : embeddedTemplate ( href , img ) ;
66112 } else {
67- var href = isForDart
68- ? 'http://angular-examples.github.io/' + ex
69- : '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
113+ href = getHref ( exLang , ex , plnkr ) ;
70114
71115 // Link to live example.
72- var template = a ( text , { href : href , target : '_blank' } ) ;
116+ template = a ( text , { href : href , target : '_blank' } ) ;
73117
74118 // The hosted example and sources are in different locations for Dart.
75119 // Also show link to sources for Dart, unless noSource is specified.
76120 if ( isForDart && ! attrs . hasOwnProperty ( 'nosource' ) ) {
77121 var srcText = attrs . srcText || 'view source' ;
78- var srcHref = 'http://github.com/angular-examples/' + ex ;
122+ href = getHref ( 'dart' , ex ) ;
79123 template = span ( template + ' (' + a ( srcText , { href : srcHref , target : '_blank' } ) + ')' ) ;
80124 }
81125 }
0 commit comments