bgrins / ExpandingTextareas

jQuery plugin for elegant expanding textareas
http://bgrins.github.com/ExpandingTextareas/
MIT License
260 stars 73 forks source link

Cant get it to work without using jQuery #73

Closed thorakmedichi closed 7 years ago

thorakmedichi commented 7 years ago

I am trying to get this awesome script to work on my newest project. I have used it tons in the past but all of those sites had jQuery Library. This current site has no jQuery and I don't want to require the jQuery library just to use this one script.

In the following code simply using: textarea.expanding(); does not work. Nor do several other things I have tried, like using the new Expanding('textarea') creator;

Here is what I am doing:

    function editDiv(div){
        originalContents = div.innerHTML;
        var parent = div.parentNode;

        textarea.value = originalContents.trim();
        parent.appendChild(textarea);
        textarea.focus();

        // Find a way to change this to be just raw JS and not use jQuery.
        $('textarea').expanding();

        save = saveContent.bind(this, div, parent);
        textarea.addEventListener('blur', save, false);
    }

Please provide a solution for my use case. Cheers

domchristie commented 7 years ago

Hi @thorakmedichi

The Expanding constructor takes a textarea DOM node as its only argument (rather than a CSS sector string). It looks like you have a reference to a textarea node, so you may want to try:

var expanding = new Expanding = (textarea)