Commit 9d773a3f authored by François Billioud's avatar François Billioud

fix __proto__

parent 270253a7
/**
* Editors
*/
var Xinha = function() {
this.name = "Xinha";
this.load = function() {
_editor_url = "xinha/";
getCurrentPage().include("xinha/XinhaCore.js","script");
getCurrentPage().include("xinha/config.js","script");
xinha_init();
}
this.saveEdition = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
getCurrentDocument().saveEdition(textArea.content);
}
this.loadContent = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
textArea.content = getCurrentDocument().getContent();
}
this.load();
}
/** /**
* Text documents * Text documents
...@@ -16,7 +39,6 @@ JSONTextDocument.prototype.saveEdition = function(content) { ...@@ -16,7 +39,6 @@ JSONTextDocument.prototype.saveEdition = function(content) {
this.setLastModification(currentTime()); this.setLastModification(currentTime());
setCurrentDocument(this); setCurrentDocument(this);
} }
JSONTextDocument.prototype.setAsCurrentDocument = function() { JSONTextDocument.prototype.setAsCurrentDocument = function() {
getCurrentPage().displayDocumentTitle(this); getCurrentPage().displayDocumentTitle(this);
getCurrentPage().displayDocumentState(this); getCurrentPage().displayDocumentState(this);
...@@ -26,34 +48,16 @@ JSONTextDocument.prototype.setAsCurrentDocument = function() { ...@@ -26,34 +48,16 @@ JSONTextDocument.prototype.setAsCurrentDocument = function() {
} }
getCurrentDocument = function() { getCurrentDocument = function() {
var doc = JSON.parse(localStorage.getItem("currentDocument")); var doc = new JSONTextDocument();
doc.__proto__ = JSONTextDocument.prototype; doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc; return doc;
} }
(new JSONTextDocument()).setAsCurrentDocument();//load the document (it's just for testing)
saveCurrentDocument = function() {
/** getCurrentPage().getEditor().saveEdition();
* Editors //saveJIO(); : JIO function
*/
var Xinha = function() {
this.name = "Xinha";
this.load = function() {
_editor_url = "http://www.ungproject.com/xinha/";
getCurrentPage().include("xinha/XinhaCore.js","script");
getCurrentPage().include("xinha/config.js","script");
xinha_init();
}
this.saveEdition = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
getCurrentDocument().setContent(textArea.content);
//saveCurrentDocument(); : JIO function
}
this.loadContent = function() {
var textArea = getCurrentPage().getHTML().getElementById("input_area");
textArea.content = getCurrentDocument().getContent();
}
this.load();
} }
......
/* /*
* global variables * global variables
*/ */
...@@ -32,6 +31,7 @@ Page.prototype = { ...@@ -32,6 +31,7 @@ Page.prototype = {
getTitle: function() {return $(this.getXML()).find("title").text();}, getTitle: function() {return $(this.getXML()).find("title").text();},
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;},
//loaders //loaders
/* load the xml document which contains the web page information */ /* load the xml document which contains the web page information */
...@@ -40,9 +40,9 @@ Page.prototype = { ...@@ -40,9 +40,9 @@ Page.prototype = {
type: "GET", type: "GET",
url: source, url: source,
dataType: "html", dataType: "html",
async: true, async: false,
success: function(data) { success: function(data) {
currentPage.setXML(data); getCurrentPage().setXML(data);
} }
}); });
}, },
...@@ -94,9 +94,7 @@ Page.prototype = { ...@@ -94,9 +94,7 @@ Page.prototype = {
} }
this.getHTML().getElementById("available_languages").innerHTML = avLang; this.getHTML().getElementById("available_languages").innerHTML = avLang;
}, },
displayUserName: function(user) { displayUserName: function(user) {this.getHTML().getElementById("userName").innerHTML = user.getName();},
//alert($(this.getHTML()).find("html").html());
this.getHTML().getElementById("user_name").innerHTML = user.getName();},
//document information //document information
displayAuthorName: function(doc) {this.getHTML().getElementById("author").innerHTML = doc.getAuthor();}, displayAuthorName: function(doc) {this.getHTML().getElementById("author").innerHTML = doc.getAuthor();},
...@@ -117,10 +115,10 @@ Page.prototype = { ...@@ -117,10 +115,10 @@ Page.prototype = {
pageContent.innerHTML = this.getContent(); pageContent.innerHTML = this.getContent();
} }
} }
getCurrentPage = function() {return currentPage;} getCurrentPage = function() {return currentPage;}
setCurrentPage = function(page) { setCurrentPage = function(page) {
currentPage = new Page(page); currentPage = new Page(page);
//window.location.reload();
} }
/* /*
...@@ -131,6 +129,8 @@ var User = function() { ...@@ -131,6 +129,8 @@ var User = function() {
this.language = "en"; this.language = "en";
this.storage = "http://www.unhosted-dav.com"; this.storage = "http://www.unhosted-dav.com";
this.identityProvider = "http://www.webfinger.com"; this.identityProvider = "http://www.webfinger.com";
this.setAsCurrentUser();
} }
User.prototype = { User.prototype = {
getName: function() {return this.name;}, getName: function() {return this.name;},
...@@ -148,18 +148,17 @@ User.prototype = { ...@@ -148,18 +148,17 @@ User.prototype = {
setAsCurrentUser: function() { setAsCurrentUser: function() {
getCurrentPage().displayUserName(this); getCurrentPage().displayUserName(this);
getCurrentPage().displayLanguages(this); getCurrentPage().displayLanguages(this);
setCurrentUser(this);
} }
} }
getCurrentUser = function() { getCurrentUser = function() {
var user = JSON.parse(localStorage.getItem("currentUser")); var user = new User();
user.__proto__ = User.prototype; user.load(JSON.parse(localStorage.getItem("currentUser")))
return user; return user;
} }
setCurrentUser = function(user) { setCurrentUser = function(user) {localStorage.setItem("currentUser", JSON.stringify(user));}
localStorage.setItem("currentUser", JSON.stringify(user));
user.setAsCurrentUser();
}
//setCurrentUser(new User());
/** /**
...@@ -175,6 +174,8 @@ var JSONDocument = function() { ...@@ -175,6 +174,8 @@ var JSONDocument = function() {
this.creation=currentTime(); this.creation=currentTime();
this.lastModification=currentTime(); this.lastModification=currentTime();
this.state=Document.states.draft; this.state=Document.states.draft;
this.setAsCurrentDocument();//temp
} }
JSONDocument.prototype = { JSONDocument.prototype = {
//type //type
...@@ -203,7 +204,9 @@ JSONDocument.prototype = { ...@@ -203,7 +204,9 @@ JSONDocument.prototype = {
setAsCurrentDocument: function() { setAsCurrentDocument: function() {
setCurrentDocument(this); setCurrentDocument(this);
} },
save: function() {}
} }
Document.states = { Document.states = {
draft:{"fr":"Brouillon","en":"Draft"}, draft:{"fr":"Brouillon","en":"Draft"},
...@@ -211,8 +214,8 @@ Document.states = { ...@@ -211,8 +214,8 @@ Document.states = {
deleted:{"fr":"Supprimé","en":"Deleted"} deleted:{"fr":"Supprimé","en":"Deleted"}
} }
getCurrentDocument = function() { getCurrentDocument = function() {
var doc = JSON.parse(localStorage.getItem("currentDocument")); var doc = new JSONDocument();
doc.__proto__ = JSONDocument.prototype; doc.load(JSON.parse(localStorage.getItem("currentDocument")));
return doc; return doc;
} }
setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.stringify(doc));} setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.stringify(doc));}
...@@ -221,7 +224,10 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON. ...@@ -221,7 +224,10 @@ setCurrentDocument = function(doc) {localStorage.setItem("currentDocument",JSON.
/* /*
* tools * tools
*/ */
currentTime = function() {return (new Date()).toUTCString();}
cancel_sharing = function() {alert("cancel");} cancel_sharing = function() {alert("cancel");}
translate = function() {alert("translate");} translate = function() {alert("translate");}
submit = function() {alert("submit");} submit = function() {alert("submit");}
\ No newline at end of file
//test = new User();
\ No newline at end of file
/***
* return true if this object implements the interface
*/
Object.prototype.Implements = function(myInterface)
{
for(var property in myInterface)
{
if( typeof myInterface[property] != "string")
continue;
if(this[property]==undefined || typeof this[property] != myInterface[property] )
return false;
}
return true;
};
/**
* Load a JSON data into an object
*/
Object.prototype.load = function(data) {
for(var property in data) {
this[property] = data[property];
}
};
/**
* returns the current date
*/
currentTime = function() {return (new Date()).toUTCString();}
\ No newline at end of file
...@@ -28,14 +28,15 @@ ...@@ -28,14 +28,15 @@
<script type="text/javascript" src="js/base64.js"></script> <script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/tools.js"></script> <script type="text/javascript" src="js/tools.js"></script>
<script type="text/javascript" src="js/theme.js"></script> <script type="text/javascript" src="js/theme.js"></script>
<script type="text/javascript" src="js/editor.js"></script>
<script type="text/javascript"> <script type="text/javascript">
// initialize // initialize
init = function() { init = function() {
setCurrentPage("editor"); setCurrentPage("editor");
new User(); new User();
doc = new document.JSONTextDocument();//load the document (it's just for testing) doc = new JSONTextDocument();//load the document (it's just for testing)
//doc.setAsCurrentDocument(); doc.setAsCurrentDocument();
} }
$(document).ready(init); $(document).ready(init);
</script> </script>
...@@ -44,7 +45,7 @@ ...@@ -44,7 +45,7 @@
<body> <body>
<form id="main_form" class="main_form" <form id="main_form" class="main_form"
onsubmit="changed=false; return true" onsubmit="changed=false; return true"
action="javascript:save_current_doc()" action="javascript:saveCurrentDocument()"
method="post"> method="post">
<div class="container"> <div class="container">
......
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