Commit 61a07f31 authored by François Billioud's avatar François Billioud

fix the asynchrone load

parent f9cec3d9
......@@ -11,10 +11,11 @@ var Xinha = function() {
xinha_init();
}
this.saveEdition = function() {
getCurrentDocument().saveEdition($("#input_area").attr("value"));
getCurrentDocument().saveEdition(xinha_editors.input_area.getEditorContent());
}
this.loadContentFromDocument = function(doc) {
$("#input_area").attr("value",doc.getContent());
var setText = function() {xinha_editors.input_area.setEditorContent(doc.getContent());}
waitBeforeSucceed(function() {return xinha_editors.input_area;},setText);
}
this.load();
}
......
......@@ -32,6 +32,7 @@ Page.prototype = {
getContent: function() {return $(this.getXML()).find("content").html();},
getDependencies: function() {return $(this.getXML()).find("dependencies");},
getEditor: function() {return this.editor;},
setEditor: function(editor) {this.editor = editor;},
//loaders
/* load the xml document which contains the web page information */
......@@ -40,7 +41,7 @@ Page.prototype = {
type: "GET",
url: source,
dataType: "html",
async: false,
async: true,
success: function(data) {
getCurrentPage().setXML(data);
}
......@@ -56,21 +57,23 @@ Page.prototype = {
$(dependencies).find("scriptfile").each(function() {currentPage.include($(this).text(),"script");});//includes js
var doc = null;
var editor = null;
switch(this.name) {
case "editor":
this.editor = new Xinha();
editor = new Xinha();
if(!doc) {doc=new JSONTextDocument();}
break;
case "table":
this.editor = new SheetEditor();
editor = new SheetEditor();
if(!doc) {doc=new JSONSheetDocument();}
break;
case "illustration":
this.editor = new SVGEditor();
editor = new SVGEditor();
if(!doc) {doc=new JSONIllustrationDocument();}
break;
}
doc.setCurrentDocument();
setCurrentDocument(doc);
this.setEditor(editor);
},
/* include a javascript or a css file */
......@@ -275,7 +278,7 @@ editDocumentSettings = function() {
saveCurrentDocument = function() {
getCurrentPage().getEditor().saveEdition();
saveXHR(address);
saveXHR(addressOfTestDocument);
//saveJIO(); : JIO function
}
......
......@@ -106,21 +106,16 @@ loadXHR = function(address) {
/*
* wait an event before execute an action
*/
tryUntilSucceed = function(func) {
waitBeforeSucceed = function(required, func) {
var nb = 2;//avoid to test too much times
var retry = function() {
try {return func.call();}
catch(e) {if(nb<100) {setTimeout(retry,nb*100); alert(e);}}
var execute = function() {
//if(test()) {tryUntilSucceed(func);}
try {
if(!required.call()) {throw 0;}
func.call();}
catch(e) {if(nb<100) {setTimeout(execute,nb*100);}}
nb*=nb;
}
retry();
}
requireBeforeSucceed = function(required, func) {
var test = function() {
try {return required.call();}
catch(e) {return null;}
}
if(test()) {tryUntilSucceed(func);} else {setTimeout(test,100);};
execute();
}
......@@ -50,8 +50,8 @@
var init = function() {
initPage();
requireBeforeSucceed(function() {return getCurrentPage().getXML();},initUser);
requireBeforeSucceed(function() {return getCurrentPage().getEditor();},initDocument);
waitBeforeSucceed(function() {return getCurrentPage().getXML();},initUser);
waitBeforeSucceed(function() {return getCurrentPage().getEditor();},initDocument);
}
$(document).ready(init);
</script>
......
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