From: Vincent Vanwaelscappel Date: Tue, 19 Jul 2022 17:39:23 +0000 (+0200) Subject: wip #4630 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=f017d8cccbe0b52aa5f93c5f533ffb40a2cc8e2a;p=fluidbook-toolbox.git wip #4630 @1 --- diff --git a/resources/views/fields/fluidbook_composition.blade.php b/resources/views/fields/fluidbook_composition.blade.php index ca76cdff3..21bbc4b96 100644 --- a/resources/views/fields/fluidbook_composition.blade.php +++ b/resources/views/fields/fluidbook_composition.blade.php @@ -26,6 +26,26 @@ } }); + $(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(''); + $("#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()) { @@ -125,7 +145,7 @@ return { selectall: { name: "{{__('Tout sélectionner')}}", - callback: function () { + callback: function (key, opt) { compositionSelectAll() }, }, @@ -138,7 +158,7 @@ }, replaceSelection: { name: "{{__('Remplacer les pages de la sélection')}}", - callback: function () { + callback: function (key, opt) { } }, @@ -149,7 +169,7 @@ return { selectall: { name: "{{__('Tout sélectionner')}}", - callback: function () { + callback: function (key, opt) { compositionSelectAll() }, }, @@ -163,45 +183,169 @@ 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(); }); @@ -256,6 +400,18 @@ 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 {