]> _ Git - fluidbook-toolbox.git/commitdiff
wip #5468 @5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 10 Nov 2022 15:57:54 +0000 (16:57 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 10 Nov 2022 15:57:54 +0000 (16:57 +0100)
16 files changed:
app/Fields/FluidbookLinkEditor/Action.php
app/Fields/FluidbookLinkEditor/Depth.php
app/Fields/FluidbookLinkEditor/Layer.php
app/Fields/FluidbookLinkEditor/MultimediaIntegration.php
app/Fields/FluidbookLinkEditor/NumberingType.php
app/Fields/FluidbookLinkEditor/RolloverAnimation.php
app/Fields/FluidbookLinkEditor/ShowLinkCloseMode.php
app/Fields/FluidbookLinkEditor/ShowLinkMode.php
app/Fields/FluidbookLinkEditor/Target.php
app/Fields/FluidbookLinkEditor/TriggerLinkEvent.php
app/Fields/FluidbookLinkEditor/WebvideoService.php
app/SubForms/Link/Base.php
resources/linkeditor/js/linkeditor.form.js
resources/linkeditor/js/linkeditor.js
resources/linkeditor/js/linkeditor.links.js
resources/linkeditor/style/form.sass

index 100dbed0c8c7dd2a06ff3ffca53454449988ca74..599ec9788a89affcf1b1f32a25ffe19fed8e204f 100644 (file)
@@ -6,29 +6,32 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class Action extends SelectFromArray
 {
-public function getOptions()
-{
-    return [
-        'index'=>__("Basculer entre la publication et l'index"),
-        'chapters'=>__('Afficher le sommaire'),
-        'print'=>__('Imprimer'),
-        'share'=>__('Partager par e-mail'),
-        'bookmarks'=>__('Ajouter un marque-page'),
-        'pdf'=>__('Télécharger le PDF'),
-        'notes'=>__('Notes'),
-        'fullscreen'=>__('Basculer entre le mode plein écran et le mode normal'),
-        'sound'=>__('Activer / Couper le son'),
-        //'2dmode'=>__('Basculer du mode 2D au mode 3D'),
-        'archives'=>__('Afficher les archives'),
-        'basket'=>__('Ouvrir le panier'),
-        'form'=>__('Ouvrir le formulaire'),
-        'facebook'=>__('Partager sur Facebook'),
-        'twitter'=>__('Partager sur Twitter'),
-        //'googleplus'=>__('Partager sur Google+'),
-        'linkedin'=>__('Partager sur LinkedIn'),
-        //'viadeo'=>__('Partager sur Viadeo'),
-        'whatsapp'=>__('Partager sur Whatsapp'),
-        'pinterest'=>__('Partager sur Pinterest'),
-    ];
-}
+    protected $_ajax = false;
+
+    public function getOptions()
+    {
+
+        return [
+            'index' => __("Basculer entre la publication et l'index"),
+            'chapters' => __('Afficher le sommaire'),
+            'print' => __('Imprimer'),
+            'share' => __('Partager par e-mail'),
+            'bookmarks' => __('Ajouter un marque-page'),
+            'pdf' => __('Télécharger le PDF'),
+            'notes' => __('Notes'),
+            'fullscreen' => __('Basculer entre le mode plein écran et le mode normal'),
+            'sound' => __('Activer / Couper le son'),
+            //'2dmode'=>__('Basculer du mode 2D au mode 3D'),
+            'archives' => __('Afficher les archives'),
+            'basket' => __('Ouvrir le panier'),
+            'form' => __('Ouvrir le formulaire'),
+            'facebook' => __('Partager sur Facebook'),
+            'twitter' => __('Partager sur Twitter'),
+            //'googleplus'=>__('Partager sur Google+'),
+            'linkedin' => __('Partager sur LinkedIn'),
+            //'viadeo'=>__('Partager sur Viadeo'),
+            'whatsapp' => __('Partager sur Whatsapp'),
+            'pinterest' => __('Partager sur Pinterest'),
+        ];
+    }
 }
index f5459fbc96a9a3b7e008f5822ed0dddf0186140d..9f25c42bb7a6be8bc3db077a08a5e874f73002ce 100644 (file)
@@ -7,6 +7,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 class Depth extends SelectFromArray
 {
     protected $_ajax = false;
+    protected $_allowNull=false;
+
+    protected $_default=-1;
+
 
     public function getOptions()
     {
index 4694af7b82d18571f231dbb60f2bbf936b676280..1b142a6867dfed3d1d953a17ff9322623a7bd7c9 100644 (file)
@@ -6,12 +6,16 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class Layer extends SelectFromArray
 {
-public function getOptions()
-{
-    return [
-        'both'=>__('Texte et image'),
-        'text'=>__('Texte'),
-        'image'=>__('Image'),
-    ];
-}
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'both';
+
+    public function getOptions()
+    {
+        return [
+            'both' => __('Texte et image'),
+            'text' => __('Texte'),
+            'image' => __('Image'),
+        ];
+    }
 }
index 3eabd6dabd4b720b20924fa49b8acdf2d5e574b5..e72b02532faf3ac0cc8550e86583fb42129f6ec3 100644 (file)
@@ -6,6 +6,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class MultimediaIntegration extends SelectFromArray
 {
+    protected $_ajax=false;
+    protected $_allowNull=false;
+    protected $_default='inline';
+
     public function getOptions()
     {
         return [
index 7204af393793d76a473a9ceb514841c2eac8ae7d..32cf124ae695f422b2eb8e83f30fc1feabf5bdc8 100644 (file)
@@ -6,6 +6,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class NumberingType extends SelectFromArray
 {
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'virtual';
+
     public function getOptions()
     {
         return [
index 903dba6617b7194dcac34fd57c565b071894c07c..8c69904fa138d0fefbddc39c388978adae8e6b3d 100644 (file)
@@ -6,6 +6,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class RolloverAnimation extends SelectFromArray
 {
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'none';
+
     public function getOptions()
     {
         return [
index a54512f019f04c5a57d91be136d1b243bbbc1c37..93e608e79e61533cbb5a731e90c44e18705e2e32 100644 (file)
@@ -6,13 +6,17 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class ShowLinkCloseMode extends SelectFromArray
 {
-public function getOptions()
-{
-    return [
-        'none' => __('Aucune'),
-        'topright' => __('En haut à droite'),
-        'topleft' => __('En haut à gauche'),
-        'whole' => __('Toute la zone'),
-    ];
-}
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'none';
+
+    public function getOptions()
+    {
+        return [
+            'none' => __('Aucune'),
+            'topright' => __('En haut à droite'),
+            'topleft' => __('En haut à gauche'),
+            'whole' => __('Toute la zone'),
+        ];
+    }
 }
index ab7e862717db0e8cffffe14dd71174c4b1460d3f..99bdbbc96ef22937dea6a4790448d124510e911e 100644 (file)
@@ -6,6 +6,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class ShowLinkMode extends SelectFromArray
 {
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'show';
+
     public function getOptions()
     {
         return [
index c702e260128eeacdf8db1099b02bc356630facf4..6376551ad259bc3b6cb33cf6461d6c55e7d1c82a 100644 (file)
@@ -6,8 +6,9 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class Target extends SelectFromArray
 {
-    protected $_ajax=false;
-    protected $_allowNull=false;
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = '_blank';
 
     public function getOptions()
     {
index 9b2e1c2b7478c457afde5fd9cfe12734fe25c32a..3f3c58fb846ee428877121b6aaa2ee22d85b38fa 100644 (file)
@@ -6,6 +6,10 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class TriggerLinkEvent extends SelectFromArray
 {
+    protected $_ajax = false;
+    protected $_allowNull = false;
+    protected $_default = 'page';
+
     public function getOptions()
     {
         return [
index 2cdf04a60e6cc2bd649d812d46694ec6da66a1fa..2a649705f6503c36298d14597aa5e116306cc1d1 100644 (file)
@@ -6,6 +6,11 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray;
 
 class WebvideoService extends SelectFromArray
 {
+    protected $_ajax = false;
+    protected $_default = 'youtube';
+    protected $_allowNull = false;
+
+
     public function getOptions()
     {
         return [
@@ -14,5 +19,5 @@ class WebvideoService extends SelectFromArray
             'vimeo' => 'Vimeo',
             'brightcove' => 'Vimeo',
         ];
-}
+    }
 }
index dd6034aa000ba87212320e8fa354f15f6ab794ce..7a2cbed7b3a5338f2139651acfac574ef9541a39 100644 (file)
@@ -5,6 +5,7 @@ namespace App\SubForms\Link;
 use App\Fields\FluidbookLinkEditor\Depth;
 use App\Fields\FluidbookLinkEditor\LinkType;
 use App\Fields\FluidbookLinkEditor\MultimediaIntegration;
+use App\Fields\FluidbookLinkEditor\RolloverAnimation;
 use App\Models\FluidbookPublication;
 use Cubist\Backpack\Magic\Fields\Checkbox;
 use Cubist\Backpack\Magic\Fields\FieldGroupEnd;
@@ -168,7 +169,7 @@ class Base extends Form
         }
         $this->addField('header_tooltip', FormSection::class, __('Infobulles'));
         $this->addField('tooltip', Text::class, __('Texte de l\'infobulle'), ['hint' => __('Laisser vide pour conserver le texte par défaut')]);
-        $this->addField('display_area', Checkbox::class, __('Afficher la zone de couleur au survol'));
+        $this->addField('display_area', Checkbox::class, __('Afficher la zone de couleur au survol'), ['default' => true]);
     }
 
     public function addTypeField()
@@ -199,10 +200,11 @@ class Base extends Form
         if ($this->_addedContents) {
             $this->addField('header_contents', FormSection::class, __('Contenus superposés'));
             $this->addField('image', FilesOrURL::class, __('Image'), array_merge($this->getFilesOrURLEntry(), ['accept' => ['.jpg', '.jpeg', '.png', '.svg', '.gif']]));
+            $this->addField('image_rollover', RolloverAnimation::class, __('Animation de l\'image au survol'));
             $this->addField('animation', FilesOrURL::class, __('Animation'), array_merge($this->getFilesOrURLEntry(), ['accept' => ['.html']]));
         }
         if ($this->_integration) {
-            $this->addField('inline', MultimediaIntegration::class, __('Intégration'), ['default' => 'inline']);
+            $this->addField('inline', MultimediaIntegration::class, __('Intégration'));
         }
         if ($this->_multimedia) {
             $this->addMultimediaFields();
index b6b4deac4fe71fb9690902c1ac4dc3b602bb96e0..c37bd8eee9de10a9e162c68d026e563361b543d0 100644 (file)
 function LinkeditorForm(linkeditor) {
     this.linkeditor = linkeditor;
+    this._maskChangeEvent = false;
+    this._maskChangeEventTimeout = null;
     this.init();
 }
 
 LinkeditorForm.prototype = {
     init: function () {
-        $(document).on('focus', "input[type=text],input[type=email],input[type=url],input[type=number],textarea", function () {
-            var $this = $(this);
-            setTimeout(function () {
-                $this.select();
-            }, 1);
+        var $this = this;
+
+        $('#linkeditor-panel-form').on('change', '[name="type"]', function () {
+            if ($this._maskChangeEvent) {
+                return;
+            }
+            $this.saveFormDataInLink();
+            $this.updateLinkForm();
+        });
+
+        $('#linkeditor-panel-form').on('change', "input, select, textarea", function () {
+            if ($this._maskChangeEvent) {
+                return;
+            }
+            $this.saveFormDataInLink();
         });
     },
 
-    initCodeMirror: function () {
-        $('#linkeditor-panel-form textarea.code').each(function () {
-            var textarea = $(this);
-            var c = CodeMirror.fromTextArea($(textarea).get(0), {
-                lineNumbers: true, mode: $(textarea).data('mode'), theme: 'dracula',
-            });
-            $(textarea).data('codemirror', c);
-            c.on('change', function (o) {
-                o.save();
-            });
+    saveFormDataInLink: function () {
+
+        var form = $("#linkeditor-panel-form form");
+        if ($(form).length === 0) {
+            return;
+        }
+
+        this.maskChangeEvent();
+        var link = $(form).data('link');
+        var data = $(form).serializeArray()
+        var ignore = ['_method', '_referrer', '_token', 'http_referrer'];
+        var map = {y: 'top', x: 'left', w: 'width', h: 'height'};
+        var savedData = {};
+        $.each(data, function (k, v) {
+            if (ignore.indexOf(v.name) >= 0) {
+                return;
+            }
+            let key = v.name;
+            if (map[v.name] !== undefined && map[v.name] !== null) {
+                key = map[v.name];
+            }
+            savedData[key] = v.value;
+            $(link).attr('fb-' + key, v.value);
         });
+        $(link).attr('fb-update', 1);
+        this.linkeditor.links.updateLinkData($(link).attr('fb-origuid'), savedData);
+        this.linkeditor.hasChanged();
+        this.unmaskChangeEvent();
     },
 
+    emptyForm: function () {
+        $('#linkeditor-panel-form .select2_from_array').each(function () {
+            $(this).select2('close');
+            $(this).select2('destroy');
+        });
+        $('#linkeditor-panel-form').html('');
+    },
+
+    updateLinkForm: function () {
+        var links = $('.link.selected:not(.pendingCreate)');
+        if (links.length != 1) {
+            this.emptyForm();
+            return;
+        }
+
+        this.emptyForm();
+        var container = $('#linkeditor-panel-form');
+        var link = $(links).eq(0);
+        var type = $(link).attr('fb-type');
+        var form = $("#linkeditor-form-template-" + type).clone(false);
+
+        $(form).attr('id', null);
+        $(form).data('link', link);
+        this.updateFormData(form);
+        container.append(form);
+
+
+        this.initSelect2();
+    },
+
+    updateFormData: function (form) {
+        var $this = this;
+        try {
+            if (form === undefined) {
+                form = $('#linkeditor-panel-form form');
+                if (form.length === 0) {
+                    return;
+                }
+            }
+            var link = $(form).data('link');
+            if (link === undefined || link === null) {
+                return;
+            }
+        } catch (e) {
+            return;
+        }
+
+
+        var types = {x: 'dimension', y: 'dimension', w: 'dimension', h: 'dimension', rot: 'dimension'}
+        var map = {top: 'y', left: 'x', width: 'w', height: 'h'};
+
+        this.maskChangeEvent();
+        $.each(this.linkeditor.links.getLinkData(link), function (k, v) {
+            if (map[k] !== undefined) {
+                k = map[k];
+            }
+            var type = 'string';
+            if (types[k] !== undefined) {
+                type = types[k];
+            }
+            if (type === 'dimension') {
+                v = parseFloat(v);
+                if (isNaN(v)) {
+                    v = 0;
+                }
+                v = Math.round(v * 100000) / 100000;
+            }
+            $(form).find('[name=' + k + ']').val(v);
+        });
+        this.unmaskChangeEvent();
+    },
+
+    maskChangeEvent: function () {
+        this._maskChangeEvent = true;
+    },
+
+    unmaskChangeEvent: function () {
+        var $this = this;
+        clearTimeout(this._maskChangeEventTimeout);
+        if (this._maskChangeEvent === false) {
+            return;
+        }
+        this._maskChangeEventTimeout = setTimeout(function () {
+            $this._maskChangeEvent = false;
+        }, 100);
+    },
+
+
     initSelect2: function () {
         // trigger select2 for each untriggered select2 box
         $('#linkeditor-panel-form .select2_from_array:not(.init)').each(function (i, obj) {
             var options = {
                 theme: "bootstrap",
             };
-            if ($(this).is('[data-ajax]')) {
-                options.ajax = {
-                    url: 'select2/' + $(this).data('ajax'), dataType: 'json', delay: 250,
-                };
-            }
             if ($(this).is('[data-allow-html="1"]')) {
                 options.escapeMarkup = function (m) {
                     return m;
                 }
             }
-            $(obj).addClass('init').select2(options);
+            $(this).addClass('init')
+            $(this).select2(options);
         });
     },
 
index 5256dcd83c5425e6bb455a8faf02cf7248378233..1269db68a0190fdcce22bcf4036ec4eb9e6a9ed8 100644 (file)
@@ -129,6 +129,7 @@ LinkEditor.prototype = {
                 deselectAll = false;
             }
             if (deselectAll) {
+                $this.form.saveFormDataInLink();
                 $this.links.deselectAllLinks();
             }
         });
@@ -232,7 +233,7 @@ LinkEditor.prototype = {
             });
             $(e).css(css).attr('fb-update', '0');
         });
-        this.links.updateFormData();
+        this.form.updateFormData();
     },
 
     fluidbookTo: function (dim, name, rect) {
index 57ade90f1851f5d2be8e9de84a60a1cc36405b34..f5f41992e642b1f3007f0f8a5e30fd06e86344c5 100644 (file)
@@ -84,7 +84,7 @@ LinkeditorLinks.prototype = {
         var link = this.duplicateLinkClick({width: 0, height: 0});
         $(link).addClass('pendingCreate');
         this.startResizeLink('se');
-        this.updateLinkForm();
+        this.linkeditor.form.updateLinkForm();
     },
 
     startResizeLink: function (corner) {
@@ -101,7 +101,7 @@ LinkeditorLinks.prototype = {
         $('.pendingCreate').each(function () {
             $this.deleteLink($(this), true);
         });
-        this.updateLinkForm();
+        this.linkeditor.form.updateLinkForm();
         this.resizeLinkPos = null;
     },
 
@@ -216,7 +216,7 @@ LinkeditorLinks.prototype = {
                 $(this).removeClass('pendingCreate');
             }
 
-            $this.updateLinkData($(this).attr('fb-uid'), {
+            $this.updateLinkData($(this).attr('fb-origuid'), {
                 top: newTop, left: newLeft, width: newWidth, height: newHeight
             });
         });
@@ -278,7 +278,7 @@ LinkeditorLinks.prototype = {
                 .attr('fb-top', top)
                 .attr('fb-update', '1');
 
-            $this.updateLinkData($(this).attr('fb-uid'), {
+            $this.updateLinkData($(this).attr('fb-origuid'), {
                 top: top, left: left,
             });
         });
@@ -291,67 +291,10 @@ LinkeditorLinks.prototype = {
         }
         $(l).addClass('selected');
         this.currentSelection.push(l);
-        this.updateLinkForm();
+        this.linkeditor.form.updateLinkForm();
         this.lastSelectedLink = l;
     },
 
-    updateLinkForm: function () {
-        var container = $('#linkeditor-panel-form');
-        container.html('');
-        var links = $('.link.selected:not(.pendingCreate)');
-        if (links.length != 1) {
-            return;
-        }
-        var link = $(links).eq(0);
-        var type = $(link).attr('fb-type');
-        var form = $("#linkeditor-form-template-" + type).clone(false);
-
-        $(form).attr('id', null);
-        $(form).data('link', link);
-        this.updateFormData(form);
-        container.append(form);
-
-        // Reset select2 fields
-        $(form).find('select.select2_from_array.init').each(function () {
-            $(this).removeClass('init');
-        });
-
-        this.linkeditor.form.initSelect2();
-        this.linkeditor.form.initCodeMirror();
-    },
-
-    updateFormData: function (form) {
-        try {
-            if (form === undefined) {
-                form = $('#linkeditor-panel-form form');
-                if (form.length === 0) {
-                    return;
-                }
-            }
-            var link = $(form).data('link');
-            if (link === undefined || link === null) {
-                return;
-            }
-        } catch (e) {
-            return;
-        }
-        var types = {x: 'dimension', y: 'dimension', w: 'dimension', h: 'dimension', rot: 'dimension'}
-        var map = {top: 'y', left: 'x', width: 'w', height: 'h'};
-        $.each(this.getLinkData(link), function (k, v) {
-            if (map[k] !== undefined) {
-                k = map[k];
-            }
-            var type = 'string';
-            if (types[k] !== undefined) {
-                type = types[k];
-            }
-            if (type === 'dimension') {
-                v = Math.round(parseFloat(v) * 100000) / 100000;
-            }
-            $(form).find('[name=' + k + ']').val(v);
-        });
-    },
-
     checkLastSelectedLink: function () {
         if (this.lastSelectedLink === null || $(this.lastSelectedLink).length === 0) {
             return;
@@ -375,7 +318,7 @@ LinkeditorLinks.prototype = {
     deselectAllLinks: function () {
         this.currentSelection = [];
         $(".link.selected").removeClass('selected');
-        this.updateLinkForm();
+        this.linkeditor.form.updateLinkForm();
     },
 
     offsetSelectedLinks: function (dim, value) {
@@ -386,10 +329,10 @@ LinkeditorLinks.prototype = {
             let data = {};
             data[dim] = newValue;
             $(this).attr('fb-' + dim, newValue).attr('fb-update', '1');
-            $this.updateLinkData($(this).attr('fb-uid'), data);
+            $this.updateLinkData($(this).attr('fb-origuid'), data);
         });
         this.linkeditor.updateFBElements();
-        this.updateFormData();
+        this.linkeditor.form.updateFormData();
     },
 
     getLinksOfPage: function (p) {
@@ -434,6 +377,8 @@ LinkeditorLinks.prototype = {
             change = true;
         }
 
+        link.origuid = link.uid;
+
         let attrs = {};
         $.each(link, function (k, v) {
             attrs['fb-' + k] = v;
@@ -477,7 +422,7 @@ LinkeditorLinks.prototype = {
         let link = this.addLink(data);
         this.deselectAllLinks();
         this.selectLink($(link));
-        this.updateFormData();
+        this.linkeditor.form.updateFormData();
         return $(link);
     },
 
@@ -493,7 +438,7 @@ LinkeditorLinks.prototype = {
         if (triggerChange === undefined) {
             triggerChange = true;
         }
-        delete LINKS[$(link).attr('fb-uid')];
+        delete LINKS[$(link).attr('fb-origuid')];
         $(link).remove();
         if (triggerChange === true) {
             this.linkeditor.hasChanged();
index 533be65d869248174a0b7bab1329e0e1441eab3b..6c64d7db4b1a86eb23e9d84114e4c80828178a31 100644 (file)
@@ -1,3 +1,6 @@
+.select2-hidden-accessible
+    position: fixed !important
+
 #linkeditor-form-templates
     display: none