summaryrefslogtreecommitdiff
path: root/wikipedia
diff options
context:
space:
mode:
authorRory MacQueen <rorymacqueen@gmail.com>2013-08-22 17:40:46 -0700
committerRory MacQueen <rorymacqueen@gmail.com>2013-08-28 04:39:09 -0700
commit2dff0bff120eb94b200960e621ebcaa4cc70f820 (patch)
treee9a9416ca88d6edd0812d509c04cf3ae9b6ed348 /wikipedia
parent0e45b609b3b74745277c255cc5b1f6104de7c72a (diff)
Functionality to show links we want
We had to add a field to WikipediaWebView in order to determine whether we want to display all links or not [endlessm/eos-sdk#271]
Diffstat (limited to 'wikipedia')
-rw-r--r--wikipedia/PrebuiltArticlesPage.js6
-rw-r--r--wikipedia/WikipediaWebView.js53
2 files changed, 52 insertions, 7 deletions
diff --git a/wikipedia/PrebuiltArticlesPage.js b/wikipedia/PrebuiltArticlesPage.js
index 74f69a0..0d0491b 100644
--- a/wikipedia/PrebuiltArticlesPage.js
+++ b/wikipedia/PrebuiltArticlesPage.js
@@ -26,9 +26,11 @@ const PrebuiltArticlesPage = new Lang.Class({
this._article_title = null;
this._article_uri = null;
+ // Empty array is placeholder until we get baby page rank
this._wiki_view = new EndlessWikipedia.WikipediaWebView({
- expand:true
- });
+ expand:true,
+ hide_links:true
+ }, []);
this.parent(props);
diff --git a/wikipedia/WikipediaWebView.js b/wikipedia/WikipediaWebView.js
index 761156b..63e85e6 100644
--- a/wikipedia/WikipediaWebView.js
+++ b/wikipedia/WikipediaWebView.js
@@ -1,12 +1,13 @@
const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
+const GObject = imports.gi.GObject;
const Lang = imports.lang;
const WebKit = imports.gi.WebKit2;
const Utils = imports.wikipedia.utils;
const hostName = "http://127.0.0.1:3000/"
-const getPageByTitleURI = "getArticleByTitle?title=";
-const getPageByQueryURI = "getTopArticleByQuery?query=";
+const getPageByTitleURI = "getArticleByTitle?";
+const getPageByQueryURI = "getTopArticleByQuery?";
// Interpret image:// URIs as wikipedia images
WebKit.WebContext.get_default().register_uri_scheme('image', function(request) {
@@ -27,8 +28,15 @@ WebKit.WebContext.get_default().register_uri_scheme('image', function(request) {
const WikipediaWebView = new Lang.Class({
Name: 'EndlessWikipediaWebView',
Extends: WebKit.WebView,
+ Properties: {
+ 'hide-links': GObject.ParamSpec.boolean('hide-links',
+ 'Hide article links',
+ 'A boolean to determine whether links should be shown',
+ GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT,
+ false)
+ },
- _init: function(params) {
+ _init: function(params, links_to_show) {
this.parent(params);
// For debugging
//let settings = this.get_settings();
@@ -36,8 +44,20 @@ const WikipediaWebView = new Lang.Class({
//this.set_settings(settings);
this.connect('context-menu', Lang.bind(this, function(){return true}));
+ this._links_to_show = links_to_show;
this.connect('decide-policy',
Lang.bind(this, this._onNavigation));
+ this.connect('load-changed',
+ Lang.bind(this, this._onLoadChange));
+ },
+
+ _getFullURL: function(base_url, params){
+ let full_url = base_url;
+ for(let key in params){
+ full_url += key + "=" + params[key] + "&";
+ }
+ full_url = full_url.slice(0, -1);
+ return full_url
},
loadArticleByURI: function(uri) {
@@ -48,11 +68,30 @@ const WikipediaWebView = new Lang.Class({
},
loadArticleByTitle: function(title) {
- this.load_uri(hostName + getPageByTitleURI + title);
+ let params = {"title":title, "hideLinks":this.hide_links};
+ let url = this._getFullURL(hostName + getPageByTitleURI, params);
+ this.load_uri(url);
},
loadArticleBySearchQuery: function(query) {
- this.load_uri(hostName + getPageByQueryURI + query);
+ let params = {"query":query, "hideLinks":this.hide_links};
+ let url = this._getFullURL(hostName + getPageByQueryURI, params);
+ this.load_uri(url);
+ },
+
+ scriptFinished: function(){
+ // NO OP
+ },
+
+ setAllowedLinks: function(){
+ // If you want to show all links, then
+ // no point in showing some subset of them as well
+ if(!this.hide_links){
+ return;
+ }
+ let str = JSON.stringify(this._links_to_show);
+ let script = "window.links_to_show = " + str;
+ this.run_javascript(script, null, this.scriptFinished, null);
},
_getArticleImagesPath: function() {
@@ -72,5 +111,9 @@ const WikipediaWebView = new Lang.Class({
}
}
return false; // not handled, default behavior
+ },
+
+ _onLoadChange: function(webview, load_event, data){
+ this.setAllowedLinks();
}
});