Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  4. import _createClass from 'babel-runtime/helpers/createClass';
  5. import _inherits from 'babel-runtime/helpers/inherits';
  6. /*
  7. Copyright 2013-2015 ASIAL CORPORATION
  8. Licensed under the Apache License, Version 2.0 (the "License");
  9. you may not use this file except in compliance with the License.
  10. You may obtain a copy of the License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unless required by applicable law or agreed to in writing, software
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. */
  18. import onsElements from '../../ons/elements';
  19. import util from '../../ons/util';
  20. import ModifierUtil from '../../ons/internal/modifier-util';
  21. import AnimatorFactory from '../../ons/internal/animator-factory';
  22. import OverlaySplitterAnimator from './overlay-animator';
  23. import PushSplitterAnimator from './push-animator';
  24. import RevealSplitterAnimator from './reveal-animator';
  25. import BaseElement from '../base/base-element';
  26. import deviceBackButtonDispatcher from '../../ons/internal/device-back-button-dispatcher';
  27. import contentReady from '../../ons/content-ready';
  28. var _animatorDict = {
  29. default: OverlaySplitterAnimator,
  30. overlay: OverlaySplitterAnimator,
  31. push: PushSplitterAnimator,
  32. reveal: RevealSplitterAnimator
  33. };
  34. /**
  35. * @element ons-splitter
  36. * @category menu
  37. * @description
  38. * [en]
  39. * A component that enables responsive layout by implementing both a two-column layout and a sliding menu layout.
  40. *
  41. * 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.
  42. * [/en]
  43. * [ja][/ja]
  44. * @codepen rOQOML
  45. * @tutorial vanilla/Reference/splitter
  46. * @guide fundamentals.html#managing-pages
  47. * [en]Managing multiple pages.[/en]
  48. * [ja]複数のページを管理する[/ja]
  49. * @seealso ons-splitter-content
  50. * [en]The `<ons-splitter-content>` component contains the main content of the page.[/en]
  51. * [ja]ons-splitter-contentコンポーネント[/ja]
  52. * @seealso ons-splitter-side
  53. * [en]The `<ons-splitter-side>` component contains the menu.[/en]
  54. * [ja]ons-splitter-sideコンポーネント[/ja]
  55. * @example
  56. * <ons-splitter id="splitter">
  57. * <ons-splitter-content>
  58. * ...
  59. * </ons-splitter-content>
  60. *
  61. * <ons-splitter-side side="left" width="80%" collapse swipeable>
  62. * ...
  63. * </ons-splitter-side>
  64. * </ons-splitter>
  65. *
  66. * <script>
  67. * var splitter = document.getElementById('splitter');
  68. * splitter.left.open();
  69. * </script>
  70. */
  71. var SplitterElement = function (_BaseElement) {
  72. _inherits(SplitterElement, _BaseElement);
  73. _createClass(SplitterElement, [{
  74. key: '_getSide',
  75. value: function _getSide(side) {
  76. var element = util.findChild(this, function (e) {
  77. return util.match(e, 'ons-splitter-side') && e.getAttribute('side') === side;
  78. });
  79. return element;
  80. }
  81. /**
  82. * @property left
  83. * @readonly
  84. * @type {HTMLElement}
  85. * @description
  86. * [en]Left `<ons-splitter-side>` element.[/en]
  87. * [ja][/ja]
  88. */
  89. }, {
  90. key: '_onDeviceBackButton',
  91. value: function _onDeviceBackButton(event) {
  92. this._sides.some(function (s) {
  93. return s.isOpen ? s.close() : false;
  94. }) || event.callParentHandler();
  95. }
  96. }, {
  97. key: '_onModeChange',
  98. value: function _onModeChange(e) {
  99. var _this2 = this;
  100. if (e.target.parentNode) {
  101. contentReady(this, function () {
  102. _this2._layout();
  103. });
  104. }
  105. }
  106. }, {
  107. key: '_layout',
  108. value: function _layout() {
  109. var _this3 = this;
  110. this._sides.forEach(function (side) {
  111. if (_this3.content) {
  112. _this3.content.style[side.side] = side.mode === 'split' ? side.style.width : 0;
  113. }
  114. });
  115. }
  116. }, {
  117. key: 'left',
  118. get: function get() {
  119. return this._getSide('left');
  120. }
  121. /**
  122. * @property right
  123. * @readonly
  124. * @type {HTMLElement}
  125. * @description
  126. * [en]Right `<ons-splitter-side>` element.[/en]
  127. * [ja][/ja]
  128. */
  129. }, {
  130. key: 'right',
  131. get: function get() {
  132. return this._getSide('right');
  133. }
  134. /**
  135. * @property side
  136. * @readonly
  137. * @type {HTMLElement}
  138. * @description
  139. * [en]First `<ons-splitter-side>` element regardless the actual side.[/en]
  140. * [ja][/ja]
  141. */
  142. }, {
  143. key: 'side',
  144. get: function get() {
  145. return util.findChild(this, 'ons-splitter-side');
  146. }
  147. }, {
  148. key: '_sides',
  149. get: function get() {
  150. return [this.left, this.right].filter(function (e) {
  151. return e;
  152. });
  153. }
  154. /**
  155. * @property content
  156. * @readonly
  157. * @type {HTMLElement}
  158. * @description
  159. * [en]The `<ons-splitter-content>` element.[/en]
  160. * [ja][/ja]
  161. */
  162. }, {
  163. key: 'content',
  164. get: function get() {
  165. return util.findChild(this, 'ons-splitter-content');
  166. }
  167. }, {
  168. key: 'topPage',
  169. get: function get() {
  170. return this.content._content;
  171. }
  172. }, {
  173. key: 'mask',
  174. get: function get() {
  175. return util.findChild(this, 'ons-splitter-mask');
  176. }
  177. /**
  178. * @property onDeviceBackButton
  179. * @type {Object}
  180. * @description
  181. * [en]Back-button handler.[/en]
  182. * [ja]バックボタンハンドラ。[/ja]
  183. */
  184. }, {
  185. key: 'onDeviceBackButton',
  186. get: function get() {
  187. return this._backButtonHandler;
  188. },
  189. set: function set(callback) {
  190. if (this._backButtonHandler) {
  191. this._backButtonHandler.destroy();
  192. }
  193. this._backButtonHandler = deviceBackButtonDispatcher.createHandler(this, callback);
  194. }
  195. }]);
  196. function SplitterElement() {
  197. _classCallCheck(this, SplitterElement);
  198. var _this = _possibleConstructorReturn(this, (SplitterElement.__proto__ || _Object$getPrototypeOf(SplitterElement)).call(this));
  199. _this._onModeChange = _this._onModeChange.bind(_this);
  200. contentReady(_this, function () {
  201. !_this.mask && _this.appendChild(document.createElement('ons-splitter-mask'));
  202. _this._layout();
  203. });
  204. return _this;
  205. }
  206. _createClass(SplitterElement, [{
  207. key: 'connectedCallback',
  208. value: function connectedCallback() {
  209. this.onDeviceBackButton = this._onDeviceBackButton.bind(this);
  210. this.addEventListener('modechange', this._onModeChange, false);
  211. }
  212. }, {
  213. key: 'disconnectedCallback',
  214. value: function disconnectedCallback() {
  215. this._backButtonHandler.destroy();
  216. this._backButtonHandler = null;
  217. this.removeEventListener('modechange', this._onModeChange, false);
  218. }
  219. }, {
  220. key: 'attributeChangedCallback',
  221. value: function attributeChangedCallback(name, last, current) {}
  222. }, {
  223. key: '_show',
  224. value: function _show() {
  225. util.propagateAction(this, '_show');
  226. }
  227. }, {
  228. key: '_hide',
  229. value: function _hide() {
  230. util.propagateAction(this, '_hide');
  231. }
  232. }, {
  233. key: '_destroy',
  234. value: function _destroy() {
  235. util.propagateAction(this, '_destroy');
  236. this.remove();
  237. }
  238. }], [{
  239. key: 'registerAnimator',
  240. value: function registerAnimator(name, Animator) {
  241. if (!(Animator instanceof SplitterAnimator)) {
  242. util.throwAnimator('Splitter');
  243. }
  244. _animatorDict[name] = Animator;
  245. }
  246. }, {
  247. key: 'SplitterAnimator',
  248. get: function get() {
  249. return SplitterAnimator;
  250. }
  251. }, {
  252. key: 'animators',
  253. get: function get() {
  254. return _animatorDict;
  255. }
  256. }]);
  257. return SplitterElement;
  258. }(BaseElement);
  259. export default SplitterElement;
  260. onsElements.Splitter = SplitterElement;
  261. customElements.define('ons-splitter', SplitterElement);