Commit 53b0e79a authored by Wolfgang's avatar Wolfgang

Fix pb-toggle-feature

parent d4da7a1d
<?xml version="1.0" encoding="UTF-8"?>
<project default="all" name="TEI-Publisher">
<xmlproperty file="build.properties.xml" semanticAttributes="true" keepRoot="false"/>
<property file="local.build.properties"/>
<xmlproperty file="build.properties.xml" semanticAttributes="true" keepRoot="false"/>
<property name="project.app" value="tei-publisher"/>
<property name="project.version" value="5.0.0"/>
<property name="project.version" value="5.0.1"/>
<property name="server.url" value="http://demo.exist-db.org/exist/apps/public-repo/public/"/>
<property name="build" value="build"/>
<property name="bundle.dir" value="build/bundle"/>
......
......@@ -23,6 +23,7 @@
* | odd | the ODD to use |
* | view | the view type: 'page', 'div' or 'single' |
* | columnSeparator | CSS selector to find elements to use as column separator |
* | xpath | XPath expression to select the fragment to render |
*
* For example, one may switch between page-by-page and by-division view using
*
......@@ -55,6 +56,8 @@
* ```
*
* It is important that `pb-toggle-feature` emits and subscribes to the same channel as the target `pb-view`.
* **Note**: by default `pb-toggle-feature` will pass its properties to the connected `pb-view` before
* this loads content for the first time.
*
* @customElement
* @polymer
......@@ -115,32 +118,64 @@
checked: {
type: Boolean,
observer: '_changed'
},
/**
* If set to true (default), `pb-toggle-feature` will pass its properties to the
* connected view before this loads content for the first time. If false,
* `pb-toggle-feature` will initialize its state depending on the setting of the view.
* This only makes sense for the special properties 'view' and 'odd' though.
*/
initFromView: {
type: Boolean,
value: false
}
};
}
constructor() {
super();
this.initializing = true;
}
connectedCallback() {
super.connectedCallback();
this.initializing = true;
let param = this.getParameter(this.name);
if (typeof param !== 'undefined') {
this.checked = param === this.on;
if (this.initFromView) {
this.subscribeTo('pb-update', this._initialize.bind(this));
} else {
this.checked = this.default === 'on';
let param = this.getParameter(this.name);
if (typeof param !== 'undefined') {
this.checked = param === this.on;
} else {
this.checked = this.default === 'on';
}
this.waitForChannel(() => {
const params = {
properties: this.checked ? this.propertiesOn : this.propertiesOff,
action: 'init'
};
this.emitTo('pb-toggle', params);
this.initializing = false;
});
}
this.waitForChannel(() => {
const params = {
properties: this.checked ? this.propertiesOn : this.propertiesOff,
action: 'init'
};
this.emitTo('pb-toggle', params);
this.initializing = false;
});
this.signalReady();
}
_initialize(ev) {
if (!this.initializing) {
return;
}
switch (this.name) {
case 'view':
this.checked = ev.detail.data.view === this.on;
break;
case 'odd':
this.checked = ev.detail.data.odd === this.on;
break;
}
this.initializing = false;
}
_changed() {
if (this.initializing) {
return;
......
......@@ -96,7 +96,8 @@
</pb-media-query>
<div class="settings">
<h3>Settings</h3>
<pb-toggle-feature emit="transcription" name="view" on="page" off="div">Page View</pb-toggle-feature>
<pb-toggle-feature emit="transcription" subscribe="transcription" name="view" on="page" off="div"
init-from-view="init-from-view">Page View</pb-toggle-feature>
<pb-select-odd label="Use ODD:" emit="transcription" subscribe="transcription" src="document1"></pb-select-odd>
<pb-select-template label="Template"></pb-select-template>
<pb-edit-xml src="document1">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment