5
5
* app this directive is contained in.
6
6
*
7
7
* Usage:
8
- * <live-example [name="..."] [plnkr='...'] [noSource] [srcText="..."]>text</live-example>
8
+ * <live-example [name="..."] [plnkr='...'] [noSource] [embedded] [ srcText="..."]>text</live-example>
9
9
* Example:
10
10
* <p>Run <live-example>Try the live example</live-example></p>.
11
11
* // ~/resources/live-examples/{chapter}/ts/plnkr.html
15
15
*
16
16
* <p>Run <live-example plnkr="minimal"></live-example></p>.
17
17
* // ~/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
18
24
*/
19
25
angularIO . directive ( 'liveExample' , [ '$location' , function ( $location ) {
20
26
@@ -26,42 +32,60 @@ angularIO.directive('liveExample', ['$location', function ($location) {
26
32
27
33
function span ( text ) { return '<span>' + text + '</span>' ; }
28
34
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
+
29
42
return {
30
43
restrict : 'E' ,
31
-
44
+ scope : true ,
32
45
compile : function ( tElement , attrs ) {
33
46
var text = tElement . text ( ) || 'live example' ;
34
47
var ex = attrs . name || NgIoUtil . getExampleName ( $location ) ;
35
- var plnkr = '' ;
48
+ var embedded = attrs . hasOwnProperty ( 'embedded' ) ;
49
+ var plnkr = embedded ? 'eplnkr' : 'plnkr' ;
36
50
var href , template ;
37
51
38
52
if ( attrs . plnkr ) {
39
- plnkr = attrs . plnkr + '.' ;
53
+ plnkr = attrs . plnkr + '.' + plnkr ;
40
54
}
41
55
42
56
var isForDart = attrs . lang === 'dart' || NgIoUtil . isDoc ( $location , 'dart' ) ;
43
57
var isForJs = attrs . lang === 'js' || NgIoUtil . isDoc ( $location , 'js' ) ;
44
58
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' ;
48
59
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' } ) ;
51
70
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
+ }
58
78
}
59
79
60
80
// UPDATE ELEMENT WITH NEW TEMPLATE
61
81
tElement . html ( template ) ;
62
82
63
83
// 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
+ } ;
65
89
}
66
90
} ;
67
91
} ] ) ;
0 commit comments