mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2025-09-24 16:40:55 -06:00
simplify createStatusbar
This commit is contained in:
parent
98bce7a7bc
commit
c2ee463010
File diff suppressed because one or more lines are too long
@ -16815,9 +16815,10 @@ var SimpleMDE = function (_Action) {
|
|||||||
if (options.element) {
|
if (options.element) {
|
||||||
_this.element = options.element;
|
_this.element = options.element;
|
||||||
} else if (options.element === null) {
|
} else if (options.element === null) {
|
||||||
|
var _ret;
|
||||||
|
|
||||||
// This means that the element option was specified, but no element was found
|
// This means that the element option was specified, but no element was found
|
||||||
console.log("SimpleMDE: Error. No element was found.");
|
return _ret = console.log("SimpleMDE: Error. No element was found."), _possibleConstructorReturn(_this, _ret);
|
||||||
return _possibleConstructorReturn(_this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle toolbar
|
// Handle toolbar
|
||||||
@ -17031,7 +17032,7 @@ var SimpleMDE = function (_Action) {
|
|||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
if (_utils2.default.isLocalStorageAvailable()) {
|
if (_utils2.default.isLocalStorageAvailable()) {
|
||||||
var _ret2 = function () {
|
var _ret3 = function () {
|
||||||
var simplemde = _this3;
|
var simplemde = _this3;
|
||||||
|
|
||||||
if (_this3.options.autosave.uniqueId == undefined || _this3.options.autosave.uniqueId == "") {
|
if (_this3.options.autosave.uniqueId == undefined || _this3.options.autosave.uniqueId == "") {
|
||||||
@ -17061,19 +17062,14 @@ var SimpleMDE = function (_Action) {
|
|||||||
if (el != null && el != undefined && el != "") {
|
if (el != null && el != undefined && el != "") {
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
var hh = d.getHours();
|
var hh = d.getHours();
|
||||||
var m = d.getMinutes();
|
var mm = d.getMinutes();
|
||||||
var dd = "am";
|
|
||||||
var h = hh;
|
|
||||||
if (h >= 12) {
|
|
||||||
h = hh - 12;
|
|
||||||
dd = "pm";
|
|
||||||
}
|
|
||||||
if (h == 0) {
|
|
||||||
h = 12;
|
|
||||||
}
|
|
||||||
m = m < 10 ? "0" + m : m;
|
|
||||||
|
|
||||||
el.innerHTML = "Autosaved: " + h + ":" + m + " " + dd;
|
// date format, output example: Autosaved: 5:45 pm
|
||||||
|
var dd = hh >= 12 ? 'pm' : 'am';
|
||||||
|
var h = hh == 0 ? 12 : hh > 12 ? hh - 12 : hh;
|
||||||
|
var m = mm < 10 ? '0' + mm : mm;
|
||||||
|
|
||||||
|
el.innerHTML = 'Autosaved: ' + h + ':' + m + ' ' + dd;
|
||||||
}
|
}
|
||||||
|
|
||||||
_this3.autosaveTimeoutId = setTimeout(function () {
|
_this3.autosaveTimeoutId = setTimeout(function () {
|
||||||
@ -17081,7 +17077,7 @@ var SimpleMDE = function (_Action) {
|
|||||||
}, _this3.options.autosave.delay || 10000);
|
}, _this3.options.autosave.delay || 10000);
|
||||||
}();
|
}();
|
||||||
|
|
||||||
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v;
|
if ((typeof _ret3 === 'undefined' ? 'undefined' : _typeof(_ret3)) === "object") return _ret3.v;
|
||||||
} else {
|
} else {
|
||||||
console.log("SimpleMDE: localStorage not available, cannot autosave");
|
console.log("SimpleMDE: localStorage not available, cannot autosave");
|
||||||
}
|
}
|
||||||
@ -17227,105 +17223,93 @@ var SimpleMDE = function (_Action) {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'createStatusbar',
|
key: 'createStatusbar',
|
||||||
value: function createStatusbar(status) {
|
value: function createStatusbar() {
|
||||||
// Initialize
|
var _this4 = this;
|
||||||
status = status || this.options.status;
|
|
||||||
var options = this.options;
|
var status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.status;
|
||||||
var cm = this.codemirror;
|
|
||||||
|
|
||||||
// Make sure the status variable is valid
|
// Make sure the status variable is valid
|
||||||
if (!status || status.length === 0) return;
|
if (!status || status.length === 0) return;
|
||||||
|
|
||||||
|
var options = this.options;
|
||||||
|
var cm = this.codemirror;
|
||||||
|
|
||||||
// Set up the built-in items
|
// Set up the built-in items
|
||||||
var items = [];
|
var items = [];
|
||||||
var i = void 0,
|
|
||||||
onUpdate = void 0,
|
|
||||||
defaultValue = void 0;
|
|
||||||
|
|
||||||
for (i = 0; i < status.length; i++) {
|
|
||||||
// Reset some values
|
|
||||||
onUpdate = undefined;
|
|
||||||
defaultValue = undefined;
|
|
||||||
|
|
||||||
// Handle if custom or not
|
|
||||||
if (_typeof(status[i]) === "object") {
|
|
||||||
items.push({
|
|
||||||
className: status[i].className,
|
|
||||||
defaultValue: status[i].defaultValue,
|
|
||||||
onUpdate: status[i].onUpdate
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var name = status[i];
|
|
||||||
|
|
||||||
if (name === "words") {
|
|
||||||
defaultValue = function defaultValue(el) {
|
|
||||||
return el.innerHTML = _utils2.default.wordCount(cm.getValue());
|
|
||||||
};
|
|
||||||
onUpdate = function onUpdate(el) {
|
|
||||||
return el.innerHTML = _utils2.default.wordCount(cm.getValue());
|
|
||||||
};
|
|
||||||
} else if (name === "lines") {
|
|
||||||
defaultValue = function defaultValue(el) {
|
|
||||||
return el.innerHTML = cm.lineCount();
|
|
||||||
};
|
|
||||||
onUpdate = function onUpdate(el) {
|
|
||||||
return el.innerHTML = cm.lineCount();
|
|
||||||
};
|
|
||||||
} else if (name === "cursor") {
|
|
||||||
defaultValue = function defaultValue(el) {
|
|
||||||
return el.innerHTML = "0:0";
|
|
||||||
};
|
|
||||||
onUpdate = function onUpdate(el) {
|
|
||||||
var pos = cm.getCursor();
|
|
||||||
el.innerHTML = pos.line + ":" + pos.ch;
|
|
||||||
};
|
|
||||||
} else if (name === "autosave") {
|
|
||||||
defaultValue = function defaultValue(el) {
|
|
||||||
if (options.autosave != undefined && options.autosave.enabled === true) {
|
|
||||||
el.setAttribute("id", "autosaved");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
className: name,
|
|
||||||
defaultValue: defaultValue,
|
|
||||||
onUpdate: onUpdate
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create element for the status bar
|
|
||||||
var bar = document.createElement("div");
|
var bar = document.createElement("div");
|
||||||
bar.className = "editor-statusbar";
|
bar.className = "editor-statusbar";
|
||||||
|
|
||||||
// Create a new span for each item
|
var statusFuncMap = {
|
||||||
for (i = 0; i < items.length; i++) {
|
words: {
|
||||||
// Store in temporary variable
|
defaultValue: function defaultValue(el) {
|
||||||
var item = items[i];
|
return el.innerHTML = _utils2.default.wordCount(cm.getValue());
|
||||||
|
},
|
||||||
// Create span element
|
onUpdate: function onUpdate(el) {
|
||||||
var el = document.createElement("span");
|
return el.innerHTML = _utils2.default.wordCount(cm.getValue());
|
||||||
el.className = item.className;
|
}
|
||||||
|
},
|
||||||
// Ensure the defaultValue is a function
|
lines: {
|
||||||
if (typeof item.defaultValue === "function") {
|
defaultValue: function defaultValue(el) {
|
||||||
item.defaultValue(el);
|
return el.innerHTML = cm.lineCount();
|
||||||
|
},
|
||||||
|
onUpdate: function onUpdate(el) {
|
||||||
|
return el.innerHTML = cm.lineCount();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cursor: {
|
||||||
|
defaultValue: function defaultValue(el) {
|
||||||
|
return el.innerHTML = "0:0";
|
||||||
|
},
|
||||||
|
onUpdate: function onUpdate(el) {
|
||||||
|
return el.innerHTML = cm.getCursor().line + ":" + cm.getCursor().ch;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
autosave: {
|
||||||
|
defaultValue: function defaultValue(el) {
|
||||||
|
if (options.autosave != undefined && options.autosave.enabled === true) {
|
||||||
|
el.setAttribute("id", "autosaved");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onUpdate: undefined
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Ensure the onUpdate is a function
|
status.forEach(function (v) {
|
||||||
if (typeof item.onUpdate === "function") {
|
if ((typeof v === 'undefined' ? 'undefined' : _typeof(v)) === "object") {
|
||||||
|
items.push({
|
||||||
|
className: v.className,
|
||||||
|
defaultValue: v.defaultValue,
|
||||||
|
onUpdate: v.onUpdate
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (statusFuncMap[v]) {
|
||||||
|
items.push({
|
||||||
|
className: v.toString(),
|
||||||
|
defaultValue: statusFuncMap[v].defaultValue,
|
||||||
|
onUpdate: statusFuncMap[v].onUpdate
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create element for the status bar
|
||||||
|
var createStatusElement = function createStatusElement(className) {
|
||||||
|
var el = document.createElement("span");
|
||||||
|
el.className = className;
|
||||||
|
return el;
|
||||||
|
};
|
||||||
|
items.forEach(function (v) {
|
||||||
|
var el = createStatusElement(v.className);
|
||||||
|
if (typeof v.defaultValue === "function") v.defaultValue(el);
|
||||||
|
if (typeof v.onUpdate === "function") {
|
||||||
// Create a closure around the span of the current action, then execute the onUpdate handler
|
// Create a closure around the span of the current action, then execute the onUpdate handler
|
||||||
this.codemirror.on("update", function (el, item) {
|
_this4.codemirror.on("update", function () {
|
||||||
return function () {
|
return v.onUpdate(el);
|
||||||
return item.onUpdate(el);
|
});
|
||||||
};
|
|
||||||
}(el, item));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the item to the status bar
|
// Append the item to the status bar
|
||||||
bar.appendChild(el);
|
bar.appendChild(el);
|
||||||
}
|
});
|
||||||
|
|
||||||
// Insert the status bar into the DOM
|
// Insert the status bar into the DOM
|
||||||
var cmWrapper = this.codemirror.getWrapperElement();
|
var cmWrapper = this.codemirror.getWrapperElement();
|
||||||
|
2
dist/simplemde.min.js
vendored
2
dist/simplemde.min.js
vendored
File diff suppressed because one or more lines are too long
@ -457,96 +457,76 @@ class SimpleMDE extends Action {
|
|||||||
return bar;
|
return bar;
|
||||||
};
|
};
|
||||||
|
|
||||||
createStatusbar(status) {
|
createStatusbar(status = this.options.status) {
|
||||||
// Initialize
|
|
||||||
status = status || this.options.status;
|
|
||||||
let options = this.options;
|
|
||||||
let cm = this.codemirror;
|
|
||||||
|
|
||||||
// Make sure the status variable is valid
|
// Make sure the status variable is valid
|
||||||
if(!status || status.length === 0) return;
|
if(!status || status.length === 0) return;
|
||||||
|
|
||||||
|
const options = this.options;
|
||||||
|
const cm = this.codemirror;
|
||||||
|
|
||||||
// Set up the built-in items
|
// Set up the built-in items
|
||||||
let items = [];
|
let items = [];
|
||||||
let i, onUpdate, defaultValue;
|
|
||||||
|
|
||||||
for(i = 0; i < status.length; i++) {
|
|
||||||
// Reset some values
|
|
||||||
onUpdate = undefined;
|
|
||||||
defaultValue = undefined;
|
|
||||||
|
|
||||||
|
|
||||||
// Handle if custom or not
|
|
||||||
if(typeof status[i] === "object") {
|
|
||||||
items.push({
|
|
||||||
className: status[i].className,
|
|
||||||
defaultValue: status[i].defaultValue,
|
|
||||||
onUpdate: status[i].onUpdate
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
let name = status[i];
|
|
||||||
|
|
||||||
if(name === "words") {
|
|
||||||
defaultValue = el => el.innerHTML = utils.wordCount(cm.getValue());
|
|
||||||
onUpdate = el => el.innerHTML = utils.wordCount(cm.getValue());
|
|
||||||
} else if(name === "lines") {
|
|
||||||
defaultValue = el => el.innerHTML = cm.lineCount();
|
|
||||||
onUpdate = el => el.innerHTML = cm.lineCount();
|
|
||||||
} else if(name === "cursor") {
|
|
||||||
defaultValue = el => el.innerHTML = "0:0";
|
|
||||||
onUpdate = el => {
|
|
||||||
const pos = cm.getCursor();
|
|
||||||
el.innerHTML = pos.line + ":" + pos.ch;
|
|
||||||
};
|
|
||||||
} else if(name === "autosave") {
|
|
||||||
defaultValue = el => {
|
|
||||||
if(options.autosave != undefined && options.autosave.enabled === true) {
|
|
||||||
el.setAttribute("id", "autosaved");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push({
|
|
||||||
className: name,
|
|
||||||
defaultValue: defaultValue,
|
|
||||||
onUpdate: onUpdate
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Create element for the status bar
|
|
||||||
let bar = document.createElement("div");
|
let bar = document.createElement("div");
|
||||||
bar.className = "editor-statusbar";
|
bar.className = "editor-statusbar";
|
||||||
|
|
||||||
|
const statusFuncMap = {
|
||||||
// Create a new span for each item
|
words: {
|
||||||
for(i = 0; i < items.length; i++) {
|
defaultValue: el => el.innerHTML = utils.wordCount(cm.getValue()),
|
||||||
// Store in temporary variable
|
onUpdate: el => el.innerHTML = utils.wordCount(cm.getValue())
|
||||||
let item = items[i];
|
},
|
||||||
|
lines: {
|
||||||
|
defaultValue: el => el.innerHTML = cm.lineCount(),
|
||||||
// Create span element
|
onUpdate: el => el.innerHTML = cm.lineCount()
|
||||||
let el = document.createElement("span");
|
},
|
||||||
el.className = item.className;
|
cursor: {
|
||||||
|
defaultValue: el => el.innerHTML = "0:0",
|
||||||
|
onUpdate: el => el.innerHTML = cm.getCursor().line + ":" + cm.getCursor().ch
|
||||||
// Ensure the defaultValue is a function
|
},
|
||||||
if(typeof item.defaultValue === "function") {
|
autosave: {
|
||||||
item.defaultValue(el);
|
defaultValue: el => {
|
||||||
|
if(options.autosave != undefined && options.autosave.enabled === true) {
|
||||||
|
el.setAttribute("id", "autosaved");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onUpdate: undefined
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status.forEach(v => {
|
||||||
|
if(typeof v === "object") {
|
||||||
|
items.push({
|
||||||
|
className: v.className,
|
||||||
|
defaultValue: v.defaultValue,
|
||||||
|
onUpdate: v.onUpdate
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if(statusFuncMap[v]) {
|
||||||
|
items.push({
|
||||||
|
className: v.toString(),
|
||||||
|
defaultValue: statusFuncMap[v].defaultValue,
|
||||||
|
onUpdate: statusFuncMap[v].onUpdate
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// Ensure the onUpdate is a function
|
// Create element for the status bar
|
||||||
if(typeof item.onUpdate === "function") {
|
const createStatusElement = className => {
|
||||||
|
let el = document.createElement("span");
|
||||||
|
el.className = className
|
||||||
|
return el
|
||||||
|
}
|
||||||
|
items.forEach(v => {
|
||||||
|
const el = createStatusElement(v.className)
|
||||||
|
if(typeof v.defaultValue === "function") v.defaultValue(el)
|
||||||
|
if(typeof v.onUpdate === "function") {
|
||||||
// Create a closure around the span of the current action, then execute the onUpdate handler
|
// Create a closure around the span of the current action, then execute the onUpdate handler
|
||||||
this.codemirror.on("update", (((el, item) => () => item.onUpdate(el))(el, item)));
|
this.codemirror.on("update", () => v.onUpdate(el));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the item to the status bar
|
// Append the item to the status bar
|
||||||
bar.appendChild(el);
|
bar.appendChild(el);
|
||||||
}
|
})
|
||||||
|
|
||||||
|
|
||||||
// Insert the status bar into the DOM
|
// Insert the status bar into the DOM
|
||||||
let cmWrapper = this.codemirror.getWrapperElement();
|
let cmWrapper = this.codemirror.getWrapperElement();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user