ichord / Caret.js

Get caret postion and offset from text field
http://ichord.github.com/Caret.js
MIT License
1.05k stars 163 forks source link

$dom[0] is undefined #20

Closed runn3r85 closed 10 years ago

runn3r85 commented 10 years ago

I've recently started using Caret.js in order to use atWho.js. I'm using it on a rails app and have installed it two ways. First using the jquery-atwho-rails gem, and then manually installing caret.js and atwho.js. Both times I'm getting the following error:

TypeError: $dom[0] is undefined
oDocument = $dom[0].ownerDocument;

It's happening here specifically on line 366:

configure = function($dom, settings) {
      var error, iframe;
      if ($.isPlainObject(settings) && (iframe = settings.iframe)) {
        $dom.data('caret-iframe', iframe);
        return setContextBy(iframe);
      } else if (iframe = $dom.data('caret-iframe')) {
        return setContextBy(iframe);
      } else {
        oDocument = $dom[0].ownerDocument;
        oWindow = oDocument.defaultView || oDocument.parentWindow;
        try {
          return oFrame = oWindow.frameElement;
        } catch (_error) {
          error = _error;
        }
      }
    };

Not sure what's causing that or how to fix it, any suggestions?

ichord commented 10 years ago

It's weird. can you show me how you use it or use dev tools to capture the call chains.

ichord commented 10 years ago

$dom is not received from outside, it's a jQuery context in $.caret . if you use $.caret it should appear.

runn3r85 commented 10 years ago

The error was happening when I was calling $('textarea').caret('pos', 47); For some reason it's now working and not throwing an error. Thanks for the reply!