Sha256: c2808fd6b787c7e3cb79d53ab14ee0a54c305ebd7f85754a18aa883b170d703e

Contents?: true

Size: 1.21 KB

Versions: 94

Compression:

Stored size: 1.21 KB

Contents

export default () => {
  const noticeCloseComplete = function(notice) {
    notice.remove()
    removeNoticesIfEmpty()
  }

  const noticeKey = function (notice) {
    const id = notice.data('notice-id')
    return `notice-dismissed(id:${id})`
  }

  const isDismissible = function (notice) {
    return notice.data('notice-dismissible')
  }

  const bootstrap = function() {
    $(document).on('click', '.notice a[data-close]', function(event) {
      const notice = $(this).parents('.notice')
      localStorage.setItem(noticeKey(notice), true)

      TweenLite.to(notice, 0.6, {
        scale: 0,
        height: 0,
        transformOrigin: "center top",
        ease: Power2.easeIn,
        onComplete: () => noticeCloseComplete(notice)
      });
    });
  }

  const removeNoticesIfEmpty = function() {
    if ($('.notices .notice').length === 0) {
      $('.notices').remove()
    }
  }

  const clearRead = function() {
    $('.notices .notice').each(function() {
      const notice = $(this)
      if(isDismissible(notice)) { return }
      if (localStorage.getItem(noticeKey(notice))) {
        $(this).remove()
      }
    })
    removeNoticesIfEmpty()
  }

  $(document).ready(function() {
    bootstrap()
    clearRead()
  });
}

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.4.6 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.5 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.4 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.3 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.2 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.1 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.0 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.3.2 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.3.1 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.3.0 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.6 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.5 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.4 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.3 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.2 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.1 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.2.0 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.1.8 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.1.7 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.1.6 lib/nexmo_developer/app/webpacker/javascript/notices/index.js