mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
Fix pronunciation for active article (if not avaialbe, fallback to the first one)
This commit is contained in:
parent
c55a3bd0fc
commit
d5c236f183
|
@ -118,12 +118,13 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
|||
result += "<link rel=\"icon\" type=\"image/png\" href=\"qrcx://localhost/flags/" + Html::escape( icon.toUtf8().data() ) + "\" />\n";
|
||||
|
||||
result += "<script type=\"text/javascript\">"
|
||||
"gdAudioLinks = { first: null, current: null };"
|
||||
"function gdMakeArticleActive( newId ) {"
|
||||
"if ( gdCurrentArticle != 'gdfrom-' + newId ) {"
|
||||
"document.getElementById( gdCurrentArticle ).className = 'gdarticle';"
|
||||
"document.getElementById( 'gdfrom-' + newId ).className = 'gdarticle gdactivearticle';"
|
||||
"gdCurrentArticle = 'gdfrom-' + newId; articleview.onJsActiveArticleChanged(gdCurrentArticle);"
|
||||
"eval( 'gdActivateAudioLink_' + newId + '();' ); } }"
|
||||
"gdCurrentArticle = 'gdfrom-' + newId; gdAudioLinks.current = newId;"
|
||||
"articleview.onJsActiveArticleChanged(gdCurrentArticle); } }"
|
||||
"var overIframeId = null;"
|
||||
"function gdSelectArticle( id ) {"
|
||||
"var selection = window.getSelection(); var range = document.createRange();"
|
||||
|
@ -465,13 +466,13 @@ void ArticleRequest::bodyFinished()
|
|||
else
|
||||
{
|
||||
// This is the first article
|
||||
head += "<script language=\"JavaScript\">"
|
||||
head += "<script type=\"text/javascript\">"
|
||||
"var gdCurrentArticle=\"" + gdFrom + "\"; "
|
||||
"articleview.onJsActiveArticleChanged(gdCurrentArticle)</script>";
|
||||
}
|
||||
|
||||
string jsVal = Html::escapeForJavaScript( dictId );
|
||||
head += "<script language=\"JavaScript\">var gdArticleContents; "
|
||||
head += "<script type=\"text/javascript\">var gdArticleContents; "
|
||||
"if ( !gdArticleContents ) gdArticleContents = \"" + jsVal +" \"; "
|
||||
"else gdArticleContents += \"" + jsVal + " \";</script>";
|
||||
|
||||
|
|
|
@ -1108,16 +1108,30 @@ void ArticleView::forward()
|
|||
|
||||
bool ArticleView::hasSound()
|
||||
{
|
||||
QVariant v = evaluateJavaScriptVariableSafe( ui.definition->page()->mainFrame(), "gdAudioLink" );
|
||||
QVariant v = ui.definition->page()->mainFrame()->evaluateJavaScript( "gdAudioLinks.first" );
|
||||
if ( v.type() == QVariant::String )
|
||||
soundScript = v.toString();
|
||||
else
|
||||
soundScript.clear();
|
||||
return !soundScript.isEmpty();
|
||||
return !v.toString().isEmpty();
|
||||
return false;
|
||||
}
|
||||
|
||||
void ArticleView::playSound()
|
||||
{
|
||||
QVariant v;
|
||||
QString soundScript;
|
||||
|
||||
v = ui.definition->page()->mainFrame()->evaluateJavaScript( "gdAudioLinks[gdAudioLinks.current]" );
|
||||
|
||||
if ( v.type() == QVariant::String )
|
||||
soundScript = v.toString();
|
||||
|
||||
// fallback to the first one
|
||||
if ( soundScript.isEmpty() )
|
||||
{
|
||||
v = ui.definition->page()->mainFrame()->evaluateJavaScript( "gdAudioLinks.first" );
|
||||
if ( v.type() == QVariant::String )
|
||||
soundScript = v.toString();
|
||||
}
|
||||
|
||||
if ( !soundScript.isEmpty() )
|
||||
openLink( QUrl::fromEncoded( soundScript.toUtf8() ), ui.definition->url() );
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ class ArticleView: public QFrame
|
|||
bool searchIsOpened;
|
||||
bool expandOptionalParts;
|
||||
QString articleToJump;
|
||||
QString soundScript;
|
||||
|
||||
/// Any resource we've decided to download off the dictionary gets stored here.
|
||||
/// Full vector capacity is used for search requests, where we have to make
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
std::string addAudioLink( std::string const & url,
|
||||
std::string const & dictionaryId )
|
||||
{
|
||||
return std::string( "<script language=\"JavaScript\">" +
|
||||
return std::string( "<script type=\"text/javascript\">" +
|
||||
makeAudioLinkScript( url, dictionaryId ) +
|
||||
"</script>" );
|
||||
}
|
||||
|
@ -33,9 +33,6 @@ std::string makeAudioLinkScript( std::string const & url,
|
|||
escaped = ( ch == '\\' );
|
||||
}
|
||||
|
||||
return std::string( "var gdAudioLink; "
|
||||
"if ( !gdAudioLink ) gdAudioLink=" ) + ref +
|
||||
"; if ( typeof gdActivateAudioLink_" + dictionaryId + " != 'function' ) {"
|
||||
"eval( 'function gdActivateAudioLink_" + dictionaryId + "() {"
|
||||
"gdAudioLink=" + ref + "; }' ); }";
|
||||
return "if ( !gdAudioLinks.first ) { gdAudioLinks.first = " + ref + "; }" +
|
||||
"gdAudioLinks['" + dictionaryId + "'] = " + ref + ";";
|
||||
}
|
||||
|
|
|
@ -2181,6 +2181,7 @@ void MainWindow::dictsListItemActivated( QListWidgetItem * item )
|
|||
{
|
||||
QString id = item->data( Qt::UserRole ).toString();
|
||||
getCurrentArticleView()->jumpToDictionary( id );
|
||||
updatePronounceAvailability();
|
||||
}
|
||||
|
||||
void MainWindow::dictsListSelectionChanged()
|
||||
|
|
Loading…
Reference in a new issue