From 034001d4076c83e3f674d42ef5e97ea3655cfeeb Mon Sep 17 00:00:00 2001 From: Zhicheng Wang Date: Sun, 23 Apr 2017 09:03:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAlive=20example=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/js/directives/live-example.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/public/resources/js/directives/live-example.js b/public/resources/js/directives/live-example.js index b676eb9023..8ae7b2fd08 100644 --- a/public/resources/js/directives/live-example.js +++ b/public/resources/js/directives/live-example.js @@ -56,20 +56,30 @@ angularIO.directive('liveExample', ['$location', function ($location) { function span(text) { return '' + text + ''; } - function embeddedTemplate(src, img, zipHref) { - return '
' + + function embeddedTemplate(src, img, zipHref, translated) { + var basic = '
' + '' + '
' + - 'plunker' + - '

你也可以下载这个例子。

'; + 'plunker'; + var download = translated + ? + '

你还可以下载这个例子

' + : + '

You can also download this example.

'; + return basic + download; } return { restrict: 'E', scope: true, 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() || '在线例子'; + 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'); @@ -95,7 +105,7 @@ angularIO.directive('liveExample', ['$location', function ($location) { if (embedded && !isForDart) { href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'; img = imageBase + (attrs.img || defaultImg); - template = embeddedTemplate(href, img, zipHref); + template = embeddedTemplate(href, img, zipHref, translated); } else { var href = isForDart ? 'http://angular-examples.github.io/' + ex @@ -105,13 +115,13 @@ angularIO.directive('liveExample', ['$location', function ($location) { var template = a(text, { href: href, target: '_blank' }); if (!noDownload) { - template += ' / ' + a('可下载的例子', { href: zipHref, target: '_blank' }); + 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 || '查看源码'; + var srcText = attrs.srcText || textViewSource; var srcHref = 'http://github.com/angular-examples/' + ex; template = span(template + ' (' + a(srcText, { href: srcHref, target: '_blank' }) + ')'); }