SC 2019.2… is it possible to extend the Applicatio...
# suitecommerce
c
SC 2019.2… is it possible to extend the ApplicationSkeleton.Layout.js initialize method? Trying to trigger the updateHeader function when the viewport is >= 1200px. Really just need to use jQuery(window).on(‘resize’… Suggestions?
s
updateHeader
just seems to re-render the view? So why not just have your JavaScript run something like
application.getLayout().getChildViewInstance('Header').render()
(where
application
could be
container
depending on context)
Or are you trying to replace its contents? Because extending its class and providing a new method with the same name would do that
c
Just need to re-render the view when the viewport is 1200px, similar to the current re-render @ 991/992px. The part I can’t figure out, perhaps I am over thinking it, is the _jQuery_(window).on(‘resize’, _.throttle(function ()…
I have tried to use layout.addToViewEventsDefintion(‘ApplicationSkeleton.Layout’, ‘resize’, _.throttle(_function_() {
s
It's binding a callback to the event of resizing. Ie, when the viewport changes sizes, it executes the callback code. The callback is wrapped in a throttle function, which limits the amounts of times it can be called (in this case, once every 1000ms). Then within the statement, it's performing a number of utility functions. It short-circuits the code if the resizing is within the current breakpoint (ie there's no point doing anything if it's already at the 'right' size). If it's different, then it performs a number of calls to re-render the views because they might have width-specific content.
So you're trying to add a new breakpoint? If so, I think you're over-thinking this. You probably just need to change what Utils.getDeviceType() does
At the moment you're trying to change what happens when a break point change happens
c
This is SC and not SCA
s
You can still overwrite the function with an extension
We don't typically recommend it but I'm not sure how else you would add a new breakpoint
c
To avoid changing default SC, I was able to extend the Utils to create a custom “getDeviceType” and it works… Just need to bind the resize… perhaps a dummy view and attach to the initialize method.
s
The existing resize handler should accommodate your changes?
Or do you need to perform additional stuff?
c
The existing resize would work
s
(If you need extra stuff, then I would just create a new jQuery.on in your entry point. It may need to be wrapped in a jQuery(document).ready(...))