diff --git a/src/article-style.css b/src/article-style.css
index 83ed6c2e..99228b9f 100644
--- a/src/article-style.css
+++ b/src/article-style.css
@@ -27,6 +27,21 @@ pre
{
}
+/* The article span. Here we have a padding/margin hack to make fragment links
+ behave better (have some space before the start of article) */
+.gdarticle
+{
+ display: block;
+ padding-top: 1px;
+ margin-top: -9px;
+ margin-bottom: 8px;
+}
+
+/* Appears between the articles */
+.gdarticleseparator
+{
+}
+
/* Dictionary query error description string */
.gderrordesc
{
diff --git a/src/article_maker.cc b/src/article_maker.cc
index e15dc625..984b574e 100644
--- a/src/article_maker.cc
+++ b/src/article_maker.cc
@@ -330,18 +330,29 @@ void ArticleRequest::bodyFinished()
string head;
+ string gdFrom = "gdfrom-" + Html::escape( dictId );
+
if ( closePrevSpan )
{
- head += "";
+ head += "";
closePrevSpan = false;
}
+ else
+ {
+ // This is the first article
+ head += "";
+ }
string jsVal = Html::escapeForJavaScript( dictId );
head += "";
- head += "";
+ head += "";
closePrevSpan = true;
diff --git a/src/articleview.cc b/src/articleview.cc
index f019b4d4..4980129e 100644
--- a/src/articleview.cc
+++ b/src/articleview.cc
@@ -80,7 +80,8 @@ ArticleView::~ArticleView()
#endif
}
-void ArticleView::showDefinition( QString const & word, unsigned group )
+void ArticleView::showDefinition( QString const & word, unsigned group,
+ QString const & scrollTo )
{
QUrl req;
@@ -89,6 +90,9 @@ void ArticleView::showDefinition( QString const & word, unsigned group )
req.addQueryItem( "word", word );
req.addQueryItem( "group", QString::number( group ) );
+ if ( scrollTo.size() )
+ req.setFragment( scrollTo );
+
ui.definition->load( req );
//QApplication::setOverrideCursor( Qt::WaitCursor );
ui.definition->setCursor( Qt::WaitCursor );
@@ -145,6 +149,17 @@ unsigned ArticleView::getGroup( QUrl const & url )
return 0;
}
+QString ArticleView::getCurrentArticle()
+{
+ QVariant v = ui.definition->page()->currentFrame()->evaluateJavaScript(
+ QString( "gdCurrentArticle;" ) );
+
+ if ( v.type() == QVariant::String )
+ return v.toString();
+ else
+ return QString();
+}
+
void ArticleView::cleanupTemp()
{
if ( desktopOpenedTempFile.size() )
@@ -157,10 +172,11 @@ void ArticleView::cleanupTemp()
void ArticleView::linkClicked( QUrl const & url )
{
- openLink( url, ui.definition->url() );
+ openLink( url, ui.definition->url(), getCurrentArticle() );
}
-void ArticleView::openLink( QUrl const & url, QUrl const & ref )
+void ArticleView::openLink( QUrl const & url, QUrl const & ref,
+ QString const & scrollTo )
{
printf( "clicked %s\n", url.toString().toLocal8Bit().data() );
@@ -168,7 +184,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
showDefinition( ( url.host().startsWith( "xn--" ) ?
QUrl::fromPunycode( url.host().toLatin1() ) :
url.host() ) + url.path(),
- getGroup( ref ) );
+ getGroup( ref ), scrollTo );
else
if ( url.scheme() == "gdlookup" ) // Plain html links inherit gdlookup scheme
{
@@ -179,7 +195,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
}
else
showDefinition( url.path().mid( 1 ),
- getGroup( ref ) );
+ getGroup( ref ), scrollTo );
}
else
if ( url.scheme() == "bres" || url.scheme() == "gdau" )
@@ -425,13 +441,14 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
linkClicked( r.linkUrl() );
else
if ( result == lookupSelection )
- showDefinition( selectedText, getGroup( ui.definition->url() ) );
+ showDefinition( selectedText, getGroup( ui.definition->url() ), getCurrentArticle() );
else
if ( !popupView && result == followLinkNewTab )
- emit openLinkInNewTab( r.linkUrl(), ui.definition->url() );
+ emit openLinkInNewTab( r.linkUrl(), ui.definition->url(), getCurrentArticle() );
else
if ( !popupView && result == lookupSelectionNewTab )
- emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ) );
+ emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ),
+ getCurrentArticle() );
else
{
// Match against table of contents
diff --git a/src/articleview.hh b/src/articleview.hh
index 096f9969..ce7e46a1 100644
--- a/src/articleview.hh
+++ b/src/articleview.hh
@@ -53,8 +53,11 @@ public:
~ArticleView();
- /// Shows the definition of the given word with the given group
- void showDefinition( QString const & word, unsigned group );
+ /// Shows the definition of the given word with the given group.
+ /// scrollTo can be optionally set to a "gdfrom-xxxx" identifier to position
+ /// the page to that article on load.
+ void showDefinition( QString const & word, unsigned group,
+ QString const & scrollTo = QString() );
/// Clears the view and sets the application-global waiting cursor,
/// which will be restored when some article loads eventually.
@@ -63,7 +66,8 @@ public:
/// Opens the given link. Supposed to be used in response to
/// openLinkInNewTab() signal. The link scheme is therefore supposed to be
/// one of the internal ones.
- void openLink( QUrl const & url, QUrl const & referrer );
+ void openLink( QUrl const & url, QUrl const & referrer,
+ QString const & scrollTo = QString() );
/// Goes back in history
void back()
@@ -108,9 +112,11 @@ signals:
void pageLoaded();
/// Singals that the following link was requested to be opened in new tab
- void openLinkInNewTab( QUrl const &, QUrl const & referrer );
+ void openLinkInNewTab( QUrl const &, QUrl const & referrer,
+ QString const & fromArticle );
/// Singals that the following definition was requested to be showed in new tab
- void showDefinitionInNewTab( QString const & word, unsigned group );
+ void showDefinitionInNewTab( QString const & word, unsigned group,
+ QString const & fromArticle );
private slots:
@@ -128,6 +134,9 @@ private:
/// returns 0.
unsigned getGroup( QUrl const & );
+ /// Returns current article in the view, in the form of "gdform-xxx" id.
+ QString getCurrentArticle();
+
/// Attempts removing last temporary file created.
void cleanupTemp();
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 551d2e85..2702beb0 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -493,11 +493,11 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
connect( view, SIGNAL( pageLoaded() ), this, SLOT( pageLoaded() ) );
- connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const & ) ),
- this, SLOT( openLinkInNewTab( QUrl const &, QUrl const & ) ) );
+ connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ),
+ this, SLOT( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ) );
- connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned ) ),
- this, SLOT( showDefinitionInNewTab( QString const &, unsigned ) ) );
+ connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
+ this, SLOT( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ) );
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
@@ -885,15 +885,19 @@ void MainWindow::wordListSelectionChanged()
}
void MainWindow::openLinkInNewTab( QUrl const & url,
- QUrl const & referrer )
+ QUrl const & referrer,
+ QString const & fromArticle )
{
- createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->openLink( url, referrer );
+ createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->
+ openLink( url, referrer, fromArticle );
}
void MainWindow::showDefinitionInNewTab( QString const & word,
- unsigned group )
+ unsigned group,
+ QString const & fromArticle )
{
- createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->showDefinition( word, group );
+ createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->
+ showDefinition( word, group, fromArticle );
}
void MainWindow::showTranslationFor( QString const & inWord )
diff --git a/src/mainwindow.hh b/src/mainwindow.hh
index 20cf4483..6cf17c81 100644
--- a/src/mainwindow.hh
+++ b/src/mainwindow.hh
@@ -176,8 +176,9 @@ private slots:
ArticleView * createNewTab( bool switchToIt,
QString const & name );
- void openLinkInNewTab( QUrl const &, QUrl const & );
- void showDefinitionInNewTab( QString const & word, unsigned group );
+ void openLinkInNewTab( QUrl const &, QUrl const &, QString const & );
+ void showDefinitionInNewTab( QString const & word, unsigned group,
+ QString const & fromArticle );
void showTranslationFor( QString const & );