Skip to content

Commit

Permalink
Ticket #85 - First steps to getting fileList working
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarGodson committed Jun 18, 2012
1 parent cc280c4 commit 5b6ac73
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
20 changes: 15 additions & 5 deletions epiceditor/js/epiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@
defaultStorage = JSON.stringify(defaultStorage);
localStorage[self.settings.localStorageName] = defaultStorage;
}
else if (JSON.parse(localStorage[self.settings.localStorageName])[self.settings.file.name] === undefined) {
_defaultFile = JSON.parse(localStorage[self.settings.localStorageName])[self.settings.file.name];
else if (self.fileList(self.settings.file.name) === undefined) {
_defaultFile = self.fileList(self.settings.file.name);
_defaultFile = self._defaultFileSchema();
_defaultFile.content = self.settings.file.defaultContent;
}
Expand Down Expand Up @@ -965,7 +965,7 @@
name = name || self.settings.file.name;
self.settings.file.name = name;
if (localStorage && localStorage[self.settings.localStorageName]) {
fileObj = JSON.parse(localStorage[self.settings.localStorageName]);
fileObj = self.fileList();
if (fileObj[name] !== undefined) {
_setText(self.editor, fileObj[name].content);
self.emit('read');
Expand Down Expand Up @@ -1105,7 +1105,7 @@
name = name || self.settings.file.name;
kind = kind || 'text';

file = JSON.parse(localStorage[self.settings.localStorageName])[name]
file = self.fileList(name);

// If the file doesn't exist just return early with undefined
if (file === undefined) {
Expand All @@ -1129,6 +1129,16 @@
}
}

EpicEditor.prototype.fileList = function (name) {
var files = JSON.parse(localStorage[this.settings.localStorageName]);
if (name) {
return files[name];
}
else {
return files;
}
}

// EVENTS
// TODO: Support for namespacing events like "preview.foo"
/**
Expand Down Expand Up @@ -1156,7 +1166,7 @@
var self = this
, x;

data = data || JSON.parse(localStorage[self.settings.localStorageName])[self.settings.file.name];
data = data || self.fileList(self.settings.file.name);

if (!this.events[ev]) {
return;
Expand Down
Loading

0 comments on commit 5b6ac73

Please # to comment.