in progress

master
jfh 2020-11-08 12:25:25 +01:00
parent 8fcaa37396
commit 9f9ec73daa
17 changed files with 38 additions and 8 deletions

View File

@ -97,9 +97,7 @@ template.innerHTML = `
<div class="menu-item">menu 1</div> <div class="menu-item">menu 1</div>
<div class="menu-item">menu 2 est un peu plus long</div> <div class="menu-item">menu 2 est un peu plus long</div>
<div class="menu-item">menu 3</div> <div class="menu-item">menu 3</div>
</div> </div>
</div> </div>
`; `;
@ -118,15 +116,16 @@ export class ExplorerButton extends HTMLElement {
// locate the component // locate the component
this.$button = this._shadowRoot.querySelector('.menu-button'); this.$button = this._shadowRoot.querySelector('.menu-button');
this.$overall = this._shadowRoot.querySelector('.overall'); this.$overall = this._shadowRoot.querySelector('.overall');
this.$img = this._shadowRoot.querySelector('img'); this.$img = this._shadowRoot.querySelector('.menu-button img');
this.$menu = this._shadowRoot.querySelector('.menu'); this.$menu = this._shadowRoot.querySelector('.menu');
this.files = [];
} }
/** /**
* @function observedAttributes * @function observedAttributes
* @returns {any} observed * @returns {any} observed
*/ */
static get observedAttributes () { static get observedAttributes () {
return ['title', 'pressed', 'disabled']; return ['title', 'pressed', 'disabled', 'lib'];
} }
/** /**
* @function attributeChangedCallback * @function attributeChangedCallback
@ -158,6 +157,29 @@ export class ExplorerButton extends HTMLElement {
this.$div.classList.remove('disabled'); this.$div.classList.remove('disabled');
} }
break; break;
case 'lib':
{
// read the json containing the list of library files.
const request = new XMLHttpRequest();
request.open('GET', newValue, true);
request.addEventListener('load', (resp) => {
if (resp.target.status >= 200 && resp.target.status < 400) {
const json = JSON.parse(resp.target.response);
const {lib} = json;
// eslint-disable-next-line no-unsanitized/property
this.$menu.innerHTML = lib.map((menu) => (
`<div class="menu-item">${menu}</div>`
)).join('');
} else {
console.error(`could not read file:${newValue}`);
}
});
request.addEventListener('error', (error) => {
console.log(error);
});
request.send();
}
break;
default: default:
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(`unknown attribute: ${name}`); console.error(`unknown attribute: ${name}`);
@ -229,6 +251,7 @@ export class ExplorerButton extends HTMLElement {
console.log(ev); console.log(ev);
switch (ev.target.nodeName) { switch (ev.target.nodeName) {
case 'SE-EXPLORERBUTTON': case 'SE-EXPLORERBUTTON':
this.$menu.classList.add('open'); this.$menu.classList.add('open');
break; break;
case 'SE-BUTTON': case 'SE-BUTTON':

View File

@ -0,0 +1,7 @@
{
"lib": [
"basic",
"animal",
"game"
]
}

View File

@ -400,7 +400,7 @@
<se-button id="tool_fhellipse" title="Free-Hand Rectangle" src="./images/fh_ellipse.svg"></se-button> <se-button id="tool_fhellipse" title="Free-Hand Rectangle" src="./images/fh_ellipse.svg"></se-button>
</se-flyingbutton> </se-flyingbutton>
<se-button id="tool_path" title="Path Tool" src="./images/path.svg" shortcut="P"></se-button> <se-button id="tool_path" title="Path Tool" src="./images/path.svg" shortcut="P"></se-button>
<se-explorerbutton id="tool_shapelib_show" title="Shape library" src="./images/shapelib.svg"></se-explorerbutton> <se-explorerbutton id="tool_shapelib_show" title="Shape library" lib="./extensions/ext-shapes/shapelib/shapelib.json"></se-explorerbutton>
<se-button id="tool_text" title="Text Tool" src="./images/text.svg" shortcut="T"></se-button> <se-button id="tool_text" title="Text Tool" src="./images/text.svg" shortcut="T"></se-button>
<se-button id="tool_image" title="Image Tool" src="./images/image.svg"></se-button> <se-button id="tool_image" title="Image Tool" src="./images/image.svg"></se-button>
<se-button id="tool_zoom" title="Zoom Tool" src="./images/zoom.svg" shortcut="Z"></se-button> <se-button id="tool_zoom" title="Zoom Tool" src="./images/zoom.svg" shortcut="Z"></se-button>