Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // When a new url is added, save it in the local storage and display the home page.
- $("#addurl").live("submit" , function(e, data) {
- var url = $("#url").val();
- addUrl(url);
- $.mobile.changePage("#home");
- return false;
- });
- // Add a URL to the list.
- function addUrl(url) {
- var myUrls = getMyUrls();
- // Check for duplicates
- if (findUrl(url) === -1) {
- myUrls = myUrls.concat(encodeURIComponent(url));
- localStorage.setItem("myUrls", JSON.stringify(myUrls));
- }
- }
- // Find URL in the url list.
- // Return index or -1 if not found.
- function findUrl(url) {
- var index = -1;
- var myUrls = getMyUrls();
- for (var i=0; i < myUrls.length; i++) {
- if (myUrls[i] === encodeURIComponent(url)) {
- return i;
- }
- }
- return index;
- }
Add Comment
Please, Sign In to add comment