mirror of
https://hk.gh-proxy.com/https://github.com/NodeBB/nodebb-plugin-poll.git
synced 2025-10-04 04:41:13 +08:00
refactor: get rid of dayjs, flatpickr use native datetime-local
This commit is contained in:
parent
4e556c338b
commit
696c6443f9
9 changed files with 2254 additions and 1786 deletions
3973
package-lock.json
generated
3973
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -29,8 +29,8 @@
|
||||||
"compatibility": "^3.2.0"
|
"compatibility": "^3.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^7.31.0",
|
"eslint": "8.57.0",
|
||||||
"eslint-config-airbnb-base": "^14.2.1",
|
"eslint-config-nodebb": "0.2.1",
|
||||||
"eslint-plugin-import": "^2.23.4"
|
"eslint-plugin-import": "2.29.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,7 @@
|
||||||
],
|
],
|
||||||
"modules": {
|
"modules": {
|
||||||
"../admin/plugins/poll.js": "public/js/admin.js",
|
"../admin/plugins/poll.js": "public/js/admin.js",
|
||||||
"poll/serializer.js": "public/js/poll/serializer.js",
|
"poll/serializer.js": "public/js/poll/serializer.js"
|
||||||
"dayjs.js": "vendor/dayjs.min.js",
|
|
||||||
"flatpickr.js": "vendor/flatpickr.min.js",
|
|
||||||
"flatpickr.i10n.js": "vendor/flatpickr.l10n.js"
|
|
||||||
},
|
},
|
||||||
"css": [
|
"css": [
|
||||||
"vendor/flatpickr.min.css"
|
"vendor/flatpickr.min.css"
|
||||||
|
|
|
@ -124,7 +124,7 @@
|
||||||
return Poll.alertError('Editing not implemented');
|
return Poll.alertError('Editing not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
require(['flatpickr', 'flatpickr.i10n', 'bootbox', 'dayjs', 'translator'], function (flatpickr, flatpickrI10N, bootbox, dayjs, Translator) {
|
require(['bootbox'], function (bootbox) {
|
||||||
app.parseAndTranslate('poll/creator', { poll: poll, config: config, isRedactor: !!$.Redactor }, function (html) {
|
app.parseAndTranslate('poll/creator', { poll: poll, config: config, isRedactor: !!$.Redactor }, function (html) {
|
||||||
// Initialise modal
|
// Initialise modal
|
||||||
var modal = bootbox.dialog({
|
var modal = bootbox.dialog({
|
||||||
|
@ -156,12 +156,9 @@
|
||||||
return error('[[poll:error.no_options]]');
|
return error('[[poll:error.no_options]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.settings.end && !dayjs(new Date(obj.settings.end)).isValid()) {
|
if (obj.settings.end) {
|
||||||
return error('[[poll:error.valid_date]]');
|
obj.settings.end = new Date(obj.settings.end).getTime();
|
||||||
} else if (obj.settings.end) {
|
|
||||||
obj.settings.end = dayjs(new Date(obj.settings.end)).valueOf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(obj);
|
callback(obj);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -191,23 +188,9 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var currentLocale = Translator.getLanguage();
|
|
||||||
var flatpickrInstance = flatpickr('.flatpickr', {
|
|
||||||
enableTime: true,
|
|
||||||
altFormat: 'F j, Y h:i K',
|
|
||||||
time_24hr: false,
|
|
||||||
wrap: true,
|
|
||||||
locale: getFlatpickrLocale(currentLocale, flatpickrI10N.default),
|
|
||||||
onOpen: function () {
|
|
||||||
modal.removeAttr('tabindex');
|
|
||||||
},
|
|
||||||
onClose: function () {
|
|
||||||
modal.attr('tabindex', -1);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (poll.settings && poll.settings.end) {
|
if (poll.settings && poll.settings.end) {
|
||||||
flatpickrInstance.setDate(poll.settings.end);
|
|
||||||
|
// flatpickrInstance.setDate(poll.settings.end);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -241,13 +224,6 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFlatpickrLocale(nodebbLocale, flatpickrLocales = {}) {
|
|
||||||
if (Object.keys(flatpickrLocales).includes(nodebbLocale.toLowerCase())) {
|
|
||||||
return flatpickrLocales[nodebbLocale];
|
|
||||||
}
|
|
||||||
return flatpickrLocales.default;
|
|
||||||
}
|
|
||||||
|
|
||||||
Poll.creator = Creator;
|
Poll.creator = Creator;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
|
@ -35,9 +35,8 @@
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="pollInputEnd">[[poll:auto_end_title]]</label>
|
<label class="form-label" for="pollInputEnd">[[poll:auto_end_title]]</label>
|
||||||
<div class="input-group date flatpickr">
|
<div class="input-group date">
|
||||||
<input id="pollInputEnd" placeholder="[[poll:auto_end_placeholder]]" name="settings.end" class="form-control" value="{poll.settings.end}" data-input>
|
<input id="pollInputEnd" placeholder="[[poll:auto_end_placeholder]]" name="settings.end" class="form-control" value="{poll.settings.end}" type="datetime-local">
|
||||||
<a class="input-group-text" data-toggle><i class="fa fa-calendar"></i></a>
|
|
||||||
</div>
|
</div>
|
||||||
<p class="form-text">[[poll:auto_end_help]]</p>
|
<p class="form-text">[[poll:auto_end_help]]</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
1
vendor/dayjs.min.js
vendored
1
vendor/dayjs.min.js
vendored
File diff suppressed because one or more lines are too long
1
vendor/flatpickr.l10n.js
vendored
1
vendor/flatpickr.l10n.js
vendored
File diff suppressed because one or more lines are too long
13
vendor/flatpickr.min.css
vendored
13
vendor/flatpickr.min.css
vendored
File diff suppressed because one or more lines are too long
2
vendor/flatpickr.min.js
vendored
2
vendor/flatpickr.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue