Dev: Use iframe to show cross origin resources

This commit is contained in:
surunzi
2016-07-28 15:53:39 +08:00
parent 292e3b2533
commit aaf0c87b67
5 changed files with 21 additions and 3 deletions

View File

@@ -238,24 +238,30 @@ export default class Resources extends Tool
sources.set(type, data);
parent.showTool('sources');
return true;
}
function linkFactory(type)
{
return function (e)
{
if (!parent.get('sources')) return;
e.preventDefault();
var url = util.$(this).attr('href');
if (!util.isCrossOrig(url))
{
e.preventDefault();
return util.get(url, (err, data) =>
{
if (err) return;
showSources(type, data);
});
} else
{
showSources('iframe', url);
}
};
}

View File

@@ -133,6 +133,7 @@ export default class Sources extends Tool
this._httpTpl = require('./http.hbs');
this._jsonTpl = require('./json.hbs');
this._rawTpl = require('./raw.hbs');
this._iframeTpl = require('./iframe.hbs');
}
_render()
{
@@ -154,6 +155,8 @@ export default class Sources extends Tool
return this._renderJson();
case 'raw':
return this._renderRaw();
case 'iframe':
return this._renderIframe();
}
}
_renderImg()
@@ -214,6 +217,10 @@ export default class Sources extends Tool
{
this._renderHtml(this._rawTpl({val: this._data.val}));
}
_renderIframe()
{
this._renderHtml(this._iframeTpl({src: this._data.val}));
}
_renderHtml(html)
{
if (html === this._lastHtml) return;

View File

@@ -62,6 +62,10 @@
margin-bottom: 10px;
}
}
iframe {
width: 100%;
height: 100%;
}
.json {
@include overflow-auto(x);
cursor: default;

1
src/Sources/iframe.hbs Normal file
View File

@@ -0,0 +1 @@
<iframe src="{{{src}}}"></iframe>