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

ons-template.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 BaseElement from './base/base-element';
  21. /**
  22. * @element ons-template
  23. * @category util
  24. * @description
  25. * [en]
  26. * Define a separate HTML fragment and use as a template. These templates can be loaded as pages in `<ons-navigator>`, `<ons-tabbar>` and `<ons-splitter>`. They can also be used to generate dialogs. Since Onsen UI 2.4.0, the native `<template>` element can be used instead of `<ons-template>` for better performance and features. `<ons-template>` is still supported for backward compatibility.
  27. * [/en]
  28. * [ja]テンプレートとして使用するためのHTMLフラグメントを定義します。この要素でHTMLを宣言すると、id属性に指定した名前をpageのURLとしてons-navigatorなどのコンポーネントから参照できます。[/ja]
  29. * @seealso ons-navigator
  30. * [en]The `<ons-navigator>` component enables stack based navigation.[/en]
  31. * [ja][/ja]
  32. * @seealso ons-tabbar
  33. * [en]The `<ons-tabbar>` component is used to add tab navigation.[/en]
  34. * [ja][/ja]
  35. * @seealso ons-splitter
  36. * [en]The `<ons-splitter>` component can be used to create a draggable menu or column based layout.[/en]
  37. * [ja][/ja]
  38. * @example
  39. * <ons-template id="foobar.html">
  40. * <ons-page>
  41. * Page content
  42. * </ons-page>
  43. * </ons-template>
  44. *
  45. * <ons-navigator page="foobar.html"></ons-navigator>
  46. */
  47. var TemplateElement = function (_BaseElement) {
  48. _inherits(TemplateElement, _BaseElement);
  49. /**
  50. * @property template
  51. * @type {String}
  52. * @description
  53. * [en]Template content. This property can not be used with AngularJS bindings.[/en]
  54. * [ja][/ja]
  55. */
  56. function TemplateElement() {
  57. _classCallCheck(this, TemplateElement);
  58. var _this = _possibleConstructorReturn(this, (TemplateElement.__proto__ || _Object$getPrototypeOf(TemplateElement)).call(this));
  59. _this.template = _this.innerHTML;
  60. while (_this.firstChild) {
  61. _this.removeChild(_this.firstChild);
  62. }
  63. return _this;
  64. }
  65. _createClass(TemplateElement, [{
  66. key: 'connectedCallback',
  67. value: function connectedCallback() {
  68. if (this.parentNode) {
  69. // Note: this.parentNode is not set in some CE0/CE1 polyfills.
  70. // Show warning when the ons-template is not located just under document.body
  71. if (this.parentNode !== document.body) {
  72. // if the parent is not document.body
  73. util.warn('ons-template (id = ' + this.getAttribute('id') + ') must be located just under document.body' + (this.parentNode.outerHTML ? ':\n\n' + this.parentNode.outerHTML : '.'));
  74. }
  75. }
  76. var event = new CustomEvent('_templateloaded', { bubbles: true, cancelable: true });
  77. event.template = this.template;
  78. event.templateId = this.getAttribute('id');
  79. this.dispatchEvent(event);
  80. }
  81. }]);
  82. return TemplateElement;
  83. }(BaseElement);
  84. export default TemplateElement;
  85. onsElements.Template = TemplateElement;
  86. customElements.define('ons-template', TemplateElement);