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

ons-toolbar.js 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _createClass from 'babel-runtime/helpers/createClass';
  4. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  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 internal from '../ons/internal';
  21. import autoStyle from '../ons/autostyle';
  22. import ModifierUtil from '../ons/internal/modifier-util';
  23. import BaseElement from './base/base-element';
  24. import contentReady from '../ons/content-ready';
  25. var defaultClassName = 'toolbar';
  26. var scheme = {
  27. '': 'toolbar--*',
  28. '.toolbar__left': 'toolbar--*__left',
  29. '.toolbar__center': 'toolbar--*__center',
  30. '.toolbar__right': 'toolbar--*__right'
  31. };
  32. /**
  33. * @element ons-toolbar
  34. * @category page
  35. * @modifier material
  36. * [en]Material Design toolbar.[/en]
  37. * [ja][/ja]
  38. * @modifier transparent
  39. * [en]Transparent toolbar.[/en]
  40. * [ja]透明な背景を持つツールバーを表示します。[/ja]
  41. * @modifier cover-content
  42. * [en]Displays the toolbar on top of the page's content. Should be combined with `transparent` modifier.[/en]
  43. * [ja][/ja]
  44. * @modifier noshadow
  45. * [en]Toolbar without shadow.[/en]
  46. * [ja]ツールバーに影を付けずに表示します。[/ja]
  47. * @description
  48. * [en]
  49. * Toolbar component that can be used with navigation.
  50. *
  51. * Left, center and right containers can be specified by class names.
  52. *
  53. * This component will automatically display as a Material Design toolbar when running on Android devices.
  54. * [/en]
  55. * [ja]ナビゲーションで使用するツールバー用コンポーネントです。クラス名により、左、中央、右のコンテナを指定できます。[/ja]
  56. * @codepen aHmGL
  57. * @tutorial vanilla/Reference/toolbar
  58. * @guide compilation.html#toolbar-compilation [en]Adding a toolbar[/en][ja]ツールバーの追加[/ja]
  59. * @seealso ons-bottom-toolbar
  60. * [en]The `<ons-bottom-toolbar>` displays a toolbar on the bottom of the page.[/en]
  61. * [ja]ons-bottom-toolbarコンポーネント[/ja]
  62. * @seealso ons-back-button
  63. * [en]The `<ons-back-button>` component displays a back button inside the toolbar.[/en]
  64. * [ja]ons-back-buttonコンポーネント[/ja]
  65. * @seealso ons-toolbar-button
  66. * [en]The `<ons-toolbar-button>` component displays a toolbar button inside the toolbar.[/en]
  67. * [ja]ons-toolbar-buttonコンポーネント[/ja]
  68. * @example
  69. * <ons-page>
  70. * <ons-toolbar>
  71. * <div class="left">
  72. * <ons-back-button>
  73. * Back
  74. * </ons-back-button>
  75. * </div>
  76. * <div class="center">
  77. * Title
  78. * </div>
  79. * <div class="right">
  80. * <ons-toolbar-button>
  81. * <ons-icon icon="md-menu"></ons-icon>
  82. * </ons-toolbar-button>
  83. * </div>
  84. * </ons-toolbar>
  85. * </ons-page>
  86. */
  87. var ToolbarElement = function (_BaseElement) {
  88. _inherits(ToolbarElement, _BaseElement);
  89. /**
  90. * @attribute inline
  91. * @initonly
  92. * @description
  93. * [en]Display the toolbar as an inline element.[/en]
  94. * [ja]ツールバーをインラインに置きます。スクロール領域内にそのまま表示されます。[/ja]
  95. */
  96. /**
  97. * @attribute static
  98. * @description
  99. * [en]Static toolbars are not animated by `ons-navigator` when pushing or popping pages. This can be useful to improve performance in some situations.[/en]
  100. * [ja][/ja]
  101. */
  102. /**
  103. * @attribute modifier
  104. * @description
  105. * [en]The appearance of the toolbar.[/en]
  106. * [ja]ツールバーの表現を指定します。[/ja]
  107. */
  108. function ToolbarElement() {
  109. _classCallCheck(this, ToolbarElement);
  110. var _this = _possibleConstructorReturn(this, (ToolbarElement.__proto__ || _Object$getPrototypeOf(ToolbarElement)).call(this));
  111. contentReady(_this, function () {
  112. _this._compile();
  113. });
  114. return _this;
  115. }
  116. _createClass(ToolbarElement, [{
  117. key: 'attributeChangedCallback',
  118. value: function attributeChangedCallback(name, last, current) {
  119. switch (name) {
  120. case 'class':
  121. util.restoreClass(this, defaultClassName, scheme);
  122. break;
  123. case 'modifier':
  124. ModifierUtil.onModifierChanged(last, current, this, scheme);
  125. break;
  126. }
  127. }
  128. /**
  129. * @method setVisibility
  130. * @signature setVisibility(visible)
  131. * @param {Boolean} visible
  132. * [en]Set to true to show the toolbar, false to hide it[/en]
  133. * [ja][/ja]
  134. * @description
  135. * [en]Shows the toolbar if visible is true, otherwise hides it.[/en]
  136. * [ja][/ja]
  137. */
  138. }, {
  139. key: 'setVisibility',
  140. value: function setVisibility(visible) {
  141. var _this2 = this;
  142. contentReady(this, function () {
  143. _this2.style.display = visible ? '' : 'none';
  144. if (_this2.parentNode) {
  145. var siblingBackground = util.findChild(_this2.parentNode, '.page__background');
  146. if (siblingBackground) {
  147. siblingBackground.style.top = visible ? null : 0;
  148. }
  149. var siblingContent = util.findChild(_this2.parentNode, '.page__content');
  150. if (siblingContent) {
  151. siblingContent.style.top = visible ? null : 0;
  152. }
  153. }
  154. });
  155. }
  156. /**
  157. * @method show
  158. * @signature show()
  159. * @description
  160. * [en]Show the toolbar.[/en]
  161. * [ja][/ja]
  162. */
  163. }, {
  164. key: 'show',
  165. value: function show() {
  166. this.setVisibility(true);
  167. }
  168. /**
  169. * @method hide
  170. * @signature hide()
  171. * @description
  172. * [en]Hide the toolbar.[/en]
  173. * [ja][/ja]
  174. */
  175. }, {
  176. key: 'hide',
  177. value: function hide() {
  178. this.setVisibility(false);
  179. }
  180. /**
  181. * @return {HTMLElement}
  182. */
  183. }, {
  184. key: '_getToolbarLeftItemsElement',
  185. value: function _getToolbarLeftItemsElement() {
  186. return this.querySelector('.left') || internal.nullElement;
  187. }
  188. /**
  189. * @return {HTMLElement}
  190. */
  191. }, {
  192. key: '_getToolbarCenterItemsElement',
  193. value: function _getToolbarCenterItemsElement() {
  194. return this.querySelector('.center') || internal.nullElement;
  195. }
  196. /**
  197. * @return {HTMLElement}
  198. */
  199. }, {
  200. key: '_getToolbarRightItemsElement',
  201. value: function _getToolbarRightItemsElement() {
  202. return this.querySelector('.right') || internal.nullElement;
  203. }
  204. /**
  205. * @return {HTMLElement}
  206. */
  207. }, {
  208. key: '_getToolbarBackButtonLabelElement',
  209. value: function _getToolbarBackButtonLabelElement() {
  210. return this.querySelector('ons-back-button .back-button__label') || internal.nullElement;
  211. }
  212. /**
  213. * @return {HTMLElement}
  214. */
  215. }, {
  216. key: '_getToolbarBackButtonIconElement',
  217. value: function _getToolbarBackButtonIconElement() {
  218. return this.querySelector('ons-back-button .back-button__icon') || internal.nullElement;
  219. }
  220. }, {
  221. key: '_compile',
  222. value: function _compile() {
  223. autoStyle.prepare(this);
  224. this.classList.add(defaultClassName);
  225. this._ensureToolbarItemElements();
  226. ModifierUtil.initModifier(this, scheme);
  227. }
  228. }, {
  229. key: '_ensureToolbarItemElements',
  230. value: function _ensureToolbarItemElements() {
  231. for (var i = this.childNodes.length - 1; i >= 0; i--) {
  232. // case of not element
  233. if (this.childNodes[i].nodeType != 1) {
  234. this.removeChild(this.childNodes[i]);
  235. }
  236. }
  237. var center = this._ensureToolbarElement('center');
  238. center.classList.add('toolbar__title');
  239. if (this.children.length !== 1 || !this.children[0].classList.contains('center')) {
  240. var left = this._ensureToolbarElement('left');
  241. var right = this._ensureToolbarElement('right');
  242. if (this.children[0] !== left || this.children[1] !== center || this.children[2] !== right) {
  243. this.appendChild(left);
  244. this.appendChild(center);
  245. this.appendChild(right);
  246. }
  247. }
  248. }
  249. }, {
  250. key: '_ensureToolbarElement',
  251. value: function _ensureToolbarElement(name) {
  252. if (util.findChild(this, '.toolbar__' + name)) {
  253. var _element = util.findChild(this, '.toolbar__' + name);
  254. _element.classList.add(name);
  255. return _element;
  256. }
  257. var element = util.findChild(this, '.' + name) || util.create('.' + name);
  258. element.classList.add('toolbar__' + name);
  259. return element;
  260. }
  261. }], [{
  262. key: 'observedAttributes',
  263. get: function get() {
  264. return ['modifier', 'class'];
  265. }
  266. }]);
  267. return ToolbarElement;
  268. }(BaseElement);
  269. export default ToolbarElement;
  270. onsElements.Toolbar = ToolbarElement;
  271. customElements.define('ons-toolbar', ToolbarElement);