display-when.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. /**
  13. * @hidden
  14. */
  15. var DisplayWhen = (function () {
  16. function DisplayWhen(conditions, _plt, zone) {
  17. this._plt = _plt;
  18. this.zone = zone;
  19. this.isMatch = false;
  20. if (!conditions)
  21. return;
  22. this.conditions = conditions.replace(/\s/g, '').split(',');
  23. // check if its one of the matching platforms first
  24. // a platform does not change during the life of an app
  25. for (var i = 0; i < this.conditions.length; i++) {
  26. if (this.conditions[i] && _plt.is(this.conditions[i])) {
  27. this.isMatch = true;
  28. return;
  29. }
  30. }
  31. if (this.orientation()) {
  32. // add window resize listener
  33. this.resizeObs = _plt.resize.subscribe(this.orientation.bind(this));
  34. }
  35. }
  36. DisplayWhen.prototype.orientation = function () {
  37. for (var i = 0; i < this.conditions.length; i++) {
  38. if (this.conditions[i] === 'portrait') {
  39. this.isMatch = this._plt.isPortrait();
  40. return true;
  41. }
  42. if (this.conditions[i] === 'landscape') {
  43. this.isMatch = this._plt.isLandscape();
  44. return true;
  45. }
  46. }
  47. return false;
  48. };
  49. DisplayWhen.prototype.ngOnDestroy = function () {
  50. this.resizeObs && this.resizeObs.unsubscribe();
  51. this.resizeObs = null;
  52. };
  53. return DisplayWhen;
  54. }());
  55. exports.DisplayWhen = DisplayWhen;
  56. });
  57. //# sourceMappingURL=display-when.js.map