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={}]
|
|
|
|
* @memberof Card
|
|
|
|
*/
|
2019-07-18 12:26:39 +02:00
|
|
|
static setup(context, htmlString, { basePath = './', modules = [] } = {}) {
|
|
|
|
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-07-18 12:26:39 +02:00
|
|
|
this._replaceAttributes(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
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends a close listener to the scatter element.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} element
|
|
|
|
* @param {*} callback
|
|
|
|
* @memberof Card
|
|
|
|
*/
|
|
|
|
static addOnCloseListener(element, callback) {
|
|
|
|
if (callback) {
|
|
|
|
element.onClose = callback
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a scatter for the card and applies the card to it,
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} html
|
|
|
|
* @param {*} scatterContainer
|
|
|
|
* @param {string} [basePath=""]
|
|
|
|
* @param {*} [opts={}]
|
|
|
|
* @returns
|
|
|
|
* @memberof Card
|
|
|
|
*/
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*Utility function to create a fully functional card scatter.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @param {*} scatterContainer
|
|
|
|
* @param {*} path
|
|
|
|
* @param {string} [basePath="."]
|
|
|
|
* @param {*} opts
|
|
|
|
* @returns
|
|
|
|
* @memberof CardScatter
|
|
|
|
*/
|
2019-07-30 16:56:29 +02:00
|
|
|
static loadAndCreateScatterCard(scatterContainer, item, { basePath = '../', modules = [], onClose = null } = {}) {
|
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-18 12:26:39 +02:00
|
|
|
if (onClose) this.addOnCloseListener(element, onClose)
|
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
|