UNPKG

1.76 kBJavaScriptView Raw
1/*
2Copyright 2013-2015 ASIAL CORPORATION
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15
16*/
17
18import onsElements from '../ons/elements.js';
19import BaseElement from './base/base-element.js';
20import util from '../ons/util.js';
21import contentReady from '../ons/content-ready.js';
22
23export default class SplitterMaskElement extends BaseElement {
24
25 constructor() {
26 super();
27
28 this._boundOnClick = this._onClick.bind(this);
29 contentReady(this, () => {
30 if (this.parentNode._sides.every(side => side.mode === 'split')) {
31 this.setAttribute('style', 'display: none !important');
32 }
33 });
34 }
35
36 _onClick(event) {
37 if (this.onClick instanceof Function) {
38 this.onClick();
39 } else if (util.match(this.parentNode, 'ons-splitter')) {
40 this.parentNode._sides.forEach(side => side.close('left').catch(() => {}));
41 }
42 event.stopPropagation();
43 }
44
45 static get observedAttributes() {
46 return [];
47 }
48
49 attributeChangedCallback(name, last, current) {
50 }
51
52 connectedCallback() {
53 this.addEventListener('click', this._boundOnClick);
54 }
55
56 disconnectedCallback() {
57 this.removeEventListener('click', this._boundOnClick);
58 }
59}
60
61onsElements.SplitterMask = SplitterMaskElement;
62customElements.define('ons-splitter-mask', SplitterMaskElement);