* alors on autorise la mise à jour de la preview
*
*/
- if(LINKS[id].type !== '39') {
- $this.linkeditor.previewLinks.updatePreview(LINKS[id]);
- }
+ //if(LINKS[id].type !== '39') {
+ $this.linkeditor.previewLinks.updatePreview(LINKS[id]);
+ //}
},
updateSelectionData: function (props) {
for(let link in links) {
let $link = $("[fb-uid=" + links[link].uid + "]")
let animationText = $link.attr("fb-image_rollover")
- let animations = this.resolveAnimation(animationText)
- let previewDiv = $("[data-id-preview=" + links[link].uid + "]")
- let el = previewDiv
+ let target = $("#linkeditor-layer-links [data-id-preview='"+links[link].uid+"']")
+ target.css("display","block")
+ let animations = this.resolveAnimation(animationText, target)
+ let previewDiv = links[link].type === '39' ? $("#linkeditor-layer-links > [data-id-preview-wrap="+links[link].uid+"] > [data-id-preview="+links[link].uid+"]") : $("[data-id-preview=" + links[link].uid + "]")
+ var el = previewDiv
- let animWithBackground = animations.filter((v) => v.backgroundColor)
- let backgroundColor = animWithBackground.length > 0 ? animWithBackground[0].backgroundColor : 'transparent'
+ let animWithBackground = animations.filter((v) => v.backgroundcolor)
+ let backgroundColor = animWithBackground.length > 0 ? animWithBackground[0].backgroundcolor : 'transparent'
if(links[link].type !== '45') {
- $link.find('.bg-preview').css('background-color', backgroundColor)
+ $("#linkeditor-layer-links [data-id-preview-wrap='"+links[link].uid+"'],[fb-uid=" + links[link].uid + "]").find('.bg-preview').css('background-color', backgroundColor)
}
/**
complete: function () {
$("#extra-font-face").remove()
$("head").append("<style id='extra-font-face'></style>")
+ $("body").append("<div id='load-extra-font'></div>")
for (let k in FONT_SIZE) {
$("#extra-font-face").append("@font-face{font-family:" + FONT_SIZE[k]['font'] + ";src:url('/fluidbook-publication/" + FLUIDBOOK_DATA.id + "/edit/links/assets/" + FONT_SIZE[k]['hash'] + "' ) format('woff');}")
+ $("#load-extra-font").append("<div id='"+k+"'></div>")
+ $("div#"+k).css("font-family", FONT_SIZE[k]['font'])
}
$("#preview-links").removeClass('disabled');
$this.linkeditor.rulers.updateRulers()
try {
const z = this.linkeditor.zoom.normalizeZoom(this.linkeditor.zoom.getZoom());
const hash = 'fb_' + window.MD5(link.image).toString().substring(0, 10);
+
const capHeight = FONT_SIZE[hash]['capHeight'];
- const cssScale = this.getCssScale()
// On récupère la hauteur du lien
// en prenant en compte le changement de dimension
// lors du zoom
- let h = link.height * z;
+ let h = Math.round((link.height * this.linkeditor.fs) / capHeight) * z;
- let fz = h;
- fz = h / capHeight
+ //console.log(this.linkeditor.fs)
$("[data-id-preview=" + link.uid + "]").text(link.to).css({
- 'font-size': fz.toFixed(2) * 0.8 + 'px',
+ 'font-size': h.toFixed(2) + 'px',
'line-height': capHeight
})
} catch (e) {
- console.log(e)
+ //console.log(e)
}
},
- getCssScale: function() {
- // Voir \Fluidbook\Tools\Compiler\
- const pageZoomFactor = 3;
- const optimalWidth = 567;
- const optimalHeight = 709;
- const pw = FLUIDBOOK_DATA.settings.width;
- const ph = FLUIDBOOK_DATA.settings.height;
-
- return pageZoomFactor * Math.min(( optimalWidth / pw), (optimalHeight / ph))
- },
-
addStyleToWrappersLinkText: function(link) {
let scaleString = false
if (link.image_rollover) {
})
},
- resolveAnimation: function(animationText) {
+ resolveAnimation: function(animationText, target = null) {
let obj = []
+ let origin, origin0_50, origin0_100, origin0_0
+ if(target) {
+ origin = target.attr("data-origin")
+ origin0_50 = target.attr("data-origin-0-50")
+ origin0_100 = target.attr("data-origin-0-100")
+ origin0_0 = target.attr("data-origin-0-0")
+ }
+
if(animationText) {
let animations = animationText.split('---')
let result = []
let o = animations[anim].trim().split('\n')
obj.push({});
result = []
+ if(origin) result['transformorigin'] = origin
for (let k in o) {
let entries = o[k].split('=')
- result[entries[0]] = entries[1]?.replace(/([\"]+)/gm, "")
+ result[entries[0].toLowerCase()] = entries[1]?.replace(/([\"]+)/gm, "")
+ if(entries[0] === "preventFlickering"){
+ result['preventflickering'] = 0
+ }
+ if(entries[0] === "transformOrigin"){
+ if(entries[1]?.replace(/([\"]+)/gm, "") === "0% 50%") {
+ result['transformorigin'] = origin0_50
+ }else if(entries[1]?.replace(/([\"]+)/gm, "") === "0% 100%") {
+ result['transformorigin'] = origin0_100
+ }else if(entries[1]?.replace(/([\"]+)/gm, "") === "0% 0%") {
+ result['transformorigin'] = origin0_0
+ }else if(entries[1]?.replace(/([\"]+)/gm, "") === "center") {
+ result['transformorigin'] = origin
+ }
+ }
}
obj[anim] = Object.assign({}, result)
}
setPreview: function(isZooming = false, reset = false) {
const links = this.linkeditor.links.getLinksOfPage(this.linkeditor.currentPage)
+ if($('#linkeditor-layer-links').length < 1) {
+ $("#linkeditor-zoom").prepend('<div id="linkeditor-layer-links"></div>')
+ }
for (let link in links) {
this.updatePreview(links[link],isZooming,reset)
}
+ this.linkeditor.links.updatePolygonLinks();
},
updatePreview: function(link, isZooming = false, reset = false) {
if ($('[data-id-preview="' + link.uid + '"]').length < 1) {
l.html("<div class='bg-preview'></div><div data-id-preview-wrap='" + link.uid + "'><div data-id-preview='" + link.uid + "'></div></div>")
+ //this.setTransformOrigin(link.uid)
}
$this.previewByType(link.type, isZooming, reset)
}
},
- createPreviewLayerHTML: function(el,zoom = false) {
+ createPreviewLayerHTML: function(el,id) {
let html = `
- <div class="linkeditor-zoom-copy">
- <div class="linkeditor-fluidbook-copy">
- <div class="linkeditor-page linkeditor-page-right-copy" data-page="1"></div>
- <div class="linkeditor-page linkeditor-page-left-copy" data-page="0"></div>
+ <div data-id-preview-wrap="${id}"> <!-- utilisé pour cliper dans la limite de la taille du lien -->
+ <div class='bg-preview'></div>
+ <div data-id-preview="${id}"> <!-- utilisé pour l'animation en general -->
+ <div class="preview"> <!-- utilisé pour l'animation sur des background-image -->
+ <div class="linkeditor-fluidbook-copy" data-id="${id}">
+ <div class="linkeditor-page linkeditor-page-right-copy" data-page="1"></div>
+ <div class="linkeditor-page linkeditor-page-left-copy" data-page="0"></div>
+ </div>
</div>
</div>
+ </div>
`;
- if(zoom) {
+ /*if(zoom) {
html = '<div class="preview-wrapper">'+html+'</div>'
+ }*/
+ if($('#linkeditor-layer-links [data-id-preview-wrap="'+id+'"]').length === 0)
+ {
+ el.append(html)
}
- el.html(html)
},
/**
'transform-origin': '0 100%'
})
- console.log(options)
if(options !== null) {
let countup = new CountUp(previewDiv.attr('id'), previewDiv.attr('data-anim-numeric-value'), options);
countup.start()
let animationText = $link.attr("fb-image_rollover")
let animations = $this.linkeditor.links.resolveAnimation(animationText)
let animZoom = animations.filter((v) => v.type === "zoomout" || v.type === "zoomin")
+ let polygon = $link.attr("fb-polygon")
var previewDiv = $("[data-id-preview=" + $this.linkData.uid + "]")
- /**
- *
- */
if(!isZooming) {
- this.createPreviewLayerHTML(previewDiv,animZoom.length > 0)
-
- if (animZoom.length > 0) {
- $("[data-id-preview=" + $this.linkData.uid + "] .preview-wrapper").addClass("img")
+ /**
+ *
+ */
+ this.createPreviewLayerHTML($("#linkeditor-layer-links"),$this.linkData.uid)
+ this.setTransformOrigin($this.linkData)
+ /*if (animZoom.length > 0) {
+ $("#linkeditor-layer-links [data-id-preview=" + $this.linkData.uid + "] .preview").addClass("img")
let srcImgLeft = $("#linkeditor-page-left .contents img.images").attr('src')
let srcTextLeft = $("#linkeditor-page-left .contents img.texts").attr('src')
bgLeft = 'url(' + srcTextLeft + ')'
}
- $("[data-id-preview=" + $this.linkData.uid + "] .linkeditor-page-left-copy").css({
- "background": bgLeft,
- "background-size": "100%"
+ $("#linkeditor-layer-links [data-id-preview=" + $this.linkData.uid + "] .preview").css({
+ "background-image": bgLeft,
+ "background-size": "100%",
+ "height": "100%"
})
if($("#linkeditor").hasClass("double")) {
bgRight = 'url(' + srcTextRight + ')'
}
- $("[data-id-preview=" + $this.linkData.uid + "] .linkeditor-page-right-copy").css({
+ $(".linkeditor-fluidbook-copy[data-id=" + $this.linkData.uid + "] .linkeditor-page-right-copy").css({
"background": bgRight,
"background-size": "100%"
})
}
//$("[data-id-preview=" + $this.linkData.uid + "] .preview-wrapper .linkeditor-page").remove()
- } else {
- if ($("[data-id-preview=" + $this.linkData.uid + "] img").length < 1) {
- $("#linkeditor-page-left .contents img").clone().addClass('left').appendTo("[data-id-preview=" + $this.linkData.uid + "] .linkeditor-page-left-copy")
- $("#linkeditor-page-right .contents img").clone().addClass('right').appendTo("[data-id-preview=" + $this.linkData.uid + "] .linkeditor-page-right-copy")
+ } else {*/
+ if ($(".linkeditor-fluidbook-copy[data-id=" + $this.linkData.uid + "] img").length < 1) {
+ $("#linkeditor-page-left .contents img").clone().addClass('left').appendTo(".linkeditor-fluidbook-copy[data-id=" + $this.linkData.uid + "] .linkeditor-page-left-copy")
+ $("#linkeditor-page-right .contents img").clone().addClass('right').appendTo(".linkeditor-fluidbook-copy[data-id=" + $this.linkData.uid + "] .linkeditor-page-right-copy")
}
- previewDiv.find(".preview-wrapper").remove()
- }
+ $("#linkeditor-layer-links [data-id-preview=" + $this.linkData.uid + "] .preview").removeClass("img")
+ /*}*/
}
const z = this.linkeditor.zoom.normalizeZoom(this.linkeditor.zoom.getZoom())
*/
let width = $("#linkeditor-fluidbook").css("width")
let height = $("#linkeditor-fluidbook").css("height")
+ let transform = $("#linkeditor-fluidbook").css("transform")
let left_ = $("#linkeditor-fluidbook").css("left")
let top_ = $("#linkeditor-fluidbook").css("top")
- let transform = $("#linkeditor-fluidbook").css("transform")
- $("[data-id-preview=" + $this.linkData.uid + "] .linkeditor-fluidbook-copy").css({'width':width,'height':height,'left':left_,'top':top_,'transform':transform})
+
+ $("#linkeditor-layer-links").css({
+ 'width':width,
+ 'height':height,
+ 'left':left_,
+ 'top':top_,
+ 'transform':transform,
+ })
+
+ $(".linkeditor-fluidbook-copy[data-id="+$this.linkData.uid+"]").css({
+ 'width':width,
+ 'height':height
+ })
+
+ if(polygon) {
+ $("#linkeditor-layer-links [data-id-preview-wrap="+$this.linkData.uid+"]").css({
+ 'z-index': 3,
+ 'clip-path': this.getPolygon($this.linkData.left,$this.linkData.top,polygon)
+ })
+ }else{
+ if(animZoom.length > 0) {
+ $("#linkeditor-layer-links [data-id-preview-wrap=" + $this.linkData.uid + "]").css({
+ 'clip-path': this.getClipPath($this.linkData.left, $this.linkData.top, $this.linkData.width, $this.linkData.height)
+ })
+ }
+ }
+
+ $("#linkeditor-layer-links [data-id-preview="+$this.linkData.uid+"], #linkeditor-layer-links [data-id-preview-wrap="+$this.linkData.uid+"] .bg-preview").css({
+ 'clip-path': this.getClipPath($this.linkData.left,$this.linkData.top,$this.linkData.width,$this.linkData.height)
+ })
+
+ $("#linkeditor-layer-links .bg-preview").css({
+ 'width':'100%',
+ 'height':'100%',
+ 'position': 'absolute',
+ 'background-color': '#fff',
+ 'z-index': 2
+ })
/**
+ *
* Application des styles pour #linkeditor-page-right-copy
+ * Pour caler la page sur la moitié droite
+ *
*/
let left__ = $("#linkeditor-page-right").css("left")
$(".linkeditor-page-right-copy").css('left',left__)
if(reset) {
$this.linkeditor.rulers.updateRulers();
}
- let linkeditorZoomRect = $("#linkeditor-zoom")[0].getBoundingClientRect()
- //console.log(this.linkeditor.globalToEditor(linkeditorZoomRect.left,linkeditorZoomRect.top))
- var left = this.linkeditor.fluidbookToGlobal($this.linkData.left, 'left') - linkeditorZoomRect.left
- var top = this.linkeditor.fluidbookToGlobal($this.linkData.top, 'top') - linkeditorZoomRect.top
-
- //
- requestAnimationFrame(function() {
- previewDiv.find(".linkeditor-zoom-copy").css({
- "left": -left - 1,
- "top": -top - 1,
- })
- })
-
- if(animZoom.length > 0) {
+ /*if(animZoom.length > 0) {
previewDiv.children().appendTo("[data-id-preview=" + $this.linkData.uid + "] .preview-wrapper")
- }
+ }*/
},
previewIframe: function($this) {
previewDiv.find("video").remove()
previewDiv.css("position","relative").append(html)
previewDiv.find("video").css({...$this.absoluteCss, ...{'object-fit': 'fill'} })
- }
+ },
-}
+ getBoundingClientRectByEl(el) {
+ return el[0].getBoundingClientRect()
+ },
+
+ setTransformOrigin(link, option) {
+ const targetDiv = $('#linkeditor-layer-links [data-id-preview="'+link.uid+'"]');
+
+ if(targetDiv !== undefined) {
+ let referenceCenterX = parseInt(link.left) + parseInt(link.width) / 2;
+ let referenceCenterY = parseInt(link.top) + parseInt(link.height) / 2;
+ targetDiv.attr("data-origin", `${referenceCenterX}px ${referenceCenterY}px`);
+
+ let referenceCenterX0 = parseInt(link.left)
+ targetDiv.attr("data-origin-0-50", `${referenceCenterX0}px ${referenceCenterY}px`);
+
+ let referenceCenterY100 = parseInt(link.top) + parseInt(link.height)
+ targetDiv.attr("data-origin-0-100", `${referenceCenterX0}px ${referenceCenterY100}px`);
+ let referenceCenterY0 = parseInt(link.top)
+ targetDiv.attr("data-origin-0-0", `${referenceCenterX0}px ${referenceCenterY0}px`);
+ }
+ },
+
+ getClipPath(x,y,w,h) {
+ let x2 = parseInt(x) + parseInt(w)
+ let y3 = parseInt(y) + parseInt(h)
+
+ return `polygon(${x}px ${y}px, ${x2}px ${y}px, ${x2}px ${y3}px, ${x}px ${y3}px)`
+ },
+
+ getPolygon(x,y,param) {
+ let json = param !== undefined ? JSON.parse(param) : {}
+ let polygon = "polygon("
+ if(json.length > 0) {
+ for(let i in json) {
+ polygon += (parseInt(x)+parseInt(json[i].x))+"px "+(parseInt(y)+parseInt(json[i].y))+"px"
+ if(+i+1 !== json.length) {
+ polygon += ','
+ }
+ }
+ }
+ polygon += ")"
+
+ return polygon
+ }
+}
export default LinkeditorPreviewLinks;