Commit e7f8a34d authored by Xiaowu Zhang's avatar Xiaowu Zhang

add indexeddbstorage&httpstorage switch

parent 8284d44e
......@@ -6,6 +6,18 @@
$.mobile.linkBindingEnabled = false;
$.mobile.hashListeningEnabled = 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) {
var overlay = document.createElement('div'),
loader = document.createElement('div'),
......@@ -51,31 +63,31 @@
return this.save[param_list[0]];
})
.allowPublicAcquisition("allDocs", function (param_list) {
return this.getDeclaredGadget("jio")
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.allDocs.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_post", function (param_list) {
return this.getDeclaredGadget("jio")
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.post.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_putAttachment", function (param_list) {
return this.getDeclaredGadget("jio")
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.putAttachment.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_getAttachment", function (param_list) {
return this.getDeclaredGadget("jio")
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.getAttachment.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_get", function (param_list) {
return this.getDeclaredGadget("jio")
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.get.apply(jio_gadget, param_list);
});
......@@ -87,13 +99,20 @@
rJS(window)
.ready(function (g) {
var jio_gadget;
return g.getDeclaredGadget("jio")
return g.getDeclaredGadget("httpStorage")
.push(function (gadget) {
return gadget.createJio(
{ "type" : "http",//indexeddb
"database" : "http://localhost:8080/"} //test
);
})
.push(function () {
return g.getDeclaredGadget("indexeddbStorage");
})
.push(function (gadget) {
jio_gadget = gadget;
return jio_gadget.createJio(
{ "type" : "http",
"database" : "http://192.168.242.63:8080/"}
return gadget.createJio(
{ "type" : "indexeddb",
"database" : "test"}
);
});
})
......@@ -109,8 +128,16 @@
return gadget.aq_pleasePublishMyState({page: "playlist"})
.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(
"../audioplayer_" + options.page + "/index.html"
gadget_list[options.page][gadget.storageType]
).push(function (g) {
disablePage(gadget);
page_gadget = g;
......
......@@ -24,7 +24,10 @@
</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>
<article class="gadget_container"></article>
......
......@@ -6,7 +6,9 @@
(function (window, rJS, RSVP, loopEventListener, $, promiseEventListener) {
"use strict";
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,
allowDefault) {
//////////////////////////
......
......@@ -29,5 +29,16 @@
<ul data-role="listview" data-split-theme="d">
</ul>
</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>
</html>
......@@ -21,6 +21,20 @@
.push(function () {
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 () {
return gadget.allDocs({"include_docs": true});
})
......@@ -29,7 +43,8 @@
i,
j,
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) {
exp = new RegExp(options.id, "i");
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