Permalink
Browse files

Added .rename() and .import() and Fixed some missing commas in the do…

…cs - Fixed #29 Fixed #28
  • Loading branch information...
1 parent 35afdeb commit 5cf1e6c77ad37bdf2afaabea2f447f657e766c01 @OscarGodson OscarGodson committed Feb 26, 2012
Showing with 82 additions and 7 deletions.
  1. +28 −3 README.md
  2. +34 −1 epiceditor.js
  3. +20 −3 index.html
View
@@ -1,4 +1,4 @@
-**alpha 0.0.1**
+**alpha 0.0.2**
_Note: this is a developer preview. We're releasing early so we can get other people's input and pull requests. While it works, there are still bugs and missing features. Use at your own risk._
@@ -55,6 +55,8 @@ The constructor is first (`EpicEditor()`), but everything after are methods of t
<li><a href="#api-options"><code>options()</code></a></li>
<li><a href="#api-get"><code>get()</code></a></li>
<li><a href="#api-open"><code>open()</code></a></li>
+ <li><a href="#api-import"><code>import()</code></a></li>
+ <li><a href="#api-rename"><code>rename()</code></a></li>
<li><a href="#api-save"><code>save()</code></a></li>
<li><a href="#api-on"><code>on()</code></a></li>
<li><a href="#api-emit"><code>emit()</code></a></li>
@@ -120,11 +122,11 @@ Lets you set options for the editor. The example below has all the options avail
```javascript
editor.options({
file:{
- name:'example'
+ name:'example',
defaultContent:'Write text in here!'
},
themes:{
- editor:'/css/epiceditor/editor-custom.css'
+ editor:'/css/epiceditor/editor-custom.css',
preview:'/css/epiceditor/preview-custom.css'
},
focusOnLoad:true
@@ -158,6 +160,29 @@ openFileBtn.onclick = function(){
}
```
+<h6 id="api-import">import(<em>filename</em>,[<em>content</em>])</h6>
+Imports a string of markdown into a file. If the file already exists, it will be overwritten. Useful if you want to inject a bunch of content via AJAX.
+
+**Example:**
+
+```javascript
+importFileBtn.onclick = function(){
+ ee.import('some-file',"#Imported markdown\nFancy, huh?"); //Imports a file when the user clicks this button
+}
+```
+
+<h6 id="api-rename">rename(<em>oldName</em>,<em>newName</em>)</h6>
+Renames a file.
+
+**Example:**
+
+```javascript
+renameFileBtn.onclick = function(){
+ var newName = prompt('What do you want to rename this file to?');
+ ee.rename('old-filename',newName); //Prompts a user and renames a file on button click
+}
+```
+
<h6 id="api-save">save()</h6>
Manually save a file. EpicEditor will save on keyup by default but if you are inserting content via ajax for example, this is useful.
View
@@ -600,7 +600,7 @@
* @param {string} name The name of the file you want to remove from localStorage
* @returns {object} EpicEditor will be returned
*/
- EpicEditor.prototype.remove = function(name) {
+ EpicEditor.prototype.remove = function(name){
var self = this;
name = name || self.settings.file.name;
var s = JSON.parse(localStorage['epiceditor']);
@@ -610,6 +610,39 @@
return this;
};
+
+ /**
+ * Imports a MD file instead of having to manual inject content via
+ * .get(editor).value = 'the content'
+ * @param {string} name The name of the file
+ * @param {stirng} content The MD to import
+ * @returns {object} EpicEditor will be returned
+ */
+ EpicEditor.prototype.import = function(name,content){
+ var self = this;
+ content = content || '';
+ self.open(name).get('editor').value = content;
+ //we reopen the file after saving so that it will preview correctly if in the previewer
+ self.save().open(name);
+ return this;
+ };
+
+ /**
+ * Renames a file
+ * @param {string} oldName The old file name
+ * @param {string} newName The new file name
+ * @returns {object} EpicEditor will be returned
+ */
+ EpicEditor.prototype.rename = function(oldName,newName){
+ var self = this;
+ var s = JSON.parse(localStorage['epiceditor']);
+ s.files[newName] = s.files[oldName];
+ delete s.files[oldName];
+ localStorage['epiceditor'] = JSON.stringify(s);
+ self.open(newName);
+ return this;
+ };
+
/**
* Converts content into HTML from markdown
* @returns {string} Returns the HTML that was converted from the markdown
View
@@ -23,7 +23,7 @@
</head>
<body>
<div id="wrapper">
- <h1>EpicEditor <span>alpha 0.0.1</span></h1>
+ <h1>EpicEditor <span>alpha 0.0.2</span></h1>
<h2>An Embeddable JavaScript Markdown Editor</h2>
<p>EpicEditor is an embeddable JavaScript <a href="http://daringfireball.net/projects/markdown/">Markdown</a> editor with some minor Markdown enhancements such as automatic link creation and code fencing.</p>
@@ -64,6 +64,8 @@ <h4 id="api">API</h4>
<li><a href="#api-options"><code>options()</code></a></li>
<li><a href="#api-get"><code>get()</code></a></li>
<li><a href="#api-open"><code>open()</code></a></li>
+ <li><a href="#api-import"><code>import()</code></a></li>
+ <li><a href="#api-rename"><code>rename()</code></a></li>
<li><a href="#api-save"><code>save()</code></a></li>
<li><a href="#api-on"><code>on()</code></a></li>
<li><a href="#api-emit"><code>emit()</code></a></li>
@@ -106,11 +108,11 @@ <h6 id="api-options">options(<em>options</em>)</h6>
<p class="example">Example:</p>
<pre><code class="javascript">editor.options({
file:{
- name:'example'
+ name:'example',
defaultContent:'Write text in here!'
},
themes:{
- editor:'/css/epiceditor/editor-custom.css'
+ editor:'/css/epiceditor/editor-custom.css',
preview:'/css/epiceditor/preview-custom.css'
},
focusOnLoad:true
@@ -136,6 +138,21 @@ <h6 id="api-open">open(<em>filename</em>)</h6>
ee.open('some-file'); //Open a file when the user clicks this button
}</code></pre>
+ <h6 id="api-import">import(<em>filename</em>,[<em>content</em>])</h6>
+ <p>Imports a string of markdown into a file. If the file already exists, it will be overwritten. Useful if you want to inject a bunch of content via AJAX.</p>
+ <p class="example">Example:</p>
+ <pre><code class="javascript">importFileBtn.onclick = function(){
+ ee.import('some-file',"#Imported markdown\nFancy, huh?"); //Imports a file when the user clicks this button
+}</code></pre>
+
+ <h6 id="api-rename">rename(<em>oldName</em>,<em>newName</em>)</h6>
+ <p>Renames a file.</p>
+ <p class="example">Example:</p>
+ <pre><code class="javascript">renameFileBtn.onclick = function(){
+ var newName = prompt('What do you want to rename this file to?');
+ ee.rename('old-filename',newName); //Prompts a user and renames a file on button click
+}</code></pre>
+
<h6 id="api-save">save()</h6>
<p>Manually save a file. EpicEditor will save on keyup by default but if you are inserting content via ajax for example, this is useful.</p>
<p class="example">Example:</p>

0 comments on commit 5cf1e6c

Please sign in to comment.