API Docs for: 0.25.0
Show:

File: addon/components/scheduled-banner/component.js

  1. import Ember from 'ember';
  2. import layout from './template';
  3. import config from 'ember-get-config';
  4. import computedStyle from 'ember-computed-style';
  5. import Analytics from '../../mixins/analytics';
  6.  
  7. /**
  8. * @module ember-osf
  9. * @submodule components
  10. */
  11.  
  12. /**
  13. * Display the current banner.
  14. *
  15. * Sample usage:
  16. * ```handlebars
  17. * {{scheduled-banner}}
  18. * ```
  19. *
  20. * @class scheduled-banner
  21. */
  22. export default Ember.Component.extend(Analytics, {
  23.  
  24. layout,
  25. toast: Ember.inject.service(),
  26.  
  27. classNames: ['banner'],
  28. attributeBindings: [
  29. 'style',
  30. 'hidden',
  31. ],
  32. color: '',
  33. defaultAltText: '',
  34. mobileAltText: '',
  35. defaultPhoto: null,
  36. mobilePhoto: null,
  37. startDate: null,
  38. endDate: null,
  39. hidden: true,
  40. link: '',
  41. name: '',
  42.  
  43. colorStyle: computedStyle('colorProperty'),
  44. colorProperty: Ember.computed('color', function() {
  45. const bgColor = this.get('color');
  46. return { 'background-color': `${bgColor}` };
  47. }),
  48.  
  49. init() {
  50. this._super(...arguments);
  51.  
  52. Ember.$.ajax({
  53. url: `${config.OSF.apiUrl}/_/banners/current`,
  54. crossDomain: true
  55. })
  56. .then(({data: { attributes: attrs, links}}) => {
  57. this.setProperties({
  58. color: attrs.color,
  59. defaultAltText: attrs.default_alt_text,
  60. mobileAltText: attrs.mobile_alt_text,
  61. defaultPhoto: links.default_photo,
  62. mobilePhoto: links.mobile_photo,
  63. startDate: attrs.start_date,
  64. link: attrs.link,
  65. name: attrs.name,
  66. });
  67. this.get('startDate') && this.set('hidden', false);
  68. })
  69. .fail(() => {
  70. this.get('toast', 'Unable to load the current banner.');
  71. });
  72. },
  73. });
  74.