137 lines
3.8 KiB
JavaScript
Raw Normal View History

2011-10-04 01:16:29 -03:00
/*
2012-10-04 20:48:01 -03:00
* Copyright [2012] [wisemapping]
2011-10-04 01:16:29 -03:00
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
mindplot.widget.ToolbarPaneItem = new Class({
Extends:mindplot.widget.ToolbarItem,
initialize : function(buttonId, model) {
$assert(buttonId, "buttonId can not be null");
$assert(model, "model can not be null");
2011-10-14 22:56:20 -03:00
this._model = model;
2011-10-04 01:16:29 -03:00
var fn = function() {
// Is the panel being displayed ?
if (this.isVisible()) {
this.hide();
} else {
this.show();
}
}.bind(this);
2011-10-04 23:59:21 -03:00
this.parent(buttonId, fn, {topicAction:true,relAction:false});
2011-10-14 22:56:20 -03:00
this._panelElem = this._init();
this._visible = false;
2011-10-04 01:16:29 -03:00
},
_init:function () {
// Load the context of the panel ...
var panelElem = this.buildPanel();
2014-03-04 23:09:39 -03:00
panelElem.css('cursor', 'default');
2011-10-04 01:16:29 -03:00
var buttonElem = this.getButtonElem();
2011-10-14 22:56:20 -03:00
var item = this;
this._tip = new mindplot.widget.FloatingTip(buttonElem, {
html: true,
position: 'bottom',
arrowOffset : 5,
center: true,
arrowSize: 7,
showDelay: 0,
hideDelay: 0,
content: function() {
return item._updateSelectedItem();
}.bind(this),
className: 'toolbarPaneTip',
motionOnShow:false,
motionOnHide:false,
motion: 0,
distance: 0,
showOn: 'xxxx',
hideOn: 'xxxx',
preventHideOnOver:true,
offset: {x:-4,y:0}
});
2014-03-05 00:14:28 -03:00
this._tip.addEvent('hide', function() {
2011-10-14 22:56:20 -03:00
this._visible = false
}.bind(this));
2014-03-05 00:14:28 -03:00
this._tip.addEvent('show', function() {
2011-10-14 22:56:20 -03:00
this._visible = true
}.bind(this));
2011-10-04 01:16:29 -03:00
return panelElem;
},
getModel : function() {
return this._model;
},
getPanelElem : function() {
2011-10-14 22:56:20 -03:00
return this._panelElem;
2011-10-04 01:16:29 -03:00
}.protect(),
show : function() {
if (!this.isVisible()) {
this.parent();
2011-10-14 22:56:20 -03:00
this._tip.show(this.getButtonElem());
this.getButtonElem().className = 'buttonExtActive';
2011-10-04 01:16:29 -03:00
}
},
hide : function() {
if (this.isVisible()) {
this.parent();
2011-10-14 22:56:20 -03:00
this._tip.hide(this.getButtonElem());
this.getButtonElem().className = 'buttonExtOn';
2011-10-04 01:16:29 -03:00
}
},
isVisible : function() {
2011-10-14 22:56:20 -03:00
return this._visible;
2011-10-04 01:16:29 -03:00
},
2011-10-14 22:56:20 -03:00
disable : function() {
2011-10-04 01:16:29 -03:00
this.hide();
2011-10-14 22:56:20 -03:00
var elem = this.getButtonElem();
if (this._enable) {
2014-03-04 23:09:39 -03:00
elem.unbind('click', this._fn);
2011-10-14 22:56:20 -03:00
elem.removeClass('buttonExtOn');
// Todo: Hack...
elem.removeClass('buttonOn');
elem.addClass('buttonExtOff');
this._enable = false;
}
2011-10-04 01:16:29 -03:00
},
2011-10-14 22:56:20 -03:00
enable : function() {
var elem = this.getButtonElem();
if (!this._enable) {
2014-03-04 23:09:39 -03:00
elem.bind('click', this._fn);
2011-10-14 22:56:20 -03:00
elem.removeClass('buttonExtOff');
elem.addClass('buttonExtOn');
this._enable = true;
}
},
2011-10-04 01:16:29 -03:00
buildPanel : function() {
throw "Method must be implemented";
}.protect()
});