@@ -29,7 +29,9 @@ export function responsive({steps}:{steps?: number | number[]}={}): Plugin{
2929 * @param  htmlPluginState {HtmlPluginState} holds cleanup callbacks and event subscriptions 
3030 * @param  analyticsOptions {BaseAnalyticsOptions} analytics options for the url to be created 
3131 */ 
32- function  responsivePlugin ( steps ?: number  |  number [ ] ,  element ?:HTMLImageElement ,  responsiveImage ?: CloudinaryImage ,  htmlPluginState ?: HtmlPluginState ,  baseAnalyticsOptions ?: BaseAnalyticsOptions ) : Promise < PluginResponse >  |  boolean  { 
32+ function  responsivePlugin ( steps ?: number  |  number [ ] ,  element ?:HTMLImageElement ,  responsiveImage ?: CloudinaryImage ,  htmlPluginState ?: HtmlPluginState ,  baseAnalyticsOptions ?: BaseAnalyticsOptions ,  plugins ?: Plugin [ ] ) : Promise < PluginResponse >  |  boolean  { 
33+ 
34+  console . debug ( plugins ) ; 
3335
3436 if ( ! isBrowser ( ) )  return  true ; 
3537
@@ -46,7 +48,28 @@ function responsivePlugin(steps?: number | number[], element?:HTMLImageElement,
4648 // Use a tagged generic action that can be later searched and replaced. 
4749 responsiveImage . addAction ( new  Action ( ) . setActionTag ( 'responsive' ) ) ; 
4850 // Immediately run the resize plugin, ensuring that first render gets a responsive image. 
49-  onResize ( steps ,  element ,  responsiveImage ,  analyticsOptions ) ; 
51+  // If we disable initial run entirely the placeholder will load non-resposive image 
52+  
53+  const  regex  =  / .* p l a c e h o l d e r .* / gm; 
54+  let  shouldRunImmediately  =  true  // TODO: logic to test if there is a placeholder plugin 
55+ 
56+  plugins . forEach ( ( p ) => { 
57+  if  ( regex . exec ( p . name )  !==  null ) { 
58+  console . debug ( "found the placeholder plugin!!!" ) ; 
59+  shouldRunImmediately  =  false ; 
60+  } 
61+  } ) ; 
62+ 
63+ 
64+  console . debug ( "analyticsOptions: " , analyticsOptions ) ; 
65+  console . debug ( "analyticsOptinos name: " , analyticsOptions . trackedAnalytics ) ; 
66+ 
67+  if ( shouldRunImmediately )  { 
68+  onResize ( steps ,  element ,  responsiveImage ,  analyticsOptions ) ; 
69+  }  else  { 
70+  // Probably this has to run on else, see comments in line 83 
71+  updateByContainerWidth ( steps ,  element ,  responsiveImage ) ; 
72+  } 
5073
5174 let  resizeRef : any ; 
5275 htmlPluginState . pluginEventSubscription . push ( ( ) => { 
@@ -67,8 +90,20 @@ function responsivePlugin(steps?: number | number[], element?:HTMLImageElement,
6790 * @param  analyticsOptions {AnalyticsOptions} analytics options for the url to be created 
6891 */ 
6992function  onResize ( steps ?: number  |  number [ ] ,  element ?:HTMLImageElement ,  responsiveImage ?: CloudinaryImage ,  analyticsOptions ?: AnalyticsOptions ) { 
93+  
7094 updateByContainerWidth ( steps ,  element ,  responsiveImage ) ; 
95+  // TODO: 1. Responsive should not load the image if placeholder is running next 
96+  // It has to know, the placeholder is in the plugins 
97+  // A. Get plugins as a new fifth argument of the `responsivePlugin` function 
98+  // B. Loop over plugins and check if any of plugin.name is equal to "bound placeholderPlugin" 
99+ 
100+  // If we disable each onResize then placeholder will render original image (!) 
101+  // So this cannot be conditional because we want run it always on window resize later 
71102 element . src  =  responsiveImage . toURL ( analyticsOptions ) ; 
103+ 
104+  // So the magic to make sure placeholder loads large image with responsive 
105+  // Is done by the updateByContainerWidth function call 
106+  // ... and we might need to make sure it's called in line 53 if shouldRunImmediately is false 
72107} 
73108
74109/** 
0 commit comments