Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MouseOverTooltipComponent = IgeEventingClass.extend({
- classId: 'MouseOverTooltipComponent',
- componentId: 'mouseOverTooltip',
- DEFAULT_TEXT: "Default text!",
- DEFAULT_PIXELS_PER_LINE: 14,
- DEFAULT_STYLE: {
- 'backgroundColor': '#3a3a3a',
- 'borderColor': '#ffffff',
- 'borderWidth': 2,
- 'borderRadius': 10,
- 'color': '#ffffff',
- 'width': 150,
- 'top': 55,
- 'left': 30,
- },
- /**
- * Options:
- * mountTaget - object - Object that the tooltip will be mounted to. Default target is the entity.
- * text - string - Text to display in the label.
- * pixelsPerLine - int - Number of pixels to space each line in the label using LineHeightComponent.
- * style - object - CSS-like object in accordance with the list of properties in IgeUiStyleExtension.
- */
- init: function (entity, options) {
- var self = this;
- this._entity = entity;
- this._enabled = true;
- this._options = {
- mountTarget: this._entity,
- text: this.DEFAULT_TEXT,
- pixelsPerLine: this.DEFAULT_PIXELS_PER_LINE,
- style: this.DEFAULT_STYLE,
- };
- //apply options
- if (options) {
- for (i in options)
- this._options[i] = options[i];
- if (options.style) { // overwrite default style with custom styles
- this._options.style = JSON.parse(JSON.stringify(this.DEFAULT_STYLE)); // clone object
- for (i in options.style)
- this._options.style[i] = options.style[i];
- }
- }
- //build tooltip
- this.tooltip = new IgeUiLabel()
- .value(this._options.text)
- .applyStyle(this._options.style)
- ;
- //customize font object of label
- this.tooltip._fontEntity
- .autoWrap(true)
- ;
- if (LineHeightComponent) { // can't use this if you don't have it
- this.tooltip._fontEntity
- .addComponent(LineHeightComponent)
- .lineHeight.pixelsPerLine(this._options.pixelsPerLine)
- ;
- }
- //enable mouse event emissions if necessary
- if (!this._entity.mouseOver())
- this._entity.mouseOver(function() {});
- if (!this._entity.mouseOut())
- this._entity.mouseOut(function() {});
- //mouse hooks on entity
- this._entity.on('mouseOver', function() {
- if (self.enabled())
- self.tooltip.mount(self._options.mountTarget);
- });
- this._entity.on('mouseOut', function() {
- if (self.enabled())
- self.tooltip.unMount();
- });
- },
- enabled: function (val) {
- if (val !== undefined) {
- if (!val)
- this.tooltip.unMount();
- this._enabled = val;
- return this._entity;
- }
- return this._enabled;
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement