I have been checking out the widgets in the core, and I am specifically looking at this one:
$:/core/modules/widgets/scrollable.js
I am wondering how I can add my own options in this section:
/*
Handle a scroll event
*/
ScrollableWidget.prototype.handleScrollEvent = function(event) {
// Pass the scroll event through if our offsetsize is larger than our scrollsize
if(this.outerDomNode.scrollWidth <= this.outerDomNode.offsetWidth && this.outerDomNode.scrollHeight <= this.outerDomNode.offsetHeight && this.fallthrough === "yes") {
return true;
}
var options = {};
if($tw.utils.hop(event.paramObject,"animationDuration")) {
options.animationDuration = event.paramObject.animationDuration;
}
if(event.paramObject && event.paramObject.selector) {
this.scrollSelectorIntoView(null,event.paramObject.selector,null,options);
} else {
this.scrollIntoView(event.target,null,options);
}
return false; // Handled event
};
I attempted to add my own paramObject, and called “position”, it didn’t work. Ideally, my widget would look something like this:
<$button>
<$action-sendmessage $position="center" $message="tm-scroll" $name="selector" $value="#{{!!field-name}}"/>
</$button>
I tried entering my own if statement, which looked like this:
/*
Handle a scroll event
*/
ScrollableWidget.prototype.handleScrollEvent = function(event) {
// Pass the scroll event through if our offsetsize is larger than our scrollsize
if(this.outerDomNode.scrollWidth <= this.outerDomNode.offsetWidth && this.outerDomNode.scrollHeight <= this.outerDomNode.offsetHeight && this.fallthrough === "yes") {
return true;
}
var options = {};
if($tw.utils.hop(event.paramObject,"animationDuration")) {
options.animationDuration = event.paramObject.animationDuration;
}
// My option
if($tw.utils.hop(event.paramObject,"position")) {
if (position == "center") {
this.scrollIntoView({behavior: 'auto', block: 'center'});
}
else { //other positions not really important right now. }
}
if(event.paramObject && event.paramObject.selector) {
this.scrollSelectorIntoView(null,event.paramObject.selector,null,options);
/*I even tried deleting this code and adding
this.scrollIntoView({behavior: 'auto', block: 'center'});
here. */
} else {
this.scrollIntoView(event.target,null,options);
}
return false; // Handled event
};
No matter what I do, it doesn’t want to cooperate.