javascript - adapting a click-to-insert by substituting alternate text -
i trying adapt script: jquery example: inserting text drag n’ drop.
the goal users click image thumbnail , have appropriate markdown image code inserted textarea.
i not familiar js, aware meat of script happening here:
$('#clickwordlist li').click(function() { $("#txtmessage").insertatcaret($(this).text()); return false }); specifically, .text() bit there, not know how alter output suit needs snippet of markdown being inserted rather just, say, list text.
markdown inline image syntax looks this: 
i tried changing list div images , changing .insertatcaret($(this).src); "undefined" insertion text.
$(this).src undefined because $(this) jquery object, , jquery objects don't have src property. assuming have image element in selector, can try:
$("#txtmessage").insertatcaret($(this).attr('src')); the .attr() jquery method, when given 1 parameter, return matched element's given attribute's value.
or
$("#txtmessage").insertatcaret($(this)[0].src); to literal dom element's src.
extra explanations (if need)
.text() jquery method, when given no parameters, return text inside of element referenced this, is, event's target, in case clicked li inside #clickwordlist element.
.insertatcaret() extended function of jquery object provided drag 'n drop plugin.
return false says, returning false in click event's handler selected element, cancels event , prevents propagation bubbling dom further.
sorry if there typos.
Comments
Post a Comment