Skip to Content
0

Personas 3.0 - Issues dynamically changing flavors

Mar 28, 2017 at 08:07 PM

164

avatar image
Former Member

Hi,

We are on Personas 3.0, SP4. I'm trying to create a series of flavors for SMEN that dynamically switch based on the user's screen resolution. I have it mostly working, but I'm having several issues with it.

  1. In examples I've seen of what I'm trying to do, the flavors are assigned by name, such as session.utils.changeFlavor("FlavorName"). This does not work for me; I have to use their GUIDs instead. Should I be able to use their names or do we have to use their GUIDs?
  2. I initially used session.findById("wnd[0]").width to get the user's screen width, but that always seemed to be one screen change behind. Instead, I'm now using window.innerWidth. Does anyone know why session.findById("wnd[0]") would not be working as expected?
  3. I have traced through my JavaScript, and it flows as expected, right down to where it sets the correct flavor using the session.utils.changeFlavor() command. But the screen does not change to the new flavor until I change the screen size again.

I've listed my code below. Thanks for your help!

var screenSize, flavor;
// Determine the proper flavor for the user's screen size.
screenSize = window.innerWidth;
if (screenSize < 600) {
  flavor = "005056AA160B1ED784DD8942217A8532";  // flv_SMEN - Generation 2x
} else if(screenSize < 800) { 
  flavor = "005056AA160B1ED784E0F7E07523C532";  // flv_SMEN - Generation 3x
} else if(screenSize < 1000) { 
  flavor = "005056AA160B1ED784E177CBD15A2532";  // flv_SMEN - Generation 4x
} else {
  flavor = "005056AA160B1ED784E1C5D21B522532";  // flv_SMEN - Generation 5x
}
// Check the current flavor and adjust it if necessary.
if (flavor != session.info.flavorId) {
  session.utils.changeFlavor(flavor);
}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

avatar image
Former Member May 09, 2017 at 12:40 AM
0

Hi,

Look at my sample code here. This works.

// 1. Check your screen size 
var screenSize, flavor; 
var screenSize = $(window).width();
// 2.Decide which flavor is the best fits 
if (screenSize < 1000) { 
    flavor = '005056920B2E1EE783EE34D5EECF2389'; 
	
} else { 
    flavor = '005056920B2E1EE783EE31BA42902389'; 
} 
// 3. Switch to the flavor if it is not already used 
if (flavor != session.info.flavorId) { 
    session.utils.changeFlavor(flavor); 
}
Share
10 |10000 characters needed characters left characters exceeded