123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 'use strict';
- define(['./staticwidget/StaticWidget', 'jquery'], function (Base, $) {
- var CustomWidget = Base.extend({
- init: function init(options) {
- CustomWidget.inherited('init', this, arguments);
- this.registry = options.registry;
- this.eventRouter = options.eventRouter;
-
- this._initContentRoot();
- this._initWidgetProperties(options.initialConfigJSON);
- this.onInit(options.registry.params);
- },
- destroy: function destroy() {
- this.onDestroy();
- CustomWidget.inherited('destroy', this, arguments);
- },
- _initContentRoot: function _initContentRoot() {
- var contentRoot = this.getContentRootNode();
- contentRoot.addClass('staticContent');
- var scroll = this.registry.scroll || 'scrollY';
- contentRoot.addClass('customWidget_' + scroll);
- },
- _initWidgetProperties: function _initWidgetProperties(config) {
- var root = this.getWidgetStyleNode();
- if (config.fillColor) {
- root.addClass('fill-' + config.fillColor);
- }
- if (config.borderColor) {
- root.addClass('border-' + config.borderColor);
- }
- },
- render: function render() {
- this.onRender();
- return Promise.resolve();
- },
-
- onInit: function onInit() /*params*/{},
-
- onDestroy: function onDestroy() {},
-
- onRender: function onRender() {},
- getWidgetStyleNode: function getWidgetStyleNode() {
- return $(this.el);
- },
- getContentRootNode: function getContentRootNode() {
- return this.$el;
- },
-
- on: function on(eventName, handler, context) {
- this.eventRouter.on(eventName, handler, context);
- },
-
- off: function off(eventName, handler, context) {
- this.eventRouter.off(eventName, handler, context);
- },
-
- trigger: function trigger(eventName, event) {
- this.eventRouter.trigger(eventName, event);
- }
- });
- return CustomWidget;
- });
|