2019-07-17 11:03:26 +02:00
|
|
|
import Card from './card.js'
|
|
|
|
|
2019-07-17 09:56:20 +02:00
|
|
|
/**
|
|
|
|
* Extends the card with scatter functionality.
|
|
|
|
*
|
|
|
|
* @class ScatterCard
|
|
|
|
*/
|
|
|
|
export default class ScatterCard extends Card {
|
|
|
|
/**
|
|
|
|
* TODO: Find a more suitable name.
|
|
|
|
* Adjusts the HTML to work in the new context.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} domElement
|
|
|
|
* @param {*} htmlString
|
|
|
|
* @param {*} basePath
|
|
|
|
* @param {*} [opts={}]
|
2019-08-13 14:31:03 +02:00
|
|
|
* @memberof ScatterCard
|
2019-07-17 09:56:20 +02:00
|
|
|
*/
|
2019-07-18 12:26:39 +02:00
|
|
|
static setup(context, htmlString, { basePath = './', modules = [] } = {}) {
|
2019-08-14 17:46:12 +02:00
|
|
|
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
|
|
|
|
|
2019-07-18 12:26:39 +02:00
|
|
|
context.classList.add('info-card')
|
2019-07-17 09:56:20 +02:00
|
|
|
|
|
|
|
this.relativePath = basePath
|
|
|
|
htmlString = this._adjustRelativeLinks(htmlString)
|
|
|
|
|
|
|
|
let parser = new DOMParser()
|
2019-07-18 12:26:39 +02:00
|
|
|
let html = parser.parseFromString(htmlString, 'text/html')
|
2019-07-17 09:56:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Conflicts with the FindTarget method of the Abstract scatter.
|
|
|
|
*/
|
2019-08-13 14:31:03 +02:00
|
|
|
this._replaceAttributes(context, html, 'onclick', this._replaceCallback)
|
2019-07-17 09:56:20 +02:00
|
|
|
|
2019-07-18 12:26:39 +02:00
|
|
|
let content = html.querySelector('.mainview')
|
2019-07-17 09:56:20 +02:00
|
|
|
context.appendChild(content)
|
|
|
|
|
|
|
|
super.setup(context, modules)
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a scatter for the card and applies the card to it,
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} html
|
|
|
|
* @param {*} scatterContainer
|
|
|
|
* @param {string} [basePath=""]
|
|
|
|
* @param {*} [opts={}]
|
|
|
|
* @returns
|
2019-08-13 14:31:03 +02:00
|
|
|
* @memberof ScatterCard
|
2019-07-17 09:56:20 +02:00
|
|
|
*/
|
2019-07-30 16:56:29 +02:00
|
|
|
static createCardScatter(html, scatterContainer, { basePath = './', modules = [] } = {}) {
|
2019-07-18 12:26:39 +02:00
|
|
|
let element = document.createElement('div')
|
2019-07-17 09:56:20 +02:00
|
|
|
|
|
|
|
scatterContainer.element.appendChild(element)
|
|
|
|
new DOMScatter(element, scatterContainer, {
|
|
|
|
width: 1400,
|
|
|
|
height: 1200
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setup(element, html, {
|
|
|
|
basePath,
|
|
|
|
modules
|
|
|
|
})
|
|
|
|
return element
|
|
|
|
}
|
|
|
|
|
2019-08-13 14:31:03 +02:00
|
|
|
/**
|
|
|
|
* Closes but NOT removes the scatter element.
|
|
|
|
*
|
|
|
|
* The remove must be called separately, it may be used in the close callback
|
|
|
|
* of the scatter.
|
|
|
|
*/
|
|
|
|
static close(context) {
|
2019-08-14 17:46:12 +02:00
|
|
|
if (typeof context.scatter != 'undefined') context.scatter.close()
|
|
|
|
else {
|
2019-08-13 14:31:03 +02:00
|
|
|
console.error('Expected a scatter element to close!', this)
|
|
|
|
}
|
2019-08-14 17:46:12 +02:00
|
|
|
|
|
|
|
// Card.close(context)
|
|
|
|
|
|
|
|
// if (context['scatter']) {
|
|
|
|
// console.error('CLOSED CARD')
|
|
|
|
// context.scatter.close()
|
|
|
|
// } else {
|
|
|
|
// console.error('Expected a scatter element to close!', this)
|
|
|
|
// }
|
2019-08-13 14:31:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up the card.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @override
|
|
|
|
* @memberof ScatterCard
|
|
|
|
*/
|
|
|
|
static remove(context) {
|
|
|
|
if (context['scatter']) {
|
|
|
|
context.scatter = null
|
|
|
|
} else {
|
|
|
|
console.error('Expected a scatter element to remove!', this)
|
|
|
|
}
|
|
|
|
|
|
|
|
Card.remove(context)
|
|
|
|
}
|
2019-08-14 17:46:12 +02:00
|
|
|
|
2019-07-17 09:56:20 +02:00
|
|
|
/**
|
|
|
|
*Utility function to create a fully functional card scatter.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} scatterContainer
|
|
|
|
* @param {*} path
|
|
|
|
* @param {string} [basePath="."]
|
|
|
|
* @param {*} opts
|
|
|
|
* @returns
|
|
|
|
* @memberof CardScatter
|
|
|
|
*/
|
2019-08-14 17:46:12 +02:00
|
|
|
static loadAndCreateScatterCard(scatterContainer, item, { basePath = '../', modules = [] } = {}) {
|
2019-07-17 09:56:20 +02:00
|
|
|
console.log(basePath)
|
|
|
|
return new Promise((resolve, reject) => {
|
2019-07-18 12:26:39 +02:00
|
|
|
let url = basePath + '/' + item + '/index.html'
|
|
|
|
console.log('Loading', url)
|
2019-07-17 09:56:20 +02:00
|
|
|
this.loadHTML(url)
|
|
|
|
.then(html => {
|
2019-07-18 12:26:39 +02:00
|
|
|
console.log('Received', html)
|
2019-07-30 16:56:29 +02:00
|
|
|
let element = this.createCardScatter(html, scatterContainer, {
|
|
|
|
basePath,
|
|
|
|
modules
|
|
|
|
})
|
2019-07-17 09:56:20 +02:00
|
|
|
resolve(element)
|
|
|
|
})
|
|
|
|
.catch(e => reject(e))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
static _setLanguage(context, language) {
|
|
|
|
context.language = language
|
|
|
|
}
|
|
|
|
|
|
|
|
static _getLanguage(context) {
|
|
|
|
return context.language
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScatterCard.selectedLanguage = 0
|
2019-07-18 12:26:39 +02:00
|
|
|
ScatterCard.languages = ['Deutsch', 'English']
|
2019-07-17 09:56:20 +02:00
|
|
|
ScatterCard.languageTags = {
|
2019-07-18 12:26:39 +02:00
|
|
|
Deutsch: 'de',
|
|
|
|
English: 'en'
|
2019-07-17 09:56:20 +02:00
|
|
|
}
|
|
|
|
ScatterCard.scatterContainer = null
|