Started indexedDB module

This commit is contained in:
Timothy Warren 2012-02-08 11:36:43 -05:00
parent 19ab4751e4
commit 6b2fab7b46
15 changed files with 229 additions and 29 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,70 @@
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
.KEYW {color: #933;}
.COMM {color: #bbb; font-style: italic;}
.NUMB {color: #393;}
.STRN {color: #393;}
.REGX {color: #339;}
.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
</style></head><body><pre><span class='line'> 1</span> <span class="COMM">/**
<span class='line'> 2</span> * Module for simplifying Indexed DB access
<span class='line'> 3</span> */</span><span class="WHIT">
<span class='line'> 4</span> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 5</span> </span><span class="WHIT"> </span><span class="STRN">"use strict"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 6</span> </span><span class="WHIT">
<span class='line'> 7</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">db</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">window.indexedDB</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.webkitIndexedDB</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.mozIndexedDB</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">window.msIndexedDB</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 8</span> </span><span class="WHIT"> </span><span class="NAME">request</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 9</span> </span><span class="WHIT"> </span><span class="NAME">indexedDB</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 10</span> </span><span class="WHIT">
<span class='line'> 11</span> </span><span class="COMM">/**
<span class='line'> 12</span> * @private
<span class='line'> 13</span> */</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="NAME">request.onerror</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 16</span> </span><span class="WHIT"> </span><span class="NAME">console.log</span><span class="PUNC">(</span><span class="STRN">"IndexedDB disallowed."</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 18</span> </span><span class="WHIT">
<span class='line'> 19</span> </span><span class="COMM">/**
<span class='line'> 20</span> * @private
<span class='line'> 21</span> */</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="WHIT"> </span><span class="NAME">request.onsuccess</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">event</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 23</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 24</span> </span><span class="WHIT"> </span><span class="COMM">// Connect to the specified db</span><span class="WHIT">
<span class='line'> 25</span> </span><span class="WHIT"> </span><span class="NAME">indexedDB.current_db</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">request.result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span>
<span class='line'> 28</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 29</span> * Module for simplifying Indexed DB access
<span class='line'> 30</span> *
<span class='line'> 31</span> * @namespace
<span class='line'> 32</span> * @name indexedDB
<span class='line'> 33</span> * @memberOf $_
<span class='line'> 34</span> */</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT"> </span><span class="NAME">indexedDB</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 36</span> </span><span class="WHIT"> </span><span class="NAME">current_db</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 37</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 38</span> * Connects to an indexedDB database
<span class='line'> 39</span> *
<span class='line'> 40</span> * @memberOf $_.indexedDB
<span class='line'> 41</span> * @name connect
<span class='line'> 42</span> * @function
<span class='line'> 43</span> * @param string dbname
<span class='line'> 44</span> * @param [int] version
<span class='line'> 45</span> * @param [function] onupgradeneeded
<span class='line'> 46</span> */</span><span class="WHIT">
<span class='line'> 47</span> </span><span class="WHIT"> </span><span class="NAME">connect</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dbname</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">version</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">onupgradeneeded</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT"> </span><span class="NAME">version</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">version</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">
<span class='line'> 51</span> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">onupgradeneeded</span><span class="WHIT"> </span><span class="PUNC">!==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT"> </span><span class="NAME">request.onupgradeneeded</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">onupgradeneeded</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">
<span class='line'> 56</span> </span><span class="COMM">// Ask for permission to use db</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT"> </span><span class="NAME">this.current_db</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">db.open</span><span class="PUNC">(</span><span class="NAME">dbname</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">version</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">
<span class='line'> 61</span> </span><span class="NAME">$_.ext</span><span class="PUNC">(</span><span class="STRN">'indexedDB'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">indexedDB</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">
<span class='line'> 63</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>

View File

@ -1044,6 +1044,72 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
// --------------------------------------------------------------------------
/**
* Module for simplifying Indexed DB access
*/
(function() {
"use strict";
var db = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB,
request = null;
indexedDB = {};
/**
* @private
*/
request.onerror = function(event)
{
console.log("IndexedDB disallowed.");
};
/**
* @private
*/
request.onsuccess = function(event)
{
// Connect to the specified db
indexedDB.current_db = request.result;
};
/**
* Module for simplifying Indexed DB access
*
* @namespace
* @name indexedDB
* @memberOf $_
*/
indexedDB = {
current_db: null,
/**
* Connects to an indexedDB database
*
* @memberOf $_.indexedDB
* @name connect
* @function
* @param string dbname
* @param [int] version
* @param [function] onupgradeneeded
*/
connect: function(dbname, version, onupgradeneeded)
{
version = version || 0;
if(typeof onupgradeneeded !== "undefined")
{
request.onupgradeneeded = onupgradeneeded;
}
// Ask for permission to use db
this.current_db = db.open(dbname, version);
}
};
$_.ext('indexedDB', indexedDB);
}());
// --------------------------------------------------------------------------
/**
* Util Object
*

10
kis-lite-min.js vendored
View File

@ -1,9 +1,9 @@
(function(){if("undefined"!==typeof document.querySelector){var e,f,d,c;e=function(a){c="undefined"===typeof a?"undefined"!==typeof e.el?e.el:document.documentElement:"object"!==typeof a?f(a):a;e.prototype.el=c;var a=d(e),b;for(b in a)if("object"===typeof a[b])a[b].el=c;a.el=c;return a};f=function(a,b){var g;if("string"!=typeof a||"undefined"===typeof a)return a;g=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);g=g.querySelectorAll(a);
(function(){if("undefined"!==typeof document.querySelector){var e,f,d,c;e=function(a){c="undefined"===typeof a?"undefined"!==typeof e.el?e.el:document.documentElement:"object"!==typeof a?f(a):a;e.prototype.el=c;var a=d(e),b;for(b in a)"object"===typeof a[b]&&(a[b].el=c);a.el=c;return a};f=function(a,b){var g;if("string"!=typeof a||"undefined"===typeof a)return a;g=null!=b&&1===b.nodeType?b:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);g=g.querySelectorAll(a);
return 1===g.length?g[0]:g};d=function(a){var b;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);b=typeof a;if(!("object"!==b&&"function"!==b))return b=function(){},b.prototype=a,new b}};e.ext=function(a,b){b.el=c;e[a]=b};e.ext("each",function(a){if("undefined"!==typeof c.length&&c!==window){var b=c.length;if(0!==b)for(var g,d=0;d<b;d++)g=c.item(d)?c.item(d):c[d],a.call(g,g)}else a.call(c,c)});e.type=function(a){return function(){return a&&a!==this}.call(a)?
(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};e=window.$_=window.$_||e;e.$=f}})();
(function(){if("undefined"===typeof window.console)window.console={log:function(){}};if("undefined"===typeof String.prototype.trim)String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};if("undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event)Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=!1}})();
(function(){"undefined"===typeof window.console&&(window.console={log:function(){}});"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=!1})})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var e={_do:function(f,d,c,a){var b=new XMLHttpRequest;"undefined"===typeof c&&(c=function(){});a=a?"POST":"GET";f+="GET"===a?"?"+this._serialize(d):"";b.open(a,f);b.onreadystatechange=function(){4===b.readyState&&c(b.responseText)};"POST"===a?(b.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),b.send(this._serialize(d))):b.send(null)},_serialize:function(f){var d,c,a=[];for(d in f)f.hasOwnProperty(d)&&"function"!==typeof f[d]&&
(c=f[d].toString(),d=encodeURIComponent(d),c=encodeURIComponent(c),a.push(d+"="+c));return a.join("&")}};$_.ext("get",function(f,d,c){e._do(f,d,c,!1)});$_.ext("post",function(f,d,c){e._do(f,d,c,!0)})}})();
(function(){var e,f,d,c;"undefined"!==typeof document.addEventListener?(e=function(a,b,g){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,g,!1)},f=function(a,b,g){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,g,!1)}):"undefined"!==typeof document.attachEvent&&(e=function(a,b,g){var h;function c(a){g.apply(a)}"undefined"!==typeof a.attachEvent?(f(b,g),a.attachEvent("on"+b,c),h=a.KIS_0_5_0=a.KIS_0_5_0||{},a=h,a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||
[],a.listeners[b].push({callback:g,_listener:c})):console.log("Failed to _attach event:"+b+" on "+a)},f=function(a,b,g){if("undefined"!==typeof a.detachEvent){var c=a.KIS_0_5_0;if(c&&c.listeners&&c.listeners[b])for(var d=c.listeners[b],f=d.length,e=0;e<f;e++)if(d[e].callback===g){a.detachEvent("on"+b,d[e]._listener);d.splice(e,1);0===d.length&&delete c.listeners[b];break}}});d=function(a,b,c,i){var h,j;if("undefined"===typeof a)return console.log(arguments),console.log(b),!1;if(b.match(/^([\w\-]+)$/))!0===
i?e(a,b,c):f(a,b,c);else{b=b.split(" ");j=b.length;for(h=0;h<j;h++)d(a,b[h],c,i)}};c=function(a,b,c,e){d(a,c,function(a){var c,d,g,a=a||window.event;d=$_.$(b);for(c in d)g=a.target||a.srcElement,g==d[c]&&(e.call(d[c],a),a.stopPropagation())},!0)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,!0)})},remove:function(a,b){$_.each(function(c){d(c,a,b,!1)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(e){c(e,a,b,d)})}})})();
(function(){var e,f,d,c;"undefined"!==typeof document.addEventListener?(e=function(a,b,g){"undefined"!==typeof a.addEventListener&&a.addEventListener(b,g,!1)},f=function(a,b,g){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(b,g,!1)}):"undefined"!==typeof document.attachEvent&&(e=function(a,b,g){function c(a){g.apply(a)}"undefined"!==typeof a.attachEvent?(f(b,g),a.attachEvent("on"+b,c),a=a.KIS_0_5_0=a.KIS_0_5_0||{},a.listeners=a.listeners||{},a.listeners[b]=a.listeners[b]||[],a.listeners[b].push({callback:g,
_listener:c})):console.log("Failed to _attach event:"+b+" on "+a)},f=function(a,b,g){if("undefined"!==typeof a.detachEvent){var c=a.KIS_0_5_0;if(c&&c.listeners&&c.listeners[b])for(var d=c.listeners[b],f=d.length,e=0;e<f;e++)if(d[e].callback===g){a.detachEvent("on"+b,d[e]._listener);d.splice(e,1);0===d.length&&delete c.listeners[b];break}}});d=function(a,b,c,i){var h,j;if("undefined"===typeof a)return console.log(arguments),console.log(b),!1;if(b.match(/^([\w\-]+)$/))!0===i?e(a,b,c):f(a,b,c);else{b=
b.split(" ");j=b.length;for(h=0;h<j;h++)d(a,b[h],c,i)}};c=function(a,b,c,e){d(a,c,function(a){var c,d,g,a=a||window.event;d=$_.$(b);for(c in d)g=a.target||a.srcElement,g==d[c]&&(e.call(d[c],a),a.stopPropagation())},!0)};$_.ext("event",{add:function(a,b){$_.each(function(c){d(c,a,b,!0)})},remove:function(a,b){$_.each(function(c){d(c,a,b,!1)})},live:function(a,b,d){c(document.documentElement,a,b,d)},delegate:function(a,b,d){$_.each(function(e){c(e,a,b,d)})}})})();

30
kis-min.js vendored
View File

@ -1,25 +1,25 @@
(function(){if("undefined"!==typeof document.querySelector){var g,f,d,b;g=function(a){b="undefined"===typeof a?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof a?f(a):a;g.prototype.el=b;var a=d(g),c;for(c in a)if("object"===typeof a[c])a[c].el=b;a.el=b;return a};f=function(a,c){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);
(function(){if("undefined"!==typeof document.querySelector){var g,f,d,b;g=function(a){b="undefined"===typeof a?"undefined"!==typeof g.el?g.el:document.documentElement:"object"!==typeof a?f(a):a;g.prototype.el=b;var a=d(g),c;for(c in a)"object"===typeof a[c]&&(a[c].el=b);a.el=b;return a};f=function(a,c){var b;if("string"!=typeof a||"undefined"===typeof a)return a;b=null!=c&&1===c.nodeType?c:document;if(a.match(/^#([\w\-]+$)/))return document.getElementById(a.split("#")[1]);b=b.querySelectorAll(a);
return 1===b.length?b[0]:b};d=function(a){var c;if("undefined"!==typeof a){if("undefined"!==typeof Object.create)return Object.create(a);c=typeof a;if(!("object"!==c&&"function"!==c))return c=function(){},c.prototype=a,new c}};g.ext=function(a,c){c.el=b;g[a]=c};g.ext("each",function(a){if("undefined"!==typeof b.length&&b!==window){var c=b.length;if(0!==c)for(var e,d=0;d<c;d++)e=b.item(d)?b.item(d):b[d],a.call(e,e)}else a.call(b,b)});g.type=function(a){return function(){return a&&a!==this}.call(a)?
(typeof a).toLowerCase():{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};g=window.$_=window.$_||g;g.$=f}})();
(function(){if("undefined"===typeof window.console)window.console={log:function(){}};if("undefined"===typeof String.prototype.trim)String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")};if("undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event)Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=!1}})();
(function(){"undefined"===typeof window.console&&(window.console={log:function(){}});"undefined"===typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g,"")});"undefined"===typeof Event.preventDefault&&"undefined"!==typeof window.event&&(Event.prototype.preventDefault=function(){window.event.stop()},Event.prototype.stopPropagation=function(){window.event.returnValue=!1})})();
"undefined"!==typeof document&&!("classList"in document.createElement("a"))&&function(g){var g=(g.HTMLElement||g.Element).prototype,f=Object,d=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},b=Array.prototype.indexOf||function(a){for(var c=0,b=this.length;c<b;c++)if(c in this&&this[c]===a)return c;return-1},a=function(a,c){this.name=a;this.code=DOMException[a];this.message=c},c=function(c,e){if(""===e)throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(e))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return b.call(c,e)},e=function(a){for(var c=d.call(a.className),c=c?c.split(/\s+/):[],b=0,e=c.length;b<e;b++)this.push(c[b]);this._updateClassName=function(){a.className=this.toString()}},j=e.prototype=[],h=function(){return new e(this)};a.prototype=Error.prototype;j.item=function(a){return this[a]||null};j.contains=function(a){return-1!==c(this,a+"")};j.add=function(a){a+="";-1===c(this,a)&&(this.push(a),this._updateClassName())};j.remove=function(a){a=c(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};j.toggle=function(a){a+="";-1===c(this,a)?this.add(a):this.remove(a)};j.toString=function(){return this.join(" ")};if(f.defineProperty){j={get:h,enumerable:!0,configurable:!0};try{f.defineProperty(g,"classList",j)}catch(i){if(-2146823252===i.number)j.enumerable=!1,f.defineProperty(g,"classList",j)}}else f.prototype.__defineGetter__&&g.__defineGetter__("classList",h)}(self);
(function(){function g(b,a,c){var e,d;if("undefined"!==typeof b.hasAttribute)b.hasAttribute(a)&&(e=b.getAttribute(a)),d=!0;else if("undefined"!==typeof b[a])e=b[a],d=!1;else if("class"===a&&"undefined"!==typeof b.className)a="className",e=b.className,d=!1;if("undefined"===typeof e&&("undefined"===typeof c||null===c))console.log(c),console.log(b),console.log("Element does not have the selected attribute");else{if("undefined"===typeof c)return e;"undefined"!==typeof c&&null!==c?!0===d?b.setAttribute(a,
c):b[a]=c:null===c&&(!0===d?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof c?c:e}}function f(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(b,a,c){var e,a=f(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof c&&"undefined"!==b.style[a])return b.style[a];if("undefined"===typeof c&&"undefined"!==b.style[e[a]])return b.style[e[a]];"undefined"!==typeof b.style[a]?b.style[a]=c:b.style[e[a]]?b.style[e[a]]=
"String contains an invalid character");return b.call(c,e)},e=function(a){for(var c=d.call(a.className),c=c?c.split(/\s+/):[],b=0,e=c.length;b<e;b++)this.push(c[b]);this._updateClassName=function(){a.className=this.toString()}},j=e.prototype=[],i=function(){return new e(this)};a.prototype=Error.prototype;j.item=function(a){return this[a]||null};j.contains=function(a){return-1!==c(this,a+"")};j.add=function(a){a+="";-1===c(this,a)&&(this.push(a),this._updateClassName())};j.remove=function(a){a=c(this,
a+"");-1!==a&&(this.splice(a,1),this._updateClassName())};j.toggle=function(a){a+="";-1===c(this,a)?this.add(a):this.remove(a)};j.toString=function(){return this.join(" ")};if(f.defineProperty){j={get:i,enumerable:!0,configurable:!0};try{f.defineProperty(g,"classList",j)}catch(h){-2146823252===h.number&&(j.enumerable=!1,f.defineProperty(g,"classList",j))}}else f.prototype.__defineGetter__&&g.__defineGetter__("classList",i)}(self);
(function(){function g(b,a,c){var e,d;"undefined"!==typeof b.hasAttribute?(b.hasAttribute(a)&&(e=b.getAttribute(a)),d=!0):"undefined"!==typeof b[a]?(e=b[a],d=!1):"class"===a&&"undefined"!==typeof b.className&&(a="className",e=b.className,d=!1);if("undefined"===typeof e&&("undefined"===typeof c||null===c))console.log(c),console.log(b),console.log("Element does not have the selected attribute");else{if("undefined"===typeof c)return e;"undefined"!==typeof c&&null!==c?!0===d?b.setAttribute(a,c):b[a]=
c:null===c&&(!0===d?b.removeAttribute(a):delete b[a]);return"undefined"!==typeof c?c:e}}function f(b){return b.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function d(b,a,c){var e,a=f(a);e={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if("undefined"===typeof c&&"undefined"!==b.style[a])return b.style[a];if("undefined"===typeof c&&"undefined"!==b.style[e[a]])return b.style[e[a]];"undefined"!==typeof b.style[a]?b.style[a]=c:b.style[e[a]]?b.style[e[a]]=
c:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(b){$_.each(function(a){a.classList.add(b)})},removeClass:function(b){$_.each(function(a){a.classList.remove(b)})},hide:function(){this.css("display","none")},show:function(b){"undefined"===typeof b&&(b="block");this.css("display",b)},attr:function(b,a){var c=this.el;if(1<c.length&&"undefined"===typeof a)console.log(c),console.log("Must be a singular element");else if(1<c.length&&"undefined"!==typeof a)$_.each(function(c){return g(c,
b,a)});else return g(c,b,a)},text:function(b){var a,c,e;e=this.el;c="undefined"!==typeof e.innerText?"innerText":"undefined"!==typeof e.textContent?"textContent":"innerHTML";a=e[c];return"undefined"!==typeof b?e[c]=b:a},css:function(b,a){if("undefined"===typeof a)return d(this.el,b);$_.each(function(c){d(c,b,a)})},append:function(b){"undefined"!==typeof document.insertAdjacentHTML?this.el.insertAdjacentHTML("beforeend",b):this.el.innerHTML+=b},prepend:function(b){"undefined"!==typeof document.insertAdjacentHTML?
this.el.insertAdjacentHTML("afterbegin",b):this.el.innerHTML=b+this.el.innerHTML},html:function(b){if("undefined"!==typeof b)this.el.innerHTML=b;return this.el.innerHTML}})})();
this.el.insertAdjacentHTML("afterbegin",b):this.el.innerHTML=b+this.el.innerHTML},html:function(b){"undefined"!==typeof b&&(this.el.innerHTML=b);return this.el.innerHTML}})})();
(function(){if(!("undefined"===typeof localStorage||"undefined"===typeof JSON)){var g=localStorage,f=sessionStorage;$_.ext("store",{get:function(d,b){var a=b?f.getItem(d):g.getItem(d);return JSON.parse(a)},set:function(d,b,a){b=JSON.stringify(b);a?f.setItem(d,b):g.setItem(d,b)},remove:function(d,b){b?f.removeItem(d):g.removeItem(d)},getAll:function(d){var b,a={},c,e;e=d?g:f;b=e.length;for(d=0;d<b;d++)c=e.key(d),a[c]=e.getItem(c);return a},clear:function(d){d?f.clear():g.clear()}})}})();
(function(){if("undefined"!==typeof window.XMLHttpRequest){var g={_do:function(f,d,b,a){var c=new XMLHttpRequest;"undefined"===typeof b&&(b=function(){});a=a?"POST":"GET";f+="GET"===a?"?"+this._serialize(d):"";c.open(a,f);c.onreadystatechange=function(){4===c.readyState&&b(c.responseText)};"POST"===a?(c.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),c.send(this._serialize(d))):c.send(null)},_serialize:function(f){var d,b,a=[];for(d in f)f.hasOwnProperty(d)&&"function"!==typeof f[d]&&
(b=f[d].toString(),d=encodeURIComponent(d),b=encodeURIComponent(b),a.push(d+"="+b));return a.join("&")}};$_.ext("get",function(f,d,b){g._do(f,d,b,!1)});$_.ext("post",function(f,d,b){g._do(f,d,b,!0)})}})();
(b=f[d].toString(),d=encodeURIComponent(d),b=encodeURIComponent(b),a.push(d+"="+b));return a.join("&")}};$_.ext("get",function(f,d,b){g._do(f,d,b,!1)});$_.ext("post",function(f,d,b){g._do(f,d,b,!0)})}})();(function(){var g=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.msIndexedDB;indexedDB={};indexedDB={current_db:null,connect:function(f,d){this.current_db=g.open(f,d||0)}};$_.ext("indexedDB",indexedDB)})();
(function(){var g=function(d){var b=[],a=0,c={},e,b=f.object_keys(d);b.sort(function(a,c){var b=parseFloat(c),e=parseFloat(a),d=b+""===c,f=e+""===a;return d&&f?b>e?1:b<e?-1:0:d&&!f?1:!d&&f?-1:c>a?1:c<a?-1:0});a=b.length;for(e=0;e<a;e++)c[b[e]]=d[b[e]];return c},f={object_keys:function(d){var b=[],a;for(a in d)d.hasOwnProperty(a)&&b.push(a);return b},object_values:function(d){var b=[],a;for(a in d)b.push(d[a]);return b},array_combine:function(d,b){var a={},c,e=0;"array"!==$_.type(d)&&(d=this.object_values(d));
"array"!==$_.type(b)&&(b=this.object_values(b));c=d.length;if(c!==b.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<c;e++)a[d[e]]=b[e];return a},object_merge:function(){var d=Array.prototype.slice.call(arguments),b=d.length,a={},c,e=0,f,h,g;c=!0;for(f=0;f<b;f++)if("array"!==$_.type(d[f])){c=!1;break}if(c){a=[];for(f=0;f<b;f++)a=a.contact(d[f]);return a}for(f=0,g=0;f<b;f++)if(c=d[f],"array"==$_.type(c))for(h=0,e=c.length;h<e;h++)a[g++]=c[h];else for(h in c)c.hasOwnProperty(h)&&
(parseInt(h,10)+""===h?a[g++]=c[h]:a[h]=c[h]);return a},str_trans:function(d,b,a){var c=[],e=[],f=!1,h=0,i=0,k="",l="",o="",m="",n;if("object"===typeof b){b=g(b);for(n in b)b.hasOwnProperty(n)&&(c.push(n),e.push(b[n]));b=c;a=e}i=d.length;h=b.length;k="string"===typeof a;l="string"===typeof b;for(c=0;c<i;c++){f=!1;if(l){d.charAt(c-1);o=d.charAt(c);d.charAt(c+1);for(e=0;e<h;e++)if(o==b.charAt(e)){f=!0;break}}else for(e=0;e<h;e++)if(d.substr(c,b[e].length)==b[e]){f=!0;c=c+b[e].length-1;break}m=f?m+(k?
"array"!==$_.type(b)&&(b=this.object_values(b));c=d.length;if(c!==b.length)return console.log("Object combine requires two arrays of the same size"),!1;for(e=0;e<c;e++)a[d[e]]=b[e];return a},object_merge:function(){var d=Array.prototype.slice.call(arguments),b=d.length,a={},c,e=0,f,g,h;c=!0;for(f=0;f<b;f++)if("array"!==$_.type(d[f])){c=!1;break}if(c){a=[];for(f=0;f<b;f++)a=a.contact(d[f]);return a}for(f=0,h=0;f<b;f++)if(c=d[f],"array"==$_.type(c))for(g=0,e=c.length;g<e;g++)a[h++]=c[g];else for(g in c)c.hasOwnProperty(g)&&
(parseInt(g,10)+""===g?a[h++]=c[g]:a[g]=c[g]);return a},str_trans:function(d,b,a){var c=[],e=[],f=!1,i=0,h=0,k="",l="",o="",m="",n;if("object"===typeof b){b=g(b);for(n in b)b.hasOwnProperty(n)&&(c.push(n),e.push(b[n]));b=c;a=e}h=d.length;i=b.length;k="string"===typeof a;l="string"===typeof b;for(c=0;c<h;c++){f=!1;if(l){d.charAt(c-1);o=d.charAt(c);d.charAt(c+1);for(e=0;e<i;e++)if(o==b.charAt(e)){f=!0;break}}else for(e=0;e<i;e++)if(d.substr(c,b[e].length)==b[e]){f=!0;c=c+b[e].length-1;break}m=f?m+(k?
a.charAt(e):a[e]):m+d.charAt(c)}return m}};$_.ext("util",f)})();
(function(){var g,f,d,b;"undefined"!==typeof document.addEventListener?(g=function(a,c,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(c,b,!1)},f=function(a,c,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(c,b,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,c,b){var e;function d(a){b.apply(a)}"undefined"!==typeof a.attachEvent?(f(c,b),a.attachEvent("on"+c,d),e=a.KIS_0_5_0=a.KIS_0_5_0||{},a=e,a.listeners=a.listeners||{},a.listeners[c]=a.listeners[c]||
[],a.listeners[c].push({callback:b,_listener:d})):console.log("Failed to _attach event:"+c+" on "+a)},f=function(a,c,b){if("undefined"!==typeof a.detachEvent){var d=a.KIS_0_5_0;if(d&&d.listeners&&d.listeners[c])for(var f=d.listeners[c],g=f.length,k=0;k<g;k++)if(f[k].callback===b){a.detachEvent("on"+c,f[k]._listener);f.splice(k,1);0===f.length&&delete d.listeners[c];break}}});d=function(a,c,b,j){var h,i;if("undefined"===typeof a)return console.log(arguments),console.log(c),!1;if(c.match(/^([\w\-]+)$/))!0===
j?g(a,c,b):f(a,c,b);else{c=c.split(" ");i=c.length;for(h=0;h<i;h++)d(a,c[h],b,j)}};b=function(a,c,b,f){d(a,b,function(a){var b,d,e,a=a||window.event;d=$_.$(c);for(b in d)e=a.target||a.srcElement,e==d[b]&&(f.call(d[b],a),a.stopPropagation())},!0)};$_.ext("event",{add:function(a,b){$_.each(function(e){d(e,a,b,!0)})},remove:function(a,b){$_.each(function(e){d(e,a,b,!1)})},live:function(a,c,d){b(document.documentElement,a,c,d)},delegate:function(a,c,d){$_.each(function(f){b(f,a,c,d)})}})})();
(function(){if("undefined"!==$_.ajax){var g,f;g={};f={};$_.ext("template",{get:function(d){var b;b=this.el.innerHTML;if(""===b)console.log("Template is empty or cannot be found");else return g[d]=b},parse:function(d,b){var a=g[d],c=[],e=/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,j=/\{([A-Z0-9_\-]+)\}/gim,c=[],h=0,i=h=0,k=0,l="",o={},m="",n,a=(""+a).replace(/\s+/gim," "),a=a.replace(/>\s+</gim,"><"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+</gim,"}<"),c=a.match(e);if(null!=c){h=c.length;for(i=0;i<
h;i++){a=a.replace(c[i],"{"+i+"}");m="";l=(""+c[i]).match(/^\{([A-Z0-9_\-]+)\}/i);o=b[l[1]];if(0<o.length){l=o.length;c[i]=c[i].replace(e,"$2");for(k=0;k<l;k++)m+=c[i].replace(j,function(a,b){return o[k][b]?o[k][b]:""})}a=a.replace("{"+i+"}",m)}}c=a.match(j);if(null!=c){h=c.length;for(i=0;i<h;i++)l=c[i].replace("{",""),l=l.replace("}",""),a=a.replace(c[i],b[l])}e=document.createDocumentFragment();e.appendChild(document.createElement("section"));e=e.querySelectorAll("section")[0];e.innerHTML=a;e=e.querySelectorAll('[src=""], [href=""]');
(function(){var g,f,d,b;"undefined"!==typeof document.addEventListener?(g=function(a,c,b){"undefined"!==typeof a.addEventListener&&a.addEventListener(c,b,!1)},f=function(a,c,b){"undefined"!==typeof a.removeEventListener&&a.removeEventListener(c,b,!1)}):"undefined"!==typeof document.attachEvent&&(g=function(a,c,b){function d(a){b.apply(a)}"undefined"!==typeof a.attachEvent?(f(c,b),a.attachEvent("on"+c,d),a=a.KIS_0_5_0=a.KIS_0_5_0||{},a.listeners=a.listeners||{},a.listeners[c]=a.listeners[c]||[],a.listeners[c].push({callback:b,
_listener:d})):console.log("Failed to _attach event:"+c+" on "+a)},f=function(a,c,b){if("undefined"!==typeof a.detachEvent){var d=a.KIS_0_5_0;if(d&&d.listeners&&d.listeners[c])for(var f=d.listeners[c],g=f.length,k=0;k<g;k++)if(f[k].callback===b){a.detachEvent("on"+c,f[k]._listener);f.splice(k,1);0===f.length&&delete d.listeners[c];break}}});d=function(a,c,b,j){var i,h;if("undefined"===typeof a)return console.log(arguments),console.log(c),!1;if(c.match(/^([\w\-]+)$/))!0===j?g(a,c,b):f(a,c,b);else{c=
c.split(" ");h=c.length;for(i=0;i<h;i++)d(a,c[i],b,j)}};b=function(a,c,b,f){d(a,b,function(a){var b,d,e,a=a||window.event;d=$_.$(c);for(b in d)e=a.target||a.srcElement,e==d[b]&&(f.call(d[b],a),a.stopPropagation())},!0)};$_.ext("event",{add:function(a,b){$_.each(function(e){d(e,a,b,!0)})},remove:function(a,b){$_.each(function(e){d(e,a,b,!1)})},live:function(a,c,d){b(document.documentElement,a,c,d)},delegate:function(a,c,d){$_.each(function(f){b(f,a,c,d)})}})})();
(function(){if("undefined"!==$_.ajax){var g,f;g={};f={};$_.ext("template",{get:function(d){var b;b=this.el.innerHTML;if(""===b)console.log("Template is empty or cannot be found");else return g[d]=b},parse:function(d,b){var a=g[d],c=[],e=/\{([A-Z0-9_\-]+)\}(.*)\{\/\1\}/gim,j=/\{([A-Z0-9_\-]+)\}/gim,c=[],i=0,h=i=0,k=0,l="",o={},m="",n,a=(""+a).replace(/\s+/gim," "),a=a.replace(/>\s+</gim,"><"),a=a.replace(/>\s+\{/gim,">{"),a=a.replace(/\}\s+</gim,"}<"),c=a.match(e);if(null!=c){i=c.length;for(h=0;h<
i;h++){a=a.replace(c[h],"{"+h+"}");m="";l=(""+c[h]).match(/^\{([A-Z0-9_\-]+)\}/i);o=b[l[1]];if(0<o.length){l=o.length;c[h]=c[h].replace(e,"$2");for(k=0;k<l;k++)m+=c[h].replace(j,function(a,b){return o[k][b]?o[k][b]:""})}a=a.replace("{"+h+"}",m)}}c=a.match(j);if(null!=c){i=c.length;for(h=0;h<i;h++)l=c[h].replace("{",""),l=l.replace("}",""),a=a.replace(c[h],b[l])}e=document.createDocumentFragment();e.appendChild(document.createElement("section"));e=e.querySelectorAll("section")[0];e.innerHTML=a;e=e.querySelectorAll('[src=""], [href=""]');
for(n in e)e[n].parentNode&&e[n].parentNode.removeChild(e[n]);return f[d]=a},apply:function(d,b,a){"undefined"===typeof b&&"undefined"===typeof a?this.el.innerHTML="undefined"!==typeof f[d]?f[d]:d:$_.get(b,{},function(b){""===b?console.log("Template is empty or can not be found"):(g[d]=b,b=this.parse(d,a),f[d]=b,this.el.innerHTML=b)})}})}})();

63
src/modules/indexedDB.js Normal file
View File

@ -0,0 +1,63 @@
/**
* Module for simplifying Indexed DB access
*/
(function() {
"use strict";
var db = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB,
request = null;
indexedDB = {};
/**
* @private
*/
request.onerror = function(event)
{
console.log("IndexedDB disallowed.");
};
/**
* @private
*/
request.onsuccess = function(event)
{
// Connect to the specified db
indexedDB.current_db = request.result;
};
/**
* Module for simplifying Indexed DB access
*
* @namespace
* @name indexedDB
* @memberOf $_
*/
indexedDB = {
current_db: null,
/**
* Connects to an indexedDB database
*
* @memberOf $_.indexedDB
* @name connect
* @function
* @param string dbname
* @param [int] version
* @param [function] onupgradeneeded
*/
connect: function(dbname, version, onupgradeneeded)
{
version = version || 0;
if(typeof onupgradeneeded !== "undefined")
{
request.onupgradeneeded = onupgradeneeded;
}
// Ask for permission to use db
this.current_db = db.open(dbname, version);
}
};
$_.ext('indexedDB', indexedDB);
}());