goldendict-ng/resources/gd-custom.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2022-01-11 12:18:46 +00:00
//document ready
2022-07-09 04:52:33 +00:00
(function ($) {
$(function () {
$(document).on("click", "a", function (event) {
2021-12-31 14:15:51 +00:00
var link = $(this).attr("href");
2022-07-09 04:52:33 +00:00
if ('string' != typeof (link)) {
return;
}
2022-06-07 13:22:37 +00:00
2022-07-09 04:52:33 +00:00
if (link.indexOf("javascript:") >= 0) {
2022-06-07 13:22:37 +00:00
return;
}
2022-07-09 04:52:33 +00:00
if (link.indexOf(":") >= 0) {
emitClickedEvent(link);
return false;
2022-01-02 01:37:43 +00:00
}
emitClickedEvent("");
2022-01-02 01:37:43 +00:00
2022-01-01 13:09:55 +00:00
var newLink;
var href = window.location.href;
2022-07-09 04:52:33 +00:00
var index = -1;
2022-01-01 13:09:55 +00:00
if (link.startsWith("#")) {
//the href may contain # fragment already.remove them before append the new #fragment
2022-01-11 12:18:46 +00:00
index = href.indexOf("#");
2022-07-09 04:52:33 +00:00
if (index > -1) {
newLink = href.substring(0, index) + link;
2022-07-09 04:52:33 +00:00
}
else {
newLink = href + link;
}
2022-01-01 13:09:55 +00:00
} else {
2022-01-11 12:18:46 +00:00
index = href.indexOf("?");
if (link.indexOf("?gdanchor") > -1) {
newLink = "gdlookup://localhost/" + link;
}
else {
if (index > -1) {
newLink = href.substring(0, index) + "?word=" + link;
}
else {
newLink = href + "?word=" + link;
}
}
2021-12-31 14:15:51 +00:00
}
2022-01-01 13:09:55 +00:00
$(this).attr("href", newLink);
2021-12-31 14:15:51 +00:00
});
2022-07-09 04:52:33 +00:00
//monitor iframe height.
2022-07-09 04:52:33 +00:00
$("iframe").on("load", function () {
var iframe = $(this);
resizeIframe(iframe[0]);
});
2022-07-09 04:52:33 +00:00
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);
}
2022-01-11 12:18:46 +00:00
});
})($_$);
2021-12-31 14:15:51 +00:00
2022-01-03 04:00:50 +00:00
function playSound(sound) {
2022-01-11 12:18:46 +00:00
var a = new Audio(sound);
a.play();
}