import Editor from '@toast-ui/editor';
+import MarkdowneditorToolbar from "./markdowneditor.toolbar";
window.$ = window.jQuery = require('jquery');
$.ajaxSetup({
MarkdownEditor.prototype = {
init: function() {
+ this.toolbar = new MarkdowneditorToolbar(this);
+
const $this = this
this.initIcons();
this.markdown();
- this.loadPage();
+ this.changePage();
$(window).on('hashchange', function () {
/*if ($this.maskHashEvent) {
return;
}*/
$this.currentPage = Math.max(1,parseInt(window.location.hash.substring(1))) || 1
- $this.loadPage();
+ $this.changePage();
});
$(window).on('mousemove', function (e) {
this.editor.getMarkdown();
},
- moveHandle: function () {
- var $this = this;
- $(".linkeditor-sidebar .handle.dragging")
- }
+ changePage: function(page) {
+ if (page === undefined) {
+ let h = window.location.hash;
+ if (h.length === 0) {
+ page = 0;
+ } else {
+ page = window.location.hash.substring(1);
+ }
+ }
+ this.currentPage = this.normalizePage(page)
+ this.loadPage();
+
+ window.location.hash = '#' + this.currentPage;
+ $("#markdowneditor-page-field input").val(this.currentPage);
+ },
+
+ firstPage: function () {
+ this.changePage(1);
+ },
+
+ nextPage: function () {
+ this.changePage(this.currentPage + 1);
+ },
+
+ previousPage: function () {
+ this.changePage(this.currentPage - 1);
+ },
+
+ lastPage: function () {
+ this.changePage(FLUIDBOOK_DATA.settings.pages);
+ },
+
+ normalizePage: function (page) {
+ page = parseInt(page);
+ return Math.max(1, Math.min(page, FLUIDBOOK_DATA.settings.pages));
+ },
+
+ runAction: function (act, args) {
+ if (args === undefined) {
+ args = [];
+ }
+ if (typeof args === 'string') {
+ args = [args];
+ }
+ var a = act.split('.');
+ var o = this;
+ let po = this;
+ for (let i in a) {
+ po = o;
+ o = o[a[i]];
+ }
+
+ try {
+ return o.apply(po, args);
+ } catch (e) {
+ console.log(e);
+ console.error('Error while calling ' + act, args);
+ }
+ },
/*isSpecialPage: function (page) {
if (page === undefined) {
--- /dev/null
+function MarkdowneditorToolbar(markdowneditor) {
+ this.markdowneditor = markdowneditor;
+ this.init();
+}
+
+MarkdowneditorToolbar.prototype = {
+ init: function () {
+ var $this = this;
+
+ $("#linkeditor-page-field input").on('change', function () {
+ $this.markdowneditor.changePage($(this).val());
+ $(this).blur();
+ return false;
+ });
+
+ $(document).on('click', '[data-action]', function () {
+ $this.markdowneditor.runAction($(this).data('action'), $(this).is('[data-action-args]') ? $(this).data('action-args') : []);
+ return false;
+ });
+ }
+};
+export default MarkdowneditorToolbar;
<a href="#" data-action="previousPage" data-icon="previous-page"
data-tooltip="{{__('Aller à la page précédente')}}"></a>
<div data-tooltip="{{__('Aller à une page')}} (Ctrl+G)" data-key="ctrl+g"
- data-action="focusPageField" id="linkeditor-page-field">
+ data-action="focusPageField" id="markdowneditor-page-field">
<input type="number" pattern="[0-9]+" step="0" min="0" max="{{$fbdata['settings']['pages']}}">
/ {{$fbdata['settings']['pages']}}</div>
<a href="#" data-action="nextPage" data-icon="next-page"