-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mikael Brassman
committed
Jun 5, 2013
0 parents
commit 4924169
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
############ | ||
## OS Specific | ||
############ | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Mac crap | ||
.DS_Store | ||
|
||
############# | ||
## Node Specifics | ||
############# | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "knockout.persist", | ||
"version": "0.1.0", | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"components" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*! Knockout Persist - v0.1.0 - 2013-06-05 | ||
* https://github.com/spoike/knockout.persist | ||
* Copyright (c) 2013 Mikael Brassman; Licensed MIT */ | ||
(function(ko) { | ||
|
||
// Don't crash on browsers that are missing localStorage | ||
if (typeof (localStorage) === "undefined") { return; } | ||
|
||
ko.extenders.persist = function(target, key) { | ||
|
||
var initialValue = target(); | ||
|
||
// Load existing value from localStorage if set | ||
if (key && localStorage.getItem(key) !== null) { | ||
try { | ||
initialValue = JSON.parse(localStorage.getItem(key)); | ||
} catch (e) { | ||
} | ||
} | ||
target(initialValue); | ||
|
||
// Subscribe to new values and add them to localStorage | ||
target.subscribe(function (newValue) { | ||
localStorage.setItem(key, ko.toJSON(newValue)); | ||
}); | ||
return target; | ||
|
||
}; | ||
|
||
})(ko); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*! Knockout Persist - v0.1.0 - 2013-06-05 | ||
* https://github.com/spoike/knockout.persist | ||
* Copyright (c) 2013 Mikael Brassman; Licensed MIT */ | ||
(function(e){"undefined"!=typeof localStorage&&(e.extenders.persist=function(t,o){var r=t();if(o&&null!==localStorage.getItem(o))try{r=JSON.parse(localStorage.getItem(o))}catch(a){}return t(r),t.subscribe(function(t){localStorage.setItem(o,e.toJSON(t))}),t})})(ko); |