Continuing the discussion from A tour of how the Widget (Virtual DOM) code in Discourse works:
In the topic-map
widget I have the below code adding an action and class name to some text in the topic-map
:
contents.push(h('li.secondary', [
h('a', { className: 'top-answer-link',
action: 'scrollTopAnswer'}, 'Jump to Top Answer')
]));
The class gets added fine and I see now errors. My issue however, is that I do not know where to define the action. Usually, I would define such an action in a component. As this is a widget, where should I place this code:
actions: {
scrollTopAnswer: function() {
alert('scrollTopAnswer');
$('html,body').animate({scrollTop: ($('.most_liked_post').offset().top-140)}, 'slow');
}
}