tblobaum / baumpress.com

0 stars 0 forks source link

Jeff Bezos Says Blue Origin’s Next CEO Will Be Bringing A Sense Of Urgency To Rocketry - BAUMPRESS #1

Open utterances-bot opened 9 months ago

utterances-bot commented 9 months ago

Jeff Bezos Says Blue Origin’s Next CEO Will Be Bringing A Sense Of Urgency To Rocketry - BAUMPRESS

http://localhost/space/spacecraft/jeff-bezos-says-blue-origins-next-ceo-will-be-bringing-a-sense-of-urgency-to-rocketry/

tblobaum commented 9 months ago

test

tblobaum commented 9 months ago
  function baumShortenTitle (selector, maxLines) {
    console.log('baumShortenTitle', selector, maxLines)
    $(selector).each(function (index) { 
      var $this = $(this)

      console.log($this)
      var titleMaxLines = Number($(this).data('title-max-lines')) || maxLines || 2
      var lineHeight = parseInt($this.css('line-height'))
      var marginTop = parseInt($this.css('margin-top'))
      var marginBottom = parseInt($this.css('margin-bottom'))
      var maxHeight = (lineHeight * titleMaxLines) 
      maxHeight = maxHeight //+ marginTop + marginBottom
      var height = $this.height()
      var title = $this.text()
      var params = {} 
      params.style = $this.css([ 
        'width', 
        'font-size', 
        'font-weight', 
        'font-family', 
        'letter-spacing',
        'line-height',
        'margin',
        'padding'
      ])

      // console.log('baumShortenTitle', titleMaxLines, params, title, maxHeight, height, marginTop, marginBottom)
      var $span = $('<span></span>')
      $('body').append($span)
      $span.css('visibility', 'hidden')
      $span.css('display', 'block')
      $span.css(params.style)
      $span.text($this.text().trim())

      function trimTitle (hasBeenTrimmed) {
        if ($span.height() > maxHeight) {
          $span.text($span.text().slice(0, -1))
          return trimTitle(true)
        } else {
          if (hasBeenTrimmed) $span.text($span.text().slice(0, -3) + '...')
          $span.remove()
          return $span.text()
        }
      }
      $this.text(trimTitle())
    })
  }