Commit 587b48f2 authored by Xiaowu Zhang's avatar Xiaowu Zhang

change use of requestAnimationFrame

parent 8bce8679
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
}) })
.allowPublicAcquisition("plGive", function (param_list) { .allowPublicAcquisition("plGive", function (param_list) {
if (this.save === undefined) { if (this.save === undefined) {
return 0; return this.save;
} }
return this.save[param_list[0]]; return this.save[param_list[0]];
}) })
...@@ -88,6 +88,12 @@ ...@@ -88,6 +88,12 @@
return jio_gadget.post.apply(jio_gadget, param_list); return jio_gadget.post.apply(jio_gadget, param_list);
}); });
}) })
.allowPublicAcquisition("invalideJioSave", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) {
return jio_gadget.invalideJioSave.apply(jio_gadget, param_list);
});
})
.allowPublicAcquisition("jio_putAttachment", function (param_list) { .allowPublicAcquisition("jio_putAttachment", function (param_list) {
return this.getDeclaredGadget(storageType(this.storageType)) return this.getDeclaredGadget(storageType(this.storageType))
.push(function (jio_gadget) { .push(function (jio_gadget) {
......
...@@ -13,6 +13,9 @@ ...@@ -13,6 +13,9 @@
.declareMethod('createJio', function (jio_options) { .declareMethod('createJio', function (jio_options) {
this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options); this.state_parameter_dict.jio_storage = jIO.createJIO(jio_options);
}) })
.declareMethod('invalideJioSave', function (jio_options) {
this.save = {};
})
.declareMethod('allDocs', function () { .declareMethod('allDocs', function () {
var storage = this.state_parameter_dict.jio_storage, var storage = this.state_parameter_dict.jio_storage,
that = this; that = this;
......
...@@ -90,12 +90,28 @@ ...@@ -90,12 +90,28 @@
} }
function promiseRequestAnimation(callback) { function promiseRequestAnimation(callback) {
var animationId; var animationId,
callback_promise;
function canceller() { function canceller() {
window.cancelAnimationFrame(animationId); window.cancelAnimationFrame(animationId);
if (callback_promise !== undefined) {
callback_promise.cancel();
}
} }
function resolver(resolve) { //xxx
animationId = window.requestAnimationFrame(callback); function resolver(resolve, reject) {
function tmp() {
callback_promise = new RSVP.Queue()
.push(function () {
callback();
animationId = window.requestAnimationFrame(tmp);
})
.push(undefined, function (error) {
canceller();
reject(error);
});
}
animationId = window.requestAnimationFrame(tmp);
} }
return new RSVP.Promise(resolver, canceller); return new RSVP.Promise(resolver, canceller);
} }
...@@ -122,9 +138,6 @@ ...@@ -122,9 +138,6 @@
gradient.addColorStop(0, '#f00'); gradient.addColorStop(0, '#f00');
that.audio.play(); that.audio.play();
drawFrame = function () { drawFrame = function () {
if (that.audio.duration !== 0) {
bar_context.max = that.audio.duration;
}
array = getFFTValue(that); array = getFFTValue(that);
canvasCtx.clearRect(0, 0, cwidth, cheight); canvasCtx.clearRect(0, 0, cwidth, cheight);
step = Math.round(array.length / meterNum); step = Math.round(array.length / meterNum);
...@@ -139,7 +152,6 @@ ...@@ -139,7 +152,6 @@
meterWidth, meterWidth,
cheight); //the meter cheight); //the meter
} }
return promiseRequestAnimation(drawFrame);
}; };
return promiseRequestAnimation(drawFrame); return promiseRequestAnimation(drawFrame);
} }
...@@ -161,13 +173,11 @@ ...@@ -161,13 +173,11 @@
return g.plGive("type"); return g.plGive("type");
}) })
.push(function (value) { .push(function (value) {
g.filter.type = value; g.filter.type = value || 0;
return g.plGive("value"); return g.plGive("value");
}) })
.push(function (value) { .push(function (value) {
if (value === 0) { value = value || 5000;
value = 5000;
}
g.filter.frequency.value = value; g.filter.frequency.value = value;
}) })
.push(function () { .push(function () {
...@@ -222,6 +232,7 @@ ...@@ -222,6 +232,7 @@
return promiseEventListener(g.audio, "loadedmetadata", false); return promiseEventListener(g.audio, "loadedmetadata", false);
}) })
.push(function () { .push(function () {
bar_context.max = g.audio.duration;
return g.plEnablePage(); return g.plEnablePage();
}) })
.push(function () { .push(function () {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
.declareAcquiredMethod("displayThisTitle", "displayThisTitle") .declareAcquiredMethod("displayThisTitle", "displayThisTitle")
.declareAcquiredMethod("plEnablePage", "plEnablePage") .declareAcquiredMethod("plEnablePage", "plEnablePage")
.declareAcquiredMethod("plDisablePage", "plDisablePage") .declareAcquiredMethod("plDisablePage", "plDisablePage")
.declareAcquiredMethod("invalideJioSave", "invalideJioSave")
.declareMethod("render", function () { .declareMethod("render", function () {
return this.displayThisTitle("upload"); return this.displayThisTitle("upload");
}) })
...@@ -66,6 +67,9 @@ ...@@ -66,6 +67,9 @@
.push(function () { .push(function () {
return g.plDisablePage(); return g.plDisablePage();
}) })
.push(function () {
return g.invalideJioSave();
})
.push(function () { .push(function () {
length = input_context.files.length; length = input_context.files.length;
for (i = 0; i < length; i += 1) { for (i = 0; i < length; i += 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