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