refIdeas: {
type: 'element',
filters: [ 'body.ns-3' ],
var text = '{{refideas\n|1=\n}}';
var textarea = context.$textarea[0]; ▼
console.log('Button clicked!');
var start = textarea.selectionStart; ▼
console.log('Context object:', context);
var end = textarea.selectionEnd; ▼
console.log('context.fn exists:', !!context.fn);
var currentText = textarea.value; ▼
console.log('context.fn.encapsulateSelection exists:', !!(context.fn && context.fn.encapsulateSelection));
console.log('context.$textarea exists:', !!context.$textarea);
textarea.value = currentText.substring(0, start) + text + currentText.substring(end); ▼
// Method 1: context.fn.encapsulateSelection
textarea.selectionStart = textarea.selectionEnd = start + text.length; ▼
if ( context.fn && context.fn.encapsulateSelection ) {
console.log('Using method 1: context.fn.encapsulateSelection');
context.fn.encapsulateSelection( {
pre: text$(textarea).trigger('input');
} );
} else if ( context.$textarea ) {
// Method 2: Direct textarea manipulation via context
console.log('Using method 2: context.$textarea');
▲ var textarea = context.$textarea[0];
▲ var start = textarea.selectionStart;
▲ var end = textarea.selectionEnd;
▲ var currentText = textarea.value;
▲ textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
▲ textarea.selectionStart = textarea.selectionEnd = start + text.length;
$(textarea).trigger('input');
} else {
// Method 3: Fallback - find textarea by ID
console.log('Using method 3: fallback #wpTextbox1');
var $textarea = $('#wpTextbox1');
console.log('Found textarea:', $textarea.length > 0);
if ( $textarea.length ) {
var textarea = $textarea[0];
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var currentText = textarea.value;
textarea.value = currentText.substring(0, start) + text + currentText.substring(end);
textarea.selectionStart = textarea.selectionEnd = start + text.length;
textarea.focus();
$textarea.trigger('input');
}
}
} );
|