Skip to content

Commit

Permalink
Media: Implement feature-flagged advanced media editing
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Jan 14, 2016
1 parent d899439 commit 493e88b
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 1 deletion.
5 changes: 5 additions & 0 deletions client/components/tinymce/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ module.exports = React.createClass( {
onTogglePin: React.PropTypes.func
},

contextTypes: {
store: React.PropTypes.object
},

getDefaultProps: function() {
return {
mode: 'tinymce',
Expand Down Expand Up @@ -256,6 +260,7 @@ module.exports = React.createClass( {
entity_encoding: 'raw',
keep_styles: false,
wpeditimage_html5_captions: true,
redux_store: this.context.store,

// Limit the preview styles in the menu/toolbar
preview_styles: 'font-family font-size font-weight font-style text-decoration text-transform',
Expand Down
38 changes: 38 additions & 0 deletions client/components/tinymce/plugins/media/advanced/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
import React from 'react';
import ReactDomServer from 'react-dom/server';

/**
* Internal dependencies
*/
import i18n from 'lib/mixins/i18n';
import config from 'config';
import { toggleEditorMediaAdvanced } from 'state/ui/editor/media/actions';
import Gridicon from 'components/gridicon';

export default function( editor ) {
const store = editor.getParam( 'redux_store' );
if ( ! config.isEnabled( 'post-editor/media-advanced' ) || ! store ) {
return;
}

editor.addButton( 'wp_img_advanced', {
tooltip: i18n.translate( 'Edit', { context: 'verb' } ),

classes: 'toolbar-segment-start',

onPostRender() {
this.innerHtml( ReactDomServer.renderToStaticMarkup(
<button type="button" role="presentation" tabIndex="-1">
<Gridicon icon="pencil" size={ 18 } />
</button>
) );
},

onClick() {
store.dispatch( toggleEditorMediaAdvanced() );
}
} );
}
2 changes: 2 additions & 0 deletions client/components/tinymce/plugins/media/plugin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var sites = require( 'lib/sites-list' )(),
notices = require( 'notices' ),
TinyMCEDropZone = require( './drop-zone' ),
restrictSize = require( './restrict-size' ),
advanced = require( './advanced' ),
Gridicon = require( 'components/gridicon' ),
config = require( 'config' );

Expand Down Expand Up @@ -647,6 +648,7 @@ function mediaButton( editor ) {
} );

restrictSize( editor );
advanced( editor );
}

module.exports = function() {
Expand Down
1 change: 1 addition & 0 deletions client/components/tinymce/plugins/wpeditimage/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function wpEditImage( editor ) {
'wpcom_img_size_decrease',
'wpcom_img_size_increase',
'wp_img_caption', // See plugins/media
'wp_img_advanced', // See plugins/media/advanced
'wp_img_remove'
] );
} );
Expand Down
9 changes: 9 additions & 0 deletions client/components/tinymce/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
color: darken( $gray, 20% );
}

.mce-toolbar .mce-btn .gridicon {
fill: darken( $gray, 20% );
}

.mce-colorbutton .mce-preview {
background-color: $gray-dark;
}
Expand Down Expand Up @@ -94,6 +98,11 @@
.mce-toolbar .mce-btn-group .mce-btn:focus .mce-ico {
color: $gray-dark;
}

.mce-toolbar .mce-btn-group .mce-btn:hover .gridicon,
.mce-toolbar .mce-btn-group .mce-btn:focus .gridicon {
fill: $gray-dark;
}
}

.mce-toolbar .mce-btn-group .mce-btn.mce-toolbar-segment-start:not( :first-child )::before,
Expand Down
43 changes: 43 additions & 0 deletions client/post-editor/editor-media-advanced/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* External depencencies
*/
import React, { PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

/**
* Internal dependencies
*/
import { toggleEditorMediaAdvanced } from 'state/ui/editor/media/actions';
import Dialog from 'components/dialog';

function EditorMediaAdvanced( { visible, toggleVisible } ) {
return (
<Dialog isVisible={ visible } onClose={ toggleVisible }>
WIP
</Dialog>
);
}

EditorMediaAdvanced.propTypes = {
visible: PropTypes.bool,
toggleVisible: PropTypes.func
};

EditorMediaAdvanced.defaultProps = {
visible: false,
toggleVisible: () => {}
};

export default connect(
( state ) => {
return {
visible: state.ui.editor.media.advanced
};
},
( dispatch ) => {
return bindActionCreators( {
toggleVisible: toggleEditorMediaAdvanced
}, dispatch );
}
)( EditorMediaAdvanced );
4 changes: 4 additions & 0 deletions client/post-editor/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var actions = require( 'lib/posts/actions' ),
EditorDrawer = require( 'post-editor/editor-drawer' ),
FeaturedImage = require( 'post-editor/editor-featured-image' ),
EditorGroundControl = require( 'post-editor/editor-ground-control' ),
EditorMediaAdvanced = require( 'post-editor/editor-media-advanced' ),
EditorTitleContainer = require( 'post-editor/editor-title/container' ),
EditorPageSlug = require( 'post-editor/editor-page-slug' ),
Button = require( 'components/button' ),
Expand Down Expand Up @@ -286,6 +287,9 @@ var PostEditor = React.createClass( {

return (
<div className="post-editor">
{ config.isEnabled( 'post-editor/media-advanced' ) && (
<EditorMediaAdvanced />
) }
<div className="post-editor__inner">
<div className="post-editor__content">
<EditorMobileNavigation site={ site } onClose={ this.onClose } />
Expand Down
1 change: 1 addition & 0 deletions client/post-editor/test/post-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mockery.registerMock( 'components/tinymce', MOCK_COMPONENT );
mockery.registerMock( 'components/popover', MOCK_COMPONENT );
mockery.registerMock( 'components/forms/clipboard-button', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-mobile-navigation', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-media-advanced', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-ground-control', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-drawer', MOCK_COMPONENT );
mockery.registerMock( 'post-editor/editor-author', MOCK_COMPONENT );
Expand Down
1 change: 1 addition & 0 deletions client/state/action-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

export const COMPLETE_EXPORT = 'COMPLETE_EXPORT';
export const CURRENT_USER_ID_SET = 'CURRENT_USER_ID_SET';
export const EDITOR_MEDIA_ADVANCED_TOGGLE = 'EDITOR_MEDIA_ADVANCED_TOGGLE';
export const FAIL_EXPORT = 'FAIL_EXPORT';
export const FETCH_SITE_PLANS = 'FETCH_SITE_PLANS';
export const FETCH_SITE_PLANS_COMPLETED = 'FETCH_SITE_PLANS_COMPLETED';
Expand Down
10 changes: 10 additions & 0 deletions client/state/ui/editor/media/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Internal dependencies
*/
import { EDITOR_MEDIA_ADVANCED_TOGGLE } from 'state/action-types';

export function toggleEditorMediaAdvanced() {
return {
type: EDITOR_MEDIA_ADVANCED_TOGGLE
};
}
23 changes: 23 additions & 0 deletions client/state/ui/editor/media/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* External dependencies
*/
import { combineReducers } from 'redux';

/**
* Internal dependencies
*/
import { EDITOR_MEDIA_ADVANCED_TOGGLE } from 'state/action-types';

function advanced( state = false, action ) {
switch ( action.type ) {
case EDITOR_MEDIA_ADVANCED_TOGGLE:
state = ! state;
break;
}

return state;
}

export default combineReducers( {
advanced
} );
13 changes: 13 additions & 0 deletions client/state/ui/editor/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* External dependencies
*/
import { combineReducers } from 'redux';

/**
* Internal dependencies
*/
import media from './media/reducer';

export default combineReducers( {
media
} );
4 changes: 3 additions & 1 deletion client/state/ui/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SET_SECTION,
CURRENT_USER_ID_SET
} from 'state/action-types';
import editor from './editor/reducer';

/**
* Tracks the currently selected site ID.
Expand Down Expand Up @@ -72,5 +73,6 @@ export default combineReducers( {
isLoading,
hasSidebar,
selectedSiteId,
currentUserId
currentUserId,
editor
} );
1 change: 1 addition & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"post-editor-github-link": false,
"post-editor/post-type-switch": false,
"post-editor/contact-form": true,
"post-editor/media-advanced": true,

"manage/media": true,
"manage/posts": true,
Expand Down

0 comments on commit 493e88b

Please sign in to comment.