mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
Automatically expand collapsed article if only one loaded
This commit is contained in:
parent
b902e5c3d2
commit
ede10cc944
|
@ -142,20 +142,28 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word,
|
||||||
"d1.alt = '[-]'; d1.src = 'qrcx://localhost/icons/collapse_opt.png'; for( i = 0; i < 1000; i++ ) { var d2=document.getElementById( optionalId + i ); if( !d2 ) break; d2.style.display='inline'; } }"
|
"d1.alt = '[-]'; d1.src = 'qrcx://localhost/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 = 'qrcx://localhost/icons/expand_opt.png'; for( i = 0; i < 1000; i++ ) { var d2=document.getElementById( optionalId + i ); if( !d2 ) break; d2.style.display='none'; } } };"
|
"else { d1.alt = '[+]'; d1.src = 'qrcx://localhost/icons/expand_opt.png'; for( i = 0; i < 1000; i++ ) { var d2=document.getElementById( optionalId + i ); if( !d2 ) break; d2.style.display='none'; } } };"
|
||||||
"function gdExpandArticle( id ) { elem = document.getElementById('gdarticlefrom-'+id); ico = document.getElementById('expandicon-'+id); art=document.getElementById('gdfrom-'+id);"
|
"function gdExpandArticle( id ) { elem = document.getElementById('gdarticlefrom-'+id); ico = document.getElementById('expandicon-'+id); art=document.getElementById('gdfrom-'+id);"
|
||||||
"t=window.event.target || window.event.srcElement;"
|
"ev=window.event; t=null;"
|
||||||
|
"if(ev) t=ev.target || ev.srcElement;"
|
||||||
"if(elem.style.display=='inline' && t==ico) {"
|
"if(elem.style.display=='inline' && t==ico) {"
|
||||||
"elem.style.display='none'; ico.className='gdexpandicon';"
|
"elem.style.display='none'; ico.className='gdexpandicon';"
|
||||||
"art.className = art.className+' gdcollapsedarticle';"
|
"art.className = art.className+' gdcollapsedarticle';"
|
||||||
"nm=document.getElementById('gddictname-'+id); nm.style.cursor='pointer';"
|
"nm=document.getElementById('gddictname-'+id); nm.style.cursor='pointer';"
|
||||||
"window.event.stopPropagation(); ico.title=''; nm.title='";
|
"if(ev) ev.stopPropagation(); ico.title=''; nm.title='";
|
||||||
result += tr( "Expand article" ).toUtf8().data();
|
result += tr( "Expand article" ).toUtf8().data();
|
||||||
result += "' } else {"
|
result += "' } else if(elem.style.display=='none') {"
|
||||||
"elem.style.display='inline'; ico.className='gdcollapseicon';"
|
"elem.style.display='inline'; ico.className='gdcollapseicon';"
|
||||||
"art.className=art.className.replace(' gdcollapsedarticle','');"
|
"art.className=art.className.replace(' gdcollapsedarticle','');"
|
||||||
"nm=document.getElementById('gddictname-'+id); nm.style.cursor='default';"
|
"nm=document.getElementById('gddictname-'+id); nm.style.cursor='default';"
|
||||||
"nm.title=''; ico.title='";
|
"nm.title=''; ico.title='";
|
||||||
result += tr( "Collapse article").toUtf8().data();
|
result += tr( "Collapse article").toUtf8().data();
|
||||||
result += "' } }"
|
result += "' } }"
|
||||||
|
"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);"
|
||||||
|
"} }"
|
||||||
"</script>";
|
"</script>";
|
||||||
|
|
||||||
result += "</head><body>";
|
result += "</head><body>";
|
||||||
|
@ -442,6 +450,9 @@ void ArticleRequest::altSearchFinished()
|
||||||
|
|
||||||
wstring wordStd = gd::toWString( word );
|
wstring wordStd = gd::toWString( word );
|
||||||
|
|
||||||
|
if( activeDicts.size() <= 1 )
|
||||||
|
articleSizeLimit = -1; // Don't collapse article if only one dictionary presented
|
||||||
|
|
||||||
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
for( unsigned x = 0; x < activeDicts.size(); ++x )
|
||||||
{
|
{
|
||||||
sptr< Dictionary::DataRequest > r =
|
sptr< Dictionary::DataRequest > r =
|
||||||
|
|
|
@ -336,6 +336,9 @@ void ArticleView::loadFinished( bool )
|
||||||
ui.definition->unsetCursor();
|
ui.definition->unsetCursor();
|
||||||
//QApplication::restoreOverrideCursor();
|
//QApplication::restoreOverrideCursor();
|
||||||
|
|
||||||
|
// Expand collapsed article if only one loaded
|
||||||
|
ui.definition->page()->mainFrame()->evaluateJavaScript( QString( "gdCheckArticlesNumber();" ) );
|
||||||
|
|
||||||
// Jump to current article after page reloading
|
// Jump to current article after page reloading
|
||||||
if( !articleToJump.isEmpty() )
|
if( !articleToJump.isEmpty() )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue