display-when.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. * @hidden
  3. */
  4. export class DisplayWhen {
  5. constructor(conditions, _plt, zone) {
  6. this._plt = _plt;
  7. this.zone = zone;
  8. this.isMatch = false;
  9. if (!conditions)
  10. return;
  11. this.conditions = conditions.replace(/\s/g, '').split(',');
  12. // check if its one of the matching platforms first
  13. // a platform does not change during the life of an app
  14. for (let i = 0; i < this.conditions.length; i++) {
  15. if (this.conditions[i] && _plt.is(this.conditions[i])) {
  16. this.isMatch = true;
  17. return;
  18. }
  19. }
  20. if (this.orientation()) {
  21. // add window resize listener
  22. this.resizeObs = _plt.resize.subscribe(this.orientation.bind(this));
  23. }
  24. }
  25. orientation() {
  26. for (let i = 0; i < this.conditions.length; i++) {
  27. if (this.conditions[i] === 'portrait') {
  28. this.isMatch = this._plt.isPortrait();
  29. return true;
  30. }
  31. if (this.conditions[i] === 'landscape') {
  32. this.isMatch = this._plt.isLandscape();
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. ngOnDestroy() {
  39. this.resizeObs && this.resizeObs.unsubscribe();
  40. this.resizeObs = null;
  41. }
  42. }
  43. //# sourceMappingURL=display-when.js.map