Commit c6f8315c authored by Romain Courteaud's avatar Romain Courteaud

Release version 0.15.0

Add onLoop service.
Allow manualBootstrap.
parent 14dbf92c
This diff is collapsed.
This diff is collapsed.
...@@ -749,6 +749,19 @@ if (typeof document.contains !== 'function') { ...@@ -749,6 +749,19 @@ if (typeof document.contains !== 'function') {
return new RSVP.Promise(itsANonResolvableTrap, canceller); return new RSVP.Promise(itsANonResolvableTrap, canceller);
} }
function promiseAnimationFrame() {
var request_id;
function canceller() {
window.cancelAnimationFrame(request_id);
}
function resolver(resolve) {
request_id = window.requestAnimationFrame(resolve);
}
return new RSVP.Promise(resolver, canceller);
}
function ajax(url) { function ajax(url) {
var xhr; var xhr;
function resolver(resolve, reject) { function resolver(resolve, reject) {
...@@ -799,7 +812,8 @@ if (typeof document.contains !== 'function') { ...@@ -799,7 +812,8 @@ if (typeof document.contains !== 'function') {
scope_increment = 0, scope_increment = 0,
isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i'), isAbsoluteOrDataURL = new RegExp('^(?:[a-z]+:)?//|data:', 'i'),
is_page_unloaded = false, is_page_unloaded = false,
error_list = []; error_list = [],
bootstrap_deferred_object = new RSVP.defer();
window.addEventListener('error', function (error) { window.addEventListener('error', function (error) {
error_list.push(error); error_list.push(error);
...@@ -1160,6 +1174,34 @@ if (typeof document.contains !== 'function') { ...@@ -1160,6 +1174,34 @@ if (typeof document.contains !== 'function') {
return this; return this;
}; };
RenderJSGadget.onLoop = function (callback, delay) {
if (delay === undefined) {
delay = 0;
}
this.__service_list.push(function () {
var queue_loop = new RSVP.Queue(),
wait = function () {
queue_loop
.push(function () {
return RSVP.delay(delay);
})
.push(function () {
// Only loop when the app has the focus
return promiseAnimationFrame();
})
.push(function () {
return callback.apply(this, []);
})
.push(function () {
wait();
});
};
wait();
return queue_loop;
});
return this;
};
function runJob(gadget, name, callback, argument_list) { function runJob(gadget, name, callback, argument_list) {
var job_promise = new RSVP.Queue() var job_promise = new RSVP.Queue()
.push(function () { .push(function () {
...@@ -1410,6 +1452,8 @@ if (typeof document.contains !== 'function') { ...@@ -1410,6 +1452,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.declareService; RenderJSGadget.declareService;
RenderJSEmbeddedGadget.onEvent = RenderJSEmbeddedGadget.onEvent =
RenderJSGadget.onEvent; RenderJSGadget.onEvent;
RenderJSEmbeddedGadget.onLoop =
RenderJSGadget.onLoop;
RenderJSEmbeddedGadget.prototype = new RenderJSGadget(); RenderJSEmbeddedGadget.prototype = new RenderJSGadget();
RenderJSEmbeddedGadget.prototype.constructor = RenderJSEmbeddedGadget; RenderJSEmbeddedGadget.prototype.constructor = RenderJSEmbeddedGadget;
...@@ -1473,6 +1517,8 @@ if (typeof document.contains !== 'function') { ...@@ -1473,6 +1517,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.declareService; RenderJSGadget.declareService;
RenderJSIframeGadget.onEvent = RenderJSIframeGadget.onEvent =
RenderJSGadget.onEvent; RenderJSGadget.onEvent;
RenderJSIframeGadget.onLoop =
RenderJSGadget.onLoop;
RenderJSIframeGadget.prototype = new RenderJSGadget(); RenderJSIframeGadget.prototype = new RenderJSGadget();
RenderJSIframeGadget.prototype.constructor = RenderJSIframeGadget; RenderJSIframeGadget.prototype.constructor = RenderJSIframeGadget;
...@@ -1842,6 +1888,8 @@ if (typeof document.contains !== 'function') { ...@@ -1842,6 +1888,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.declareService; RenderJSGadget.declareService;
tmp_constructor.onEvent = tmp_constructor.onEvent =
RenderJSGadget.onEvent; RenderJSGadget.onEvent;
tmp_constructor.onLoop =
RenderJSGadget.onLoop;
tmp_constructor.prototype = new RenderJSGadget(); tmp_constructor.prototype = new RenderJSGadget();
tmp_constructor.prototype.constructor = tmp_constructor; tmp_constructor.prototype.constructor = tmp_constructor;
tmp_constructor.prototype.__path = url; tmp_constructor.prototype.__path = url;
...@@ -1989,6 +2037,16 @@ if (typeof document.contains !== 'function') { ...@@ -1989,6 +2037,16 @@ if (typeof document.contains !== 'function') {
// Bootstrap process. Register the self gadget. // Bootstrap process. Register the self gadget.
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// Manually initializes the self gadget if the DOMContentLoaded event
// is triggered before everything was ready.
// (For instance, the HTML-tag for the self gadget gets inserted after
// page load)
renderJS.manualBootstrap = function () {
bootstrap_deferred_object.resolve();
};
function bootstrap() { function bootstrap() {
var url = removeHash(window.location.href), var url = removeHash(window.location.href),
TmpConstructor, TmpConstructor,
...@@ -2054,6 +2112,8 @@ if (typeof document.contains !== 'function') { ...@@ -2054,6 +2112,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.declareService; RenderJSGadget.declareService;
TmpConstructor.onEvent = TmpConstructor.onEvent =
RenderJSGadget.onEvent; RenderJSGadget.onEvent;
TmpConstructor.onLoop =
RenderJSGadget.onLoop;
TmpConstructor.prototype = new RenderJSGadget(); TmpConstructor.prototype = new RenderJSGadget();
TmpConstructor.prototype.constructor = TmpConstructor; TmpConstructor.prototype.constructor = TmpConstructor;
TmpConstructor.prototype.__path = url; TmpConstructor.prototype.__path = url;
...@@ -2182,6 +2242,8 @@ if (typeof document.contains !== 'function') { ...@@ -2182,6 +2242,8 @@ if (typeof document.contains !== 'function') {
RenderJSGadget.declareJob; RenderJSGadget.declareJob;
TmpConstructor.onEvent = TmpConstructor.onEvent =
RenderJSGadget.onEvent; RenderJSGadget.onEvent;
TmpConstructor.onLoop =
RenderJSGadget.onLoop;
TmpConstructor.declareAcquiredMethod = TmpConstructor.declareAcquiredMethod =
RenderJSGadget.declareAcquiredMethod; RenderJSGadget.declareAcquiredMethod;
TmpConstructor.allowPublicAcquisition = TmpConstructor.allowPublicAcquisition =
...@@ -2301,7 +2363,16 @@ if (typeof document.contains !== 'function') { ...@@ -2301,7 +2363,16 @@ if (typeof document.contains !== 'function') {
throw e; throw e;
}); });
} }
document.addEventListener('DOMContentLoaded', init, false); document.addEventListener('DOMContentLoaded',
bootstrap_deferred_object.resolve, false);
// Return Promies/Queue here instead of directly calling init()
return new RSVP.Queue()
.push(function () {
return bootstrap_deferred_object.promise;
})
.push(function () {
return init();
});
}); });
loading_gadget_promise loading_gadget_promise
......
This diff is collapsed.
{ {
"name": "renderjs", "name": "renderjs",
"version": "0.14.1", "version": "0.15.0",
"description": "RenderJs provides HTML5 gadgets", "description": "RenderJs provides HTML5 gadgets",
"main": "dist/renderjs-latest.js", "main": "dist/renderjs-latest.js",
"dependencies": { "dependencies": {
......
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