-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- change api to make Kizzy lowercase to kizzy
- remove stupid old and busted build process - add smoosh to build - new make task for building - rearrange tests - set commonjs module exports to cache - update readme with extra usage notes (twice) - output kizzy.js to root of project - add package.json
- Loading branch information
Showing
11 changed files
with
329 additions
and
85 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
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,2 @@ | ||
boosh: | ||
node make/build.js |
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
Submodule sink
updated
13 files
+3 −0 | .gitmodules | |
+2 −0 | Makefile | |
+43 −7 | README.md | |
+1 −0 | build/colors | |
+10 −0 | make/make.js | |
+11 −0 | package.json | |
+3 −0 | src/headless.js | |
+3 −2 | src/sink.css | |
+127 −28 | src/sink.js | |
+6 −5 | src/template.html | |
+0 −32 | src/test.html | |
+15 −0 | tests/tests.html | |
+42 −0 | tests/tests.js |
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,194 @@ | ||
/*! Kizzy - a cross-browser LocalStorage API | ||
* Copyright: Dustin Diaz 2011 | ||
* https://github.com/ded/kizzy | ||
* License: MIT | ||
*/ | ||
!function (win, doc, localStorage, store) { | ||
|
||
function noop() {} | ||
|
||
var hasLocalStorage, | ||
html5 = 0, | ||
writeThrough = function () { | ||
return 1; | ||
}; | ||
|
||
|
||
try { | ||
// HTML5 local storage | ||
hasLocalStorage = !!localStorage || !!globalStorage; | ||
localStorage = localStorage || globalStorage[store]; | ||
html5 = 1; | ||
} catch (ex1) { | ||
html5 = 0; | ||
// IE local storage | ||
try { | ||
// this try / if is required. trust me | ||
if (doc.documentElement.addBehavior) { | ||
html5 = 0; | ||
hasLocalStorage = 1; | ||
var dataStore = doc.documentElement; | ||
dataStore.addBehavior('#default#userData'); | ||
dataStore.load(store); | ||
var xmlDoc = dataStore.xmlDocument; | ||
var xmlDocEl = xmlDoc.documentElement; | ||
} | ||
} catch (ex2) { | ||
hasLocalStorage = false; | ||
} | ||
} | ||
|
||
var setLocalStorage = noop, | ||
getLocalStorage = noop, | ||
removeLocalStorage = noop, | ||
clearLocalStorage = noop; | ||
|
||
if (hasLocalStorage) { | ||
setLocalStorage = html5 ? html5setLocalStorage : setUserData; | ||
getLocalStorage = html5 ? html5getLocalStorage : getUserData; | ||
removeLocalStorage = html5 ? html5removeLocalStorage : removeUserData; | ||
clearLocalStorage = html5 ? html5clearLocalStorage : clearUserData; | ||
|
||
writeThrough = function (inst) { | ||
try { | ||
setLocalStorage(inst.ns, JSON.stringify(inst._)); | ||
return 1; | ||
} catch (x) { | ||
return 0; | ||
} | ||
}; | ||
} | ||
|
||
|
||
function time() { | ||
return +new Date(); | ||
} | ||
|
||
function checkExpiry(inst, k) { | ||
if (inst._[k] && inst._[k].e && inst._[k].e < time()) { | ||
inst.remove(k); | ||
} | ||
} | ||
|
||
function isNumber(n) { | ||
return typeof n === 'number' && isFinite(n); | ||
} | ||
|
||
function html5getLocalStorage(k) { | ||
return localStorage[k]; | ||
} | ||
|
||
function html5setLocalStorage(k, v) { | ||
localStorage[k] = v; | ||
return v; | ||
} | ||
|
||
function html5removeLocalStorage(k) { | ||
delete localStorage[k]; | ||
} | ||
|
||
function html5clearLocalStorage() { | ||
localStorage.clear(); | ||
} | ||
|
||
function getNodeByName(name) { | ||
var childNodes = xmlDocEl.childNodes, | ||
node, | ||
returnVal = null; | ||
|
||
for (var i = 0, len = childNodes.length; i < len; i++) { | ||
node = childNodes.item(i); | ||
if (node.getAttribute("key") == name) { | ||
returnVal = node; | ||
break; | ||
} | ||
} | ||
return returnVal; | ||
} | ||
|
||
function getUserData(name) { | ||
var node = getNodeByName(name); | ||
var returnVal = null; | ||
if (node) { | ||
returnVal = node.getAttribute("value"); | ||
} | ||
return returnVal; | ||
} | ||
|
||
function setUserData(name, value) { | ||
var node = getNodeByName(name); | ||
if (!node) { | ||
node = xmlDoc.createNode(1, "item", ""); | ||
node.setAttribute("key", name); | ||
node.setAttribute("value", value); | ||
xmlDocEl.appendChild(node); | ||
} | ||
else { | ||
node.setAttribute("value", value); | ||
} | ||
dataStore.save(store); | ||
return value; | ||
} | ||
|
||
function removeUserData(name) { | ||
getNodeByName(name) && xmlDocEl.removeChild(node); | ||
dataStore.save(store); | ||
} | ||
|
||
function clearUserData() { | ||
while (xmlDocEl.firstChild) { | ||
xmlDocEl.removeChild(xmlDocEl.firstChild); | ||
} | ||
dataStore.save(store); | ||
} | ||
|
||
function _Kizzy() { | ||
this._ = {}; | ||
} | ||
|
||
_Kizzy.prototype = { | ||
|
||
set: function (k, v, optTtl) { | ||
this._[k] = { | ||
value: v, | ||
e: isNumber(optTtl) ? time() + optTtl : 0 | ||
}; | ||
writeThrough(this) || this.remove(k); | ||
return v; | ||
}, | ||
|
||
get: function (k) { | ||
checkExpiry(this, k); | ||
return this._[k] ? this._[k].value : undefined; | ||
}, | ||
|
||
remove: function (k) { | ||
delete this._[k]; | ||
writeThrough(this); | ||
}, | ||
|
||
clear: function () { | ||
this._ = {}; | ||
writeThrough(this); | ||
} | ||
}; | ||
|
||
function Kizzy(ns) { | ||
this.ns = ns; | ||
this._ = JSON.parse(getLocalStorage(ns) || '{}'); | ||
} | ||
|
||
Kizzy.prototype = _Kizzy.prototype; | ||
|
||
function kizzy(ns) { | ||
return new Kizzy(ns); | ||
} | ||
|
||
kizzy.remove = removeLocalStorage; | ||
kizzy.clear = clearLocalStorage; | ||
|
||
win.kizzy = kizzy; | ||
|
||
typeof module !== 'undefined' && module.exports && (module.exports.cache = kizzy); | ||
|
||
}(this, document, localStorage, document.domain); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
require('smoosh').config({ | ||
"JAVASCRIPT": { | ||
"DIST_DIR": "./", | ||
"kizzy": [ | ||
"./src/header.js", | ||
"./src/kizzy.js" | ||
] | ||
}, | ||
"JSHINT_OPTS": { | ||
"boss": true, | ||
"forin": false, | ||
"curly": true, | ||
"debug": false, | ||
"devel": false, | ||
"evil": false, | ||
"regexp": false, | ||
"undef": false, | ||
"sub": false, | ||
"white": true, | ||
"indent": 2, | ||
"whitespace": true, | ||
"asi": false | ||
} | ||
}).run().build().analyze(); |
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,13 @@ | ||
{ | ||
"name": "kizzy", | ||
"description": "x-browser LocalStorage API with a memcached interface", | ||
"keywords": ["cache", "local storage", "caching", "expiration", "dom"], | ||
"version": "0.0.1", | ||
"homepage": "https://github.com/ded/kizzy", | ||
"author": "Dustin Diaz <@ded>", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ded/kizzy.git" | ||
}, | ||
"main": "./kizzy.js" | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/*! Kizzy v1.0 | ||
* https://github.com/polvero/kizzy | ||
* Copyright: @ded Dustin Diaz 2011 | ||
* License: CC Attribution: http://creativecommons.org/licenses/by/3.0/ | ||
/*! Kizzy - a cross-browser LocalStorage API | ||
* Copyright: Dustin Diaz 2011 | ||
* https://github.com/ded/kizzy | ||
* License: MIT | ||
*/ |
Oops, something went wrong.