HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/public_html/wp-content/plugins/sermone/src/notice-box.js
/**
 * Notice Box 
 * 
 * @package sermone 
 * @version 1.0.0
 */

export default class NoticeBox {

  constructor ( options ) {
    this.opts = window.jQuery.extend( {
      content: '',
      autoClose: true,
      autoCloseTimer: 5000
    }, options )

    this.showTimeout

    return this
  }

  template ( content ) {
    let html = `
    <div class="notice-box-container">
      <div class="notice-box--content">
        ${ content }
      </div>
    </div>`
    return window.jQuery( html )
  }

  setContent ( newContent ) { console.log( newContent )
    this.opts.content = newContent
    if( this.$box ) this.$box.find( '.notice-box--content' ).html( this.opts.content )
  }

  show () {
    let self = this
    clearTimeout( self.showTimeout )

    if( this.$box ) {

      self.showTimeout = setTimeout( () => {
        self.hide()
      }, this.opts.autoCloseTimer )

      return
    }

    this.$box = this.template( this.opts.content )

    window.jQuery( 'body' ).append( this.$box )
    this.$box.find( '.notice-box--content' ).animate( {
      bottom: 20,
    }, 'slow' )

    if( this.opts.autoClose == true ) {
      self.showTimeout = setTimeout( () => {
        self.hide()
      }, this.opts.autoCloseTimer )
    }
  }

  hide () {
    let self = this 

    if( ! self.$box ) return

    this.$box.find( '.notice-box--content' ).animate( {
      bottom: -150,
    }, 'slow', () => {
      self.$box.remove()
      self.$box = null
    } )
  }
}