vectorsize / substance-text

Substance Text
substance.github.com/text
MIT License
282 stars 26 forks source link

does not work on dynamically inserted HTML #12

Closed rsaccon closed 12 years ago

rsaccon commented 12 years ago

observed this on latest Chrome and Safari on Mac OS X Lion.

Everything fine if the HTML node where I want to activate the editor exists statically at page load time.

I am using sproutcore and the app gets generated from JS templates. Now I try to activate the editor on a Node which has been dynamically generated via JS, and I get:

Chrome Error:

TypeError: Cannot read property 'startContainer' of null

Safari Error:

TypeError: 'null' is not an object (evaluating 'sel.startContainer')
timjb commented 12 years ago

The dynamically generated element must be in the dom tree when activate is called.

rsaccon commented 12 years ago

yes, of course, and it is. I have no idea what is the reason of this error, somehow it seems to come from selection

timjb commented 12 years ago

Yes, the selection seems to be null. But this should not possible since in activate the element's focus method is called.

rsaccon commented 12 years ago

I will do some experimentation with my own barebone content editable wrapper, maybe this will shed some light on this issue.

timjb commented 12 years ago

Please make really sure that the element is in the DOM. As far as I know SproutCore defers the DOM insertion to synchronize bindings.

rsaccon commented 12 years ago

Well, I did also manually activate proper, at that stage it is sure stuff is in DOM

timjb commented 12 years ago

I did this:

var div = document.createElement('div');
document.body.appendChild(div);
var proper = new Proper();
proper.activate(div);

And it worked in Google Chrome 15 on Ubuntu. Can you try this on your Mac?

rsaccon commented 12 years ago

that works as expected (on the same page as the sproutcore stuff). but if I choose a domnode to activate which has been generated by a handlebar template, again the same error message. Maybe there is some overlapping in the setup of bindungs over the DOM node, from sproutcore and backbone inspired proper.js

timjb commented 12 years ago

It's true that proper uses Backbone's Event object, but nothing else from Backbone. Therefore, I don't think that this is caused by a overlapping between proper and Sproutcore. I suspect that this error is caused by a weird behavior of SproutCore or Handlebars. I can look into this if you give me some code.

rsaccon commented 12 years ago

the problem seems to be unique to my app, I created a jsfiddle, and there it works. I am closing the issue, it is definitely not propers fault. Thanks for the help.

http://jsfiddle.net/rsaccon/umjcC/30/