Added prepare method

This commit is contained in:
Uwe Oestermeier 2019-08-03 09:02:58 +02:00
parent a44fd6c469
commit e502c97de5

View File

@ -1,6 +1,7 @@
/* eslint-disable no-unused-vars */
/* global PDFJS Power1 */
import { getId } from './utils.js' import { getId } from './utils.js'
import { DOMScatter } from './scatter.js' import { DOMScatter } from './scatter.js'
import { InteractionMapper } from './interaction.js'
export class CardLoader { export class CardLoader {
constructor( constructor(
@ -22,7 +23,7 @@ export class CardLoader {
this.x = x this.x = x
this.y = y this.y = y
this.scale = scale this.scale = scale
this.rotation = 0 this.rotation = rotation
this.maxScale = maxScale this.maxScale = maxScale
this.minScale = minScale this.minScale = minScale
this.wantedWidth = width this.wantedWidth = width
@ -30,12 +31,6 @@ export class CardLoader {
this.maxWidth = maxWidth != null ? maxWidth : window.innerWidth this.maxWidth = maxWidth != null ? maxWidth : window.innerWidth
this.maxHeight = maxHeight != null ? maxHeight : window.innerHeight this.maxHeight = maxHeight != null ? maxHeight : window.innerHeight
this.addedNode = null this.addedNode = null
console.log({
width,
height,
maxWidth,
maxHeight
})
} }
unload() { unload() {
@ -120,7 +115,6 @@ export class FrameLoader extends CardLoader {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let isFrame = domNode instanceof HTMLIFrameElement let isFrame = domNode instanceof HTMLIFrameElement
let iframe = isFrame ? domNode : document.createElement('iframe') let iframe = isFrame ? domNode : document.createElement('iframe')
console.log('FrameLoader.load', isFrame, iframe, this.src)
iframe.frameBorder = 0 iframe.frameBorder = 0
iframe.style.scrolling = false iframe.style.scrolling = false
iframe.width = this.wantedWidth iframe.width = this.wantedWidth
@ -147,14 +141,9 @@ export class HTMLLoader extends CardLoader {
let xhr = new XMLHttpRequest() let xhr = new XMLHttpRequest()
xhr.open('GET', this.src, false) xhr.open('GET', this.src, false)
xhr.onload = e => { xhr.onload = e => {
domNode.innerHTML = xhr.response domNode.innerHTML = this.prepare(xhr.response)
this.addedNode = domNode.firstElementChild this.addedNode = domNode.firstElementChild
let { width, height } = this.size(this.addedNode) let { width, height } = this.size(this.addedNode)
console.log('HTMLLoader.load', {
added: this.addedNode,
width,
height
})
if (width) this.wantedWidth = width || this.wantedWidth if (width) this.wantedWidth = width || this.wantedWidth
if (height) this.wantedHeight = height || this.wantedHeight if (height) this.wantedHeight = height || this.wantedHeight
resolve(this) resolve(this)
@ -166,6 +155,18 @@ export class HTMLLoader extends CardLoader {
}) })
} }
/**
* Preoares the html before it is assigned with innerHTML.
* Can be overwritten in subclasses.
*
* @param {*} html
* @returns
* @memberof HTMLLoader
*/
prepare(html) {
return html
}
/** /**
* Tries to determine the size of the addedNode. * Tries to determine the size of the addedNode.
* Checks for explicit width and height style attributes. * Checks for explicit width and height style attributes.
@ -321,7 +322,6 @@ export class DOMFlip {
} }
setupFlippable(flippable, loader) { setupFlippable(flippable, loader) {
console.log('setupFlippable', loader.wantedWidth)
flippable.wantedWidth = loader.wantedWidth flippable.wantedWidth = loader.wantedWidth
flippable.wantedHeight = loader.wantedHeight flippable.wantedHeight = loader.wantedHeight
flippable.wantedScale = loader.scale flippable.wantedScale = loader.scale
@ -331,7 +331,6 @@ export class DOMFlip {
} }
start({ targetCenter = null } = {}) { start({ targetCenter = null } = {}) {
console.log('DOMFlip.start', targetCenter)
if (this.preloadBack) { if (this.preloadBack) {
this.flippable.start({ duration: this.flipDuration, targetCenter }) this.flippable.start({ duration: this.flipDuration, targetCenter })
} else { } else {
@ -481,7 +480,6 @@ export class DOMFlippable {
clickInfo() { clickInfo() {
this.bringToFront() this.bringToFront()
console.log('clickInfo')
this.infoBtn.click() this.infoBtn.click()
} }
@ -508,6 +506,7 @@ export class DOMFlippable {
let startScale = this.element._gsTransform.scaleX let startScale = this.element._gsTransform.scaleX
let w = this.element.style.width let w = this.element.style.width
let h = this.element.style.height let h = this.element.style.height
// eslint-disable-next-line no-console
console.log(info, startX, startY, startAngle, startScale, w, h) console.log(info, startX, startY, startAngle, startScale, w, h)
} }
@ -577,14 +576,12 @@ export class DOMFlippable {
let y = this.flipped ? yy : this.startY let y = this.flipped ? yy : this.startY
let onUpdate = this.onUpdate !== null ? () => this.onUpdate(this) : null let onUpdate = this.onUpdate !== null ? () => this.onUpdate(this) : null
console.log('start', this.flipDuration)
TweenLite.to(this.card, this.flipDuration, { TweenLite.to(this.card, this.flipDuration, {
rotationY: targetY, rotationY: targetY,
ease: Power1.easeOut, ease: Power1.easeOut,
transformOrigin: '50% 50%', transformOrigin: '50% 50%',
onUpdate, onUpdate,
onComplete: e => { onComplete: e => {
console.log('start end', this.flipDuration)
if (this.flipped) { if (this.flipped) {
//this.hide(this.front) //this.hide(this.front)
this.enable(this.backBtn) this.enable(this.backBtn)
@ -615,8 +612,6 @@ export class DOMFlippable {
}, },
force3D: true force3D: true
}) })
console.log('start 2', this.wantedWidth, this.startWidth, { w, h })
// See https://greensock.com/forums/topic/7997-rotate-the-shortest-way/ // See https://greensock.com/forums/topic/7997-rotate-the-shortest-way/
TweenLite.to(this.element, this.flipDuration / 2, { TweenLite.to(this.element, this.flipDuration / 2, {
scale: targetScale, scale: targetScale,