Commit e7f8a34d authored by Xiaowu Zhang's avatar Xiaowu Zhang

add indexeddbstorage&httpstorage switch

parent 8284d44e
...@@ -6,6 +6,18 @@ ...@@ -6,6 +6,18 @@
$.mobile.linkBindingEnabled = false; $.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = false; $.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false; $.mobile.pushStateEnabled = false;
var gadget_list = {
"upload" : {"0" : "../audioplayer_upload/index.html",
"1" : "../audioplayer_playlist/index.html"},
"playlist" : {"0" : "../audioplayer_playlist/index.html",
"1" : "../audioplayer_playlist/index.html"},
"control" : {"0" : "../audioplayer_control/index.html",
"1" : "../audioplayer_control/index.html"}
},
allStorageType = ["indexeddbStorage", "httpStorage"];
function storageType(type) {
return allStorageType[type];
}
function disablePage(g) { function disablePage(g) {
var overlay = document.createElement('div'), var overlay = document.createElement('div'),
loader = document.createElement('div'), loader = document.createElement('div'),
...@@ -51,31 +63,31 @@ ...@@ -51,31 +63,31 @@
return this.save[param_list[0]]; return this.save[param_list[0]];
}) })
.allowPublicAcquisition("allDocs", function (param_list) { .allowPublicAcquisition("allDocs", function (param_list) {
return this.getDeclaredGadget("jio") return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.allDocs.apply(jio_gadget, param_list); return jio_gadget.allDocs.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("jio_post", function (param_list) { .allowPublicAcquisition("jio_post", function (param_list) {
return this.getDeclaredGadget("jio") return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list); return jio_gadget.post.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("jio_putAttachment", function (param_list) { .allowPublicAcquisition("jio_putAttachment", function (param_list) {
return this.getDeclaredGadget("jio") return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list); return jio_gadget.putAttachment.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("jio_getAttachment", function (param_list) { .allowPublicAcquisition("jio_getAttachment", function (param_list) {
return this.getDeclaredGadget("jio") return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.getAttachment.apply(jio_gadget, param_list); return jio_gadget.getAttachment.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("jio_get", function (param_list) { .allowPublicAcquisition("jio_get", function (param_list) {
return this.getDeclaredGadget("jio") return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
return jio_gadget.get.apply(jio_gadget, param_list); return jio_gadget.get.apply(jio_gadget, param_list);
}); });
...@@ -87,13 +99,20 @@ ...@@ -87,13 +99,20 @@
rJS(window) rJS(window)
.ready(function (g) { .ready(function (g) {
var jio_gadget; return g.getDeclaredGadget("httpStorage")
return g.getDeclaredGadget("jio") .push(function (gadget) {
return gadget.createJio(
{ "type" : "http",//indexeddb
"database" : "http://localhost:8080/"} //test
);
})
.push(function () {
return g.getDeclaredGadget("indexeddbStorage");
})
.push(function (gadget) { .push(function (gadget) {
jio_gadget = gadget; return gadget.createJio(
return jio_gadget.createJio( { "type" : "indexeddb",
{ "type" : "http", "database" : "test"}
"database" : "http://192.168.242.63:8080/"}
); );
}); });
}) })
...@@ -109,8 +128,16 @@ ...@@ -109,8 +128,16 @@
return gadget.aq_pleasePublishMyState({page: "playlist"}) return gadget.aq_pleasePublishMyState({page: "playlist"})
.push(gadget.pleaseRedirectMyHash.bind(gadget)); .push(gadget.pleaseRedirectMyHash.bind(gadget));
} }
gadget.storageType = gadget.storageType || 0;
if (options.page === "playlist") {
if (options.id === "indexeddbStorage") {
gadget.storageType = 0;
} else if (options.id === "httpStorage") {
gadget.storageType = 1;
}
}
return gadget.declareGadget( return gadget.declareGadget(
"../audioplayer_" + options.page + "/index.html" gadget_list[options.page][gadget.storageType]
).push(function (g) { ).push(function (g) {
disablePage(gadget); disablePage(gadget);
page_gadget = g; page_gadget = g;
......
...@@ -24,7 +24,10 @@ ...@@ -24,7 +24,10 @@
</div> </div>
<div class="jio" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="jio" > <div class="indexeddbStorage" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="indexeddbStorage" >
</div>
<div class="httpStorage" data-gadget-url="../audioplayer_bridge/index.html" data-gadget-scope="httpStorage" >
</div> </div>
<article class="gadget_container"></article> <article class="gadget_container"></article>
......
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
(function (window, rJS, RSVP, loopEventListener, $, promiseEventListener) { (function (window, rJS, RSVP, loopEventListener, $, promiseEventListener) {
"use strict"; "use strict";
var gk = rJS(window), var gk = rJS(window),
audioCtx = new window.AudioContext(), AudioContext = window.AudioContext || window.webkitAudioContext
|| window.mozAudiocontext || window.msAudioContext,
audioCtx = new AudioContext(),
myLoopEventListener = function (target, type, callback, myLoopEventListener = function (target, type, callback,
allowDefault) { allowDefault) {
////////////////////////// //////////////////////////
......
...@@ -29,5 +29,16 @@ ...@@ -29,5 +29,16 @@
<ul data-role="listview" data-split-theme="d"> <ul data-role="listview" data-split-theme="d">
</ul> </ul>
</div> </div>
<div data-role="footer" data-position="fixed" data-theme="b">
<div data-role="navbar">
<ul>
<li><a data-role="button" class="indexeddbStorage" data-icon="arrow-l">indexeddbStorage</a></li>
<li><a data-role="button" class="httpStorage" data-icon="arrow-r">httpStorage</a></li>
</ul>
</div><!-- /navbar -->
</div><!-- /footer -->
</body> </body>
</html> </html>
...@@ -21,6 +21,20 @@ ...@@ -21,6 +21,20 @@
.push(function () { .push(function () {
return gadget.displayThisTitle("playlist"); return gadget.displayThisTitle("playlist");
}) })
.push(function () {
return RSVP.all([
gadget.displayThisPage({page: "playlist",
id : "indexeddbStorage"}),
gadget.displayThisPage({page: "playlist",
id : "httpStorage"})
]);
})
.push(function (param_list) {
gadget.__element.getElementsByClassName('indexeddbStorage')[0]
.href = param_list[0];
gadget.__element.getElementsByClassName('httpStorage')[0]
.href = param_list[1];
})
.push(function () { .push(function () {
return gadget.allDocs({"include_docs": true}); return gadget.allDocs({"include_docs": true});
}) })
...@@ -29,7 +43,8 @@ ...@@ -29,7 +43,8 @@
i, i,
j, j,
exp; exp;
if (options.id !== undefined) { if (options.id !== undefined && options.id !== "indexeddbStorage"
&& options.id !== "httpStorage") {
for (i = 0, j = 0; i < e.data.rows.length; i += 1) { for (i = 0, j = 0; i < e.data.rows.length; i += 1) {
exp = new RegExp(options.id, "i"); exp = new RegExp(options.id, "i");
if (e.data.rows[i].doc.title.search(exp) !== -1) { if (e.data.rows[i].doc.title.search(exp) !== -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment