javascript - Display function output within an anonymous function -
i trying output selected text within javascript code. created function selected text , want output when submit button output.
here's javascript getting selected html or text.
function getselectionhtml() { var html = ""; if (typeof window.getselection != "undefined") { var sel = window.getselection(); if (sel.rangecount) { var container = document.createelement("div"); (var = 0, len = sel.rangecount; < len; ++i) { container.appendchild(sel.getrangeat(i).clonecontents()); } html = container.innerhtml; } } else if (typeof document.selection != "undefined") { if (document.selection.type == "text") { html = document.selection.createrange().htmltext; } } document.write(html); }
here's code outputting other content plus function above (but wont show up)
(function() { tinymce.pluginmanager.add('my_mce_button', function( editor, url ) { editor.addbutton( 'my_mce_button', { icon: false, text: 'tooltip', onclick: function() { editor.windowmanager.open( { title: 'tooltip option', body: [ { type: 'textbox', name: 'textboxtooltipname', label: 'tooltip text', value: '' }, { type: 'listbox', name: 'listboxclassname', label: 'class', 'values': [ {text: 'top tooltip', value: 'top_tooltip'}, {text: 'left tooltip', value: 'left_tooltip'}, {text: 'right tooltip', value: 'right_tooltip'}, {text: 'bottom tooltip', value: 'bottom_tooltip'} ] } ], onsubmit: function( e ) { editor.insertcontent( '[tooltip class="' + e.data.listboxclassname + '" title="' + e.data.textboxtooltipname + '"] html [/tooltip]'); } }); } }); }); })();
now line 1 responsible displaying selected text + other attributes. basically, created html variable catch selected text not displaying on code. check out code:
onsubmit: function( e ) { editor.insertcontent( '[tooltip class="' + e.data.listboxclassname + '" title="' + e.data.textboxtooltipname + '"] html [/tooltip]'); }
any idea what's up? how can display output of getselectionhtml function output of anonymous function properly?
your getselectionhtml()
function gets text selected on page, think want text selected in tinymce editor.
try:
editor.insertcontent( '[tooltip class="' + e.data.listboxclassname + '" title="' + e.data.textboxtooltipname + '"]' + editor.selection.getcontent() + '[/tooltip]');
Comments
Post a Comment