mirror of
https://github.com/liriliri/eruda.git
synced 2026-04-13 10:48:35 +08:00
Dev: Use iframe to show cross origin resources
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
1
src/Sources/iframe.hbs
Normal file
@@ -0,0 +1 @@
|
||||
<iframe src="{{{src}}}"></iframe>
|
||||
Reference in New Issue
Block a user