Fixed closing issue with cards.

This commit is contained in:
2019-08-14 17:46:12 +02:00
parent 30c7113713
commit 28a7a0b6a2
6 changed files with 375 additions and 262 deletions
+24 -34
View File
@@ -18,6 +18,17 @@ export default class ScatterCard extends Card {
* @memberof ScatterCard
*/
static setup(context, htmlString, { basePath = './', modules = [] } = {}) {
if (typeof context.scatter == 'undefined') {
console.error(
"You need to wrap the context inside a DOMScatter before executing the ScatterCard's setup function."
)
}
/**
* This is required for the callback functions to work properly
*/
window.ScatterCard = ScatterCard
context.classList.add('info-card')
this.relativePath = basePath
@@ -38,29 +49,6 @@ export default class ScatterCard extends Card {
return context
}
/**
* Appends a close listener to the scatter element.
*
* @static
* @param {*} element
* @param {*} callback
* @memberof Card
*/
static addOnCloseListener(element, callback) {
if (callback) {
element.onClose = callback
}
}
/**
* Removes the close listener from a card element.
*
* @static
* @param {HTMLElement} element - Context of the Card.
* @memberof ScatterCard
*/
static removeOnCloseListener(element) {
element.onClose = null
}
/**
* Creates a scatter for the card and applies the card to it,
*
@@ -95,15 +83,19 @@ export default class ScatterCard extends Card {
* of the scatter.
*/
static close(context) {
Card.close(context)
if (context['scatter']) {
console.error('CLOSED CARD')
context.scatter.close()
} else {
if (typeof context.scatter != 'undefined') context.scatter.close()
else {
console.error('Expected a scatter element to close!', this)
}
// Card.close(context)
// if (context['scatter']) {
// console.error('CLOSED CARD')
// context.scatter.close()
// } else {
// console.error('Expected a scatter element to close!', this)
// }
}
/**
@@ -116,14 +108,13 @@ export default class ScatterCard extends Card {
static remove(context) {
if (context['scatter']) {
context.scatter = null
console.error('REMOVED CARD')
} else {
console.error('Expected a scatter element to remove!', this)
}
Card.remove(context)
}
/**
*Utility function to create a fully functional card scatter.
*
@@ -135,7 +126,7 @@ export default class ScatterCard extends Card {
* @returns
* @memberof CardScatter
*/
static loadAndCreateScatterCard(scatterContainer, item, { basePath = '../', modules = [], onClose = null } = {}) {
static loadAndCreateScatterCard(scatterContainer, item, { basePath = '../', modules = [] } = {}) {
console.log(basePath)
return new Promise((resolve, reject) => {
let url = basePath + '/' + item + '/index.html'
@@ -147,7 +138,6 @@ export default class ScatterCard extends Card {
basePath,
modules
})
if (onClose) this.addOnCloseListener(element, onClose)
resolve(element)
})
.catch(e => reject(e))