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.5.16 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.15 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.14 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.13 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.12 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.11 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.10 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.9 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.8 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.7 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.6 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.5 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.4 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.3 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.2 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.1 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.5.0 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.9 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.8 lib/nexmo_developer/app/webpacker/javascript/notices/index.js
station-0.4.7 lib/nexmo_developer/app/webpacker/javascript/notices/index.js