localStorage
This commit is contained in:
parent
1aa633a94e
commit
b4e4e2fbae
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,5 @@
|
||||
node_modules/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
|
@ -1,8 +1,33 @@
|
||||
//var bla = function
|
||||
|
||||
$(document).ready(function(){
|
||||
var row = function(data){
|
||||
function storeObject(name,obj){
|
||||
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+
|
||||
//" </div>"+ "<div class='presLink'><button 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(){
|
||||
console.log("Hey")
|
||||
@ -19,9 +58,10 @@ $(document).ready(function(){
|
||||
console.log(data)
|
||||
if (data.url){
|
||||
//$("#ressources_list").append("<div> <p>"+data.title +"</p></div>")
|
||||
addObject("url_ressources", data)
|
||||
$("#ressources_list").append(row(data))
|
||||
$(".presLink").click(function(){
|
||||
console.log(this.value)
|
||||
$.post('/set', {url:this.value}, function(data) {console.log("hop")})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
8
main.js
8
main.js
@ -47,6 +47,14 @@ webapp.use(bodyParser.urlencoded({ // to support URL-encoded bodies
|
||||
webapp.get('/', function (req, res) {
|
||||
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){
|
||||
|
||||
console.log("/new")
|
||||
|
Loading…
Reference in New Issue
Block a user