diff --git a/article-style.css b/article-style.css index 5101b89c..7dd6a0fc 100644 --- a/article-style.css +++ b/article-style.css @@ -2713,3 +2713,19 @@ in bg url to hide it from iemac */ .mwiki .infl-table { display: none } /****default hide dict icon ***/ .gddicticon{display:none;} + +.gdexpandicon { + cursor:pointer; + width:16px; + height:16px; + vertical-align: text-bottom; + background-image:url('qrcx://localhost/icons/arrow.png'); +} + +.gdcollapseicon { + cursor:pointer; + width:16px; + height:16px; + vertical-align: text-bottom; + background-image:url('qrcx://localhost/icons/downarrow.png'); +} diff --git a/article_maker.cc b/article_maker.cc index 30358f35..de55347e 100644 --- a/article_maker.cc +++ b/article_maker.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include "folding.hh" #include "langcoder.hh" #include "dprintf.hh" @@ -28,6 +29,8 @@ ArticleMaker::ArticleMaker( vector< sptr< Dictionary::Class > > const & dictiona displayStyle( displayStyle_ ), addonStyle( addonStyle_ ), needExpandOptionalParts( true ) +, collapseBigArticles( true ) +, articleLimitSize( 500 ) { } @@ -121,8 +124,8 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, "gdAudioLinks = { first: null, current: null };" "function gdMakeArticleActive( newId ) {" "if ( gdCurrentArticle != 'gdfrom-' + newId ) {" - "document.getElementById( gdCurrentArticle ).className = 'gdarticle';" - "document.getElementById( 'gdfrom-' + newId ).className = 'gdarticle gdactivearticle';" + "el=document.getElementById( gdCurrentArticle ); el.className = el.className.replace(' gdactivearticle','');" + "el=document.getElementById( 'gdfrom-' + newId ); el.className = el.className + ' gdactivearticle';" "gdCurrentArticle = 'gdfrom-' + newId; gdAudioLinks.current = newId;" "articleview.onJsActiveArticleChanged(gdCurrentArticle); } }" "var overIframeId = null;" @@ -137,7 +140,22 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, "window.addEventListener('load', init, false);" "function gdExpandOptPart( expanderId, optionalId ) { var d1=document.getElementById(expanderId); var i = 0; if( d1.alt == '[+]' ) {" "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);" + "t=window.event.target || window.event.srcElement;" + "if(elem.style.display=='inline' && t==ico) {" + "elem.style.display='none'; ico.className='gdexpandicon';" + "art.className = art.className+' gdcollapsedarticle';" + "nm=document.getElementById('gddictname-'+id); nm.style.cursor='pointer';" + "window.event.stopPropagation(); ico.title=''; nm.title='"; + result += tr( "Expand article" ).toUtf8().data(); + result += "' } else {" + "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='"; + result += tr( "Collapse article").toUtf8().data(); + result += "' } }" ""; result += ""; @@ -259,11 +277,13 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( unmutedDicts.push_back( activeDicts[ x ] ); return new ArticleRequest( inWord.trimmed(), activeGroup ? activeGroup->name : "", - contexts, unmutedDicts, header ); + contexts, unmutedDicts, header, + collapseBigArticles ? articleLimitSize : -1 ); } else return new ArticleRequest( inWord.trimmed(), activeGroup ? activeGroup->name : "", - contexts, activeDicts, header ); + contexts, activeDicts, header, + collapseBigArticles ? articleLimitSize : -1 ); } sptr< Dictionary::DataRequest > ArticleMaker::makeNotFoundTextFor( @@ -315,6 +335,13 @@ void ArticleMaker::setExpandOptionalParts( bool expand ) needExpandOptionalParts = expand; } +void ArticleMaker::setCollapseParameters( bool autoCollapse, int articleSize ) +{ + collapseBigArticles = autoCollapse; + articleLimitSize = articleSize; +} + + bool ArticleMaker::adjustFilePath( QString & fileName ) { QFileInfo info( fileName ); @@ -338,11 +365,13 @@ ArticleRequest::ArticleRequest( QString const & word_, QString const & group_, QMap< QString, QString > const & contexts_, vector< sptr< Dictionary::Class > > const & activeDicts_, - string const & header ): + string const & header, + int sizeLimit ): word( word_ ), group( group_ ), contexts( contexts_ ), activeDicts( activeDicts_ ), altsDone( false ), bodyDone( false ), foundAnyDefinitions( false ), closePrevSpan( false ) +, articleSizeLimit( sizeLimit ) { // No need to lock dataMutex on construction @@ -461,7 +490,7 @@ void ArticleRequest::bodyFinished() if ( closePrevSpan ) { - head += ""; + head += "
"; } else { @@ -471,6 +500,22 @@ void ArticleRequest::bodyFinished() "articleview.onJsActiveArticleChanged(gdCurrentArticle)"; } + bool collapse = false; + if( articleSizeLimit >= 0 ) + { + try + { + Mutex::Lock _( dataMutex ); + QString text = QString::fromUtf8( req.getFullData().data(), req.getFullData().size() ); + int size = QTextDocumentFragment::fromHtml( text ).toPlainText().length(); + if( size > articleSizeLimit ) + collapse = true; + } + catch(...) + { + } + } + string jsVal = Html::escapeForJavaScript( dictId ); head += "