mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-04 00:24:29 -06:00
Added DateTimeFormat support for autosave.
Signed-off-by: Dmitry Mazurov <dimabzz@gmail.com>
This commit is contained in:
parent
8a1e2e5d5b
commit
1e64cba17e
13
README.md
13
README.md
@ -122,7 +122,7 @@ easyMDE.value('New input for **EasyMDE**');
|
|||||||
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
|
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
|
||||||
- **submit_delay**: Delay before assuming that submit of the form failed and saving the text, in milliseconds. Defaults to `autosave.delay` or `10000` (10s).
|
- **submit_delay**: Delay before assuming that submit of the form failed and saving the text, in milliseconds. Defaults to `autosave.delay` or `10000` (10s).
|
||||||
- **uniqueId**: You must set a unique string identifier so that EasyMDE can autosave. Something that separates this from other instances of EasyMDE elsewhere on your website.
|
- **uniqueId**: You must set a unique string identifier so that EasyMDE can autosave. Something that separates this from other instances of EasyMDE elsewhere on your website.
|
||||||
- **timeFormat**: Time format 12/24. Defaults to 12.
|
- **timeFormat**: Set DateTimeFormat. More information see [DateTimeFormat instances](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat). Default `locale: en-US, format: hour:minute`.
|
||||||
- **text**: Set text for autosave.
|
- **text**: Set text for autosave.
|
||||||
- **blockStyles**: Customize how certain buttons that style blocks of text behave.
|
- **blockStyles**: Customize how certain buttons that style blocks of text behave.
|
||||||
- **bold**: Can be set to `**` or `__`. Defaults to `**`.
|
- **bold**: Can be set to `**` or `__`. Defaults to `**`.
|
||||||
@ -208,7 +208,16 @@ var editor = new EasyMDE({
|
|||||||
uniqueId: "MyUniqueID",
|
uniqueId: "MyUniqueID",
|
||||||
delay: 1000,
|
delay: 1000,
|
||||||
submit_delay: 5000,
|
submit_delay: 5000,
|
||||||
timeFormat: 24,
|
timeFormat: {
|
||||||
|
locale: 'en-US',
|
||||||
|
format: {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: '2-digit',
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
},
|
||||||
|
},
|
||||||
text: "Autosaved: "
|
text: "Autosaved: "
|
||||||
},
|
},
|
||||||
blockStyles: {
|
blockStyles: {
|
||||||
|
@ -1479,6 +1479,14 @@ var promptTexts = {
|
|||||||
image: 'URL of the image:',
|
image: 'URL of the image:',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var timeFormat = {
|
||||||
|
locale: 'en-US',
|
||||||
|
format: {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
var blockStyles = {
|
var blockStyles = {
|
||||||
'bold': '**',
|
'bold': '**',
|
||||||
'code': '```',
|
'code': '```',
|
||||||
@ -1619,6 +1627,12 @@ function EasyMDE(options) {
|
|||||||
options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
|
options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
|
||||||
|
|
||||||
|
|
||||||
|
if (options.autosave != undefined) {
|
||||||
|
// Merging the Autosave timeFormat, with the given options
|
||||||
|
options.autosave.timeFormat = extend({}, timeFormat, options.autosave.timeFormat || {});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Merging the shortcuts, with the given options
|
// Merging the shortcuts, with the given options
|
||||||
options.shortcuts = extend({}, shortcuts, options.shortcuts || {});
|
options.shortcuts = extend({}, shortcuts, options.shortcuts || {});
|
||||||
|
|
||||||
@ -2000,31 +2014,10 @@ EasyMDE.prototype.autosave = function () {
|
|||||||
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();
|
||||||
var hh = d.getHours();
|
var dd = new Intl.DateTimeFormat([this.options.autosave.timeFormat.locale, 'en-US'], this.options.autosave.timeFormat.format).format(d);
|
||||||
var m = d.getMinutes();
|
|
||||||
var dd = 'am';
|
|
||||||
var h = hh;
|
|
||||||
var html = '';
|
|
||||||
var save = this.options.autosave.text == undefined ? 'Autosaved: ' : this.options.autosave.text;
|
var save = this.options.autosave.text == undefined ? 'Autosaved: ' : this.options.autosave.text;
|
||||||
|
|
||||||
m = m < 10 ? '0' + m : m;
|
el.innerHTML = save + dd;
|
||||||
|
|
||||||
if (this.options.autosave.timeFormat == undefined || this.options.autosave.timeFormat == 12) {
|
|
||||||
if (h >= 12) {
|
|
||||||
h = hh - 12;
|
|
||||||
dd = 'pm';
|
|
||||||
}
|
|
||||||
if (h == 0) {
|
|
||||||
h = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
html = save + h + ':' + m + ' ' + dd;
|
|
||||||
}
|
|
||||||
if (this.options.autosave.timeFormat == 24) {
|
|
||||||
html = save + h + ':' + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
el.innerHTML = html;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.autosaveTimeoutId = setTimeout(function () {
|
this.autosaveTimeoutId = setTimeout(function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user