123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. (function (factory) {
  12. if (typeof module === "object" && typeof module.exports === "object") {
  13. var v = factory(require, exports);
  14. if (v !== undefined) module.exports = v;
  15. }
  16. else if (typeof define === "function" && define.amd) {
  17. define(["require", "exports", "@angular/core", "../ion", "../../util/util", "../../config/config", "../../platform/platform"], factory);
  18. }
  19. })(function (require, exports) {
  20. "use strict";
  21. Object.defineProperty(exports, "__esModule", { value: true });
  22. var core_1 = require("@angular/core");
  23. var ion_1 = require("../ion");
  24. var util_1 = require("../../util/util");
  25. var config_1 = require("../../config/config");
  26. var platform_1 = require("../../platform/platform");
  27. var QUERY = {
  28. xs: '(min-width: 0px)',
  29. sm: '(min-width: 576px)',
  30. md: '(min-width: 768px)',
  31. lg: '(min-width: 992px)',
  32. xl: '(min-width: 1200px)',
  33. never: ''
  34. };
  35. /**
  36. * @hidden
  37. */
  38. var RootNode = (function () {
  39. function RootNode() {
  40. }
  41. return RootNode;
  42. }());
  43. exports.RootNode = RootNode;
  44. /**
  45. * @name SplitPane
  46. *
  47. * @description
  48. * SplitPane is a component that makes it possible to create multi-view layout.
  49. * Similar to iPad apps, SplitPane allows UI elements, like Menus, to be
  50. * displayed as the viewport increases.
  51. *
  52. * If the devices screen size is below a certain size, the SplitPane will
  53. * collapse and the menu will become hidden again. This is especially useful when
  54. * creating an app that will be served over a browser or deployed through the app
  55. * store to phones and tablets.
  56. *
  57. * @usage
  58. * To use SplitPane, simply add the component around your root component.
  59. * In this example, we'll be using a sidemenu layout, similar to what is
  60. * provided from the sidemenu starter template.
  61. *
  62. * ```html
  63. * <ion-split-pane>
  64. * <!-- our side menu -->
  65. * <ion-menu [content]="content">
  66. * <ion-header>
  67. * <ion-toolbar>
  68. * <ion-title>Menu</ion-title>
  69. * </ion-toolbar>
  70. * </ion-header>
  71. * </ion-menu>
  72. *
  73. * <!-- the main content -->
  74. * <ion-nav [root]="root" main #content></ion-nav>
  75. * </ion-split-pane>
  76. * ```
  77. *
  78. * Here, SplitPane will look for the element with the `main` attribute and make
  79. * that the central component on larger screens. The `main` component can be any
  80. * Ionic component (`ion-nav` or `ion-tabs`) except `ion-menu`.
  81. *
  82. * ### Setting breakpoints
  83. *
  84. * By default, SplitPane will expand when the screen is larger than 768px.
  85. * If you want to customize this, use the `when` input. The `when` input can
  86. * accept any valid media query, as it uses `matchMedia()` underneath.
  87. *
  88. * ```
  89. * <ion-split-pane when="(min-width: 475px)">
  90. *
  91. * <!-- our side menu -->
  92. * <ion-menu [content]="content">
  93. * ....
  94. * </ion-menu>
  95. *
  96. * <!-- the main content -->
  97. * <ion-nav [root]="root" main #content></ion-nav>
  98. * </ion-split-pane>
  99. * ```
  100. *
  101. * SplitPane also provides some predefined media queries that can be used.
  102. *
  103. * ```html
  104. * <!-- could be "xs", "sm", "md", "lg", or "xl" -->
  105. * <ion-split-pane when="lg">
  106. * ...
  107. * </ion-split-pane>
  108. * ```
  109. *
  110. *
  111. * | Size | Value | Description |
  112. * |------|-----------------------|-----------------------------------------------------------------------|
  113. * | `xs` | `(min-width: 0px)` | Show the split-pane when the min-width is 0px (meaning, always) |
  114. * | `sm` | `(min-width: 576px)` | Show the split-pane when the min-width is 576px |
  115. * | `md` | `(min-width: 768px)` | Show the split-pane when the min-width is 768px (default break point) |
  116. * | `lg` | `(min-width: 992px)` | Show the split-pane when the min-width is 992px |
  117. * | `xl` | `(min-width: 1200px)` | Show the split-pane when the min-width is 1200px |
  118. *
  119. * You can also pass in boolean values that will trigger SplitPane when the value
  120. * or expression evaluates to true.
  121. *
  122. *
  123. * ```html
  124. * <ion-split-pane [when]="isLarge">
  125. * ...
  126. * </ion-split-pane>
  127. * ```
  128. *
  129. * ```ts
  130. * class MyClass {
  131. * public isLarge = false;
  132. * constructor(){}
  133. * }
  134. * ```
  135. *
  136. * Or
  137. *
  138. * ```html
  139. * <ion-split-pane [when]="shouldShow()">
  140. * ...
  141. * </ion-split-pane>
  142. * ```
  143. *
  144. * ```ts
  145. * class MyClass {
  146. * constructor(){}
  147. * shouldShow(){
  148. * if(conditionA){
  149. * return true
  150. * } else {
  151. * return false
  152. * }
  153. * }
  154. * }
  155. * ```
  156. *
  157. */
  158. var SplitPane = (function (_super) {
  159. __extends(SplitPane, _super);
  160. function SplitPane(_zone, _plt, config, elementRef, renderer) {
  161. var _this = _super.call(this, config, elementRef, renderer, 'split-pane') || this;
  162. _this._zone = _zone;
  163. _this._plt = _plt;
  164. _this._init = false;
  165. _this._visible = false;
  166. _this._isEnabled = true;
  167. _this._mediaQuery = QUERY['md'];
  168. /**
  169. * @hidden
  170. */
  171. _this.sideContent = null;
  172. /**
  173. * @hidden
  174. */
  175. _this.mainContent = null;
  176. /**
  177. * @output {any} Expression to be called when the split-pane visibility has changed
  178. */
  179. _this.ionChange = new core_1.EventEmitter();
  180. return _this;
  181. }
  182. Object.defineProperty(SplitPane.prototype, "_setchildren", {
  183. /**
  184. * @hidden
  185. */
  186. set: function (query) {
  187. var _this = this;
  188. var children = this._children = query.filter((function (child) { return child !== _this; }));
  189. children.forEach(function (child) {
  190. var isMain = child.initPane();
  191. _this._setPaneCSSClass(child.getElementRef(), isMain);
  192. });
  193. },
  194. enumerable: true,
  195. configurable: true
  196. });
  197. Object.defineProperty(SplitPane.prototype, "when", {
  198. get: function () {
  199. return this._mediaQuery;
  200. },
  201. /**
  202. * @input {string | boolean} When the split-pane should be shown.
  203. * Can be a CSS media query expression, or a shortcut expression.
  204. * Can also be a boolean expression.
  205. */
  206. set: function (query) {
  207. if (typeof query === 'boolean') {
  208. this._mediaQuery = query;
  209. }
  210. else {
  211. var defaultQuery = QUERY[query];
  212. this._mediaQuery = (defaultQuery)
  213. ? defaultQuery
  214. : query;
  215. }
  216. this._update();
  217. },
  218. enumerable: true,
  219. configurable: true
  220. });
  221. Object.defineProperty(SplitPane.prototype, "enabled", {
  222. get: function () {
  223. return this._isEnabled;
  224. },
  225. /**
  226. * @input {boolean} If `false`, the split-pane is disabled, ie. the side pane will
  227. * never be displayed. Default `true`.
  228. */
  229. set: function (val) {
  230. this._isEnabled = util_1.isTrueProperty(val);
  231. this._update();
  232. },
  233. enumerable: true,
  234. configurable: true
  235. });
  236. /**
  237. * @hidden
  238. */
  239. SplitPane.prototype._register = function (node, isMain, callback) {
  240. if (this.getElementRef().nativeElement !== node.getElementRef().nativeElement.parentNode) {
  241. return false;
  242. }
  243. this._setPaneCSSClass(node.getElementRef(), isMain);
  244. if (callback) {
  245. this.ionChange.subscribe(callback);
  246. }
  247. if (isMain) {
  248. if (this.mainContent) {
  249. console.error('split pane: main content was already set');
  250. }
  251. this.mainContent = node;
  252. }
  253. return true;
  254. };
  255. /**
  256. * @hidden
  257. */
  258. SplitPane.prototype.ngAfterViewInit = function () {
  259. this._init = true;
  260. this._update();
  261. };
  262. /**
  263. * @hidden
  264. */
  265. SplitPane.prototype._update = function () {
  266. var _this = this;
  267. if (!this._init) {
  268. return;
  269. }
  270. // Unlisten
  271. this._rmListener && this._rmListener();
  272. this._rmListener = null;
  273. // Check if the split-pane is disabled
  274. if (!this._isEnabled) {
  275. this._setVisible(false);
  276. return;
  277. }
  278. var query = this._mediaQuery;
  279. if (typeof query === 'boolean') {
  280. this._setVisible(query);
  281. return;
  282. }
  283. if (query && query.length > 0) {
  284. // Listen
  285. var callback_1 = function (query) { return _this._setVisible(query.matches); };
  286. var mediaList_1 = this._plt.win().matchMedia(query);
  287. mediaList_1.addListener(callback_1);
  288. this._setVisible(mediaList_1.matches);
  289. this._rmListener = function () {
  290. mediaList_1.removeListener(callback_1);
  291. };
  292. }
  293. else {
  294. this._setVisible(false);
  295. }
  296. };
  297. /**
  298. * @hidden
  299. */
  300. SplitPane.prototype._updateChildren = function () {
  301. this.mainContent = null;
  302. this.sideContent = null;
  303. var visible = this._visible;
  304. this._children.forEach(function (child) { return child.paneChanged && child.paneChanged(visible); });
  305. };
  306. /**
  307. * @hidden
  308. */
  309. SplitPane.prototype._setVisible = function (visible) {
  310. var _this = this;
  311. if (this._visible === visible) {
  312. return;
  313. }
  314. this._visible = visible;
  315. this.setElementClass('split-pane-visible', visible);
  316. this._updateChildren();
  317. this._zone.run(function () {
  318. _this.ionChange.emit(_this);
  319. });
  320. };
  321. /**
  322. * @hidden
  323. */
  324. SplitPane.prototype.isVisible = function () {
  325. return this._visible;
  326. };
  327. /**
  328. * @hidden
  329. */
  330. SplitPane.prototype.setElementClass = function (className, add) {
  331. this._renderer.setElementClass(this._elementRef.nativeElement, className, add);
  332. };
  333. /**
  334. * @hidden
  335. */
  336. SplitPane.prototype._setPaneCSSClass = function (elementRef, isMain) {
  337. var ele = elementRef.nativeElement;
  338. this._renderer.setElementClass(ele, 'split-pane-main', isMain);
  339. this._renderer.setElementClass(ele, 'split-pane-side', !isMain);
  340. };
  341. /**
  342. * @hidden
  343. */
  344. SplitPane.prototype.ngOnDestroy = function () {
  345. (void 0) /* assert */;
  346. this._rmListener && this._rmListener();
  347. this._rmListener = null;
  348. };
  349. /**
  350. * @hidden
  351. */
  352. SplitPane.prototype.initPane = function () {
  353. return true;
  354. };
  355. SplitPane.decorators = [
  356. { type: core_1.Directive, args: [{
  357. selector: 'ion-split-pane',
  358. providers: [{ provide: RootNode, useExisting: core_1.forwardRef(function () { return SplitPane; }) }]
  359. },] },
  360. ];
  361. /** @nocollapse */
  362. SplitPane.ctorParameters = function () { return [
  363. { type: core_1.NgZone, },
  364. { type: platform_1.Platform, },
  365. { type: config_1.Config, },
  366. { type: core_1.ElementRef, },
  367. { type: core_1.Renderer, },
  368. ]; };
  369. SplitPane.propDecorators = {
  370. '_setchildren': [{ type: core_1.ContentChildren, args: [RootNode, { descendants: false },] },],
  371. 'when': [{ type: core_1.Input },],
  372. 'enabled': [{ type: core_1.Input },],
  373. 'ionChange': [{ type: core_1.Output },],
  374. };
  375. return SplitPane;
  376. }(ion_1.Ion));
  377. exports.SplitPane = SplitPane;
  378. });
  379. //# sourceMappingURL=split-pane.js.map