/*
	Author: Adrian Arellano
	Filename: multiline.js
	Description: This is to apply ellipsis on multilined text 
	Dependencies:
		jQuery.ellipsis
	How to use:
		1. add the class of '.js-multiline' on the element that will limit the no. of lines that will be shown only 
	Note: 
		- the height of the element must be fixed
		- overflow in the element must be set to hidden
*/

;(function($) {
  B2C.multiline = {
    init: function(option) {
      this._default = {
        target: ".js-multiline",
        config: {
          responsive: true // updates the multiline ellipsis on resize
        }
      }

      this._option = $.extend(true, this._default, option)

      if (!$(this._option.target).length) return

      // checks if the there is a passed no of line to be set as a limit
      this.setLines()

      //   initializes the multiline ellipsis with passed options
      $(this._option.target).ellipsis(this._option.config)
    },

    setLines: function() {
      this._option = $.extend(true, this._option, {
        config: {
          lines: $(this._option.target).data("max-line") // forces the multilined text to be on ellipsis on a set line no.
        }
      })
    }
  }

  const multiline = Object.create(B2C.multiline)

  multiline.init()
})(jQuery)
