{"version":3,"sources":["webpack:///./src/ktu/js/components/Component.js","webpack:///./src/ktu/js/components/ReadMore.js","webpack:///./src/ktu/js/helpers/getLineHeight.js"],"names":["domTree","WeakMap","configuration","Component","el","config","arguments","length","undefined","_classCallCheck","this","Error","$el","jQuery","$","set","hasOwnProperty","dom","setupDefaults","addListeners","get","elements","_component","__webpack_require__","_getLineHeight","ReadMore","_this","_possibleConstructorReturn","__proto__","Object","getPrototypeOf","call","$text","wrapInner","$textInner","find","css","configureComponent","activeBreakpoint","isInitialized","isExpanded","appliedConfig","margins","$window","window","textSelector","on","bind","buttonClass","toggleTextHeight","_this2","textHeight","height","lineHeight","getLineHeight","responsive","forEach","matchMedia","breakpoint","matches","_extends","totalLines","childElements","children","filter","i","each","textLines","maxLines","parseInt","shouldInitialize","addClass","insertAfter","$link","removeClass","remove","event","preventDefault","html","data","elem","lh"],"mappings":"ohBAAA,IAAMA,EAAU,IAAIC,QACdC,EAAgB,IAAID,QA4BpBE,aAOJ,SAAAA,EAAYC,GAAgB,IAAZC,EAAYC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,MAC1B,+FAD0BG,CAAAC,KAAAP,QACR,IAAPC,EACT,MAAM,IAAIO,MAAM,wEASlBD,KAAKE,IAAMR,aAAcS,EAAST,EAAKU,EAAEV,GAEjB,IAApBM,KAAKE,IAAIL,SAEbP,EAAQe,IAAIL,SACZR,EAAca,IAAIL,KAAML,GAEpBK,KAAKL,OAAOW,eAAe,SAC7BN,KAAKO,IAAMP,KAAKL,OAAOY,KAGzBP,KAAKQ,gBACLR,KAAKS,0IAuCL,OAAOjB,EAAckB,IAAIV,gCA6BnBW,GACNA,OACKX,KAAKO,IACLI,GAGLrB,EAAQe,IAAIL,KAAMW,mBAYlB,OAAOrB,EAAQoB,IAAIV,yBAIRP,uhBCrJfmB,EAAAC,EAAA,yCACAC,EAAAD,EAAA,SAEME,cACJ,SAAAA,EAAYrB,EAAIC,gGAAQI,CAAAC,KAAAe,GAAA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SAAA0B,GAC3B,IAAIC,EAAKD,EAAK5C,IAAI,eAMlB,MALW,WAAP6C,IAGFA,EAAuC,IAAlCZ,SAASW,EAAK5C,IAAI,eAElBiC,SAASY","file":"24.7fd4ca4ad94e78998b23.js","sourcesContent":["const domTree = new WeakMap();\nconst configuration = new WeakMap();\n\n/**\n * Component is a class that should be extended for every component that's being made. It\n * is a helper class to keep the code uniform.\n *\n * __PLEASE NOTE__: This is only to be extended, not instantiated.\n *\n * @example\n * import Component from 'component';\n *\n * class Foo extends Component {\n *   construction(el){\n *     super(el);\n *   }\n *\n *   setupDefaults(){\n *     // ...defaults go here\n *   }\n *\n *   addListeners(){\n *     // ...listeners go here\n *   }\n * }\n *\n * // Create a new Foo component\n * new Foo('.foo');\n */\nclass Component {\n  /**\n   * Component constructor - see {@link config} on how to pass in additional configuration to the constructor\n   *\n   * @param {string|Object} el - Main DOM element, you can pass a string such as `'.foo'` __or__ a jQuery object such as `$('.foo')`\n   * @param {Object} [config={ }] - Additional component configuration; reachable with `this.config`\n   */\n  constructor(el, config = {}){\n    if (typeof el === 'undefined') {\n      throw new Error('You must provide an element as a String type or a jQuery object type');\n    }\n\n    /**\n     * Main class element, this will be a jQuery instance\n     * This can be reachable at any time in your superclass with `this.$el`\n     *\n     * @type {Object}\n     */\n    this.$el = el instanceof jQuery ? el : $(el);\n\n    if (this.$el.length === 0) return;\n\n    domTree.set(this, {});\n    configuration.set(this, config);\n\n    if (this.config.hasOwnProperty('dom')) {\n      this.dom = this.config.dom;\n    }\n\n    this.setupDefaults();\n    this.addListeners();\n  }\n\n  /**\n   * This method is used for override;\n   * It's called directly after the element and configuration have been set up\n   * @abstract\n   */\n  setupDefaults(){}\n\n  /**\n   * This method is used for override;\n   * It's called directly after `setupDefaults()`, so everything is ready and setup at this point.\n   * @abstract\n   */\n  addListeners(){}\n\n  /**\n   * Get component configuration\n   *\n   * @example\n   * class Foo extends Component {\n   *   construction(el, config){\n   *     super(el, config);\n   *   }\n   *\n   *   setupDefaults(){\n   *     console.log(this.config.name); // Outputs \"Foo\"\n   *   }\n   * }\n   *\n   * // Create a new Foo component with some configuration\n   * new Foo('.foo', {\n   *   name: 'Foo'\n   * });\n   *\n   * @type {Object}\n   */\n  get config(){\n    return configuration.get(this);\n  }\n\n  /**\n   * Set DOM object\n   *\n   * @example\n   * class Foo extends Component {\n   *   construction(el){\n   *     super(el);\n   *   }\n   *\n   *   setupDefaults(){\n   *     this.dom = {\n   *       $container: this.$el.find('.container')\n   *     }\n   *   }\n   *\n   *   addListeners(){\n   *     //DOM object is available\n   *     console.log(this.dom.$container);\n   *   }\n   * }\n   *\n   * // Create a new Foo component\n   * new Foo('.foo');\n   *\n   * @type {Object}\n   */\n  set dom(elements){\n    elements = {\n      ...this.dom,\n      ...elements\n    };\n\n    domTree.set(this, elements);\n  }\n\n  /**\n   * Get DOM object\n   *\n   * @example\n   * this.dom\n   *\n   * @type {Object}\n   */\n  get dom(){\n    return domTree.get(this);\n  }\n}\n\nexport default Component;\n\n\n\n// WEBPACK FOOTER //\n// ./src/ktu/js/components/Component.js","import Component from 'component';\nimport { getLineHeight } from '../helpers/getLineHeight';\n\nclass ReadMore extends Component {\n  constructor(el, config) {\n    super(el, config);\n\n    this.dom.$text.wrapInner('<div class=\"read-more__inner\"></div>');\n    this.dom.$textInner = this.dom.$text.find('.read-more__inner');\n    this.dom.$textInner.css('overflow', 'hidden');\n\n    this.configureComponent();\n  }\n\n  setupDefaults() {\n    this.activeBreakpoint;\n    this.isInitialized = false;\n    this.isExpanded = false;\n    this.appliedConfig = this.config;\n    this.margins = 0;\n\n    this.dom = {\n      $window: $(window),\n      $text: this.$el.find(this.config.textSelector)\n    };\n  }\n\n  addListeners() {\n    this.dom.$window.on('resize', ::this.configureComponent);\n    this.$el.on(\n      'click',\n      `.${this.config.buttonClass || 'btn-read-more'}`,\n      ::this.toggleTextHeight\n    );\n  }\n\n  configureComponent() {\n    this.appliedConfig = this.config;\n    this.textHeight = this.dom.$textInner.height();\n    this.lineHeight = getLineHeight(this.dom.$textInner);\n\n    // Check if current mq has custom config\n    if (this.config.responsive && this.config.responsive.length) {\n      this.config.responsive.forEach(responsive => {\n        if (\n          window.matchMedia(`(max-width: ${responsive.breakpoint}px)`).matches\n        ) {\n          this.appliedConfig = { ...this.config, ...responsive.config };\n        }\n      });\n    }\n\n    let totalLines = 0;\n    // Get child block elements\n    const childElements = this.dom.$textInner.children().filter((i, el) => {\n      return $(el).css('display') === 'block';\n    });\n\n    // Check if element has child elements\n    if (childElements.length) {\n      this.margins = 0;\n      childElements.each((i, el) => {\n        // Get number of lines for each p tag\n        const textHeight = $(el).height();\n        const textLines = textHeight / this.lineHeight;\n\n        totalLines += textLines;\n\n        if (\n          this.appliedConfig.maxLines &&\n          totalLines < this.appliedConfig.maxLines\n        ) {\n          this.margins +=\n            parseInt($(el).css('margin-top')) +\n            parseInt($(el).css('margin-bottom'));\n        } else if (\n          this.appliedConfig.maxLines &&\n          totalLines === this.appliedConfig.maxLines\n        ) {\n          this.margins += parseInt($(el).css('margin-top'));\n        }\n      });\n    } else {\n      totalLines = this.textHeight / this.lineHeight;\n    }\n\n    const shouldInitialize =\n      this.appliedConfig.maxLines && totalLines > this.appliedConfig.maxLines;\n\n    if (this.isInitialized !== shouldInitialize) {\n      this.isInitialized = shouldInitialize;\n      if (shouldInitialize) {\n        this.$el.addClass('read-more__initialized');\n        $('<button class=\"btn-read-more\"></button>').insertAfter(\n          this.dom.$text\n        );\n        this.dom.$link = this.$el.find('.btn-read-more');\n        this.toggleTextHeight();\n      } else {\n        this.$el.removeClass('read-more__initialized');\n        this.dom.$text.css('height', '');\n        this.$el.find('.btn-read-more').remove();\n      }\n    }\n  }\n\n  toggleTextHeight(event) {\n    if (event) {\n      event.preventDefault();\n      this.isExpanded = !this.isExpanded;\n    }\n\n    if (this.isExpanded) {\n      this.$el.addClass('read-more__expanded');\n      this.dom.$text.height(this.textHeight);\n      this.dom.$link.html(\n        `<svg><use xlink:href=\"#minus\" /></svg>${\n          this.$el.data('readLessLabel') || ''\n        }`\n      );\n    } else {\n      this.$el.removeClass('read-more__expanded');\n      this.dom.$text.height(\n        this.appliedConfig.maxLines * this.lineHeight + this.margins\n      );\n      this.dom.$link.html(\n        `<svg><use xlink:href=\"#plus\" /></svg>${\n          this.$el.data('readMoreLabel') || ''\n        }`\n      );\n    }\n  }\n}\n\nexport default ReadMore;\n\n\n\n// WEBPACK FOOTER //\n// ./src/ktu/js/components/ReadMore.js","//-- Get Line Height\n\nexport const getLineHeight = elem => {\n  let lh = elem.css('line-height')\n  if (lh === 'normal') {\n    // Normal line heights vary from browser to browser. The spec recommends\n    // a value between 1.0 and 1.2 of the font size. Using 1.1 to split the diff.\n    lh = parseInt(elem.css('font-size')) * 1.1;\n  }\n  return parseInt(lh);\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/ktu/js/helpers/getLineHeight.js"],"sourceRoot":""}