summaryrefslogtreecommitdiff
path: root/wikipedia
diff options
context:
space:
mode:
authormattdangerw <mattdangerw@gmail.com>2013-08-08 13:40:29 -0700
committermattdangerw <mattdangerw@gmail.com>2013-08-08 13:40:29 -0700
commit544c137fc8524c5929c7672768775763ea10d848 (patch)
tree6102d3bc7647842a801a3ef4c467fcff1e1dc5f3 /wikipedia
parent0a7043965f27677551ad11511f55110d61147289 (diff)
parentb09ccf8994123ba4a62136bdc84d44579b4fe85d (diff)
Merge pull request #254 from endlessm/issues/253
Issues/253
Diffstat (limited to 'wikipedia')
-rw-r--r--wikipedia/PrebuiltArticlesPage.js2
-rw-r--r--wikipedia/views/wikipedia_view.js91
2 files changed, 20 insertions, 73 deletions
diff --git a/wikipedia/PrebuiltArticlesPage.js b/wikipedia/PrebuiltArticlesPage.js
index f5c133b..933e3b4 100644
--- a/wikipedia/PrebuiltArticlesPage.js
+++ b/wikipedia/PrebuiltArticlesPage.js
@@ -55,7 +55,7 @@ const PrebuiltArticlesPage = new Lang.Class({
set article_uri(value) {
this._article_uri = value;
if(value !== null && value !== "") {
- this._wiki_view.loadArticleByTitle(this._article_uri, this._article_title);
+ this._wiki_view.loadArticleByTitle(this._article_uri);
}
},
diff --git a/wikipedia/views/wikipedia_view.js b/wikipedia/views/wikipedia_view.js
index 261e879..bcd6270 100644
--- a/wikipedia/views/wikipedia_view.js
+++ b/wikipedia/views/wikipedia_view.js
@@ -1,17 +1,28 @@
+const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
const Soup = imports.gi.Soup;
const WebKit = imports.gi.WebKit2;
const Utils = imports.utils;
-const getPageURL = "http://127.0.0.1:3000/getArticleByTitle?title=";
+const getPageURL = "http://127.0.0.1:3000/getDomainSpecificArticle?title=";
+
+// Interpret image:// URIs as wikipedia images
+WebKit.WebContext.get_default().register_uri_scheme('image', function(request) {
+ let filename = request.get_uri().slice('image://'.length);
+ filename = decodeURI(filename);
+ let pictures_dir = request.get_web_view()._getArticleImagesPath();
+ let parent = Gio.File.new_for_path(pictures_dir);
+ let file = parent.get_child(filename);
+ let stream = file.read(null);
+ request.finish(stream, -1, 'image/png');
+});
const WikipediaView = new Lang.Class({
Name: 'EndlessWikipediaView',
Extends: WebKit.WebView,
_init: function(params) {
- this._httpSession = new Soup.Session();
this.parent(params);
// For debugging
//let settings = this.get_settings();
@@ -20,79 +31,15 @@ const WikipediaView = new Lang.Class({
this.connect('context-menu', Lang.bind(this, function(){return true}));
},
- _get_body_html:function(articleHTML, title, image_path){
- let html = "";
- html += "<div id='main'>";
- html += "<section id='main-content'>";
- html += "<header id='header-content'>";
- html += "<h1>" + title + "</h1>";
- html += "</header>";
- html += "<section image_path=" + image_path +" id='inside-content'>";
- html += "<hr class='hr-title'>";
- html += articleHTML;
- html += "</section>";
- html += "</section>";
- html += "</div>";
- return html;
- },
-
- _get_style_sheet_html: function(current_dir, sheets){
- let html = "";
- for(let i = 0; i < sheets.length; i++){
- html += "<link rel='stylesheet' href=" + current_dir + "/css/" + sheets[i] + ">";
- }
- return html;
- },
-
- _get_script_html:function(current_dir, scripts){
- let html = "";
- for(let i = 0; i < scripts.length; i++){
- html += "<script src='" + current_dir + "/js/" + scripts[i] + "'></script>";
- }
- return html;
- },
-
- _get_meta_html:function(){
- let html = "";
- html += "<meta charset='utf-8'>";
- html += "<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>";
- html += "<meta name='description' content=''>";
- html += "<title></title>";
- html += "<meta name='viewport' content='width=device-width'>";
- return html;
- },
-
- loadArticleByTitle: function(url, human_title) {
+ loadArticleByTitle: function(url) {
let parts = url.split("/");
let suffix = parts[parts.length - 1];
let title = decodeURI(suffix.replace("_", " ", 'g'));
- let request = Soup.Message.new("GET", getPageURL + title);
- this._httpSession.queue_message(request, Lang.bind(this, function(_httpSession, message) {
- if(message.status_code !== 200) {
- print(message.status_code);
- return;
- }
- let articleJSON = request.response_body.data;
- let article = JSON.parse(articleJSON);
- let articleHTML = article["text"];
- let title = article['title'];
- let current_dir = Endless.getCurrentFileDir();
-
- let cur_exec = this.get_toplevel().get_application().application_base_path;
- let image_path = cur_exec + "/web_view/article_images/";
-
- let documentHTML = this._get_meta_html() + this._get_body_html(articleHTML, human_title, image_path);
-
- let sheets = new Array("first_load.css", "second_load.css","main.css","wikipedia.css","nolinks.css");
- documentHTML = this._get_style_sheet_html(current_dir, sheets) + documentHTML;
-
- let scripts = new Array("jquery-min.js", "main.js");
- documentHTML = documentHTML + this._get_script_html(current_dir, scripts);
+ this.load_uri(getPageURL + title);
+ },
- let temp_uri = Utils.write_contents_to_temp_file("wiki.html", documentHTML);
- // TODO: Ask about how we can load directly from HTML using load_html.
- // Right now, this doesn't work, regardless of what we put in for base_uri
- this.load_uri(temp_uri);
- }));
+ _getArticleImagesPath: function() {
+ let cur_exec = this.get_toplevel().get_application().application_base_path;
+ return cur_exec + "/web_view/article_images/";
}
});