-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from Automattic/add/clean-tabindex-plugin
Editor: Clean GPL implementation of tabindex
- Loading branch information
Showing
3 changed files
with
41 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
client/components/tinymce/plugins/wpcom-tabindex/plugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import tinymce from 'tinymce/tinymce'; | ||
|
||
// Returns a function that sets the tabindex on an editor instance. | ||
// The returned function assumes that `this` is set to the editor instance | ||
function setTabIndexOnEditorIframe( tabindex ) { | ||
return function() { | ||
// At this point, there's an iframe in the DOM with the id of `${editor.id}_ifr`. | ||
// Can't find a way to get at it without hopping out to the DOM :/ | ||
const editorIframe = document.getElementById( `${this.id}_ifr` ); | ||
|
||
if ( ! editorIframe ) { | ||
return; | ||
} | ||
|
||
editorIframe.setAttribute( 'tabIndex', tabindex ); | ||
} | ||
} | ||
|
||
function wpcomTabIndexPlugin( editor ) { | ||
const settings = editor && editor.settings; | ||
|
||
if ( ! settings || ! ( 'tabindex' in settings ) ) { | ||
return; | ||
} | ||
|
||
const tabindex = Math.min( 32767, Number( settings.tabindex ) ); | ||
if ( ! Number.isInteger( tabindex ) ) { | ||
return; | ||
} | ||
|
||
editor.on( 'init', setTabIndexOnEditorIframe( tabindex ) ); | ||
} | ||
|
||
export default function() { | ||
tinymce.PluginManager.add( 'wpcom/tabindex', wpcomTabIndexPlugin ); | ||
}; |