aaronpowell / KnockoutJS-Pre-parser

A pre-parser for KnockoutJS to use more convention-based discovery for the data binding
MIT License
5 stars 0 forks source link

Template parsing issue in IE < 9 #1

Open rniemeyer opened 13 years ago

rniemeyer commented 13 years ago

I was testing the template parsing aspects of your script in the context of this discussion: https://github.com/bsatrom/Knockout.Unobtrusive/issues/2#issuecomment-1808219

I wanted to see if your preparser could handle templates properly in earlier versions of IE. This fiddle shows a problem: http://jsfiddle.net/rniemeyer/fF9nu/

I didn't debug into it too much, but the error is happening in jQuery.html() from this call in your parseTemplate function:

template.html(templateWrapper.html());

Additionally, as I mentioned on the other thread, there is a subtle issue in IE < 9 that can cause bindings to not be found by Knockout . If you rewrite the template by loading the script contents into a DOM structure, then manipulate it, then rewrite it back. If the rewritten script content ultimately uses the innerHTML of the DOM structure (which .html() does), then you can end up with attributes like class that no longer have quotes around their value.

<div class=item data-bind="text: name"></div>

Knockout has an issue finding the data-bind in that case based on a regex that is uses to parse attributes.

aaronpowell commented 13 years ago

I'll have a look into it but I'm wondering if this is more a jQuery bug than my code (although I should be able to work around it) and if it's a jQuery bug then does it need to be raised.

On your point about knockout having issues with unquoted attributes that seems strange. If knockout is using regexes to check attributes (which I do too) then it should be using the attributes NodeList which then should hand it attribute-by-attribute.

rniemeyer commented 13 years ago

Knockout does some rewriting of the text content of templates (as a string) and uses the regex as part of the parsing.

aaronpowell commented 13 years ago

Oh, I thought it passes it off to the chosen template engine to handle, my bad!