From 9b21a2c0c7521ea5967533f3ff973d74e153429b Mon Sep 17 00:00:00 2001 From: undemian Date: Fri, 4 May 2018 18:17:36 +0300 Subject: [PATCH] Add minimize panel option --- src/api.js | 2 ++ src/index.js | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/api.js b/src/api.js index 13e7011d..543b232b 100644 --- a/src/api.js +++ b/src/api.js @@ -47,6 +47,7 @@ const api = { entryOptions, groups, layout = LAYOUT_MAX_WIDTH_FIXED_HEIGHT, + minimized = false, nodeId, user, } ) => { @@ -63,6 +64,7 @@ const api = { entryOptions, groups, layout, + minimized, userObject, } ) ) diff --git a/src/index.js b/src/index.js index b2b5ab2a..57c1b03b 100644 --- a/src/index.js +++ b/src/index.js @@ -62,19 +62,19 @@ const createIframe = ( props, assetsLoadedHook = () => {} ) => { let iframeWidth = 0; switch ( layout ) { case LAYOUT_MAX_WIDTH_FIXED_HEIGHT: - const primaryHasAnySecondary = options => + const primaryHasAnySecondary = options => Array.isArray( options ) && find( options, opt => opt.secondaryOptions ); - const isThereAnySecondaryOptions = options => + const isThereAnySecondaryOptions = options => options && ( options.secondaryOptions || primaryHasAnySecondary( entryOptions.primaryOptions ) ); // Calculate height based on the number of components // the iframe may need to render. iframeHeight = 480; - iframeHeight = iframeHeight + ( entryOptions && entryOptions.primaryOptions ? 110 : 0 ); - iframeHeight = iframeHeight + ( isThereAnySecondaryOptions( entryOptions ) ? 110 : 0 ); - iframeHeight = iframeHeight + ( entryOptions && entryOptions.itemList ? 70 : 0 ); + iframeHeight = iframeHeight + ( entryOptions && entryOptions.primaryOptions ? 110 : 0 ); + iframeHeight = iframeHeight + ( isThereAnySecondaryOptions( entryOptions ) ? 110 : 0 ); + iframeHeight = iframeHeight + ( entryOptions && entryOptions.itemList ? 70 : 0 ); iframeHeight = iframeHeight + 'em'; iframeWidth = '100%'; @@ -144,8 +144,8 @@ const createIframe = ( props, assetsLoadedHook = () => {} ) => { iframeElement.contentDocument.head.appendChild( styleLoading ); // Then, we inject the stylesheets: the noticon custom font, Happychat, and the theme if any. - // We want to tell Happychat when they are downloaded, and we do so by means of the onload method - // of the stylesheets, which will resolve the Promise.all() + // We want to tell Happychat when they are downloaded, and we do so by means of the onload + // method of the stylesheets, which will resolve the Promise.all() const styleNoticon = document.createElement( 'link' ); styleNoticon.setAttribute( 'rel', 'stylesheet' ); styleNoticon.setAttribute( 'type', 'text/css' ); @@ -167,8 +167,13 @@ const createIframe = ( props, assetsLoadedHook = () => {} ) => { if ( groups && groups.length > 0 ) { const groupName = groups[ 0 ]; if ( groupName === 'woo' || groupName === 'jpop' ) { - styleHCTheme.setAttribute( 'href', 'https://widgets.wp.com/happychat/' + groupName + '.css' ); - styleHCThemePromise = new Promise( resolve => ( styleHCTheme.onload = () => resolve() ) ); + styleHCTheme.setAttribute( + 'href', + 'https://widgets.wp.com/happychat/' + groupName + '.css' + ); + styleHCThemePromise = new Promise( + resolve => ( styleHCTheme.onload = () => resolve() ) + ); } } @@ -228,6 +233,8 @@ export const renderHappychat = ( canChat = true, entry = ENTRY_FORM, entryOptions = {}, + minimized, + layout, } ) => { const { fallbackTicket } = entryOptions; @@ -250,7 +257,12 @@ export const renderHappychat = ( ReactDOM.render( - + , targetNode );