123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
"use strict";
modulum('TopMenuCommandWidget', ['TextWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.TopMenuCommandWidget = context.oo.Class(cls.TextWidgetBase, function($super) {
return {
__name: 'TopMenuCommandWidget',
_image: null,
_anchorElement: null,
_commentContainer: null,
_initElement: function(initialInformation) {
$super._initElement.call(this, initialInformation);
this._image = cls.WidgetFactory.createWidget('ImageWidget', this.getBuildParameters());
this._image.setAutoScale(true);
this._element.prependChild(this._image.getElement());
this._anchorElement = this._element.querySelector('span.anchor');
this._commentContainer = this._element.querySelector('span.gbc-label-comment-container');
this._element.on('mouseover.TopMenuCommandWidget', this._onMouseover.bind(this));
},
destroy: function() {
if (this._element) {
this._element.off('mouseover.TopMenuCommandWidget');
}
if (this._image) {
this._image.destroy();
this._image = null;
}
$super.destroy.call(this);
},
manageMouseClick: function(domEvent) {
if (this.isEnabled() || this.isInterruptable()) {
this.emit(context.constants.widgetEvents.click, domEvent);
}
return true;
},
_onMouseover: function(event) {
if (cls.DropDownWidget.hasAnyVisible()) {
var lastDropDown = cls.DropDownWidget.getActiveDropDown();
if (!lastDropDown.getElement().contains(event.target)) {
lastDropDown.remove();
}
}
},
setText: function(text) {
this._setTextContent(text, "_anchorElement");
},
setComment: function(comment) {
var regex = /([^A-Za-z]*\+|\-)([A-Za-z])/g;
if (window.browserInfo.isSafari) {
comment = comment.replace(/control/ig, "⌘")
.replace(regex, function(match) {
return match.toUpperCase();
})
.replace("-", " ");
} else {
comment = comment.replace("-", "+")
.replace(/control/ig, "Ctrl")
.replace(regex, function(match) {
return match.toUpperCase();
});
}
this._commentContainer.textContent = comment;
},
getText: function() {
return this._anchorElement.textContent;
},
setImage: function(image) {
this._image.setSrc(image);
},
getImage: function() {
if (this._image) {
return this._image.getSrc();
}
return null;
}
};
});
cls.WidgetFactory.registerBuilder('TopMenuCommand', cls.TopMenuCommandWidget);
});