I like the first, there was an issue with multi-string .append where the first one was '[' that resulted in me needing to use document.createTextNode to work around it. Don't like the second, I don't see the purpose and it looks like it might have some issues working as an implementation. Not really a fan of third. Fourth, I don't think jQuery is the place for that, write a plugin.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name] Tobias Hoffmann wrote: > Attached are four extensions to jquery. > > One is a > $.text('Test text') utility function, that simplifies cases like > $('div.content').append($.text('Test test <m...@email.com > <mailto:m...@email.com>> here')); > Second the same thing with > $.html('some <div>html</div> with everything') > Third the combination: > $.toHtml('some < special') > which for example encodes the entities. Possible use case: "nl2br()": > $.html($.toHtml(text).replace('\n','<br/>\n')); > > I think there should be /some/ way in jquery to accomplish these > (without completely replacing the div's content), and /I/ haven't > found them in the API. > Their implementation is simple - but improvements are welcome. > > Fourth, a simple (but powerful) template engine (less than 2K): > E.g. with > <div id="#templates" style="display: none"> > <div class="tdata1"> > Hello <span class="tname"></span>. > <div class="trep"> > <span class="val1"></span><span class="val2"></span> > </div> > <div class="sub2"> > <span class="twrong">This Text wants to be removed.</span> > <div><div class="deep"><a>First</a><a > href="#">Link</a></div></div> > </div> > </div> > </div> > you can do: > > $('#templates .tdata1').template({ > '.tname': 'World <i...@me.com <mailto:i...@me.com>>', > '.trep': [ > {'val1': 5, val2: ' beer'}, > 'Throw the old inner stuff away', > $('<span>NEW</span>') > ], > '.sub .twrong': null, > '.sub div .deep': { > 'a[href]': function (e) { > e.click(function () { alert('Yes!'); return false;}); > } > } > }).insertAfter('...'); > > Or the simple examples: > $('<span>Test</span>').template('New text'); => long way to write > .text('New test') > $('<span>Test</span>').template($('<del>X</del>')); => another way > to write .empty().append('<del>X</del>') > $('<span>Test</span>').template(['A','B']); => short way to write ... > > I'm not sure, whether a template engine should be part of core jquery. > But maybe the name is a bit misleading: think about it as > $.fn.contents /*_on_steroids*/ (args); > > Comments, improvements, ... are welcome. > > - Tobias > > -- > > You received this message because you are subscribed to the Google > Groups "jQuery Development" group. > To post to this group, send email to jquery-...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/jquery-dev?hl=en. -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.