|
|
|
@ -17017,58 +17017,49 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
}, {
|
|
|
|
|
key: 'autosave',
|
|
|
|
|
value: function autosave() {
|
|
|
|
|
var _this3 = this;
|
|
|
|
|
|
|
|
|
|
if (_utils2.default.isLocalStorageAvailable()) {
|
|
|
|
|
var _ret3 = function () {
|
|
|
|
|
var simplemde = _this3;
|
|
|
|
|
|
|
|
|
|
if (_this3.options.autosave.uniqueId == undefined || _this3.options.autosave.uniqueId == "") {
|
|
|
|
|
return {
|
|
|
|
|
v: console.log("SimpleMDE: You must set a uniqueId to use the autosave feature")
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (simplemde.element.form != null && simplemde.element.form != undefined) {
|
|
|
|
|
simplemde.element.form.addEventListener("submit", function () {
|
|
|
|
|
localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!_utils2.default.isLocalStorageAvailable()) {
|
|
|
|
|
return console.log("SimpleMDE: localStorage not available, cannot autosave");
|
|
|
|
|
}
|
|
|
|
|
var simplemde = this;
|
|
|
|
|
|
|
|
|
|
if (_this3.options.autosave.loaded !== true) {
|
|
|
|
|
if (typeof localStorage.getItem("smde_" + _this3.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + _this3.options.autosave.uniqueId) != "") {
|
|
|
|
|
_this3.codemirror.setValue(localStorage.getItem("smde_" + _this3.options.autosave.uniqueId));
|
|
|
|
|
_this3.options.autosave.foundSavedValue = true;
|
|
|
|
|
}
|
|
|
|
|
if (this.options.autosave.uniqueId == undefined || this.options.autosave.uniqueId == "") {
|
|
|
|
|
return console.log("SimpleMDE: You must set a uniqueId to use the autosave feature");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_this3.options.autosave.loaded = true;
|
|
|
|
|
}
|
|
|
|
|
if (simplemde.element.form != null && simplemde.element.form != undefined) {
|
|
|
|
|
simplemde.element.form.addEventListener("submit", function () {
|
|
|
|
|
localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
localStorage.setItem("smde_" + _this3.options.autosave.uniqueId, simplemde.value());
|
|
|
|
|
if (this.options.autosave.loaded !== true) {
|
|
|
|
|
if (typeof localStorage.getItem("smde_" + this.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + this.options.autosave.uniqueId) != "") {
|
|
|
|
|
this.codemirror.setValue(localStorage.getItem("smde_" + this.options.autosave.uniqueId));
|
|
|
|
|
this.options.autosave.foundSavedValue = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var el = document.getElementById("autosaved");
|
|
|
|
|
if (el != null && el != undefined && el != "") {
|
|
|
|
|
var d = new Date();
|
|
|
|
|
var hh = d.getHours();
|
|
|
|
|
var mm = d.getMinutes();
|
|
|
|
|
this.options.autosave.loaded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
localStorage.setItem("smde_" + this.options.autosave.uniqueId, simplemde.value());
|
|
|
|
|
|
|
|
|
|
el.innerHTML = 'Autosaved: ' + h + ':' + m + ' ' + dd;
|
|
|
|
|
}
|
|
|
|
|
var el = document.getElementById("autosaved");
|
|
|
|
|
if (el != null && el != undefined && el != "") {
|
|
|
|
|
var d = new Date();
|
|
|
|
|
var hh = d.getHours();
|
|
|
|
|
var mm = d.getMinutes();
|
|
|
|
|
|
|
|
|
|
_this3.autosaveTimeoutId = setTimeout(function () {
|
|
|
|
|
simplemde.autosave();
|
|
|
|
|
}, _this3.options.autosave.delay || 10000);
|
|
|
|
|
}();
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
if ((typeof _ret3 === 'undefined' ? 'undefined' : _typeof(_ret3)) === "object") return _ret3.v;
|
|
|
|
|
} else {
|
|
|
|
|
console.log("SimpleMDE: localStorage not available, cannot autosave");
|
|
|
|
|
el.innerHTML = 'Autosaved: ' + h + ':' + m + ' ' + dd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.autosaveTimeoutId = setTimeout(function () {
|
|
|
|
|
simplemde.autosave();
|
|
|
|
|
}, this.options.autosave.delay || 10000);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
key: 'clearAutosavedValue',
|
|
|
|
@ -17088,8 +17079,9 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
var cm = this.codemirror;
|
|
|
|
|
var wrapper = cm.getWrapperElement();
|
|
|
|
|
var preview = wrapper.nextSibling;
|
|
|
|
|
var notCreate = !preview || !/editor-preview-side/.test(preview.className);
|
|
|
|
|
|
|
|
|
|
if (!preview || !/editor-preview-side/.test(preview.className)) {
|
|
|
|
|
if (notCreate) {
|
|
|
|
|
preview = document.createElement("div");
|
|
|
|
|
preview.className = "editor-preview-side";
|
|
|
|
|
wrapper.parentNode.insertBefore(preview, wrapper.nextSibling);
|
|
|
|
@ -17120,7 +17112,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
}, {
|
|
|
|
|
key: 'createToolbar',
|
|
|
|
|
value: function createToolbar() {
|
|
|
|
|
var _this4 = this;
|
|
|
|
|
var _this3 = this;
|
|
|
|
|
|
|
|
|
|
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.toolbar;
|
|
|
|
|
|
|
|
|
@ -17136,8 +17128,8 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
var toolbarData = {};
|
|
|
|
|
var nextLoop = function nextLoop(v, i) {
|
|
|
|
|
var name = v.name;
|
|
|
|
|
if (name == "guide" && _this4.options.toolbarGuideIcon === false) return true;
|
|
|
|
|
if (_this4.options.hideIcons && _this4.options.hideIcons.indexOf(name) != -1) return true;
|
|
|
|
|
if (name == "guide" && _this3.options.toolbarGuideIcon === false) return true;
|
|
|
|
|
if (_this3.options.hideIcons && _this3.options.hideIcons.indexOf(name) != -1) return true;
|
|
|
|
|
|
|
|
|
|
// Fullscreen does not work well on mobile devices (even tablets)
|
|
|
|
|
// In the future, hopefully this can be resolved
|
|
|
|
@ -17146,8 +17138,8 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
// Don't include trailing separators
|
|
|
|
|
if (v === "|") {
|
|
|
|
|
var nonSeparatorIconsFollow = true;
|
|
|
|
|
for (var x = i + 1; x < _this4.toolbar.length; x++) {
|
|
|
|
|
if (_this4.toolbar[x] !== "|" && (!_this4.options.hideIcons || _this4.options.hideIcons.indexOf(name) == -1)) {
|
|
|
|
|
for (var x = i + 1; x < _this3.toolbar.length; x++) {
|
|
|
|
|
if (_this3.toolbar[x] !== "|" && (!_this3.options.hideIcons || _this3.options.hideIcons.indexOf(name) == -1)) {
|
|
|
|
|
nonSeparatorIconsFollow = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -17157,7 +17149,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
};
|
|
|
|
|
var createElement = function createElement(v) {
|
|
|
|
|
if (v === "|") return createSep();
|
|
|
|
|
return createIcon(v, _this4.options.toolbarTips, _this4.options.shortcuts);
|
|
|
|
|
return createIcon(v, _this3.options.toolbarTips, _this3.options.shortcuts);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.toolbar.every(function (v, i) {
|
|
|
|
@ -17171,7 +17163,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
if (typeof v.action === "function") {
|
|
|
|
|
el.onclick = function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
v.action(_this4);
|
|
|
|
|
v.action(_this3);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (typeof v.action === "string") {
|
|
|
|
@ -17186,7 +17178,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
});
|
|
|
|
|
this.toolbarElements = toolbarData;
|
|
|
|
|
this.codemirror.on("cursorActivity", function () {
|
|
|
|
|
var stat = _base2.default.getState(_this4.codemirror);
|
|
|
|
|
var stat = _base2.default.getState(_this3.codemirror);
|
|
|
|
|
|
|
|
|
|
for (var key in toolbarData) {
|
|
|
|
|
(function (key) {
|
|
|
|
@ -17209,7 +17201,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
}, {
|
|
|
|
|
key: 'createStatusbar',
|
|
|
|
|
value: function createStatusbar() {
|
|
|
|
|
var _this5 = this;
|
|
|
|
|
var _this4 = this;
|
|
|
|
|
|
|
|
|
|
var status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.options.status;
|
|
|
|
|
|
|
|
|
@ -17287,7 +17279,7 @@ var SimpleMDE = function (_Action) {
|
|
|
|
|
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
|
|
|
|
|
_this5.codemirror.on("update", function () {
|
|
|
|
|
_this4.codemirror.on("update", function () {
|
|
|
|
|
return v.onUpdate(el);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|