]> _ Git - fluidbook-toolbox.git/commitdiff
wip #7634
authorsoufiane <soufiane@cubedesigners.com>
Thu, 17 Jul 2025 13:32:04 +0000 (15:32 +0200)
committersoufiane <soufiane@cubedesigners.com>
Thu, 17 Jul 2025 13:32:04 +0000 (15:32 +0200)
resources/linkeditor/js/linkeditor.toolbar.js
resources/markdowneditor/js/markdowneditor.js
resources/markdowneditor/js/markdowneditor.toolbar.js [new file with mode: 0644]
resources/markdowneditor/style/style.sass
resources/views/fluidbook_publication/markdown_editor.blade.php

index bf6d6205ba2647efc89bd73698c5aff6017a2b3d..74326387551e308b295685f7930ca94945438765 100644 (file)
@@ -6,7 +6,7 @@ function LinkeditorToolbar(linkeditor) {
 LinkeditorToolbar.prototype = {
     init: function () {
         var $this = this;
-        $("#linkeditor-page-field input").on('change', function () {
+        $("#markdowneditor-page-field input").on('change', function () {
             $this.linkeditor.changePage($(this).val());
             $(this).blur();
             return false;
index 51377faf0b9637253e88c4814fa8e25517f9f11d..6fec349284448cf5a05750d222c5b2f67264126b 100644 (file)
@@ -1,4 +1,5 @@
 import Editor from '@toast-ui/editor';
+import MarkdowneditorToolbar from "./markdowneditor.toolbar";
 window.$ = window.jQuery = require('jquery');
 
 $.ajaxSetup({
@@ -21,17 +22,19 @@ function MarkdownEditor() {
 
 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) {
@@ -152,10 +155,65 @@ MarkdownEditor.prototype = {
         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) {
diff --git a/resources/markdowneditor/js/markdowneditor.toolbar.js b/resources/markdowneditor/js/markdowneditor.toolbar.js
new file mode 100644 (file)
index 0000000..c36ffb1
--- /dev/null
@@ -0,0 +1,22 @@
+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;
index 88a9045cc28446ea142f008855d6cd6360c9aa5b..cd4eb42ffecffbf30024b6ae0a196501a502fe90 100644 (file)
@@ -34,7 +34,7 @@ body
         div
             display: inline-block
             vertical-align: top
-        #linkeditor-page-field
+        #markdowneditor-page-field
             padding: 2px 10px
             border-radius: 5px
             cursor: text
@@ -68,6 +68,7 @@ body
 
     &-toolbar-center
         justify-content: center
+        align-items: center
 
     &-revision
         height: 100vh
@@ -100,6 +101,8 @@ body
         position: absolute
         top: 0
         width: 100%
+        display: flex
+        align-items: center
     &-editor
         display: flex
         height: 100vh
index 9d978b1a4e04b714a9b6b249c47a3bd54a484fb2..a8e07c7a375e934cf1c400ba50f1b4d63ba34a19 100644 (file)
@@ -40,7 +40,7 @@
                     <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"