summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. F. Chimento <philip.chimento@gmail.com>2013-08-06 11:37:05 -0700
committerP. F. Chimento <philip.chimento@gmail.com>2013-08-06 11:37:05 -0700
commitda44c7be3a095c917876d04e3ddfd6d61e2e3097 (patch)
treede159dc174bb0b37aa75501574825c65e4a68059
parent199105c35da09282f1377c8ea4a553799e36f9c7 (diff)
parente7fb92889791785ad3c663808d4e40cb481d1503 (diff)
Merge pull request #221 from endlessm/issues/220
#220 Dealt with relative paths in wikipedia view
-rw-r--r--data/css/eos-wikipedia-domain.css2
-rw-r--r--wikipedia/utils.js17
-rw-r--r--wikipedia/views/index.html29
-rw-r--r--wikipedia/views/js/main.js64
-rw-r--r--wikipedia/views/wikipedia_view.js79
5 files changed, 106 insertions, 85 deletions
diff --git a/data/css/eos-wikipedia-domain.css b/data/css/eos-wikipedia-domain.css
index acbab1c..f6a6ae5 100644
--- a/data/css/eos-wikipedia-domain.css
+++ b/data/css/eos-wikipedia-domain.css
@@ -25,6 +25,7 @@ Gjs_ArticleList .button {
padding-bottom: 15px;
font-size: 15px;
color: #464646;
+ font-family: "Source Sans Pro";
background-image: url('resource:///com/endlessm/wikipedia-domain/assets/submenu_bg_normal.jpg');
background-size: cover;
}
@@ -50,6 +51,7 @@ Gjs_ArticleList .button:active {
color:rgba(255, 255, 255, 1.0);
background-color: rgba(0, 0, 0, 0);
font-size: 12px;
+ font-family: "Source Sans Pro";
}
#category_title{
diff --git a/wikipedia/utils.js b/wikipedia/utils.js
index 0edb6d4..234efcd 100644
--- a/wikipedia/utils.js
+++ b/wikipedia/utils.js
@@ -1,5 +1,6 @@
const Gio = imports.gi.Gio;
const GdkPixbuf = imports.gi.GdkPixbuf;
+const GLib = imports.gi.GLib;
const set_default = function(obj, key, val) {
// Similar to python's dict.setdefault(key, val)
@@ -47,9 +48,25 @@ function load_file_from_resource(filename) {
return data[0];
}
+function get_path_for_relative_path(relative_path){
+ let file = Gio.file_new_for_path(relative_path);
+ return file.get_path();
+}
+
function write_contents_to_file(filename, content){
let file = Gio.file_new_for_path(filename);
file.replace_contents(content, null, false, 0, null);
+ return file.get_uri();
+}
+
+function write_contents_to_temp_file(name, content){
+ let file = Gio.file_new_tmp(name + "XXXXXX")[0];
+ file.replace_contents(content, null, false, 0, null);
+ return file.get_uri();
+}
+
+function make_temp_dir(name){
+ return GLib.dir_make_tmp(name + "XXXXXX");
}
/*
diff --git a/wikipedia/views/index.html b/wikipedia/views/index.html
deleted file mode 100644
index b0aefd0..0000000
--- a/wikipedia/views/index.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title></title>
- <meta name="description" content="">
- <meta name="viewport" content="width=device-width">
- <link rel="stylesheet" href="css/first_load.css">
- <link rel="stylesheet" href="css/second_load.css">
- <link rel="stylesheet" href="css/main.css">
- <link rel="stylesheet" href="css/wikipedia.css">
- <link rel="stylesheet" href="css/nolinks.css">
- <script src="js/jquery-min.js"></script>
- </head>
- <body class="">
- <div id="main">
-
- <section id="main-content">
- <header id="header-content">
- </header>
-
- <section id="inside-content">
- </section>
- </section>
- </div>
- <script src="js/main.js"></script>
- </body>
-</html> \ No newline at end of file
diff --git a/wikipedia/views/js/main.js b/wikipedia/views/js/main.js
index bd76576..531d7fa 100644
--- a/wikipedia/views/js/main.js
+++ b/wikipedia/views/js/main.js
@@ -10,63 +10,49 @@ Endless.Wikipedia = Endless.Wikipedia || {};
$body = $("body"),
$image = $(".image"),
$main = $("#main"),
- $main_wrapper_home = $("#main-wrapper-home"),
- $main_results = $("#main-results"),
- $main_wrapper = $("#main-wrapper"),
$main_content = $("#main-content"),
$inside_content = $("#inside-content"),
$header_content = $("#header-content"),
- $main_wrapper_middle = $("#main-wrapper-middle"),
$wiki_content = $("#wiki_content"),
lang = "pt",
- _resultPageView = function(pageHtml, titlePage, resultError) {
- if (resultError === false) {
- $inside_content.html(pageHtml);
- $header_content.html('<h1>' + titlePage + '</h1>');
- $('#inside-content').prepend('<hr class="hr-title">');
-
- $('#inside-content [src^="//"]').each(function() {
- var parent = $(this).parent();
- if($(this).is("img")){
- var url = $(this).attr("src");
- var theSplit = url.split("/");
- var filename = theSplit[theSplit.length - 2];
- if(filename.length == 2){
- filename = theSplit[theSplit.length - 1];
- }
- var newSrc = "article_images/" + encodeURI(filename)
- if(newSrc.substring(newSrc.length - 4) == ".svg"){
- newSrc += ".png";
- }
- $(this).attr('src', newSrc);
+ _resultPageView = function(image_path) {
+ $('#inside-content [src^="//"]').each(function() {
+ var parent = $(this).parent();
+ if($(this).is("img")){
+ var url = $(this).attr("src");
+ var theSplit = url.split("/");
+ var filename = theSplit[theSplit.length - 2];
+ if(filename.length == 2){
+ filename = theSplit[theSplit.length - 1];
+ }
+ var newSrc = image_path + encodeURI(filename)
+ if(newSrc.substring(newSrc.length - 4) == ".svg"){
+ newSrc += ".png";
}
-
- });
- }
+ $(this).attr('src', newSrc);
+ }
+ });
+ // May need this back at some point
+ // $('link[rel=stylesheet]').each(function(){
+ // var src = $(this).attr("href");
+ // console.log(asset_path + src);
+ // $(this).attr("href", asset_path + "/" + src);
+ // });
},
wresize = function() {
- $main_wrapper_home.height($(window).height());
- $main_results.height($(window).height());
- $main_wrapper.height($(window).height());
- $main_content.height($(window).height() - $("#header-top").outerHeight());
+ $main_content.height($(window).height());
$inside_content.height($main_content.outerHeight() - ($("#header-content").outerHeight() + 15));
- $main_wrapper_home.css("background-size", "100% " + $(window).height() + "px");
- $main_results.css("background-size", "100% " + $(window).height() + "px");
}
return {
init: function() {
$(document).hide();
- $(window).resize(wresize);
- var content = $('#wiki_content').html();
- var title = $('#wiki_content').attr('name');
- _resultPageView(content, title, false);
- $('#wiki_content').remove();
+ var image_path = $inside_content.attr('image_path');
+ _resultPageView(image_path);
wresize();
$(document).show();
-
},
wresize: wresize
};
diff --git a/wikipedia/views/wikipedia_view.js b/wikipedia/views/wikipedia_view.js
index 09ef6fe..05d7647 100644
--- a/wikipedia/views/wikipedia_view.js
+++ b/wikipedia/views/wikipedia_view.js
@@ -14,10 +14,51 @@ const WikipediaView = new Lang.Class({
this._httpSession = new Soup.Session();
this.parent(params);
// For debugging
- // let settings = this.get_settings();
- // settings.set_enable_developer_extras(true);
- // this.set_settings(settings);
- this._is_first_time = true;
+ //let settings = this.get_settings();
+ //settings.set_enable_developer_extras(true);
+ //this.set_settings(settings);
+ },
+
+ _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(title) {
@@ -31,19 +72,23 @@ const WikipediaView = new Lang.Class({
let article = JSON.parse(articleJSON);
let articleHTML = article["text"];
let title = article['title'];
- let skeletonHTML = Utils.load_file("views/index.html");
- skeletonHTML = skeletonHTML + "<div id='wiki_content' name='"+ title +"'>" + articleHTML + "</div>"
- Utils.write_contents_to_file("views/temp.html", skeletonHTML);
-
- // TODO: Ask about how we can load directly from HTML. Right now, WebKit can't seem to open
- // CSS file correctly. All characters in CSS file are in Chinese
-
- if(this._is_first_time) {
- this.load_uri("file:///home/endless/checkout/eos-sdk/wikipedia/src/views/temp.html", null);
- this._is_first_time = false;
- } else {
- this.reload();
- }
+ let current_dir = Endless.getCurrentFileDir();
+ let cur_exec = Utils.get_path_for_relative_path(".");
+ let image_path = cur_exec + "/web_view/article_images/";
+
+ let documentHTML = this._get_meta_html() + this._get_body_html(articleHTML, 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);
+
+ 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);
}));
}
});