-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 #165 from WordPress/add/register-control-api
Single TinyMCE: Add TinyMCE-unaware control registration APIs
- Loading branch information
Showing
14 changed files
with
162 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
( function( wp ) { | ||
var _blocks, _controls; | ||
|
||
_blocks = {}; | ||
_controls = {}; | ||
|
||
wp.blocks = { | ||
registerBlock: function( settings ) { | ||
// Note, elements should probably only be registered by core. | ||
// Maybe for each block, we should offer to extend the settings (add buttons). | ||
|
||
if ( settings.elements ) { | ||
settings.elements.forEach( function( element ) { | ||
_blocks[ 'element:' + element ] = settings; | ||
_blocks[ 'element:' + element ]._id = 'element:' + element; | ||
} ); | ||
} else if ( settings.namespace && settings.name ) { | ||
_blocks[ settings.namespace + ':' + settings.name ] = settings; | ||
_blocks[ settings.namespace + ':' + settings.name ]._id = settings.namespace + ':' + settings.name; | ||
} | ||
}, | ||
registerControl: function( name, settings ) { | ||
_controls[ name ] = settings; | ||
}, | ||
getBlockSettings: function( name ) { | ||
return _blocks[ name ]; | ||
}, | ||
getControlSettings: function( name ) { | ||
return _controls[ name ]; | ||
}, | ||
getBlockSettingsByElement: function( element ) { | ||
var blockType = element.getAttribute( 'data-wp-block-type' ); | ||
var nodeName = element.nodeName.toLowerCase(); | ||
|
||
return this.getBlockSettings( blockType || 'element:' + nodeName ); | ||
}, | ||
getBlocks: function() { | ||
return _blocks; | ||
}, | ||
getControls: function() { | ||
return _controls; | ||
} | ||
}; | ||
} )( window.wp = window.wp || {} ); |
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 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 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 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 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 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 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 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.
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 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,45 @@ | ||
( function( wp, $ ) { | ||
var RX_ALIGN_CLASSNAME = /^(text-align-|align)([\w-]+)/; | ||
|
||
function createOnClick( classNamePrefix, position ) { | ||
return function( node ) { | ||
return $( node ) | ||
.removeClass( function( i, className ) { | ||
return RX_ALIGN_CLASSNAME.test( className ) ? className : ''; | ||
} ) | ||
.addClass( classNamePrefix + position ); | ||
}; | ||
} | ||
|
||
function createIsActive( classNamePrefix, position ) { | ||
return function( node ) { | ||
var classNames = node.className.split( ' ' ), | ||
i, className, match; | ||
|
||
for ( i = 0; i < classNames.length; i++ ) { | ||
className = classNames[ i ]; | ||
match = className.match( RX_ALIGN_CLASSNAME ); | ||
|
||
if ( match && classNamePrefix === match[ 1 ] ) { | ||
return position === match[ 2 ]; | ||
} | ||
} | ||
|
||
return 'left' === position; | ||
}; | ||
} | ||
|
||
[ 'left', 'center', 'right' ].forEach( function( position ) { | ||
wp.blocks.registerControl( 'text-align-' + position, { | ||
icon: 'gridicons-align-' + position, | ||
onClick: createOnClick( 'text-align-', position ), | ||
isActive: createIsActive( 'text-align-', position ) | ||
} ); | ||
|
||
wp.blocks.registerControl( 'block-align-' + position, { | ||
icon: 'gridicons-align-image-' + position, | ||
onClick: createOnClick( 'align', position ), | ||
isActive: createIsActive( 'align', position ) | ||
} ); | ||
} ); | ||
} )( window.wp = window.wp || {}, window.jQuery ); |
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
Oops, something went wrong.