goldendict-ng/scripts/gd-builtin.js

126 lines
3.5 KiB
JavaScript
Raw Normal View History

// seperate from cpp code.
2022-02-25 14:48:43 +00:00
var gdAudioLinks = {
"first": null,
"current": null
};
2022-02-25 14:48:43 +00:00
function gdMakeArticleActive(newId,noEvent) {
var gdCurrentArticle = $_$(".gdactivearticle").attr("id")
if (gdCurrentArticle !== 'gdfrom-' + newId) {
2022-02-25 14:48:43 +00:00
$_$(".gdactivearticle").removeClass("gdactivearticle")
var newFormId = 'gdfrom-' + newId
$_$("#" + newFormId).addClass("gdactivearticle")
gdCurrentArticle = 'gdfrom-' + newId
gdAudioLinks.current = newId
if(!noEvent)
articleview.onJsActiveArticleChanged('gdfrom-' + newId);
}
}
2022-02-25 14:48:43 +00:00
var overIframeId = null;
function gdSelectArticle(id) {
2022-02-25 14:48:43 +00:00
var selection = window.getSelection()
var range = document.createRange()
range.selectNodeContents(document.getElementById('gdfrom-' + id))
selection.removeAllRanges()
selection.addRange(range)
}
function processIframeMouseOut() {
2022-02-25 14:48:43 +00:00
overIframeId = null
top.focus()
}
2022-02-25 14:48:43 +00:00
function processIframeMouseOver(newId) {
overIframeId = newId
}
function processIframeClick() {
if (overIframeId != null) {
2022-02-25 14:48:43 +00:00
overIframeId = overIframeId.replace('gdexpandframe-', '')
gdMakeArticleActive(overIframeId)
}
}
2022-02-25 14:48:43 +00:00
function init() {
window.addEventListener('blur', processIframeClick, false)
}
window.addEventListener('load', init, false)
function gdExpandOptPart(expanderId, optionalId) {
2022-02-25 14:48:43 +00:00
var d1 = document.getElementById(expanderId)
var i = 0
if (d1.alt == '[+]') {
2022-02-25 14:48:43 +00:00
d1.alt = '[-]'
d1.src = 'qrc:///icons/collapse_opt.png'
for (i = 0; i < 1000; i++) {
2022-02-25 14:48:43 +00:00
var d2 = document.getElementById(optionalId + i)
if (!d2)
break
d2.style.display = 'inline'
}
} else {
2022-02-25 14:48:43 +00:00
d1.alt = '[+]'
d1.src = 'qrc:///icons/expand_opt.png'
for (i = 0; i < 1000; i++) {
2022-02-25 14:48:43 +00:00
var d2 = document.getElementById(optionalId + i)
if (!d2)
break
d2.style.display = 'none'
}
}
2022-02-16 13:17:29 +00:00
}
function emitClickedEvent(link) {
2022-02-25 14:48:43 +00:00
try {
if ('string' != typeof(link)) {
return;
}
articleview.linkClickedInHtml(link)
2022-02-25 14:48:43 +00:00
} catch (error) {
console.error(error)
}
}
function gdExpandArticle(id) {
2022-02-25 14:48:43 +00:00
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') {
2022-02-25 14:48:43 +00:00
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() {
2022-02-25 14:48:43 +00:00
elems = document.getElementsByClassName('gddictname')
if (elems.length == 1) {
2022-02-25 14:48:43 +00:00
el = elems.item(0)
s = el.id.replace('gddictname-', '')
el = document.getElementById('gdfrom-' + s)
if (el && el.className.search('gdcollapsedarticle') > 0)
gdExpandArticle(s)
}
}