]> _ Git - fluidbook-toolbox.git/commitdiff
wip #4630 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Jul 2022 17:39:23 +0000 (19:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 19 Jul 2022 17:39:23 +0000 (19:39 +0200)
resources/views/fields/fluidbook_composition.blade.php

index ca76cdff3088d98279126e34fe650f04e74e44fe..21bbc4b965746d03a8ff80043d3e98c7fdcd762c 100644 (file)
                         }
                     });
 
+                    $(document).on('blur', '#pagenumber_input', function () {
+                        $("#pagenumber_input").remove();
+                    });
+
+                    $(document).on('change', '#pagenumber_input', function () {
+                        var v = $(this).val();
+                        var p = $(this).closest('.page').index() + 1;
+                        $("#pagenumber_input").remove();
+                        updateNumFromEdit(v,p);
+                    });
+
+                    $(document).on('click', '#composition_pages .page span', function () {
+                        $("#pagenumber_input").remove();
+                        $(this).append('<input type="text" id="pagenumber_input" value="' + $(this).text() + '" />');
+                        $("#pagenumber_input").focus();
+                        $("#pagenumber_input").get(0).setSelectionRange(0, $(this).text().length);
+
+                        return false;
+                    });
+
                     var listener = new window.keypress.Listener();
                     listener.simple_combo("meta a", function () {
                         if (!compositionIsActive()) {
                     return {
                         selectall: {
                             name: "{{__('Tout sélectionner')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
                                 compositionSelectAll()
                             },
                         },
                         },
                         replaceSelection: {
                             name: "{{__('Remplacer les pages de la sélection')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
 
                             }
                         },
                     return {
                         selectall: {
                             name: "{{__('Tout sélectionner')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
                                 compositionSelectAll()
                             },
                         },
                         sep2: "---------",
                         insertBefore: {
                             name: "{{__('Insérer des pages avant')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
 
                             }
                         },
                         insertAfter: {
                             name: "{{__('Insérer des pages après cette page')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
 
                             }
                         },
                         sep3: "---------",
                         nonum: {
                             name: "{{__('Pas de numérotation à partir de cette page')}}",
-                            callback: function () {
-
+                            callback: function (key, opt) {
+                                updateNum('nonum', opt.$trigger[0]);
                             },
                         },
                         decnum: {
                             name: "{{__("Numérotation décimale à partir de cette page")}}",
-                            callback: function () {
-
+                            callback: function (key, opt) {
+                                updateNum('decnum', opt.$trigger[0]);
                             },
                         },
                         romannum: {
                             name: "{{__("Numérotation romaine à partir de cette page")}}",
-                            callback: function () {
-
+                            callback: function (key, opt) {
+                                updateNum('romnum', opt.$trigger[0]);
                             },
                         },
                         sep4: "---------",
                         links: {
                             name: "{{__('Editer les liens')}}",
-                            callback: function () {
+                            callback: function (key, opt) {
 
                             },
                         },
                     }
                 }
 
+                function getPageNumber() {
+                    return $("#composition_pages .page").length;
+                }
+
+                function updateNum(type, page, start, prefix, separator) {
+                    if (prefix === undefined) {
+                        prefix = '';
+                    }
+                    if (separator === undefined) {
+                        separator = '';
+                    }
+                    if (start === undefined) {
+                        start = 1;
+                    }
+                    var from = page;
+                    if (page === undefined) {
+                        from = 1;
+                    } else if ($(page).is('.page')) {
+                        from = $(page).index() + 1;
+                    }
+
+                    var j = start;
+                    var pages = getPageNumber();
+                    console.log(type, from, start);
+                    for (var i = from; i <= pages; i++) {
+                        var n = prefix + separator + getNumByType(j, type);
+                        console.log(n);
+                        $("#composition_pages .page").eq(i - 1).find('span').text(n);
+                        j++;
+                    }
+                    updateComposition();
+                }
+
+                function updateNumFromEdit(v,p){
+                    /*var from:int = e.info.from;
+                    var text:String = e.info.text;
+                    var type:String;
+                    var start:int;
+                    var prefix:String = '';
+                    var separator:String = '';
+
+                    if (text.indexOf('.') != -1)
+                    {
+                        separator = '.';
+                    }
+                    else if (text.indexOf(' ') != -1)
+                    {
+                        separator = ' ';
+                    }
+
+                    if (separator != '')
+                    {
+                        var ex:Array = text.split(separator);
+                        text = ex.pop();
+                        prefix = ex.join(separator);
+                    }
+
+                    if (text == '')
+                    {
+                        type = 'nonum';
+                        start = 1;
+                    }
+                    else if (CubeMath.isRoman(text))
+                    {
+                        if (CubeString.isUpperCase(text))
+                        {
+                            type = 'romnum';
+                        }
+                        else
+                        {
+                            type = 'lromnum';
+                        }
+                        start = CubeMath.deromanize(text.toUpperCase());
+                    }
+                    else if (CubeMath.isInt(text))
+                    {
+                        type = 'decnum';
+                        start = parseInt(text);
+                    }
+                    else
+                    {
+                        return;
+                    }
+                    updateNum(type, from, start, prefix, separator);*/
+                }
+
+                function getNumByType(val, type) {
+                    if (type === 'nonum') {
+                        return '';
+                    } else if (type === 'decnum') {
+                        return val.toString();
+                    } else if (type === 'romnum') {
+                        return romanize(val);
+                    } else if (type === 'lromnum') {
+                        return romanize(val).toLowerCase();
+                    }
+                    return '';
+                }
+
+                function romanize(num) {
+                    var lookup = {
+                        M: 1000,
+                        CM: 900,
+                        D: 500,
+                        CD: 400,
+                        C: 100,
+                        XC: 90,
+                        L: 50,
+                        XL: 40,
+                        X: 10,
+                        IX: 9,
+                        V: 5,
+                        IV: 4,
+                        I: 1
+                    }, roman = '', i;
+                    for (i in lookup) {
+                        while (num >= lookup[i]) {
+                            roman += i;
+                            num -= lookup[i];
+                        }
+                    }
+                    return roman;
+                }
+
                 initPages();
             });
         </script>
                 min-width: 20px;
                 height: 20px;
                 margin-top: 2px;
+                position: relative;
+            }
+
+            #composition_pages .page span input {
+                position: absolute;
+                top: 0;
+                left: 0;
+                width: 100%;
+                height: 100%;
+                z-index: 1;
+                outline: 0;
+                text-align: center;
             }
 
             #composition_pages .page img {