1
1
/**
2
2
* Angular.io Live Example Directive
3
3
*
4
- * Renders a link to a live/host example of the doc chapter
4
+ * Renders a link to a live/host example of the doc page
5
5
* app this directive is contained in.
6
6
*
7
7
* Usage:
8
- * <live-example [name="..."] [plnkr='...'] [noSource] [embedded] [srcText="..."]>text</live-example>
8
+ * <live-example
9
+ * [name="..."]
10
+ * [plnkr='...']
11
+ * [noSource]
12
+ * [embedded]
13
+ * [embedded-style]
14
+ * [srcText="..."]
15
+ * [title="..."]>text</live-example>
9
16
* Example:
10
17
* <p>Run <live-example>Try the live example</live-example></p>.
11
- * // ~/resources/live-examples/{chapter }/ts/plnkr.html
18
+ * // ~/resources/live-examples/{page }/ts/plnkr.html
12
19
*
13
20
* <p>Run <live-example name="toh-1">this example</live-example></p>.
14
- * // ~/resources/live-examples/toh-1/ts/minimal.plnkr.html
21
+ * // ~/resources/live-examples/toh-1/ts/plnkr.html
22
+ *
23
+ * // Link to the default plunker in the toh-1 sample
24
+ * // The title overrides default ("live example") with "Tour of Heroes - Part 1"
25
+ * <p>Run <live-example name="toh-1" title="Tour of Heroes - Part 1"></live-example></p>.
26
+ * // ~/resources/live-examples/toh-1/ts/plnkr.html
15
27
*
16
28
* <p>Run <live-example plnkr="minimal"></live-example></p>.
17
- * // ~/resources/live-examples/{chapter}/ts/minimal.plnkr.html
29
+ * // ~/resources/live-examples/{page}/ts/minimal.plnkr.html
30
+ *
31
+ * // Embed the current page's default plunker
32
+ * // Text within tag is "live example"
33
+ * // No title (no tooltip)
34
+ * <live-example embedded title=""></live-example>
35
+ * // ~/resources/live-examples/{page}/ts/eplnkr.html
18
36
*
19
- * <live-example embedded></live-example>
20
- * // ~/resources/live-examples/{chapter}/ts/eplnkr.html
37
+ * // Links to a *new* tab as an embedded style plunker editor
38
+ * <live-example embedded-style>this example</live-example>
39
+ * // ~/resources/live-examples/{page}//ts/eplnkr.html
21
40
*
22
- * <live-example embedded plnkr="minimal"></live-example>
23
- * // ~/resources/live-examples/{chapter}/ts/minimal.eplnkr.html
41
+ * // Displays in *same* tab as an embedded style plunker editor
42
+ * <live-example name="toh-1" embedded plnkr="minimal" img="toh>Tour of Heroes - Part 1</live-example>
43
+ * // ~/resources/live-examples/toh-1/ts/minimal.eplnkr.html
24
44
*/
25
45
angularIO . directive ( 'liveExample' , [ '$location' , function ( $location ) {
26
46
@@ -43,11 +63,13 @@ angularIO.directive('liveExample', ['$location', function ($location) {
43
63
restrict : 'E' ,
44
64
scope : true ,
45
65
compile : function ( tElement , attrs ) {
66
+ var href , template ;
46
67
var text = tElement . text ( ) || 'live example' ;
68
+ if ( attrs [ 'title' ] == undefined ) { tElement [ 0 ] . setAttribute ( 'title' , text ) ; } // set default title (tooltip)
47
69
var ex = attrs . name || NgIoUtil . getExampleName ( $location ) ;
48
70
var embedded = attrs . hasOwnProperty ( 'embedded' ) ;
49
- var plnkr = embedded ? 'eplnkr' : 'plnkr' ;
50
- var href , template ;
71
+ var embeddedStyle = embedded || attrs . hasOwnProperty ( 'embeddedstyle' ) || attrs . hasOwnProperty ( 'embeddedStyle' ) ;
72
+ var plnkr = embeddedStyle ? 'eplnkr' : 'plnkr' ;
51
73
var imageBase = '/resources/images/' ;
52
74
var defaultImg = 'plunker/placeholder.png' ;
53
75
0 commit comments