Commit fd43ee53 authored by Alexandra Rogova's avatar Alexandra Rogova

first commit

parents
<!doctype html>
<html>
<head>
<title>Model Gadget</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="gadget_model.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function (window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.ready(function(){
this.search_storage = jIO.createJIO({
type : "query",
sub_storage:{
type : "uuid",
sub_storage : {
type: "indexeddb",
database: "mynij-v1"
}
}
});
this.info = jIO.createJIO({
type : "indexeddb",
database : "mynij-v1-info"
});
})
.declareMethod("put", function () {
return this.search_storage.post.apply(this.search_storage, arguments);
})
.declareMethod("get", function () {
return this.search_storage.get.apply(this.search_storage, arguments);
})
.declareMethod("search", function() {
return this.search_storage.allDocs.apply(this.search_storage, arguments)
})
.declareMethod("loaded_doc", function(){
return this.info.put.apply(this.info, arguments);
})
.declareMethod("all_loaded_docs", function(){
return this.info.allDocs.apply(this.info, arguments);
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
<!doctype html>
<html>
<head>
<title>Parser Gadget</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="gadget_parser.js"></script>
</head>
<body>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function(window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.declareAcquiredMethod("get_model", "get_model")
.declareMethod("readFile", function(link) {
var storage;
var gadget = this;
gadget.get_model()
.push(function(result) {
storage = result;
})
.push(function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 200 && xmlhttp.readyState == 4) {
var cur_text = xmlhttp.responseText,
promise_list = [],
feed_title;
feed_title = cur_text.slice(cur_text.indexOf("<title>")+7, cur_text.indexOf("</title>"));
gadget.is_already_parsed(storage, feed_title)
.push (function (resultat){
if (!resultat){
promise_list.push(storage.loaded_doc(feed_title, {"loaded" : "true"}));
cur_text = cur_text.slice(cur_text.indexOf("<item>"), cur_text.length - 1);
while (cur_text.indexOf("<item>") > -1) {
promise_list.push(gadget.parse(cur_text, storage));
cur_text = cur_text.slice(cur_text.indexOf("</item>") + 6, cur_text.length - 1);
}
RSVP.all(promise_list);
}
});
}
};
xmlhttp.open("GET", link, true);
xmlhttp.send();
});
})
.declareMethod("parse", function(local_cur_text, storage) {
var title_start = local_cur_text.indexOf("<title>") + 7,
title_end = local_cur_text.indexOf("</title>"),
link_start = local_cur_text.indexOf("<link>") + 6,
link_end = local_cur_text.indexOf("</link>"),
body_start = local_cur_text.indexOf("<description>"),
body_end = local_cur_text.indexOf("</description>") + 14;
return this.parse_body(local_cur_text.slice(body_start, body_end))
.push (function(result){
return storage.put({
"title": local_cur_text.slice(title_start, title_end),
"link": local_cur_text.slice(link_start, link_end),
"body": result
});
});
})
.declareMethod("parse_body", function(body){
/*var before,
after;
while (body.indexOf("&lt;span style") > -1){
before = body.slice(0, body.indexOf("&lt;span style"));
after = body.slice(body.indexOf("&quot;&gt"), body.length -1);
body = before + after;
}
console.log(body);*/
return body;
})
.declareMethod("is_already_parsed", function(storage, title){
return storage.all_loaded_docs()
.push(function (result){
var i;
for (i = 0; i<result.data.rows.length; i+=1){
//console.log(result.data.rows[i].id);
if (result.data.rows[i].id === title) return true;
}
return false;
})
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
<!doctype html>
<html>
<head>
<title>Result Gadget</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="gadget_result.js"></script>
</head>
<body>
<ul id="list">
</ul>
</body>
</html>
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80*/
/*global window, RSVP, rJS, jIO*/
(function(window, RSVP, rJS, jIO) {
"use strict";
rJS(window)
.declareMethod("addItem", function(item, key) {
var list,
list_item,
title,
link,
body,
body_text,
parser,
xmlDoc;
list = document.getElementById("list");
list_item = document.createElement("LI");
title = document.createElement("a");
title.appendChild(document.createTextNode(item.title));
title.className="title";
title.href = item.link;
list_item.appendChild(title);
link = document.createElement("a");
link.appendChild(document.createTextNode(item.link));
link.href = item.link;
link.className = "link";
var link_par = document.createElement('p');
link_par.appendChild(link);
list_item.appendChild(link_par);
body = document.createElement('p');
body.className = "body";
if (key === ""){
body.innerHTML = "";
list.appendChild(list_item);
} else {
parser = new DOMParser();
xmlDoc = parser.parseFromString(item.body,"text/xml");
body_text = xmlDoc.getElementsByTagName("description")[0].childNodes[0].nodeValue;
console.log("ok : " + item.title);
return this.cut_description(body_text, key)
.push(function (result){
//console.log(item.title);
if (result === null) body.innerHTML = "";
else body.innerHTML = result.slice(1);
list_item.appendChild(body);
list.appendChild(list_item);
})
}
})
.declareMethod("clear", function(){
var list = document.getElementById("list");
while (list.firstChild) {
list.removeChild(list.firstChild);
}
})
.declareMethod("cut_description", function(body, key){
var regEx,
result;
regEx = new RegExp('[^.]*' +" " + key + " " + '[^.]*\.', 'g');
result = regEx.exec(body);
if (result === null) return null;
else return result[0];
});
}(window, RSVP, rJS, jIO));
\ No newline at end of file
body {
padding: 0;
margin: 0;
height: 100vh;
width: 100%;
background: #2b2b5d;
}
form{
position: relative;
top: 5%;
left: 50%;
transform: translate(-50%,-50%);
transition: all 1s;
width: 500px;
height: 50px;
background: white;
box-sizing: border-box;
border-radius: 25px;
border: 4px solid white;
padding: 5px;
}
input{
position: absolute;
top: 0;
left: 0;
width: 100%;;
height: 42.5px;
line-height: 30px;
outline: 0;
border: 0;
font-size: 1em;
border-radius: 20px;
padding: 0 20px;
text-align: center;
}
.fa{
box-sizing: border-box;
padding: 10px;
width: 42.5px;
height: 42.5px;
position: absolute;
top: 0;
right: 0;
border-radius: 50%;
color: #07051a;
text-align: center;
font-size: 1.2em;
transition: all 1s;
background: #2b2b5d;
}
form:hover{
cursor: pointer;
}
form:hover input{
display: block;
}
ul, il{
margin : 0;
}
li {
list-style-type: none;
position: relative;
font-size: large;
padding: 2% 0;
margin: auto;
margin-top: 3%;
margin-bottom: 2%;
background: #fff;
color: #2b2b5d;
width: 40%;
box-shadow: 10px 20px #1e1e44;
}
.title {
margin-left : 5%;
color: #2b2b5d;
text-decoration: none;
font-size: x-large;
}
.link, .link:visited {
margin-left : 5%;
text-decoration: none;
color: #5c7ece;
}
.body{
margin-left : 5%;
}
a {
position: relative;
}
a:after {
content: '';
position: absolute;
bottom: -.4em;
left: 50%;
right: 50%;
height: 1px;
background: #2b2b5d;
transition: all ease .2s;
}
a:hover:after {
left: 0;
right: 0;
height: 2px;
}
a:before {
position: absolute;
transform: translateX(-100%);
left: -10px;
color: #2b2b5d;
opacity: .3;
font-weight: 100;
font-size: .8em;
}
<!doctype html>
<html>
<head>
<title>Mynij</title>
<script src="../jio/external/rsvp-2.0.4.js"></script>
<script src="../jio/dist/jio-latest.js"></script>
<script src="../renderjs/dist/renderjs-latest.js"></script>
<script src="search.js"></script>
<link rel="stylesheet" type="text/css" href="mynij.css">
</head>
<body>
<form id = "search_bar">
<input type="search" required>
<i class="fa fa-search"></i>
</form>
<div data-gadget-url="gadget_result.html"
data-gadget-scope="result"
data-gadget-sandbox="public">
<div data-gadget-url="gadget_model.html"
data-gadget-scope="model"
data-gadget-sandbox="public">
<div data-gadget-url="gadget_parser.html"
data-gadget-scope="parser"
data-gadget-sandbox="public">
</div>
</body>
</html>
(function (window, document, rJS, RSVP) {
var gadget;
rJS(window)
.setState({
counter: 0,
model_gadget : null,
parser_gadget : null,
result_gadget : null
})
.allowPublicAcquisition("get_model", function(){
return this.getDeclaredGadget("model");
})
.allowPublicAcquisition("get_counter", function(){
counter += 1;
return counter;
})
.ready(function(){
var model_gadget,
result_gadget;
console.log("ready !");
counter = 0;
var gadget = this;
return gadget.getDeclaredGadget("model")
.push(function(model){
model_gadget = model;
})
.push(function(){
return gadget.getDeclaredGadget("result");
})
.push(function(result){
result_gadget = result;
})
.push(function(){
return gadget.getDeclaredGadget("parser");
})
.push(function(result){
return gadget.changeState({
model_gadget : model_gadget,
parser_gadget : result,
result_gadget : result_gadget
});
});
})
.onStateChange(function (modification_dict){
var gadget = this;
return new RSVP.Queue()
.push(function (){
gadget.state.parser_gadget.readFile("../rss-files/vivelessvt.rss");
})
.push (function (result) {
gadget.state.parser_gadget.readFile("../rss-files/italienfacile.rss");
})
.push (function (result) {}, function (err) {
console.warn(error);
throw(error);
});
})
.declareMethod("search", function (key){
var gadget = this,
options;
options = {
query:'(title:"% '+key+' %") OR (title:"'+key+' %")OR (body:"% '+key+' %")'
};
return gadget.state.result_gadget.clear()
.push(function(){
return gadget.state.model_gadget.search(options);
})
.push (function(result){
if (result.data.rows.length === 0){
return gadget.state.result_gadget.addItem({
title : "No results found",
link : ""
});
}
var i,
id,
promise_list = [];
for (i = 0; i < result.data.rows.length; i+=1){
id = result.data.rows[i].id;
promise_list.push(gadget.state.model_gadget.get(id));
console.log(id);
}
return RSVP.all(promise_list);
})
.push(function(result_list){
var j,
promise_list = [];
for (j = 0; j < result_list.length; j+=1){
promise_list.push(gadget.state.result_gadget.addItem(result_list[j]));
}
return RSVP.all(promise_list);
});
})
.onEvent("submit", function(event){
this.search(event.target.elements[0].value);
});
}(window, document, rJS, RSVP));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment