Commit a5af6cbd authored by Roque's avatar Roque

erp5_notebook: jsmd editor getContent method

parent 8dffd3c2
/*global window, rJS, console, RSVP, jIO, DOMParser, Blob, document, /*global window, rJS, console, RSVP, jIO, DOMParser, Blob, document,
URL, loopEventListener, promiseEventListener */ URL, loopEventListener */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, RSVP, jIO, DOMParser, document, URL, (function (window, rJS, RSVP, jIO, DOMParser, document, URL,
loopEventListener) { loopEventListener) {
...@@ -24,6 +24,10 @@ ...@@ -24,6 +24,10 @@
} }
rJS(window) rJS(window)
.ready(function (gadget) {
gadget.property_dict = {};
})
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -38,6 +42,7 @@ ...@@ -38,6 +42,7 @@
var gadget = this, var gadget = this,
base_url = document.location.toString(), base_url = document.location.toString(),
doc; doc;
gadget.property_dict.deferred = RSVP.defer();
return fetchHTML("gadget_jsmd_eval.html", base_url) return fetchHTML("gadget_jsmd_eval.html", base_url)
.push(function (result) { .push(function (result) {
...@@ -80,19 +85,33 @@ ...@@ -80,19 +85,33 @@
}); });
}) })
.declareJob('listenMessage', function () { .declareMethod('getContent', function () {
var gadget = this; var gadget = this,
content_dict = {},
dict = gadget.property_dict;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return promiseEventListener(window, "message", true); return dict.deferred.promise;
}) })
.push(function (event) { .push(function () {
content_dict[gadget.state.key] = gadget.element.querySelector("iframe")
.contentDocument.firstChild.innerHTML;
return content_dict;
});
})
.declareJob('listenMessage', function () {
var gadget = this,
dict = gadget.property_dict;
return loopEventListener(window, 'message', false, function (event) {
//only handle jsmd eval child messages //only handle jsmd eval child messages
if ((event.origin !== window.origin) || (event.data !== "jsmd_eval_done")) if ((event.origin !== window.origin) || (event.data !== "jsmd_eval_done"))
return gadget.listenMessage(); return;
console.log("JSMD Eval Done."); console.log("JSMD Eval Done.");
document.querySelector('[id="js-spinner"]').remove(); document.querySelector('[id="js-spinner"]').remove();
}); return dict.deferred.resolve();
}
);
}) })
.declareJob('listenResize', function () { .declareJob('listenResize', function () {
...@@ -106,4 +125,4 @@ ...@@ -106,4 +125,4 @@
return loopEventListener(window, 'resize', false, resize); return loopEventListener(window, 'resize', false, resize);
}); });
}(window, rJS, RSVP, jIO, DOMParser, document, URL, loopEventListener, promiseEventListener)); }(window, rJS, RSVP, jIO, DOMParser, document, URL, loopEventListener));
\ No newline at end of file \ No newline at end of file
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