localStorage

This commit is contained in:
pg 2016-01-23 00:26:58 +01:00
parent 1aa633a94e
commit b4e4e2fbae
3 changed files with 54 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
node_modules/ node_modules/
*.swp *.swp
*.swo
*~

View File

@ -1,8 +1,33 @@
//var bla = function //var bla = function
$(document).ready(function(){ function storeObject(name,obj){
var row = function(data){ console.log("storeObject: ",obj)
localStorage.setItem(name,JSON.stringify(obj))
}
function loadObject(name){
return JSON.parse(localStorage.getItem(name))
}
function addObject(name, obj){
var entry = loadObject(name)
console.log('add object '+entry)
if (entry == null ){
entry = new Array()
//storeObject(name,)
}
entry.push(obj)
storeObject(name,entry)
}
$(document).ready(function(){
// DELETE STORAGE
//localStorage.removeItem("url_ressources")
var row = function(data){
var htmlobj = "<div>"+data.title+" |"+ data.url+ var htmlobj = "<div>"+data.title+" |"+ data.url+
//" </div>"+ "<div class='presLink'><button value='"+ data.url+"'> launch </button></div>" //" </div>"+ "<div class='presLink'><button value='"+ data.url+"'> launch </button></div>"
"<button class='presLink' value='"+data.url+"' > launch </button></div>" "<button class='presLink' value='"+data.url+"' > launch </button></div>"
@ -11,6 +36,20 @@ $(document).ready(function(){
} }
var browser_ressource = loadObject("url_ressources")
console.log()
if (browser_ressource != null && browser_ressource.forEach != null){
browser_ressource.forEach(function (o,i,l){
if (o.url){
$("#ressources_list").append(row(o))
$(".presLink").click(function(){
$.post('/set', {url:this.value}, function(data) {console.log("hop")})
})
}
})
}
$("#addUrl").click(function(){ $("#addUrl").click(function(){
console.log("Hey") console.log("Hey")
@ -19,9 +58,10 @@ $(document).ready(function(){
console.log(data) console.log(data)
if (data.url){ if (data.url){
//$("#ressources_list").append("<div> <p>"+data.title +"</p></div>") //$("#ressources_list").append("<div> <p>"+data.title +"</p></div>")
addObject("url_ressources", data)
$("#ressources_list").append(row(data)) $("#ressources_list").append(row(data))
$(".presLink").click(function(){ $(".presLink").click(function(){
console.log(this.value) $.post('/set', {url:this.value}, function(data) {console.log("hop")})
}) })
} }
}) })

View File

@ -47,6 +47,14 @@ webapp.use(bodyParser.urlencoded({ // to support URL-encoded bodies
webapp.get('/', function (req, res) { webapp.get('/', function (req, res) {
res.render('index', {ressources:[]}); res.render('index', {ressources:[]});
}); });
webapp.post('/set', function (req, res) {
var candidate = req.body.url
if( validUrl.isUri(candidate) )
refresh.emit('event',candidate)
res.send({ressources:[]});
});
webapp.post("/", function(req,res){ webapp.post("/", function(req,res){
console.log("/new") console.log("/new")