ion.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { Input } from '@angular/core';
  2. /**
  3. * Base class for all Ionic components. Exposes some common functionality
  4. * that all Ionic components need, such as accessing underlying native elements and
  5. * sending/receiving app-level events.
  6. */
  7. /** @hidden */
  8. var Ion = (function () {
  9. function Ion(config, elementRef, renderer, componentName) {
  10. this._config = config;
  11. this._elementRef = elementRef;
  12. this._renderer = renderer;
  13. this._componentName = componentName;
  14. if (componentName) {
  15. this._setComponentName();
  16. this._setMode(config.get('mode'));
  17. }
  18. }
  19. Object.defineProperty(Ion.prototype, "color", {
  20. get: function () {
  21. return this._color;
  22. },
  23. /**
  24. * @input {string} The color to use from your Sass `$colors` map.
  25. * Default options are: `"primary"`, `"secondary"`, `"danger"`, `"light"`, and `"dark"`.
  26. * For more information, see [Theming your App](/docs/theming/theming-your-app).
  27. */
  28. set: function (val) {
  29. this._setColor(val);
  30. },
  31. enumerable: true,
  32. configurable: true
  33. });
  34. Object.defineProperty(Ion.prototype, "mode", {
  35. get: function () {
  36. return this._mode;
  37. },
  38. /**
  39. * @input {string} The mode determines which platform styles to use.
  40. * Possible values are: `"ios"`, `"md"`, or `"wp"`.
  41. * For more information, see [Platform Styles](/docs/theming/platform-specific-styles).
  42. */
  43. set: function (val) {
  44. this._setMode(val);
  45. },
  46. enumerable: true,
  47. configurable: true
  48. });
  49. /** @hidden */
  50. Ion.prototype.setElementClass = function (className, isAdd) {
  51. this._renderer.setElementClass(this._elementRef.nativeElement, className, isAdd);
  52. };
  53. /** @hidden */
  54. Ion.prototype.setElementAttribute = function (attributeName, attributeValue) {
  55. this._renderer.setElementAttribute(this._elementRef.nativeElement, attributeName, attributeValue);
  56. };
  57. /** @hidden */
  58. Ion.prototype.setElementStyle = function (property, value) {
  59. this._renderer.setElementStyle(this._elementRef.nativeElement, property, value);
  60. };
  61. /** @hidden */
  62. Ion.prototype._setColor = function (newColor, componentName) {
  63. if (componentName) {
  64. // This is needed for the item-radio
  65. this._componentName = componentName;
  66. }
  67. if (this._color) {
  68. this.setElementClass(this._componentName + "-" + this._mode + "-" + this._color, false);
  69. }
  70. if (newColor) {
  71. this.setElementClass(this._componentName + "-" + this._mode + "-" + newColor, true);
  72. this._color = newColor;
  73. }
  74. };
  75. /** @hidden */
  76. Ion.prototype._setMode = function (newMode) {
  77. if (this._mode) {
  78. this.setElementClass(this._componentName + "-" + this._mode, false);
  79. }
  80. if (newMode) {
  81. this.setElementClass(this._componentName + "-" + newMode, true);
  82. // Remove the color class associated with the previous mode,
  83. // change the mode, then add the new color class
  84. this._setColor(null);
  85. this._mode = newMode;
  86. this._setColor(this._color);
  87. }
  88. };
  89. /** @hidden */
  90. Ion.prototype._setComponentName = function () {
  91. this.setElementClass(this._componentName, true);
  92. };
  93. /** @hidden */
  94. Ion.prototype.getElementRef = function () {
  95. return this._elementRef;
  96. };
  97. /** @hidden */
  98. Ion.prototype.getNativeElement = function () {
  99. return this._elementRef.nativeElement;
  100. };
  101. Ion.propDecorators = {
  102. 'color': [{ type: Input },],
  103. 'mode': [{ type: Input },],
  104. };
  105. return Ion;
  106. }());
  107. export { Ion };
  108. //# sourceMappingURL=ion.js.map