add note js
This commit is contained in:
parent
66f21cb870
commit
2f19c7d111
1 changed files with 74 additions and 0 deletions
74
upload/admin_area/styles/cb_2014/theme/js/main.js
Normal file
74
upload/admin_area/styles/cb_2014/theme/js/main.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
|
||||
//like in my previous post, I will set the value of window.onload
|
||||
|
||||
//equals to init and then define it separately
|
||||
|
||||
window.onload = init;
|
||||
|
||||
function init(){
|
||||
|
||||
for (var i=0; i < localStorage.length; i++){
|
||||
|
||||
var key = localStorage.key(i);
|
||||
|
||||
if (key.substring(0, 6) === 'sticky'){ //will explain this
|
||||
|
||||
var value = localStorage.getItem(key);
|
||||
|
||||
addStickiesToPage(value); //we will create this one
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
//this function will insert the sticky notes to the DOM
|
||||
|
||||
//inside the <ul> element we created in the index.html file
|
||||
|
||||
function addStickiesToPage(value){
|
||||
|
||||
var stickies = document.getElementById("stickies");
|
||||
|
||||
var sticky = document.createElement("li");
|
||||
|
||||
var span = document.createElement("span");
|
||||
|
||||
span.setAttribute("class", "sticky");
|
||||
|
||||
span.innerHTML = value;
|
||||
|
||||
sticky.appendChild(span);
|
||||
|
||||
stickies.appendChild(sticky);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function init(){
|
||||
|
||||
var button = document.getElementById("add_sticky");
|
||||
|
||||
button.onclick = makeSticky; //we have to define this function
|
||||
|
||||
//continue the init function here as shown above by adding
|
||||
|
||||
//the for loop to get items from localStorage
|
||||
|
||||
}
|
||||
|
||||
|
||||
function makeSticky(){
|
||||
|
||||
var value = document.getElementById("note").value;
|
||||
|
||||
var key = "sticky_" + localStorage.length;
|
||||
|
||||
localStorage.setItem(key, value);
|
||||
|
||||
addStickiesToPage(value);
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue