// apply tagOpen/tagClose to selection in textarea,
// use sampleText instead of selection if there is none
function insertTags( tagOpen, tagClose, sampleText ) {
- if ( typeof $j != 'undefined' && typeof $j.fn.textSelection != 'undefined' ) {
+ if ( typeof $j != 'undefined' && typeof $j.fn.textSelection != 'undefined' &&
+ ( currentFocused.nodeName.toLowerCase() == 'iframe' || currentFocused.id == 'wpTextbox1' ) ) {
$j( '#wpTextbox1' ).textSelection(
'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
);
return;
}
function onfocus( e ) {
- var elm = e.target;
+ var elm = e.target || e.srcElement;
if ( !elm ) {
return;
}
var tagName = elm.tagName.toLowerCase();
- var type = elm.type.toLowerCase();
+ var type = elm.type || '';
if ( tagName !== 'textarea' && tagName !== 'input' ) {
return;
}
- if ( tagName === 'input' && type && type !== 'text' ) {
+ if ( tagName === 'input' && type.toLowerCase() !== 'text' ) {
return;
}
// IE needs a specific trick here since it doesn't support the standard
editForm.attachEvent( 'onfocusin', function() { onfocus( event ); } );
}
+
+ // HACK: make currentFocused work with the usability iframe
+ // With proper focus detection support (HTML 5!) this'll be much cleaner
+ if ( typeof $j != 'undefined' ) {
+ var iframe = $j( '.wikiEditor-ui-text iframe' );
+ if ( iframe.length > 0 ) {
+ $j( iframe.get( 0 ).contentWindow.document )
+ .add( iframe.get( 0 ).contentWindow.document.body ) // for IE
+ .focus( function() { currentFocused = iframe.get( 0 ); } );
+ }
+ }
editForm
} );