in public/resources/js/directives/live-example.js [75:139]
compile: function (tElement, attrs) {
var translated = tElement.parent().hasClass('translated');
var textLiveExample = translated?'在线例子':'live example';
var textDownloadableExample = translated? '可下载的例子':'downloadable example';
var textViewSource = translated ? '查看源码':'view source';
var href, template;
var text = tElement.text() || textLiveExample;
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 noDownload = attrs.hasOwnProperty('nodownload') || attrs.hasOwnProperty('noDownload');
var flatStyle = attrs.hasOwnProperty('flatstyle') || attrs.hasOwnProperty('flatStyle');
var embeddedStyle = embedded || attrs.hasOwnProperty('embeddedstyle') || attrs.hasOwnProperty('embeddedStyle');
var plnkr = (embeddedStyle || !flatStyle) ? 'eplnkr' : 'plnkr';
var zipHref = ex;
var imageBase = '/resources/images/';
var defaultImg = 'plunker/placeholder.png';
if (attrs.plnkr) {
plnkr = attrs.plnkr + '.' + plnkr;
zipHref = attrs.plnkr + '.' + zipHref;
}
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';
zipHref = '/resources/zips/' + ex + '/' + zipHref + '.zip';
if (embedded && !isForDart) {
href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html';
img = imageBase + (attrs.img || defaultImg);
template = embeddedTemplate(href, img, zipHref, translated);
} 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' });
if (!noDownload) {
template += ' / ' + a(textDownloadableExample, { href: zipHref, 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 || textViewSource;
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;
}
};
}