Coder Social home page Coder Social logo

Table updates do not work about textfit HOT 4 CLOSED

tiofabby avatar tiofabby commented on May 31, 2024
Table updates do not work

from textfit.

Comments (4)

STRML avatar STRML commented on May 31, 2024

I am unable to replicate this. TextFit is working fine with Arrays or NodeLists. Please reopen if you have failing code or are still experiencing this issue.

from textfit.

jdietrch avatar jdietrch commented on May 31, 2024

What textFit does not work fine with, however, is HTMLCollection objects. And in Firefox 46 and Chrome 50, getElementsByClassName() returns a HTMLCollection object. See https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName.

Here's a simplified testcase illustrating document.getElementsByClassName() not working. Try it in the latest version of Firefox or Chrome. The first two divs get their text expanded, and the last two do not.

<!DOCTYPE html>
<html>
  <head>
    <title>Problem with textFit() and document.getElementsByClassName() array</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script src="textFit.js"></script>
    <style>
      div{
        height: 150px;
        width: 150px;
        color: white;
        background: black;
        margin: 5px;
      }
    </style>
  </head>
  <body>
    <div id="tf">
      Text
    </div>
    <div class="tg">
      Text
    </div>
    <div class="th">
      Text
    </div>
    <div class="th">
      Text
    </div>
    <script>
        textFit(document.getElementById('tf'));
        textFit(document.getElementsByClassName('tg')[0]);
        textFit(document.getElementsByClassName('th'));
    </script>
  </body>
</html>

I fixed this by changing the line
if (elType !== '[object Array]' && elType !== '[object NodeList]'){
to

if (elType !== '[object Array]' && elType !== '[object NodeList]' &&
        elType !== '[object HTMLCollection]'){

Thank you.

from textfit.

STRML avatar STRML commented on May 31, 2024

Thanks - could you make a PR for this?

from textfit.

STRML avatar STRML commented on May 31, 2024

Fixed in 2.3.1. Thanks for the PR.

from textfit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.