goldendict-ng/scripts/gd-builtin.js
shenleban tongying 540dda26ed cleanup: Replace all usages of qrcx://localhost with qrc://
The replacement command:
git grep -l 'qrcx://localhost' | xargs sed -i 's/qrcx:\/\/localhost/qrc:\/\//g'

The qrcx:// URL scheme was introduced in 2009 or earlier - it is present
in the first commit in GoldenDict's git history. Back then GoldenDict
supported Qt versions earlier than 4.6, in which
QWebSecurityOrigin::addLocalScheme() was introduced. Adding the qrc URL
scheme as local obsoletes the qrcx URL scheme. GoldenDict does not
compile against Qt versions earlier than 4.6, so there is no reason to
use this custom URL scheme anymore.

Co-authored-by:  Igor Kushnir <[email protected]>
2023-03-05 15:20:05 -05:00

126 lines
3.5 KiB
JavaScript

// seperate from cpp code.
var gdAudioLinks = {
"first": null,
"current": null
};
function gdMakeArticleActive(newId,noEvent) {
var gdCurrentArticle = $_$(".gdactivearticle").attr("id")
if (gdCurrentArticle !== 'gdfrom-' + newId) {
$_$(".gdactivearticle").removeClass("gdactivearticle")
var newFormId = 'gdfrom-' + newId
$_$("#" + newFormId).addClass("gdactivearticle")
gdCurrentArticle = 'gdfrom-' + newId
gdAudioLinks.current = newId
if(!noEvent)
articleview.onJsActiveArticleChanged('gdfrom-' + newId);
}
}
var overIframeId = null;
function gdSelectArticle(id) {
var selection = window.getSelection()
var range = document.createRange()
range.selectNodeContents(document.getElementById('gdfrom-' + id))
selection.removeAllRanges()
selection.addRange(range)
}
function processIframeMouseOut() {
overIframeId = null
top.focus()
}
function processIframeMouseOver(newId) {
overIframeId = newId
}
function processIframeClick() {
if (overIframeId != null) {
overIframeId = overIframeId.replace('gdexpandframe-', '')
gdMakeArticleActive(overIframeId)
}
}
function init() {
window.addEventListener('blur', processIframeClick, false)
}
window.addEventListener('load', init, false)
function gdExpandOptPart(expanderId, optionalId) {
var d1 = document.getElementById(expanderId)
var i = 0
if (d1.alt == '[+]') {
d1.alt = '[-]'
d1.src = 'qrc:///icons/collapse_opt.png'
for (i = 0; i < 1000; i++) {
var d2 = document.getElementById(optionalId + i)
if (!d2)
break
d2.style.display = 'inline'
}
} else {
d1.alt = '[+]'
d1.src = 'qrc:///icons/expand_opt.png'
for (i = 0; i < 1000; i++) {
var d2 = document.getElementById(optionalId + i)
if (!d2)
break
d2.style.display = 'none'
}
}
}
function emitClickedEvent(link) {
try {
if ('string' != typeof(link)) {
return;
}
articleview.linkClickedInHtml(link)
} catch (error) {
console.error(error)
}
}
function gdExpandArticle(id) {
emitClickedEvent()
elem = document.getElementById('gdarticlefrom-' + id)
ico = document.getElementById('expandicon-' + id)
art = document.getElementById('gdfrom-' + id)
ev = window.event
t = null
if (ev)
t = ev.target || ev.srcElement
if (elem.style.display == 'inline') {
elem.style.display = 'none'
ico.className = 'gdexpandicon'
art.className = art.className + ' gdcollapsedarticle'
nm = document.getElementById('gddictname-' + id)
nm.style.cursor = 'pointer'
if (ev)
ev.stopPropagation()
ico.title = tr("Expand article")
nm.title = ''
} else if (elem.style.display == 'none') {
elem.style.display = 'inline'
ico.className = 'gdcollapseicon'
art.className = art.className.replace(' gdcollapsedarticle', '')
nm = document.getElementById('gddictname-' + id)
nm.style.cursor = 'default'
nm.title = ''
ico.title = tr("Collapse article")
}
}
function gdCheckArticlesNumber() {
elems = document.getElementsByClassName('gddictname')
if (elems.length == 1) {
el = elems.item(0)
s = el.id.replace('gddictname-', '')
el = document.getElementById('gdfrom-' + s)
if (el && el.className.search('gdcollapsedarticle') > 0)
gdExpandArticle(s)
}
}