chore: add _self target to embedded plunkers (#2201)

This commit is contained in:
Jesús Rodríguez 2016-08-26 19:09:35 +02:00 committed by Ward Bell
parent 8e15829189
commit 6962f03f30
2 changed files with 9 additions and 15 deletions

View File

@ -32,9 +32,9 @@ angularIO.directive('liveExample', ['$location', function ($location) {
function span(text) { return '<span>' + text + '</span>'; } function span(text) { return '<span>' + text + '</span>'; }
function embeddedTemplate(src, name) { function embeddedTemplate(src) {
return '<div ng-if="embeddedShow">' + return '<div ng-if="embeddedShow">' +
'<iframe frameborder="0" width="100%" height="100%" name="' + name + '" src="' + src + '"></iframe>' + '<iframe frameborder="0" width="100%" height="100%" src="' + src + '"></iframe>' +
'</div>' + '</div>' +
'<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="/resources/images/plunker/placeholder.png" alt="plunker">'; '<img ng-click="toggleEmbedded()" ng-if="!embeddedShow" src="/resources/images/plunker/placeholder.png" alt="plunker">';
} }
@ -57,9 +57,9 @@ angularIO.directive('liveExample', ['$location', function ($location) {
var isForJs = attrs.lang === 'js' || NgIoUtil.isDoc($location, 'js'); var isForJs = attrs.lang === 'js' || NgIoUtil.isDoc($location, 'js');
var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts'; var exLang = isForDart ? 'dart' : isForJs ? 'js' : 'ts';
if (attrs.hasOwnProperty('embedded') && !isForDart) { if (embedded && !isForDart) {
href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html' href = '/resources/live-examples/' + ex + '/' + exLang + '/' + plnkr + '.html'
template = embeddedTemplate(href, plnkr); template = embeddedTemplate(href);
} else { } else {
var href = isForDart var href = isForDart
? 'http://angular-examples.github.io/' + ex ? 'http://angular-examples.github.io/' + ex

View File

@ -83,7 +83,7 @@ class PlunkerBuilder {
var config = this._initConfigAndCollectFileNames(configFileName); var config = this._initConfigAndCollectFileNames(configFileName);
var postData = this._createPostData(config); var postData = this._createPostData(config);
this._addPlunkerFiles(config, postData); this._addPlunkerFiles(config, postData);
var html = this._createPlunkerHtml(postData, altFileName); var html = this._createPlunkerHtml(postData);
if (this.options.writeNoLink) { if (this.options.writeNoLink) {
fs.writeFileSync(outputFileName, html, 'utf-8'); fs.writeFileSync(outputFileName, html, 'utf-8');
} }
@ -106,15 +106,9 @@ class PlunkerBuilder {
} }
} }
_createBasePlunkerHtml(embedded, altFileName) { _createBasePlunkerHtml(embedded) {
// We extract the filename without extension
var targetName = '';
if (altFileName) {
targetName = altFileName.split('/').pop().slice(0, -5);
}
var target = embedded ? targetName : '_self';
var html = '<!DOCTYPE html><html lang="en"><body>' var html = '<!DOCTYPE html><html lang="en"><body>'
html += `<form id="mainForm" method="post" action="${this.options.url}" target="${target}">` html += `<form id="mainForm" method="post" action="${this.options.url}" target="_self">`
// html += '<div class="button"><button id="formButton" type="submit">Create Plunker</button></div>' // html += '<div class="button"><button id="formButton" type="submit">Create Plunker</button></div>'
// html += '</form><script>document.getElementById("formButton").click();</script>' // html += '</form><script>document.getElementById("formButton").click();</script>'
@ -183,8 +177,8 @@ class PlunkerBuilder {
return postData; return postData;
} }
_createPlunkerHtml(postData, altFileName) { _createPlunkerHtml(postData) {
var baseHtml = this._createBasePlunkerHtml(this.options.embedded, altFileName); var baseHtml = this._createBasePlunkerHtml(this.options.embedded);
var doc = jsdom.jsdom(baseHtml); var doc = jsdom.jsdom(baseHtml);
var form = doc.querySelector('form'); var form = doc.querySelector('form');
_.forEach(postData, (value, key) => { _.forEach(postData, (value, key) => {