Working on stacked buttons.
This commit is contained in:
+37
-139
@@ -32,8 +32,7 @@ export default class Card {
|
||||
console.log('Setup Card...', modules)
|
||||
context.modules = []
|
||||
modules.forEach(module => {
|
||||
if (module.apply(context))
|
||||
context.modules.push(module.constructor.name)
|
||||
if (module.apply(context)) context.modules.push(module.constructor.name)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,10 +137,7 @@ export default class Card {
|
||||
event.stopPropagation()
|
||||
if (callStack) callStack.call(that, ...args)
|
||||
else {
|
||||
console.error(
|
||||
'Could not call callback function ' + attributeVal,
|
||||
...args
|
||||
)
|
||||
console.error('Could not call callback function ' + attributeVal, ...args)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -168,9 +164,7 @@ export default class Card {
|
||||
/<\s*(a|video|img|image|circle)\s(.*?)(xlink:href|href|src)\s*=\s*["'](\..*?)["']\s*(.*?)>/g,
|
||||
function(data) {
|
||||
let path = that._getRelativePath(arguments[4])
|
||||
const tag = `<${arguments[1]} ${arguments[2]} ${
|
||||
arguments[3]
|
||||
}="${path}" ${arguments[5]}>`
|
||||
const tag = `<${arguments[1]} ${arguments[2]} ${arguments[3]}="${path}" ${arguments[5]}>`
|
||||
/* if (that.debug) */ console.log('Adjusted: ', tag)
|
||||
return tag
|
||||
}
|
||||
@@ -328,16 +322,13 @@ export default class Card {
|
||||
//Test if meanwhile another popup was registered...
|
||||
this._getPopup(context) ||
|
||||
// Or if an highlight was loaded, if the highlight already was closed.
|
||||
(highlight !== null &&
|
||||
!this._isHighlightActive(context, highlight))
|
||||
(highlight !== null && !this._isHighlightActive(context, highlight))
|
||||
) {
|
||||
//.. if so remove the create popup instantly.
|
||||
popup.remove()
|
||||
} else {
|
||||
// Otherwise set the popup regularly.
|
||||
let popupParagraphs = popup.element.querySelectorAll(
|
||||
'.popupContent > *'
|
||||
)
|
||||
let popupParagraphs = popup.element.querySelectorAll('.popupContent > *')
|
||||
|
||||
// Remove a design error of naming two adjacent elements popup.
|
||||
// Todo: fix this properly and remove this code.
|
||||
@@ -388,8 +379,7 @@ export default class Card {
|
||||
* @memberof Card
|
||||
*/
|
||||
static _createPopup(context, position, content, options = {}) {
|
||||
if (this.debug)
|
||||
console.log('Create Popup.', context, position, content, options)
|
||||
if (this.debug) console.log('Create Popup.', context, position, content, options)
|
||||
let popup = new Popup(
|
||||
Object.assign(
|
||||
{
|
||||
@@ -482,9 +472,7 @@ export default class Card {
|
||||
node = event.target
|
||||
}
|
||||
if (local == null) {
|
||||
let globalClick = event.center
|
||||
? event.center
|
||||
: { x: event.x, y: event.y }
|
||||
let globalClick = event.center ? event.center : { x: event.x, y: event.y }
|
||||
local = Points.fromPageToNode(context, globalClick)
|
||||
}
|
||||
if (this.debug) console.log('loadPopup', event)
|
||||
@@ -517,17 +505,11 @@ export default class Card {
|
||||
|
||||
// Extract the body from the Popup site.
|
||||
let parser = new DOMParser()
|
||||
let popupPage = parser.parseFromString(
|
||||
xhr.responseText,
|
||||
'text/html'
|
||||
)
|
||||
let popupPage = parser.parseFromString(xhr.responseText, 'text/html')
|
||||
|
||||
//Fix the relative path of loaded images in the popup.
|
||||
popupPage.querySelectorAll('img').forEach(node => {
|
||||
node.setAttribute(
|
||||
'src',
|
||||
that._getRelativePath(node.getAttribute('src'))
|
||||
)
|
||||
node.setAttribute('src', that._getRelativePath(node.getAttribute('src')))
|
||||
})
|
||||
let html = popupPage.body.innerHTML
|
||||
/**
|
||||
@@ -549,18 +531,10 @@ export default class Card {
|
||||
Card._cleanup(context)
|
||||
|
||||
if (!isSame) {
|
||||
Card._activateCorrespondingHighlights(
|
||||
context,
|
||||
node,
|
||||
parentArticle
|
||||
)
|
||||
Card._activateCorrespondingHighlights(context, node, parentArticle)
|
||||
|
||||
let callback = (popup, callback) => {
|
||||
if (this.debug)
|
||||
console.log(
|
||||
'Close popup (Editable = ' + editable + ').',
|
||||
popup
|
||||
)
|
||||
if (this.debug) console.log('Close popup (Editable = ' + editable + ').', popup)
|
||||
if (editable) {
|
||||
let isDirty = mainController.askSaveNode()
|
||||
if (isDirty)
|
||||
@@ -596,8 +570,7 @@ export default class Card {
|
||||
}
|
||||
//console.log("onreadystatechange", editable)
|
||||
if (editable) {
|
||||
if (this.debug)
|
||||
console.log('pushController', src, popup.insertedNode)
|
||||
if (this.debug) console.log('pushController', src, popup.insertedNode)
|
||||
mainController.pushController(popup.insertedNode, src)
|
||||
}
|
||||
}
|
||||
@@ -627,10 +600,7 @@ export default class Card {
|
||||
}
|
||||
if (correspondingHighlights.length > 0) {
|
||||
for (let highlight of correspondingHighlights) {
|
||||
if (
|
||||
highlight.parentNode &&
|
||||
highlight.parentNode.nodeName.toLowerCase() == 'g'
|
||||
) {
|
||||
if (highlight.parentNode && highlight.parentNode.nodeName.toLowerCase() == 'g') {
|
||||
Highlight.openHighlight(highlight, {
|
||||
animation: Card.highlightAnimation
|
||||
})
|
||||
@@ -729,10 +699,7 @@ export default class Card {
|
||||
let matrix = node.getCTM()
|
||||
|
||||
let point = svgPoint.matrixTransform(matrix)
|
||||
let global = Points.fromNodeToPage(
|
||||
node.closest('div'),
|
||||
point
|
||||
)
|
||||
let global = Points.fromNodeToPage(node.closest('div'), point)
|
||||
let local = Points.fromPageToNode(context, global)
|
||||
|
||||
let overlay = document.createElement('div')
|
||||
@@ -778,16 +745,12 @@ export default class Card {
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status == 200 || xhr.status == 0) {
|
||||
let html = this.postProcessResponseText(
|
||||
xhr.responseText
|
||||
)
|
||||
let html = this.postProcessResponseText(xhr.responseText)
|
||||
let selector = Card.popupHtmlSelector
|
||||
let content = { html: html.body.innerHTML, selector }
|
||||
resolve(content)
|
||||
} else {
|
||||
reject(
|
||||
` Popup request failed (Code: ${xhr.status}): Could not load resource: ${src}`
|
||||
)
|
||||
reject(` Popup request failed (Code: ${xhr.status}): Could not load resource: ${src}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -802,8 +765,7 @@ export default class Card {
|
||||
|
||||
let editable = Card.isEditable()
|
||||
if (editable) {
|
||||
if (node.classList.contains('zoomable-icon'))
|
||||
this._openZoomable(event)
|
||||
if (node.classList.contains('zoomable-icon')) this._openZoomable(event)
|
||||
return
|
||||
}
|
||||
this._openZoomable(event)
|
||||
@@ -852,10 +814,7 @@ export default class Card {
|
||||
globalBottomRight = Points.fromNodeToPage(zoomable, globalBottomRight)
|
||||
let globalFigurePos = Points.fromNodeToPage(zoomable, { x: 0, y: 0 })
|
||||
let localFigurePos = Points.fromPageToNode(wrapper, globalFigurePos)
|
||||
let relativeBottomRight = Points.fromPageToNode(
|
||||
zoomable,
|
||||
globalBottomRight
|
||||
)
|
||||
let relativeBottomRight = Points.fromPageToNode(zoomable, globalBottomRight)
|
||||
|
||||
let width =
|
||||
relativeBottomRight.x +
|
||||
@@ -969,12 +928,8 @@ export default class Card {
|
||||
})
|
||||
|
||||
let zoomedFigStyle = window.getComputedStyle(zoomedFig)
|
||||
let borderX =
|
||||
parseFloat(zoomedFigStyle.borderLeftWidth) +
|
||||
parseFloat(zoomedFigStyle.borderRightWidth)
|
||||
let borderY =
|
||||
parseFloat(zoomedFigStyle.borderBottomWidth) +
|
||||
parseFloat(zoomedFigStyle.borderTopWidth)
|
||||
let borderX = parseFloat(zoomedFigStyle.borderLeftWidth) + parseFloat(zoomedFigStyle.borderRightWidth)
|
||||
let borderY = parseFloat(zoomedFigStyle.borderBottomWidth) + parseFloat(zoomedFigStyle.borderTopWidth)
|
||||
|
||||
const scaleFactor = 2
|
||||
const transformOrigin = 'bottom right'
|
||||
@@ -1026,14 +981,7 @@ export default class Card {
|
||||
.to(zoomCaption, this.animation.fade, {
|
||||
autoAlpha: 1
|
||||
})
|
||||
} else
|
||||
this._openZoomableEditorBehaviour(
|
||||
wrapper,
|
||||
img,
|
||||
zoomable,
|
||||
zoomedFig,
|
||||
current
|
||||
)
|
||||
} else this._openZoomableEditorBehaviour(wrapper, img, zoomable, zoomedFig, current)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1066,13 +1014,7 @@ export default class Card {
|
||||
return parent.querySelector('.icon')
|
||||
}
|
||||
|
||||
static _openZoomableEditorBehaviour(
|
||||
wrapper,
|
||||
img,
|
||||
zoomable,
|
||||
zoomedFig,
|
||||
current
|
||||
) {
|
||||
static _openZoomableEditorBehaviour(wrapper, img, zoomable, zoomedFig, current) {
|
||||
let zoomContainer = document.createElement('div')
|
||||
let zoomIcon = zoomable.querySelector('.zoom-icon')
|
||||
zoomContainer.style.position = 'relative'
|
||||
@@ -1166,8 +1108,7 @@ export default class Card {
|
||||
* @memberof Card
|
||||
*/
|
||||
static closeZoomable(context, zoomable, zoomedFig) {
|
||||
if (this.debug)
|
||||
console.log('Close Zoomable', context, zoomable, zoomedFig)
|
||||
if (this.debug) console.log('Close Zoomable', context, zoomable, zoomedFig)
|
||||
|
||||
if (zoomable) {
|
||||
this._unsetZoomable(context)
|
||||
@@ -1218,13 +1159,7 @@ export default class Card {
|
||||
* @param {*} src - The src of the expanded element
|
||||
* @param {*} callback - A callback that is called when the expanded element is closed
|
||||
*/
|
||||
static expandIndexCard(
|
||||
card,
|
||||
html,
|
||||
tagName = 'article',
|
||||
src = null,
|
||||
callback = null
|
||||
) {
|
||||
static expandIndexCard(card, html, tagName = 'article', src = null, callback = null) {
|
||||
let editable = Card.isEditable()
|
||||
|
||||
let context = this.getContext(card)
|
||||
@@ -1257,10 +1192,7 @@ export default class Card {
|
||||
|
||||
let globalPreviewRect = Card._getGlobalRect(card)
|
||||
let globalIndexCardRect = Card._getGlobalRect(indexbox)
|
||||
let localOrigin = Points.fromPageToNode(
|
||||
indexbox,
|
||||
Rect.getPosition(globalPreviewRect)
|
||||
)
|
||||
let localOrigin = Points.fromPageToNode(indexbox, Rect.getPosition(globalPreviewRect))
|
||||
|
||||
let scaleX = globalPreviewRect.width / globalIndexCardRect.width
|
||||
let scaleY = globalPreviewRect.height / globalIndexCardRect.height
|
||||
@@ -1331,15 +1263,12 @@ export default class Card {
|
||||
let cardName = strparts[strparts.length - 1]
|
||||
strparts = card.className.split(' ')
|
||||
let cardType = strparts[1]
|
||||
let msg =
|
||||
'Card: ' + cardID + ': openTopic: ' + cardType + ', ' + cardName
|
||||
let msg = 'Card: ' + cardID + ': openTopic: ' + cardType + ', ' + cardName
|
||||
console.log('Logging:', msg)
|
||||
Logging.log(msg)
|
||||
}
|
||||
|
||||
let desiredBorderBottomWidth = parseInt(
|
||||
window.getComputedStyle(titlebar).borderBottomWidth
|
||||
)
|
||||
let desiredBorderBottomWidth = parseInt(window.getComputedStyle(titlebar).borderBottomWidth)
|
||||
TweenLite.to(clone, Card.animation.articleTransition, {
|
||||
x: -padding,
|
||||
y: -padding,
|
||||
@@ -1360,8 +1289,7 @@ export default class Card {
|
||||
})
|
||||
|
||||
// Retain the border at same visual thickness.
|
||||
titlebar.style.borderBottomWidth =
|
||||
desiredBorderBottomWidth / transform.scaleY + 'px'
|
||||
titlebar.style.borderBottomWidth = desiredBorderBottomWidth / transform.scaleY + 'px'
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1384,13 +1312,7 @@ export default class Card {
|
||||
let cardName = strparts[strparts.length - 1]
|
||||
strparts = card.className.split(' ')
|
||||
let cardType = strparts[1]
|
||||
let msg =
|
||||
'Card: ' +
|
||||
cardID +
|
||||
': closeTopic: ' +
|
||||
cardType +
|
||||
', ' +
|
||||
cardName
|
||||
let msg = 'Card: ' + cardID + ': closeTopic: ' + cardType + ', ' + cardName
|
||||
console.log('Logging:', msg)
|
||||
Logging.log(msg)
|
||||
}
|
||||
@@ -1457,8 +1379,7 @@ export default class Card {
|
||||
})
|
||||
|
||||
// Retain the border at same visual thickness.
|
||||
titlebar.style.borderBottomWidth =
|
||||
desiredBorderBottomWidth / transform.scaleY + 'px'
|
||||
titlebar.style.borderBottomWidth = desiredBorderBottomWidth / transform.scaleY + 'px'
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1468,9 +1389,7 @@ export default class Card {
|
||||
|
||||
if (iconClone == null) {
|
||||
iconClone = clone.querySelector('.cardicon')
|
||||
console.warn(
|
||||
"Legacy selector. Change it to 'card-icon' and find a more suitable name."
|
||||
)
|
||||
console.warn("Legacy selector. Change it to 'card-icon' and find a more suitable name.")
|
||||
}
|
||||
|
||||
if (iconClone.tagName == 'img') {
|
||||
@@ -1478,11 +1397,7 @@ export default class Card {
|
||||
}
|
||||
//console.log("ICON: ", iconClone)
|
||||
iconClone.classList.remove('info')
|
||||
iconClone.classList.add(
|
||||
'close',
|
||||
'view-button',
|
||||
'transparent-background'
|
||||
)
|
||||
iconClone.classList.add('close', 'view-button', 'transparent-background')
|
||||
|
||||
// We append the icon clone to the subcard-content.
|
||||
// Then it's always on the content and not on the background
|
||||
@@ -1589,13 +1504,7 @@ export default class Card {
|
||||
// card.insertAdjacentElement('afterbegin', article)
|
||||
// TweenLite.set(article, { autoAlpha: 0 })
|
||||
|
||||
Card.expandIndexCard(
|
||||
card,
|
||||
parsedHTML,
|
||||
'article',
|
||||
relativeSource,
|
||||
saveCallback
|
||||
)
|
||||
Card.expandIndexCard(card, parsedHTML, 'article', relativeSource, saveCallback)
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
@@ -1632,9 +1541,7 @@ export default class Card {
|
||||
let dom = child.closest('.info-card')
|
||||
if (!dom) {
|
||||
dom = child.querySelector('.wrapper')
|
||||
console.warn(
|
||||
"Change the 'wrapper' class to 'info-card' it's more suitable."
|
||||
)
|
||||
console.warn("Change the 'wrapper' class to 'info-card' it's more suitable.")
|
||||
}
|
||||
return dom // (dom == null) ? document.body : dom
|
||||
}
|
||||
@@ -1782,9 +1689,7 @@ export default class Card {
|
||||
if (indexbox != null) {
|
||||
// column != null ||
|
||||
let links = Array.from(indexbox.getElementsByTagName('a'))
|
||||
let globalClick = event.center
|
||||
? event.center
|
||||
: { x: event.x, y: event.y }
|
||||
let globalClick = event.center ? event.center : { x: event.x, y: event.y }
|
||||
let localClick = Points.fromPageToNode(indexbox, globalClick)
|
||||
|
||||
let linkRects = links.map(link => {
|
||||
@@ -1819,16 +1724,9 @@ export default class Card {
|
||||
let closestLinkIndex = distances.indexOf(Math.min(...distances))
|
||||
let closestLink = links[closestLinkIndex]
|
||||
|
||||
console.log(
|
||||
'finding closest links',
|
||||
closestLink,
|
||||
closestLink.getClientRects()
|
||||
)
|
||||
console.log('finding closest links', closestLink, closestLink.getClientRects())
|
||||
|
||||
if (
|
||||
distances[closestLinkIndex] < 44 &&
|
||||
closestLink.getAttribute('href')
|
||||
) {
|
||||
if (distances[closestLinkIndex] < 44 && closestLink.getAttribute('href')) {
|
||||
// Adapt context and local position
|
||||
let context = this.getContext(closestLink)
|
||||
let local = Points.fromPageToNode(context, globalClick)
|
||||
|
||||
+7
-29
@@ -60,10 +60,7 @@ export default class Highlight extends Object {
|
||||
if (circle.classList.length == 0) {
|
||||
circle.removeAttribute('class')
|
||||
}
|
||||
if (
|
||||
circle.hasAttribute('id') &&
|
||||
circle.getAttribute('id').startsWith('@@')
|
||||
) {
|
||||
if (circle.hasAttribute('id') && circle.getAttribute('id').startsWith('@@')) {
|
||||
circle.removeAttribute('id')
|
||||
}
|
||||
circle.removeAttribute('data-svg-origin')
|
||||
@@ -78,10 +75,7 @@ export default class Highlight extends Object {
|
||||
}
|
||||
}
|
||||
|
||||
static expand(
|
||||
obj,
|
||||
{ scale = 2, duration = 3, stroke = 2, onComplete = null } = {}
|
||||
) {
|
||||
static expand(obj, { scale = 2, duration = 3, stroke = 2, onComplete = null } = {}) {
|
||||
if (obj == null) return
|
||||
//console.log("expand")
|
||||
obj.classList.add('zooming')
|
||||
@@ -166,9 +160,7 @@ export default class Highlight extends Object {
|
||||
this.shrink(maskImage, { stroke })
|
||||
return
|
||||
}
|
||||
let circles = Array.from(circleGroup.children).filter(
|
||||
e => e.tagName == 'circle'
|
||||
)
|
||||
let circles = Array.from(circleGroup.children).filter(e => e.tagName == 'circle')
|
||||
for (let c of circles) {
|
||||
//console.log("shrinking all circles")
|
||||
this.shrink(c, { stroke })
|
||||
@@ -188,10 +180,7 @@ export default class Highlight extends Object {
|
||||
return false
|
||||
}
|
||||
|
||||
static openHighlight(
|
||||
target,
|
||||
{ animation = 0.5, scale = 2, onExpanded = null } = {}
|
||||
) {
|
||||
static openHighlight(target, { animation = 0.5, scale = 2, onExpanded = null } = {}) {
|
||||
if (Highlight._isExpanded(target)) {
|
||||
console.log('Target is already expanded!')
|
||||
return
|
||||
@@ -205,10 +194,7 @@ export default class Highlight extends Object {
|
||||
let image = parent.querySelector(imageId)
|
||||
if (image) {
|
||||
this._bringToFront(image)
|
||||
} else
|
||||
console.error(
|
||||
'Could not find corresponding image element.'
|
||||
)
|
||||
} else console.error('Could not find corresponding image element.')
|
||||
} else console.log('Element was no parent:', target)
|
||||
}
|
||||
this._bringToFront(target)
|
||||
@@ -253,12 +239,7 @@ export default class Highlight extends Object {
|
||||
if (target && parent) {
|
||||
parent.removeChild(target)
|
||||
parent.appendChild(target)
|
||||
} else
|
||||
console.error(
|
||||
'Could not bring to front. Either no target or no parent.',
|
||||
target,
|
||||
parent
|
||||
)
|
||||
} else console.error('Could not bring to front. Either no target or no parent.', target, parent)
|
||||
}
|
||||
|
||||
static _getSVGMask(circle, { svgRoot = null, image = null } = {}) {
|
||||
@@ -293,10 +274,7 @@ export default class Highlight extends Object {
|
||||
* @returns
|
||||
* @memberof Highlight
|
||||
*/
|
||||
static _createSVGMask(
|
||||
element,
|
||||
{ svgRoot = null, image = null, id = null } = {}
|
||||
) {
|
||||
static _createSVGMask(element, { svgRoot = null, image = null, id = null } = {}) {
|
||||
// We can fetch these values here, but it's more efficient to
|
||||
// simply pass them in, as it's likely they were already retrieved beforehand.
|
||||
if (svgRoot == null) svgRoot = element.closest('svg')
|
||||
|
||||
+16
-57
@@ -48,10 +48,7 @@ export class CardPluginBase {
|
||||
}
|
||||
|
||||
_getVerificationFunctions(context) {
|
||||
return [
|
||||
this._verifyContext.bind(this, context),
|
||||
this._verifyRequirements.bind(this, context)
|
||||
]
|
||||
return [this._verifyContext.bind(this, context), this._verifyRequirements.bind(this, context)]
|
||||
}
|
||||
|
||||
_verifyContext(context) {
|
||||
@@ -139,11 +136,7 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
constructor(
|
||||
wrapperSelector,
|
||||
overlaySelector = null,
|
||||
{
|
||||
zoomAnimationDuration = 0.4,
|
||||
fadeAnimationDuration = 0.4,
|
||||
interactionType = 'tap'
|
||||
} = {}
|
||||
{ zoomAnimationDuration = 0.4, fadeAnimationDuration = 0.4, interactionType = 'tap' } = {}
|
||||
) {
|
||||
super()
|
||||
this.wrapperSelector = wrapperSelector
|
||||
@@ -160,14 +153,7 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
|
||||
_getVerificationFunctions(context) {
|
||||
let arr = super._getVerificationFunctions(context)
|
||||
let funcs = [
|
||||
this._verifyElementsExist.bind(
|
||||
this,
|
||||
context,
|
||||
this.wrapperSelector,
|
||||
this.overlaySelector
|
||||
)
|
||||
]
|
||||
let funcs = [this._verifyElementsExist.bind(this, context, this.wrapperSelector, this.overlaySelector)]
|
||||
return arr.concat(funcs)
|
||||
}
|
||||
|
||||
@@ -252,9 +238,7 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
* The minor side should not exceed the height of the context window.
|
||||
*/
|
||||
const maxMinorSize =
|
||||
context.offsetHeight -
|
||||
2 * parseInt(headerStlye.paddingTop) -
|
||||
2 * parseInt(headerStlye.marginTop)
|
||||
context.offsetHeight - 2 * parseInt(headerStlye.paddingTop) - 2 * parseInt(headerStlye.marginTop)
|
||||
|
||||
const max = {
|
||||
width: context.offsetWidth * maxFillRatio,
|
||||
@@ -284,10 +268,7 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
// const minorImageSize = getImageSize(minorSide)
|
||||
|
||||
let ratio = getImageSize(minorSide) / getImageSize(majorSide)
|
||||
let size =
|
||||
majorImageSize > max[majorSide.name]
|
||||
? max[majorSide.name]
|
||||
: majorImageSize
|
||||
let size = majorImageSize > max[majorSide.name] ? max[majorSide.name] : majorImageSize
|
||||
|
||||
if (size * ratio > maxMinorSize) {
|
||||
size = maxMinorSize / ratio
|
||||
@@ -298,10 +279,7 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
height: 0
|
||||
}
|
||||
|
||||
let position = Points.fromPageToNode(
|
||||
context,
|
||||
Points.fromNodeToPage(source, { x: 0, y: 0 })
|
||||
)
|
||||
let position = Points.fromPageToNode(context, Points.fromNodeToPage(source, { x: 0, y: 0 }))
|
||||
|
||||
let targetOffset = {
|
||||
x: 0,
|
||||
@@ -312,13 +290,9 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
targetDimensions[minorSide.name] = size * ratio
|
||||
|
||||
targetOffset[majorSide.axis] =
|
||||
(context['offset' + capitalize(majorSide.name)] -
|
||||
targetDimensions[majorSide.name]) /
|
||||
2
|
||||
(context['offset' + capitalize(majorSide.name)] - targetDimensions[majorSide.name]) / 2
|
||||
targetOffset[minorSide.axis] =
|
||||
(context['offset' + capitalize(minorSide.name)] -
|
||||
targetDimensions[minorSide.name]) /
|
||||
2
|
||||
(context['offset' + capitalize(minorSide.name)] - targetDimensions[minorSide.name]) / 2
|
||||
|
||||
overlay.appendChild(imageWrapper)
|
||||
|
||||
@@ -358,18 +332,14 @@ CardPlugin.EnlargeableThumbnail = class EnlargeableThumbnail extends CardPluginB
|
||||
}
|
||||
|
||||
getBorderHeight(style) {
|
||||
const borderWidth =
|
||||
parseInt(style.borderTopWidth) + parseInt(style.borderBottomWidth)
|
||||
const padding =
|
||||
parseInt(style.paddingTop) + parseInt(style.paddingBottom)
|
||||
const borderWidth = parseInt(style.borderTopWidth) + parseInt(style.borderBottomWidth)
|
||||
const padding = parseInt(style.paddingTop) + parseInt(style.paddingBottom)
|
||||
return parseInt(style.width) + borderWidth + padding
|
||||
}
|
||||
|
||||
getBorderWidth(style) {
|
||||
const borderWidth =
|
||||
parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth)
|
||||
const padding =
|
||||
parseInt(style.paddingLeft) + parseInt(style.paddingRight)
|
||||
const borderWidth = parseInt(style.borderLeftWidth) + parseInt(style.borderRightWidth)
|
||||
const padding = parseInt(style.paddingLeft) + parseInt(style.paddingRight)
|
||||
return parseInt(style.width) + borderWidth + padding
|
||||
}
|
||||
|
||||
@@ -404,16 +374,12 @@ CardPlugin.Ui = class UiPlugin extends CardPluginBase {
|
||||
_doesParentExist(context, parent) {
|
||||
if (parent == null) return true
|
||||
let valid = context.querySelector(parent) != null
|
||||
if (!valid)
|
||||
console.error('Could not find parent on context.', context, parent)
|
||||
if (!valid) console.error('Could not find parent on context.', context, parent)
|
||||
return valid
|
||||
}
|
||||
|
||||
append(context) {
|
||||
parent =
|
||||
this.parent == null
|
||||
? context
|
||||
: context.querySelector(this.parent).appendChild(container)
|
||||
parent = this.parent == null ? context : context.querySelector(this.parent).appendChild(container)
|
||||
let container = document.createElement('div')
|
||||
container.className = this.className
|
||||
parent.appendChild(container)
|
||||
@@ -513,15 +479,8 @@ CardPlugin.Speech = class SpeechPlugin extends CardPluginBase {
|
||||
|
||||
utterance.onboundary = () => {
|
||||
console.log('onboundary', node.innerText)
|
||||
if (
|
||||
this.currentText.substring(0, 5) !=
|
||||
node.innerText.substring(0, 5)
|
||||
) {
|
||||
console.log(
|
||||
'text for speech synth changed!',
|
||||
this.currentText,
|
||||
node.innerText
|
||||
)
|
||||
if (this.currentText.substring(0, 5) != node.innerText.substring(0, 5)) {
|
||||
console.log('text for speech synth changed!', this.currentText, node.innerText)
|
||||
this._stop()
|
||||
}
|
||||
}
|
||||
|
||||
+6
-18
@@ -63,11 +63,7 @@ export default class ScatterCard extends Card {
|
||||
* @returns
|
||||
* @memberof Card
|
||||
*/
|
||||
static createCardScatter(
|
||||
html,
|
||||
scatterContainer,
|
||||
{ basePath = './', modules = [] } = {}
|
||||
) {
|
||||
static createCardScatter(html, scatterContainer, { basePath = './', modules = [] } = {}) {
|
||||
let element = document.createElement('div')
|
||||
|
||||
scatterContainer.element.appendChild(element)
|
||||
@@ -94,11 +90,7 @@ export default class ScatterCard extends Card {
|
||||
* @returns
|
||||
* @memberof CardScatter
|
||||
*/
|
||||
static loadAndCreateScatterCard(
|
||||
scatterContainer,
|
||||
item,
|
||||
{ basePath = '../', modules = [], onClose = null } = {}
|
||||
) {
|
||||
static loadAndCreateScatterCard(scatterContainer, item, { basePath = '../', modules = [], onClose = null } = {}) {
|
||||
console.log(basePath)
|
||||
return new Promise((resolve, reject) => {
|
||||
let url = basePath + '/' + item + '/index.html'
|
||||
@@ -106,14 +98,10 @@ export default class ScatterCard extends Card {
|
||||
this.loadHTML(url)
|
||||
.then(html => {
|
||||
console.log('Received', html)
|
||||
let element = this.createCardScatter(
|
||||
html,
|
||||
scatterContainer,
|
||||
{
|
||||
basePath,
|
||||
modules
|
||||
}
|
||||
)
|
||||
let element = this.createCardScatter(html, scatterContainer, {
|
||||
basePath,
|
||||
modules
|
||||
})
|
||||
if (onClose) this.addOnCloseListener(element, onClose)
|
||||
resolve(element)
|
||||
})
|
||||
|
||||
+6
-12
@@ -5,10 +5,7 @@ import Events from '../events.js'
|
||||
import { Points } from '../utils.js'
|
||||
|
||||
export default class CardWrapper extends Object {
|
||||
constructor(
|
||||
domNode,
|
||||
{ triggerSVGClicks = true, allowClickDistance = 44 } = {}
|
||||
) {
|
||||
constructor(domNode, { triggerSVGClicks = true, allowClickDistance = 44 } = {}) {
|
||||
super()
|
||||
this.domNode = domNode
|
||||
this.triggerSVGClicks = triggerSVGClicks
|
||||
@@ -57,7 +54,7 @@ export default class CardWrapper extends Object {
|
||||
|
||||
isClickable(node) {
|
||||
if (node == null) return false
|
||||
// console.log("isClickable", node, this.isClickPrevented(node))
|
||||
// console.log("isClickable", node, this.isClickPrevented(node))
|
||||
if (this.isClickPrevented(node)) {
|
||||
return false
|
||||
}
|
||||
@@ -99,9 +96,7 @@ export default class CardWrapper extends Object {
|
||||
nearestActive(event) {
|
||||
let element = this.domNode
|
||||
let activeNodes = this.activeNodes()
|
||||
let globalClick = event.center
|
||||
? event.center
|
||||
: { x: event.x, y: event.y }
|
||||
let globalClick = event.center ? event.center : { x: event.x, y: event.y }
|
||||
let localClick = Points.fromPageToNode(element, globalClick)
|
||||
|
||||
let clickRects = activeNodes.map(link => {
|
||||
@@ -154,7 +149,7 @@ export default class CardWrapper extends Object {
|
||||
}
|
||||
|
||||
nodeTapped(node, event) {
|
||||
console.log("nodeTapped", node, this.isClickable(node))
|
||||
console.log('nodeTapped', node, this.isClickable(node))
|
||||
if (this.isClickable(node)) {
|
||||
this.simulateClick(node, event)
|
||||
return true
|
||||
@@ -165,7 +160,7 @@ export default class CardWrapper extends Object {
|
||||
return true
|
||||
}
|
||||
for (let [selector, handler] of this.tapHandler.entries()) {
|
||||
console.log("nodeTapped", selector)
|
||||
console.log('nodeTapped', selector)
|
||||
for (let obj of this.domNode.querySelectorAll(selector)) {
|
||||
if (node == obj) {
|
||||
handler(event, node)
|
||||
@@ -177,10 +172,9 @@ export default class CardWrapper extends Object {
|
||||
}
|
||||
|
||||
tap(event, calledBy = 'unknown') {
|
||||
|
||||
if (event.isTrusted) {
|
||||
let node = this.nearestActive(event)
|
||||
console.log("tap", node)
|
||||
console.log('tap', node)
|
||||
this.nodeTapped(node, event)
|
||||
|
||||
/* let node = document.elementFromPoint(event.clientX, event.clientY)
|
||||
|
||||
Reference in New Issue
Block a user