/** * Angular.io Live Example Directive * * Renders a link to a live/host example of the doc page * app this directive is contained in. * * Usage: * text * Example: *

Run Try the live example

. * // ~/resources/live-examples/{page}/ts/plnkr.html * *

Run this example

. * // ~/resources/live-examples/toh-1/ts/plnkr.html * * // Link to the default plunker in the toh-1 sample * // The title overrides default ("live example") with "Tour of Heroes - Part 1" *

Run

. * // ~/resources/live-examples/toh-1/ts/plnkr.html * *

Run

. * // ~/resources/live-examples/{page}/ts/minimal.plnkr.html * * // Embed the current page's default plunker * // Text within tag is "live example" * // No title (no tooltip) * * // ~/resources/live-examples/{page}/ts/eplnkr.html * * // Links to a *new* tab as an embedded style plunker editor * this example * // ~/resources/live-examples/{page}//ts/eplnkr.html * * // Links to a *new* tab in the flat (original editor) style plunker editor * this example * // ~/resources/live-examples/{page}//ts/eplnkr.html * * // Displays in *same* tab as an embedded style plunker editor * ' + text + ''; } function span(text) { return '' + text + ''; } function embeddedTemplate(src, img) { return '
' + '' + '
' + 'plunker'; } return { restrict: 'E', scope: true, compile: function (tElement, attrs) { var href, template; var text = tElement.text() || 'live example'; if (attrs['title'] == undefined) { tElement[0].setAttribute('title', text); } // set default title (tooltip) var ex = attrs.name || NgIoUtil.getExampleName($location); var embedded = attrs.hasOwnProperty('embedded'); var flatStyle = attrs.hasOwnProperty('flatstyle') || attrs.hasOwnProperty('flatStyle'); var embeddedStyle = embedded || attrs.hasOwnProperty('embeddedstyle') || attrs.hasOwnProperty('embeddedStyle'); var plnkr = (embeddedStyle || !flatStyle) ? 'eplnkr' : 'plnkr'; var imageBase = '/resources/images/'; var defaultImg = 'plunker/placeholder.png'; if (attrs.plnkr) { plnkr = attrs.plnkr + '.' + plnkr; } var isForDart = attrs.lang === 'dart' || NgIoUtil.isDoc($location, 'dart'); var isForJs = attrs.lang === 'js' || NgIoUtil.isDoc($location, 'js'); var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts'; if (embedded && !isForDart) { href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'; img = imageBase + (attrs.img || defaultImg); template = embeddedTemplate(href, img); } else { var href = isForDart ? 'http://angular-examples.github.io/' + ex : '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html' // Link to live example. var template = a(text, { href: href, target: '_blank' }); // The hosted example and sources are in different locations for Dart. // Also show link to sources for Dart, unless noSource is specified. if (isForDart && !attrs.hasOwnProperty('nosource')) { var srcText = attrs.srcText || 'view source'; var srcHref = 'http://github.com/angular-examples/' + ex; template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')'); } } // UPDATE ELEMENT WITH NEW TEMPLATE tElement.html(template); // RETURN ELEMENT return function (scope, element, attrs) { scope.toggleEmbedded = function() { scope.embeddedShow = !scope.embeddedShow; } }; } }; }]);