{"size": 5962, "ext": "js", "max_stars_repo_path": "proyecto/www/lib/onsenui/core-src/elements/ons-splitter/index.js", "max_stars_repo_name": "santagorha/sa", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "proyecto/www/lib/onsenui/core-src/elements/ons-splitter/index.js", "max_issues_repo_name": "santagorha/sa", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "proyecto/www/lib/onsenui/core-src/elements/ons-splitter/index.js", "max_forks_repo_name": "santagorha/sa", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.6982758621, "max_line_length": 190, "alphanum_fraction": 0.661019792}
/*
Copyright 2013-2015 ASIAL CORPORATION

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

import util from '../../ons/util';
import ModifierUtil from '../../ons/internal/modifier-util';
import AnimatorFactory from '../../ons/internal/animator-factory';
import OverlaySplitterAnimator from './overlay-animator';
import PushSplitterAnimator from './push-animator';
import RevealSplitterAnimator from './reveal-animator';
import BaseElement from '../base/base-element';
import deviceBackButtonDispatcher from '../../ons/device-back-button-dispatcher';
import contentReady from '../../ons/content-ready';

const _animatorDict = {
  default: OverlaySplitterAnimator,
  overlay: OverlaySplitterAnimator,
  push: PushSplitterAnimator,
  reveal: RevealSplitterAnimator
};

/**
 * @element ons-splitter
 * @category menu
 * @description
 *  [en]
 *    A component that enables responsive layout by implementing both a two-column layout and a sliding menu layout.
 *
 *    It can be configured to automatically expand into a column layout on large screens and collapse the menu on smaller screens. When the menu is collapsed the user can open it by swiping.
 *  [/en]
 *  [ja][/ja]
 * @codepen rOQOML
 * @tutorial vanilla/Reference/splitter
 * @guide fundamentals.html#managing-pages
 *  [en]Managing multiple pages.[/en]
 *  [ja]複数のページを管理する[/ja]
 * @seealso ons-splitter-content
 *  [en]The `<ons-splitter-content>` component contains the main content of the page.[/en]
 *  [ja]ons-splitter-contentコンポーネント[/ja]
 * @seealso ons-splitter-side
 *  [en]The `<ons-splitter-side>` component contains the menu.[/en]
 *  [ja]ons-splitter-sideコンポーネント[/ja]
 * @example
 * <ons-splitter id="splitter">
 *   <ons-splitter-content>
 *     ...
 *   </ons-splitter-content>
 *
 *   <ons-splitter-side side="left" width="80%" collapse swipeable>
 *     ...
 *   </ons-splitter-side>
 * </ons-splitter>
 *
 * <script>
 *   var splitter = document.getElementById('splitter');
 *   splitter.left.open();
 * </script>
 */
export default class SplitterElement extends BaseElement {

  _getSide(side) {
    const element = util.findChild(this, e => {
      return util.match(e, 'ons-splitter-side') && e.getAttribute('side') === side;
    });
    return element;
  }

  /**
   * @property left
   * @readonly
   * @type {HTMLElement}
   * @description
   *   [en]Left `<ons-splitter-side>` element.[/en]
   *   [ja][/ja]
   */
  get left() {
    return this._getSide('left');
  }
  /**
   * @property right
   * @readonly
   * @type {HTMLElement}
   * @description
   *   [en]Right `<ons-splitter-side>` element.[/en]
   *   [ja][/ja]
   */
  get right() {
    return this._getSide('right');
  }

  /**
   * @property side
   * @readonly
   * @type {HTMLElement}
   * @description
   *   [en]First `<ons-splitter-side>` element regardless the actual side.[/en]
   *   [ja][/ja]
   */
  get side() {
    return util.findChild(this, 'ons-splitter-side');
  }

  get _sides() {
    return [this.left, this.right].filter(e => e);
  }
  /**
   * @property content
   * @readonly
   * @type {HTMLElement}
   * @description
   *   [en]The `<ons-splitter-content>` element.[/en]
   *   [ja][/ja]
   */
  get content() {
    return util.findChild(this, 'ons-splitter-content');
  }

  get topPage() {
    return this.content._content;
  }

  get mask() {
    return util.findChild(this, 'ons-splitter-mask');
  }

  /**
   * @property onDeviceBackButton
   * @type {Object}
   * @description
   *   [en]Back-button handler.[/en]
   *   [ja]バックボタンハンドラ。[/ja]
   */
  get onDeviceBackButton() {
    return this._backButtonHandler;
  }

  set onDeviceBackButton(callback) {
    if (this._backButtonHandler) {
      this._backButtonHandler.destroy();
    }

    this._backButtonHandler = deviceBackButtonDispatcher.createHandler(this, callback);
  }

  _onDeviceBackButton(event) {
    this._sides.some(s => s.isOpen ? s.close() : false) || event.callParentHandler();
  }

  _onModeChange(e) {
    if (e.target.parentNode) {
      contentReady(this, () => {
        this._layout();
      });
    }
  }

  _layout() {
    this._sides.forEach(side => {
      if (this.content) {
        this.content.style[side.side] = side.mode === 'split' ? side.style.width : 0;
      }
    });
  }

  constructor() {
    super();

    this._onModeChange = this._onModeChange.bind(this);

    contentReady(this, () => {
      !this.mask && this.appendChild(document.createElement('ons-splitter-mask'));
      this._layout();
    });
  }

  connectedCallback() {
    this.onDeviceBackButton = this._onDeviceBackButton.bind(this);
    this.addEventListener('modechange', this._onModeChange, false);
  }

  disconnectedCallback() {
    this._backButtonHandler.destroy();
    this._backButtonHandler = null;
    this.removeEventListener('modechange', this._onModeChange, false);
  }

  attributeChangedCallback(name, last, current) {}

  _show() {
    util.propagateAction(this, '_show');
  }

  _hide() {
    util.propagateAction(this, '_hide');
  }

  _destroy() {
    util.propagateAction(this, '_destroy');
    this.remove();
  }

  static registerAnimator(name, Animator) {
    if (!(Animator instanceof SplitterAnimator)) {
      throw new Error('Animator parameter must be an instance of SplitterAnimator.');
    }
    _animatorDict[name] = Animator;
  }

  static get SplitterAnimator() {
    return SplitterAnimator;
  }

  static get animators() {
    return _animatorDict;
  }
}

customElements.define('ons-splitter', SplitterElement);
