html - jQuery TinyMCE like textbox menu -
so looking tutorial or guideline how make simple text box menu jquery (like tinymce or editor here @ stackoverflow when u ask question). need simple provide 2 buttons on click insert text text box? don't know how called i'm sure it's pretty common...
try (some of code borrowed google , modified bit):
<div id="toolbar"> <input type="button" value="button 1" id="button1" /> <input type="button" value="button 2" id="button2" /> </div> $.fn.extend({ insertatcaret: function(myvalue) { this1 = $(this).get(0); if (document.selection) { this1.focus(); sel = document.selection.createrange(); sel.text = myvalue; this1.focus(); } else if (this1.selectionstart || this1.selectionstart == '0') { var startpos = this1.selectionstart; var endpos = this1.selectionend; var scrolltop = this1.scrolltop; this1.value = this1.value.substring(0, startpos) + myvalue + this1.value.substring(endpos, this1.value.length); this1.focus(); this1.selectionstart = startpos + myvalue.length; this1.selectionend = startpos + myvalue.length; this1.scrolltop = scrolltop; } else { this1.value += myvalue; this1.focus(); } } }); $('#button1').click(function() { $('#text1').insertatcaret('text 1'); }); $('#button2').click(function() { $('#text1').insertatcaret('text 2'); }); look @ working here.
Comments
Post a Comment