Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit e0e2e40

Browse files
authored
chore: add default title and embedded-style options to <live-example> (#2882)
Adds default title (tooltip) of the example text unless overiden with "title" attribute The "embedded-style" attribute causes link to open in new tab in the embedded style. Use for samples that have a confusingly large number of files. The "embedded" attribute option remains and displays _inline_ in the _same_ tab.
1 parent a4f0a32 commit e0e2e40

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

public/resources/js/directives/live-example.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
11
/**
22
* Angular.io Live Example Directive
33
*
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
55
* app this directive is contained in.
66
*
77
* 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>
916
* Example:
1017
* <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
1219
*
1320
* <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
1527
*
1628
* <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
1836
*
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
2140
*
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
2444
*/
2545
angularIO.directive('liveExample', ['$location', function ($location) {
2646

@@ -43,11 +63,13 @@ angularIO.directive('liveExample', ['$location', function ($location) {
4363
restrict: 'E',
4464
scope: true,
4565
compile: function (tElement, attrs) {
66+
var href, template;
4667
var text = tElement.text() || 'live example';
68+
if (attrs['title'] == undefined) { tElement[0].setAttribute('title', text); } // set default title (tooltip)
4769
var ex = attrs.name || NgIoUtil.getExampleName($location);
4870
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';
5173
var imageBase = '/resources/images/';
5274
var defaultImg = 'plunker/placeholder.png';
5375

0 commit comments

Comments
 (0)