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