mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-07-02 23:54:28 -06:00
Merge pull request #45 from frmendes/development
Adds Gulpfile and a few extra options
This commit is contained in:
commit
e84f985e3d
3
.gitignore
vendored
3
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
localtesting/*
|
localtesting/*
|
||||||
|
node_modules/
|
||||||
|
@ -29,7 +29,7 @@ Pure JavaScript method
|
|||||||
|
|
||||||
```HTML
|
```HTML
|
||||||
<script>
|
<script>
|
||||||
var simplemde = new SimpleMDE({ element: document.getElementById("MyID") });
|
var simplemde = new SimpleMDE( {element: document.getElementById("MyID")} );
|
||||||
simplemde.render();
|
simplemde.render();
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
@ -38,7 +38,7 @@ jQuery method
|
|||||||
|
|
||||||
```HTML
|
```HTML
|
||||||
<script>
|
<script>
|
||||||
var simplemde = new SimpleMDE({ element: $("#MyID")[0] });
|
var simplemde = new SimpleMDE( {element: $("#MyID")[0]} );
|
||||||
simplemde.render();
|
simplemde.render();
|
||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
@ -170,4 +170,4 @@ As mentioned earlier, SimpleMDE is an improvement of [lepture's Editor project](
|
|||||||
- Simplified the toolbar
|
- Simplified the toolbar
|
||||||
- Many new options during instantiation
|
- Many new options during instantiation
|
||||||
- New icons and tooltips
|
- New icons and tooltips
|
||||||
- Additional keyboard shortcuts
|
- Additional keyboard shortcuts
|
||||||
|
8
dist/simplemde.min.css
vendored
8
dist/simplemde.min.css
vendored
File diff suppressed because one or more lines are too long
20
dist/simplemde.min.js
vendored
20
dist/simplemde.min.js
vendored
File diff suppressed because one or more lines are too long
36
gulpfile.js
Normal file
36
gulpfile.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
var gulp = require('gulp'),
|
||||||
|
minifycss = require('gulp-minify-css'),
|
||||||
|
uglify = require('gulp-uglify'),
|
||||||
|
concat = require('gulp-concat');
|
||||||
|
|
||||||
|
gulp.task('scripts', function() {
|
||||||
|
var js_files = [
|
||||||
|
'./src/js/codemirror/codemirror.js',
|
||||||
|
'./src/js/codemirror/continuelist.js',
|
||||||
|
'./src/js/codemirror/fullscreen.js',
|
||||||
|
'./src/js/codemirror/markdown.js',
|
||||||
|
'./src/js/codemirror/overlay.js',
|
||||||
|
'./src/js/codemirror/gfm.js',
|
||||||
|
'./src/js/codemirror/xml.js',
|
||||||
|
'./src/js/typo.js',
|
||||||
|
'./src/js/spell-checker.js',
|
||||||
|
'./src/js/marked.js',
|
||||||
|
'./src/js/simplemde.js'];
|
||||||
|
|
||||||
|
return gulp.src(js_files)
|
||||||
|
.pipe(concat('simplemde.min.js'))
|
||||||
|
.pipe(gulp.dest('dist'))
|
||||||
|
.pipe(uglify())
|
||||||
|
.pipe(gulp.dest('dist'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('styles', function() {
|
||||||
|
return gulp.src('./src/css/*.css')
|
||||||
|
.pipe(concat('simplemde.min.css'))
|
||||||
|
.pipe(gulp.dest('dist'))
|
||||||
|
.pipe(minifycss())
|
||||||
|
.pipe(gulp.dest('dist'));
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('default', ['scripts', 'styles']);
|
||||||
|
|
14
package.json
Normal file
14
package.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name" : "simplemde-markdown-editor",
|
||||||
|
"main" : "gulpfile.js",
|
||||||
|
"dependencies" : {
|
||||||
|
"gulp" : "*",
|
||||||
|
"gulp-minify-css" : "*",
|
||||||
|
"gulp-uglify" : "*",
|
||||||
|
"gulp-concat" : "*"
|
||||||
|
},
|
||||||
|
"repository" : {
|
||||||
|
"type" : "git",
|
||||||
|
"url" : "https://github.com/NextStepWebs/simplemde-markdown-editor"
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
# How to compile
|
|
||||||
Minify the JS in this order:
|
|
||||||
|
|
||||||
1. `codemirror/codemirror.js`
|
|
||||||
1. `codemirror/continuelist.js`
|
|
||||||
1. `codemirror/fullscreen.js`
|
|
||||||
1. `codemirror/markdown.js`
|
|
||||||
1. `codemirror/overlay.js`
|
|
||||||
1. `codemirror/gfm.js`
|
|
||||||
1. `codemirror/xml.js`
|
|
||||||
1. `typo/typo.js`
|
|
||||||
1. `spell-checker/spell-checker.js`
|
|
||||||
1. `marked.js`
|
|
||||||
1. `simplemde.js`
|
|
||||||
|
|
||||||
Minify the CSS in this order:
|
|
||||||
|
|
||||||
1. `codemirror/codemirror.css`
|
|
||||||
1. `simplemde.css`
|
|
||||||
1. `spell-checker/spell-checker.css`
|
|
@ -1,3 +1,3 @@
|
|||||||
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment) {
|
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment) {
|
||||||
background: rgba(255, 0, 0, .15);
|
background: rgba(255, 0, 0, .15);
|
||||||
}
|
}
|
@ -33,10 +33,10 @@ function createIcon(options, enableTooltips) {
|
|||||||
options = options || {};
|
options = options || {};
|
||||||
var el = document.createElement('a');
|
var el = document.createElement('a');
|
||||||
enableTooltips = (enableTooltips == undefined) ? true : enableTooltips;
|
enableTooltips = (enableTooltips == undefined) ? true : enableTooltips;
|
||||||
|
|
||||||
if (options.title && enableTooltips) {
|
if (options.title && enableTooltips) {
|
||||||
el.title = options.title;
|
el.title = options.title;
|
||||||
|
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
el.title = el.title.replace('Ctrl', '⌘');
|
el.title = el.title.replace('Ctrl', '⌘');
|
||||||
el.title = el.title.replace('Alt', '⌥');
|
el.title = el.title.replace('Alt', '⌥');
|
||||||
@ -96,9 +96,9 @@ function getState(cm, pos) {
|
|||||||
function toggleFullScreen(editor) {
|
function toggleFullScreen(editor) {
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
|
||||||
|
|
||||||
var toolbarButton = editor.toolbarElements.fullscreen;
|
var toolbarButton = editor.toolbarElements.fullscreen;
|
||||||
|
|
||||||
if (!/active/.test(toolbarButton.className)) {
|
if (!/active/.test(toolbarButton.className)) {
|
||||||
toolbarButton.className += " active";
|
toolbarButton.className += " active";
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ function togglePreview(editor) {
|
|||||||
function _replaceSelection(cm, active, start, end) {
|
function _replaceSelection(cm, active, start, end) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var text;
|
var text;
|
||||||
var startPoint = cm.getCursor('start');
|
var startPoint = cm.getCursor('start');
|
||||||
var endPoint = cm.getCursor('end');
|
var endPoint = cm.getCursor('end');
|
||||||
@ -273,7 +273,7 @@ function _replaceSelection(cm, active, start, end) {
|
|||||||
function _toggleLine(cm, name) {
|
function _toggleLine(cm, name) {
|
||||||
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
if (/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stat = getState(cm);
|
var stat = getState(cm);
|
||||||
var startPoint = cm.getCursor('start');
|
var startPoint = cm.getCursor('start');
|
||||||
var endPoint = cm.getCursor('end');
|
var endPoint = cm.getCursor('end');
|
||||||
@ -310,7 +310,7 @@ function _toggleLine(cm, name) {
|
|||||||
function _toggleBlock(editor, type, start_chars, end_chars) {
|
function _toggleBlock(editor, type, start_chars, end_chars) {
|
||||||
if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className))
|
if (/editor-preview-active/.test(editor.codemirror.getWrapperElement().lastChild.className))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars;
|
end_chars = (typeof end_chars === 'undefined') ? start_chars : end_chars;
|
||||||
var cm = editor.codemirror;
|
var cm = editor.codemirror;
|
||||||
var stat = getState(cm);
|
var stat = getState(cm);
|
||||||
@ -459,7 +459,7 @@ function SimpleMDE(options) {
|
|||||||
if (options.element) {
|
if (options.element) {
|
||||||
this.element = options.element;
|
this.element = options.element;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.toolbar !== false)
|
if (options.toolbar !== false)
|
||||||
options.toolbar = options.toolbar || SimpleMDE.toolbar;
|
options.toolbar = options.toolbar || SimpleMDE.toolbar;
|
||||||
|
|
||||||
@ -467,10 +467,17 @@ function SimpleMDE(options) {
|
|||||||
options.status = ['autosave', 'lines', 'words', 'cursor'];
|
options.status = ['autosave', 'lines', 'words', 'cursor'];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
|
||||||
// If user has passed an element, it should auto rendered
|
// If user has passed an element, it should auto rendered
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
|
// The codemirror component is only available after rendering
|
||||||
|
// so, the setter for the defaultValue can only run after
|
||||||
|
// the element has been rendered
|
||||||
|
if (options.defaultValue) {
|
||||||
|
this.value(options.defaultValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -524,15 +531,15 @@ SimpleMDE.prototype.render = function(el) {
|
|||||||
keyMaps["Esc"] = function(cm) {
|
keyMaps["Esc"] = function(cm) {
|
||||||
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
|
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
|
||||||
};
|
};
|
||||||
|
|
||||||
var mode = "spell-checker";
|
var mode = "spell-checker";
|
||||||
var backdrop = "gfm";
|
var backdrop = "gfm";
|
||||||
|
|
||||||
if (options.spellChecker === false) {
|
if (options.spellChecker === false) {
|
||||||
mode = "gfm";
|
mode = "gfm";
|
||||||
backdrop = undefined;
|
backdrop = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.codemirror = CodeMirror.fromTextArea(el, {
|
this.codemirror = CodeMirror.fromTextArea(el, {
|
||||||
mode: mode,
|
mode: mode,
|
||||||
backdrop: backdrop,
|
backdrop: backdrop,
|
||||||
@ -562,29 +569,29 @@ SimpleMDE.prototype.render = function(el) {
|
|||||||
SimpleMDE.prototype.autosave = function() {
|
SimpleMDE.prototype.autosave = function() {
|
||||||
var content = this.value();
|
var content = this.value();
|
||||||
var simplemde = this;
|
var simplemde = this;
|
||||||
|
|
||||||
if(this.options.autosave.unique_id == undefined || this.options.autosave.unique_id == ""){
|
if(this.options.autosave.unique_id == undefined || this.options.autosave.unique_id == ""){
|
||||||
console.log("SimpleMDE: You must set a unique_id to use the autosave feature");
|
console.log("SimpleMDE: You must set a unique_id to use the autosave feature");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(simplemde.element.form != null && simplemde.element.form != undefined){
|
if(simplemde.element.form != null && simplemde.element.form != undefined){
|
||||||
simplemde.element.form.addEventListener("submit", function(){
|
simplemde.element.form.addEventListener("submit", function(){
|
||||||
localStorage.setItem(simplemde.options.autosave.unique_id, "");
|
localStorage.setItem(simplemde.options.autosave.unique_id, "");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.options.autosave.loaded !== true){
|
if(this.options.autosave.loaded !== true){
|
||||||
if(localStorage.getItem(this.options.autosave.unique_id) != null)
|
if(localStorage.getItem(this.options.autosave.unique_id) != null)
|
||||||
this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id));
|
this.codemirror.setValue(localStorage.getItem(this.options.autosave.unique_id));
|
||||||
|
|
||||||
this.options.autosave.loaded = true;
|
this.options.autosave.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(localStorage) {
|
if(localStorage) {
|
||||||
localStorage.setItem(this.options.autosave.unique_id, content);
|
localStorage.setItem(this.options.autosave.unique_id, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
var el = document.getElementById("autosaved");
|
var el = document.getElementById("autosaved");
|
||||||
if(el != null && el != undefined && el != ""){
|
if(el != null && el != undefined && el != ""){
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
@ -600,10 +607,10 @@ SimpleMDE.prototype.autosave = function() {
|
|||||||
h = 12;
|
h = 12;
|
||||||
}
|
}
|
||||||
m = m<10?"0"+m:m;
|
m = m<10?"0"+m:m;
|
||||||
|
|
||||||
el.innerHTML = "Autosaved: "+h+":"+m+" "+dd;
|
el.innerHTML = "Autosaved: "+h+":"+m+" "+dd;
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
simplemde.autosave();
|
simplemde.autosave();
|
||||||
}, this.options.autosave.delay || 10000);
|
}, this.options.autosave.delay || 10000);
|
||||||
@ -628,7 +635,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
|
|||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
if(items[i].name == "guide" && self.options.toolbarGuideIcon === false)
|
if(items[i].name == "guide" && self.options.toolbarGuideIcon === false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
(function(item) {
|
(function(item) {
|
||||||
var el;
|
var el;
|
||||||
if (item === '|') {
|
if (item === '|') {
|
||||||
@ -652,7 +659,7 @@ SimpleMDE.prototype.createToolbar = function(items) {
|
|||||||
bar.appendChild(el);
|
bar.appendChild(el);
|
||||||
})(items[i]);
|
})(items[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.toolbarElements = toolbar_data;
|
self.toolbarElements = toolbar_data;
|
||||||
|
|
||||||
var cm = this.codemirror;
|
var cm = this.codemirror;
|
||||||
@ -714,7 +721,7 @@ SimpleMDE.prototype.createStatusbar = function(status) {
|
|||||||
bar.appendChild(el);
|
bar.appendChild(el);
|
||||||
})(status[i]);
|
})(status[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmWrapper = this.codemirror.getWrapperElement();
|
var cmWrapper = this.codemirror.getWrapperElement();
|
||||||
cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
|
cmWrapper.parentNode.insertBefore(bar, cmWrapper.nextSibling);
|
||||||
return bar;
|
return bar;
|
||||||
@ -724,11 +731,11 @@ SimpleMDE.prototype.createStatusbar = function(status) {
|
|||||||
* Get or set the text content.
|
* Get or set the text content.
|
||||||
*/
|
*/
|
||||||
SimpleMDE.prototype.value = function(val) {
|
SimpleMDE.prototype.value = function(val) {
|
||||||
if (val) {
|
if (val === undefined) {
|
||||||
|
return this.codemirror.getValue();
|
||||||
|
} else {
|
||||||
this.codemirror.getDoc().setValue(val);
|
this.codemirror.getDoc().setValue(val);
|
||||||
return this;
|
return this;
|
||||||
} else {
|
|
||||||
return this.codemirror.getValue();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -791,4 +798,4 @@ SimpleMDE.prototype.togglePreview = function() {
|
|||||||
};
|
};
|
||||||
SimpleMDE.prototype.toggleFullScreen = function() {
|
SimpleMDE.prototype.toggleFullScreen = function() {
|
||||||
toggleFullScreen(this);
|
toggleFullScreen(this);
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user