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 divhtml/div with nbsp; 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/spanspan class=val2/span
/div
div class=sub2
span class=twrongThis Text wants to be removed./span
divdiv class=deepaFirst/aa
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',
$('spanNEW/span')
],
'.sub .twrong': null,
'.sub div .deep': {
'a[href]': function (e) {
e.click(function () { alert('Yes!'); return false;});
}
}
}).insertAfter('...');
Or the simple examples:
$('spanTest/span').template('New text'); = long way to write
.text('New test')
$('spanTest/span').template($('delX/del')); = another way
to write .empty().append('delX/del')
$('spanTest/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.