-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrates into Google Docs Shortcode plugin v0.5.0. See #21.
- Loading branch information
Showing
3 changed files
with
158 additions
and
0 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,9 @@ | ||
.mexp-gdrive-gutenberg { | ||
background: transparent; | ||
border: 0; | ||
margin-top: -3.5em; | ||
padding-bottom: 1.5em; | ||
position: relative; | ||
text-align: center; | ||
z-index: 99999; | ||
} |
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,118 @@ | ||
var el = wp.element.createElement, | ||
Component = wp.element.Component, | ||
addButton; | ||
|
||
addButton = wp.compose.createHigherOrderComponent( function( BlockEdit ) { | ||
return function( props ) { | ||
var attr = props.attributes, | ||
onSelect, | ||
sidebarControls; | ||
|
||
if ( 'ray/google-drive' !== props.name || attr.link ) { | ||
return el( | ||
BlockEdit, | ||
props | ||
); | ||
} | ||
|
||
onSelect = function( media ) { | ||
var width = media.width * 1, | ||
height = media.height * 1; | ||
|
||
// Set some defaults if dimensions aren't yet available. | ||
if ( ! width ) { | ||
media.width = 640; | ||
} | ||
if ( ! height ) { | ||
media.height = 360; | ||
} | ||
|
||
return props.setAttributes( media ); | ||
}; | ||
|
||
return el( | ||
wp.element.Fragment, | ||
{}, | ||
el( | ||
BlockEdit, | ||
props | ||
), | ||
el( GDrive, { | ||
onSelect: onSelect, | ||
render: function( obj ) { | ||
return el( 'div', { | ||
className: 'component-panel mexp-gdrive-gutenberg', | ||
}, | ||
el( | ||
wp.components.Button, { | ||
className: 'button button-large', | ||
onClick: obj.open | ||
}, | ||
wp.i18n.__( 'Or Select From Drive' ) | ||
) | ||
); | ||
} | ||
} ) | ||
); | ||
}; | ||
}, 'withInspectorControls' ); | ||
|
||
wp.hooks.addFilter( 'editor.BlockEdit', 'mexp/google-drive', addButton ); | ||
|
||
// Our media modal launcher, adapted from the MediaUpload component. | ||
// @link https://github.com/WordPress/gutenberg/blob/master/edit-post/hooks/components/media-upload/index.js | ||
class GDrive extends Component { | ||
constructor() { | ||
super( ...arguments ); | ||
this.openModal = this.openModal.bind( this ); | ||
this.onOpen = this.onOpen.bind( this ); | ||
this.onClose = this.onClose.bind( this ); | ||
this.onInsert = this.onInsert.bind( this ); | ||
|
||
this.frame = wp.media( { | ||
frame: 'post', | ||
|
||
// Default tab to select when modal is loaded. | ||
state: 'mexp-service-gdrive', | ||
|
||
// Disables plupload dropzone; we'll be handling uploading ourselves. | ||
uploader: false | ||
} ); | ||
|
||
// When an image is selected in the media frame... | ||
this.frame.on( 'open', this.onOpen ); | ||
this.frame.on( 'close', this.onClose ); | ||
this.frame.on( 'gDrive:insert', this.onInsert ); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.frame.remove(); | ||
} | ||
|
||
onInsert( shortcode ) { | ||
const { onSelect } = this.props; | ||
onSelect( shortcode ); | ||
} | ||
|
||
onOpen() { | ||
$( '.media-frame' ).addClass( 'hide-menu' ); | ||
$( '.media-modal' ).addClass( 'smaller' ); | ||
} | ||
|
||
onClose() { | ||
$( '.media-modal' ).removeClass( 'smaller' ); | ||
const { onClose } = this.props; | ||
|
||
if ( onClose ) { | ||
onClose(); | ||
} | ||
} | ||
|
||
openModal() { | ||
this.frame.open(); | ||
} | ||
|
||
render() { | ||
return this.props.render( { open: this.openModal } ); | ||
} | ||
} |
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