});
$(document).on('mousedown', '.link', function (e) {
- console.log('mousedown')
if ($this.linkeditor.rightClick) {
return true;
}
}
},
- updatePreview: function(link, zoom = false) {
+ updatePreview: function(link, zooming = false) {
if($("#preview-links").hasClass("active")) {
let linkData = link
})
this.updateFontSize(link)
} else if (linkData.type === '39') {
- const pw = $(".linkeditor-page").get(0).getBoundingClientRect().width
- const ph = $(".linkeditor-page").get(0).getBoundingClientRect().height
+ const pw = $(".linkeditor-page img").get(0).getBoundingClientRect().width
+ const ph = $(".linkeditor-page img").get(0).getBoundingClientRect().height
if($("[data-id-preview=" + linkData.uid + "] .canvas").length < 1) {
- $("[data-id-preview=" + linkData.uid + "]").css({
- 'transform': 'translate(-1px, -1px)'
- }).html('<canvas id="canvas'+ linkData.uid+'" width="'+pw* this.linkeditor.zoom.zoom+'" height="'+ph* this.linkeditor.zoom.zoom+'"></canvas>')
- //$("[data-id-preview=" + linkData.uid + "]").html("<div class='canvas' style='height:100%;clip-path:inset(0 0 0 0);'></div>")
+ $("[data-id-preview=" + linkData.uid + "]").html('<div class="container-canvas"><div class="wrapper-canvas"><canvas id="canvas'+ linkData.uid+'" width="'+pw+'" height="'+ph+'"></canvas></div></div>')
}
- /*if($("[data-id-preview=" + linkData.uid + "] .canvas img").length < 1) {
- let wp = $(".linkeditor-page").get(0).getBoundingClientRect().width
- let hp = $(".linkeditor-page").get(0).getBoundingClientRect().height
- $("#linkeditor-page-left .contents img").clone().addClass('left').appendTo("[data-id-preview=" + linkData.uid + "] .canvas")
- $("#linkeditor-page-right .contents img").clone().addClass('right').appendTo("[data-id-preview=" + linkData.uid + "] .canvas")
- $('[data-id-preview="' + linkData.uid + '"] .canvas img.right').parents().css("transform-style","preserve-3d")
- $('[data-id-preview="' + linkData.uid + '"] .canvas img').css({
- "transform-style":"preserve-3d",
- 'backface-visibility': 'hidden',
- 'overflow': 'hidden',
- 'position': 'absolute',
- 'will-change': 'transform, left, top'
- })
- }*/
const pageRightRect = $("#linkeditor-page-right").get(0).getBoundingClientRect()
const pageLeftRect = $("#linkeditor-page-left").get(0).getBoundingClientRect()
- const linkeditorFluidbookStyle = $("#linkeditor-fluidbook")[0].style
- let scale = $("#linkeditor-fluidbook")[0].style.transform.split('(')[1].replace(')',''),
- width = $(".linkeditor-page")[0].style.width.replace('px',''),
- height = $(".linkeditor-page")[0].style.height.replace('px','')
-
-
const $this = this
- requestAnimationFrame(function() {
-
- let yRight = ($this.linkeditor.fluidbookToGlobal(linkData.top, "top") - (pageRightRect.y)),
- xRight = ($this.linkeditor.fluidbookToGlobal(linkData.left, "left") - (pageRightRect.x)),
- yLeft = ($this.linkeditor.fluidbookToGlobal(linkData.top, "top") - (pageLeftRect.y)),
- xLeft = ($this.linkeditor.fluidbookToGlobal(linkData.left, "left") - (pageLeftRect.x))
-
- /*$('[data-id-preview="' + linkData.uid + '"] .canvas img').css({
- 'width': ((width*scale))+'px',
- 'height': ((height*scale))+'px',
- 'transform': 'scale('+$this.linkeditor.zoom.zoom+')',
- 'transform-origin': 'top left'
- })
- $('[data-id-preview="' + linkData.uid + '"] .canvas img.left').css({
- 'left': -xLeft + ($this.linkeditor.zoom.zoom / 2) +'px',
- 'top': -yLeft + ($this.linkeditor.zoom.zoom / 2) +'px',
- })
- $('[data-id-preview="' + linkData.uid + '"] .canvas img.right').css({
- 'left': -xRight + ($this.linkeditor.zoom.zoom / 2) +'px',
- 'top': -yRight + ($this.linkeditor.zoom.zoom / 2) + 'px',
- })*/
+ $('.wrapper-canvas').css({
+ 'transform-origin': '0 0'
+ })
+ $('[data-id-preview="' + linkData.uid + '"] #canvas'+ linkData.uid).css({
+ 'transform-origin': '0 0'
+ })
+
+ let ultimateTop = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my).y - (this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my).y - linkData.top),
+ ultimateLeft = this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my).x - (this.linkeditor.globalToFluidbook(this.linkeditor.mx, this.linkeditor.my).x - linkData.left)
+
+ let yRight = $this.linkeditor.fluidbookToGlobal(ultimateTop, 'top') - (pageRightRect.y),
+ xRight = $this.linkeditor.fluidbookToGlobal(ultimateLeft, 'left') - (pageRightRect.x),
+ yLeft = $this.linkeditor.fluidbookToGlobal(ultimateTop, 'top') - (pageLeftRect.y),
+ xLeft = $this.linkeditor.fluidbookToGlobal(ultimateLeft, 'left') - (pageLeftRect.x)
+
+ /*
+ * TEST LOG
+ * */
+ let imgRect = $("#linkeditor-page-right .images").get(0).getBoundingClientRect()
+ console.log("imgRect",imgRect.x,imgRect.y)
+ console.log("imgRect global to fluidbook",this.linkeditor.globalToFluidbook(imgRect.x,imgRect.y))
+ console.log("linkData",linkData)
+ console.log("xRight,yRight",xRight.toFixed(2),yRight)
+ console.log("pw,ph",pw,ph)
+ console.log("getFluidbookPositionOfCursor", this.linkeditor.zoom.getFluidbookPositionOfCursor())
+ console.log("------")
+ /*
+ *
+ *
+ * */
+
+ requestAnimationFrame(function () {
const canvas = $('#canvas'+ linkData.uid).get(0),
ctx = canvas.getContext('2d')
var texts2 = new Image();
texts2.src = $("#linkeditor-page-right .contents .texts").attr('src')
- ctx.drawImage(image,-xLeft,-yLeft,-(width*scale) * $this.linkeditor.zoom.zoom,(height*scale) * $this.linkeditor.zoom.zoom);
- ctx.drawImage(texts,-xLeft,-yLeft,-(width*scale) * $this.linkeditor.zoom.zoom,(height*scale) * $this.linkeditor.zoom.zoom);
- ctx.drawImage(image2,-xRight,-yRight,(width*scale) * $this.linkeditor.zoom.zoom,(height*scale) * $this.linkeditor.zoom.zoom);
- ctx.drawImage(texts2,-xRight,-yRight,(width*scale) * $this.linkeditor.zoom.zoom,(height*scale) * $this.linkeditor.zoom.zoom);
+ ctx.drawImage(image,-xLeft,-yLeft,pw,ph);
+ ctx.drawImage(texts,-xLeft,-yLeft,pw,ph);
+ ctx.drawImage(image2,-xRight.toFixed(2),-yRight,pw,ph);
+ ctx.drawImage(texts2,-xRight.toFixed(2),-yRight,pw,ph);
})
-
}
+
if (linkData.type === '10') {
let paramIframe = 'accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share;'
}
},
- setPreview: function() {
+ setPreview: function(zooming = false) {
const links = this.getLinksOfPage(this.linkeditor.currentPage)
for(let link in links) {
- this.updatePreview(links[link])
+ this.updatePreview(links[link], zooming)
}
},