Brak opisu

ons-card.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 autoStyle from '../ons/autostyle';
  21. import ModifierUtil from '../ons/internal/modifier-util';
  22. import BaseElement from './base/base-element';
  23. import contentReady from '../ons/content-ready';
  24. var defaultClassName = 'card';
  25. var scheme = {
  26. '': 'card--*',
  27. '.card__title': 'card--*__title',
  28. '.card__content': 'card--*__content'
  29. };
  30. /**
  31. * @element ons-card
  32. * @category visual
  33. * @modifier material
  34. * [en]A card with material design.[/en]
  35. * [ja]リストの上下のボーダーが無いリストを表示します。[/ja]
  36. * @description
  37. * [en]
  38. * Component to create a card that displays some information.
  39. *
  40. * The card may be composed by divs with specially prepared classes `title` and/or `content`. You can also add your own content as you please.[/en]
  41. * [ja][/ja]
  42. * @tutorial vanilla/Reference/card
  43. * @example
  44. * <ons-card>
  45. * <p>Some content</p>
  46. * </ons-card>
  47. */
  48. var CardElement = function (_BaseElement) {
  49. _inherits(CardElement, _BaseElement);
  50. /**
  51. * @attribute modifier
  52. * @type {String}
  53. * @description
  54. * [en]The appearance of the card.[/en]
  55. * [ja]リストの表現を指定します。[/ja]
  56. */
  57. function CardElement() {
  58. _classCallCheck(this, CardElement);
  59. var _this = _possibleConstructorReturn(this, (CardElement.__proto__ || _Object$getPrototypeOf(CardElement)).call(this));
  60. contentReady(_this, function () {
  61. _this._compile();
  62. });
  63. return _this;
  64. }
  65. _createClass(CardElement, [{
  66. key: '_compile',
  67. value: function _compile() {
  68. var title = void 0,
  69. content = void 0;
  70. for (var i = 0; i < this.children.length; i++) {
  71. var el = this.children[i];
  72. if (el.classList.contains('title')) {
  73. el.classList.add('card__title');
  74. title = el;
  75. } else if (el.classList.contains('content')) {
  76. el.classList.add('card__content');
  77. content = el;
  78. }
  79. }
  80. autoStyle.prepare(this);
  81. this.classList.add(defaultClassName);
  82. ModifierUtil.initModifier(this, scheme);
  83. }
  84. }, {
  85. key: 'attributeChangedCallback',
  86. value: function attributeChangedCallback(name, last, current) {
  87. switch (name) {
  88. case 'class':
  89. util.restoreClass(this, defaultClassName, scheme);
  90. break;
  91. case 'modifier':
  92. ModifierUtil.onModifierChanged(last, current, this, scheme);
  93. break;
  94. }
  95. }
  96. }], [{
  97. key: 'observedAttributes',
  98. get: function get() {
  99. return ['modifier', 'class'];
  100. }
  101. }]);
  102. return CardElement;
  103. }(BaseElement);
  104. export default CardElement;
  105. onsElements.Card = CardElement;
  106. customElements.define('ons-card', CardElement);