fab-container.js 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "@angular/core", "../../platform/platform", "../../gestures/ui-event-manager", "./fab", "./fab-list"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var platform_1 = require("../../platform/platform");
  14. var ui_event_manager_1 = require("../../gestures/ui-event-manager");
  15. var fab_1 = require("./fab");
  16. var fab_list_1 = require("./fab-list");
  17. /**
  18. * @name FabContainer
  19. * @module ionic
  20. *
  21. * @description
  22. * `<ion-fab>` is not a FAB button by itself but a container that assist the fab button (`<button ion-fab>`) allowing it
  23. * to be placed in fixed position that does not scroll with the content. It is also used to implement "material design speed dial",
  24. * ie. a FAB buttons displays a small lists of related actions when clicked.
  25. *
  26. * @property [top] - Places the container on the top of the content
  27. * @property [bottom] - Places the container on the bottom of the content
  28. * @property [left] - Places the container on the left
  29. * @property [right] - Places the container on the right
  30. * @property [middle] - Places the container on the middle vertically
  31. * @property [center] - Places the container on the center horizontally
  32. * @property [edge] - Used to place the container between the content and the header/footer
  33. *
  34. * @usage
  35. *
  36. * ```html
  37. * <!-- this fab is placed at top right -->
  38. * <ion-content>
  39. * <ion-fab top right>
  40. * <button ion-fab>Button</button>
  41. * </ion-fab>
  42. *
  43. * <!-- this fab is placed at the center of the content viewport -->
  44. * <ion-fab center middle>
  45. * <button ion-fab>Button</button>
  46. * </ion-fab>
  47. * </ion-content>
  48. * ```
  49. *
  50. * Ionic's FAB also supports "material design's fab speed dial". It is a normal fab button
  51. * that shows a list of related actions when clicked.
  52. *
  53. * The same `ion-fab` container can contain several `ion-fab-list` with different side values:
  54. * `top`, `bottom`, `left` and `right`. For example, if you want to have a list of button that are
  55. * on the top of the main button, you should use `side="top"` and so on. By default, if side is ommited, `side="bottom"`.
  56. *
  57. * ```html
  58. * <ion-content>
  59. * <!-- this fab is placed at bottom right -->
  60. * <ion-fab bottom right >
  61. * <button ion-fab>Share</button>
  62. * <ion-fab-list side="top">
  63. * <button ion-fab>Facebook</button>
  64. * <button ion-fab>Twitter</button>
  65. * <button ion-fab>Youtube</button>
  66. * </ion-fab-list>
  67. * <ion-fab-list side="left">
  68. * <button ion-fab>Vimeo</button>
  69. * </ion-fab-list>
  70. * </ion-fab>
  71. * </ion-content>
  72. * ```
  73. *
  74. * A FAB speed dial can also be closed programatically.
  75. *
  76. * ```html
  77. * <ion-content>
  78. * <ion-fab bottom right #fab>
  79. * <button ion-fab>Share</button>
  80. * <ion-fab-list side="top">
  81. * <button ion-fab (click)="share('facebook', fab)">Facebook</button>
  82. * <button ion-fab (click)="share('twitter', fab)">Twitter</button>
  83. * </ion-fab-list>
  84. * </ion-fab>
  85. * </ion-content>
  86. * ```
  87. *
  88. * ```ts
  89. * share(socialNet: string, fab: FabContainer) {
  90. * fab.close();
  91. * console.log("Sharing in", socialNet);
  92. * }
  93. * ```
  94. *
  95. * @demo /docs/demos/src/fab/
  96. * @see {@link /docs/components#fabs FAB Component Docs}
  97. */
  98. var FabContainer = (function () {
  99. function FabContainer(plt) {
  100. /**
  101. * @hidden
  102. */
  103. this._listsActive = false;
  104. this._events = new ui_event_manager_1.UIEventManager(plt);
  105. }
  106. /**
  107. * @hidden
  108. */
  109. FabContainer.prototype.ngAfterContentInit = function () {
  110. var mainButton = this._mainButton;
  111. if (!mainButton || !mainButton.getNativeElement()) {
  112. console.error('FAB container needs a main <button ion-fab>');
  113. return;
  114. }
  115. this._events.listen(mainButton.getNativeElement(), 'click', this.clickHandler.bind(this), { zone: true });
  116. };
  117. /**
  118. * @hidden
  119. */
  120. FabContainer.prototype.clickHandler = function (ev) {
  121. if (this.canActivateList(ev)) {
  122. this.toggleList();
  123. }
  124. };
  125. /**
  126. * @hidden
  127. */
  128. FabContainer.prototype.canActivateList = function (ev) {
  129. if (this._fabLists.length > 0 && this._mainButton && ev.target) {
  130. var ele = ev.target.closest('ion-fab>[ion-fab]');
  131. return (ele && ele === this._mainButton.getNativeElement());
  132. }
  133. return false;
  134. };
  135. /**
  136. * @hidden
  137. */
  138. FabContainer.prototype.toggleList = function () {
  139. this.setActiveLists(!this._listsActive);
  140. };
  141. /**
  142. * @hidden
  143. */
  144. FabContainer.prototype.setActiveLists = function (isActive) {
  145. if (isActive === this._listsActive) {
  146. return;
  147. }
  148. var lists = this._fabLists.toArray();
  149. for (var _i = 0, lists_1 = lists; _i < lists_1.length; _i++) {
  150. var list = lists_1[_i];
  151. list.setVisible(isActive);
  152. }
  153. this._mainButton.setActiveClose(isActive);
  154. this._listsActive = isActive;
  155. };
  156. /**
  157. * Close an active FAB list container
  158. */
  159. FabContainer.prototype.close = function () {
  160. this.setActiveLists(false);
  161. };
  162. /**
  163. * @hidden
  164. */
  165. FabContainer.prototype.ngOnDestroy = function () {
  166. this._events.destroy();
  167. };
  168. FabContainer.decorators = [
  169. { type: core_1.Component, args: [{
  170. selector: 'ion-fab',
  171. template: '<ng-content></ng-content>'
  172. },] },
  173. ];
  174. /** @nocollapse */
  175. FabContainer.ctorParameters = function () { return [
  176. { type: platform_1.Platform, },
  177. ]; };
  178. FabContainer.propDecorators = {
  179. '_mainButton': [{ type: core_1.ContentChild, args: [fab_1.FabButton,] },],
  180. '_fabLists': [{ type: core_1.ContentChildren, args: [fab_list_1.FabList,] },],
  181. };
  182. return FabContainer;
  183. }());
  184. exports.FabContainer = FabContainer;
  185. });
  186. //# sourceMappingURL=fab-container.js.map