Skip to content

Commit

Permalink
opt: use iframe resizer plugin to resize the iframe height.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed Sep 4, 2022
1 parent 6584954 commit 349ac86
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
5 changes: 4 additions & 1 deletion article_maker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
result += "<script> var $_$=$.noConflict(); </script>";

//custom javascript
result += "<script type=\"text/javascript\" src=\"qrc:///resources/gd-custom.js\"></script>";
result += "<script type=\"text/javascript\" src=\"qrc:///resources/gd-custom.js\"></script>";

//iframe resizer javascript
result += "<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.min.js\"></script>";
}

// add qwebchannel
Expand Down
1 change: 1 addition & 0 deletions goldendict.pro
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ CONFIG( chinese_conversion_support ) {
}

RESOURCES += resources.qrc \
scripts.qrc \
flags.qrc
#EXTRA_TRANSLATIONS += thirdparty/qwebengine_ts/qtwebengine_zh_CN.ts
TRANSLATIONS += locale/ru_RU.ts \
Expand Down
3 changes: 2 additions & 1 deletion iframeschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
QString baseTagHtml = "<base href=\"" + base + "\">";

QString depressionFocus =
"<script type=\"application/javascript\">HTMLElement.prototype.focus=function(){console.log(\".focus has been depressed \");}</script>";
QStringLiteral( "<script type=\"application/javascript\">HTMLElement.prototype.focus=function(){console.log(\".focus has been depressed \");}</script>"
"<script type=\"text/javascript\" src=\"qrc:///scripts/iframeResizer.contentWindow.min.js\"></script>");

// remove existed base tag
articleString.remove( baseTag ) ;
Expand Down
18 changes: 1 addition & 17 deletions resources/gd-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,7 @@
});

//monitor iframe height.

$("iframe").on("load", function () {
var iframe = $(this);
resizeIframe(iframe[0]);
});

function resizeIframe(obj) {
setInterval(function () {
//in some cases ,the website in iframe will load result after document has been loaded. the height will continue to change.
var height = $(obj).contents().height();
$(obj).height(Math.min(2000, height));
if (height >= 2000) {
obj.scrolling = "yes";
}
}, 500);
}

$('iframe').iFrameResize({ checkOrigin:false,maxHeight :1500,scrolling:true,warningTimeout:0,minHeight :250});
});
})($_$);

Expand Down
9 changes: 9 additions & 0 deletions scripts.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<RCC>
<qresource prefix="/">
<file>scripts/iframeResizer.contentWindow.min.js</file>
<file>scripts/iframeResizer.min.js</file>
<file>scripts/gd-builtin.js</file>
<file>scripts/gd-custom.js</file>
<file>scripts/jquery-3.6.0.slim.min.js</file>
</qresource>
</RCC>
10 changes: 10 additions & 0 deletions scripts/iframeResizer.contentWindow.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 349ac86

Please sign in to comment.