Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Clean GPL implementation of tabindex #345

Merged
merged 1 commit into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/components/tinymce/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ require( './plugins/wpeditimage/plugin.js' )();
require( './plugins/wplink/plugin.js' )();
require( './plugins/media/plugin' )();
require( './plugins/advanced/plugin' )();
require( './plugins/tabindex/plugin' )();
require( './plugins/wpcom-tabindex/plugin' )();
require( './plugins/touch-scroll-toolbar/plugin' )();
require( './plugins/editor-button-analytics/plugin' )();
require( './plugins/calypso-alert/plugin' )();
Expand Down Expand Up @@ -89,6 +89,7 @@ const PLUGINS = [
'wpcom/advanced',
'wpcom/help',
'wpcom/charmap',
'wpcom/tabindex',
'wpcom/touchscrolltoolbar',
'wpcom/view',
'wpcom/editorbuttonanalytics',
Expand Down
24 changes: 0 additions & 24 deletions client/components/tinymce/plugins/tabindex/plugin.js

This file was deleted.

39 changes: 39 additions & 0 deletions client/components/tinymce/plugins/wpcom-tabindex/plugin.js
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 );
};