2009-06-07 20:59:43 +02:00
|
|
|
/*
|
2011-07-27 13:25:10 +02:00
|
|
|
* Copyright [2011] [wisemapping]
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
mindplot.BubbleTip = new Class({
|
|
|
|
initialize : function(divContainer) {
|
|
|
|
this.options = {
|
|
|
|
panel:null,
|
|
|
|
container:null,
|
|
|
|
divContainer:divContainer,
|
|
|
|
content:null,
|
|
|
|
onShowComplete:Class.empty,
|
|
|
|
onHideComplete:Class.empty,
|
|
|
|
width:null,
|
|
|
|
height:null,
|
|
|
|
form:null
|
|
|
|
};
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(this.options.form))
|
2009-06-07 20:59:43 +02:00
|
|
|
this.scanElements(this.options.form);
|
|
|
|
this.buildBubble();
|
2011-07-27 13:25:10 +02:00
|
|
|
this._isMouseOver = false;
|
|
|
|
this._open = false;
|
|
|
|
},
|
|
|
|
scanElements : function(form) {
|
2009-06-07 20:59:43 +02:00
|
|
|
$$($(form).getElements('a')).each(function(el) {
|
|
|
|
if (el.href && el.hasClass('bubble') && !el.onclick) {
|
2011-07-27 13:25:10 +02:00
|
|
|
el.addEvent('mouseover', this.click.bindWithEvent(this, el));
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
}, this);
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
buildBubble : function() {
|
2009-06-07 20:59:43 +02:00
|
|
|
var opts = this.options;
|
|
|
|
|
|
|
|
var panel = new Element('div').addClass('bubbleContainer');
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(opts.height))
|
2009-06-07 20:59:43 +02:00
|
|
|
panel.setStyle('height', opts.height);
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(opts.width))
|
2009-06-07 20:59:43 +02:00
|
|
|
panel.setStyle('width', opts.width);
|
|
|
|
|
|
|
|
this.center = new Element('div').addClass('bubblePart').addClass('bubbleCenterBlue');
|
2011-01-20 19:58:30 +01:00
|
|
|
this.center.inject(panel);
|
2011-07-28 18:06:15 +02:00
|
|
|
if (!$defined(opts.divContainer)) {
|
2011-07-27 13:25:10 +02:00
|
|
|
opts.divContainer = document.body;
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
|
|
|
panel.injectTop(opts.divContainer);
|
|
|
|
opts.panel = $(panel);
|
2011-07-27 13:25:10 +02:00
|
|
|
opts.panel.setStyle('opacity', 0);
|
|
|
|
opts.panel.addEvent('mouseover', function() {
|
|
|
|
this._isMouseOver = true;
|
|
|
|
}.bind(this));
|
|
|
|
opts.panel.addEvent('mouseleave', function(event) {
|
|
|
|
this.close(event);
|
|
|
|
}.bindWithEvent(this));//this.close.bindWithEvent(this)
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
click : function(event, el) {
|
2009-06-07 20:59:43 +02:00
|
|
|
return this.open(event, el);
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
open : function(event, content, source) {
|
|
|
|
this._isMouseOver = true;
|
2009-06-07 20:59:43 +02:00
|
|
|
this._evt = new Event(event);
|
2011-07-27 13:25:10 +02:00
|
|
|
this.doOpen.delay(500, this, [content,source]);
|
|
|
|
},
|
|
|
|
doOpen : function(content, source) {
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(this._isMouseOver) && !$defined(this._open) && !$defined(this._opening)) {
|
2011-07-27 13:25:10 +02:00
|
|
|
this._opening = true;
|
2009-06-07 20:59:43 +02:00
|
|
|
var container = new Element('div');
|
|
|
|
$(content).inject(container);
|
2011-07-27 13:25:10 +02:00
|
|
|
this.options.content = content;
|
|
|
|
this.options.container = container;
|
2009-06-07 20:59:43 +02:00
|
|
|
$(this.options.container).inject(this.center);
|
2011-07-27 13:25:10 +02:00
|
|
|
this.init(this._evt, source);
|
|
|
|
$(this.options.panel).effect('opacity', {duration:500, onComplete:function() {
|
|
|
|
this._open = true;
|
|
|
|
this._opening = false;
|
|
|
|
}.bind(this)}).start(0, 100);
|
2009-06-07 20:59:43 +02:00
|
|
|
}
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
updatePosition : function(event) {
|
2009-06-07 20:59:43 +02:00
|
|
|
this._evt = new Event(event);
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
close : function(event) {
|
|
|
|
this._isMouseOver = false;
|
|
|
|
this.doClose.delay(50, this, new Event(event));
|
|
|
|
},
|
|
|
|
doClose : function(event) {
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-28 18:06:15 +02:00
|
|
|
if (!$defined(this._isMouseOver) && $defined(this._opening))
|
2011-07-27 13:25:10 +02:00
|
|
|
this.doClose.delay(500, this, this._evt);
|
|
|
|
|
2011-07-28 18:06:15 +02:00
|
|
|
if (!$defined(this._isMouseOver) && $defined(this._open)) {
|
2009-06-07 20:59:43 +02:00
|
|
|
this.forceClose();
|
|
|
|
}
|
2011-07-27 13:25:10 +02:00
|
|
|
},
|
|
|
|
forceClose : function() {
|
|
|
|
this.options.panel.effect('opacity', {duration:100, onComplete:function() {
|
|
|
|
this._open = false;
|
2009-06-07 20:59:43 +02:00
|
|
|
$(this.options.panel).setStyles({left:0,top:0});
|
|
|
|
$(this.options.container).remove();
|
2011-07-27 13:25:10 +02:00
|
|
|
}.bind(this)}).start(100, 0);
|
|
|
|
},
|
|
|
|
init : function(event, source) {
|
2009-06-07 20:59:43 +02:00
|
|
|
var opts = this.options;
|
|
|
|
var coordinates = $(opts.panel).getCoordinates();
|
|
|
|
var panelHeight = coordinates.height; //not total height, but close enough
|
2011-01-20 19:58:30 +01:00
|
|
|
var panelWidth = coordinates.width; //not total height, but close enough
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
var offset = designer.getWorkSpace().getScreenManager().getWorkspaceIconPosition(source);
|
|
|
|
|
|
|
|
var containerCoords = $(opts.divContainer).getCoordinates();
|
|
|
|
var screenWidth = containerCoords.width;
|
|
|
|
var screenHeight = containerCoords.height;
|
|
|
|
|
2011-01-20 19:58:30 +01:00
|
|
|
var width = $(this.center).getCoordinates().width;
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-01-20 19:58:30 +01:00
|
|
|
var invert = !(offset.y > panelHeight); //hint goes on the bottom
|
2011-07-27 13:25:10 +02:00
|
|
|
var invertX = (screenWidth - offset.x > panelWidth); // hint goes on the right
|
2011-01-20 19:58:30 +01:00
|
|
|
$(this.options.panel).remove();
|
|
|
|
this.buildBubble();
|
|
|
|
$(this.options.container).inject(this.center);
|
2009-06-07 20:59:43 +02:00
|
|
|
|
|
|
|
var height = $(this.center).getCoordinates().height;
|
|
|
|
$(opts.panel).setStyles({width:width,height:height});
|
2011-07-27 13:25:10 +02:00
|
|
|
this.moveTopic(offset, $(opts.panel).getCoordinates().height, $(opts.panel).getCoordinates().width, invert, invertX);
|
|
|
|
},
|
|
|
|
moveTopic : function(offset, panelHeight, panelWidth, invert, invertX) {
|
|
|
|
var f = 1, fX = 1;
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(invert))
|
2011-07-27 13:25:10 +02:00
|
|
|
f = 0;
|
2011-07-28 18:06:15 +02:00
|
|
|
if ($defined(invertX))
|
2011-07-27 13:25:10 +02:00
|
|
|
fX = 0;
|
2009-06-07 20:59:43 +02:00
|
|
|
var opts = this.options;
|
2011-07-27 13:25:10 +02:00
|
|
|
$(opts.panel).setStyles({left:offset.x - (panelWidth * fX), top:offset.y - (panelHeight * f)});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2009-06-07 20:59:43 +02:00
|
|
|
|
2011-07-27 13:25:10 +02:00
|
|
|
mindplot.BubbleTip.getInstance = function(divContainer) {
|
2009-06-07 20:59:43 +02:00
|
|
|
var result = mindplot.BubbleTip.instance;
|
2011-07-27 18:44:09 +02:00
|
|
|
if (!$defined(result)) {
|
2009-06-07 20:59:43 +02:00
|
|
|
mindplot.BubbleTip.instance = new mindplot.BubbleTip(divContainer);
|
|
|
|
result = mindplot.BubbleTip.instance;
|
|
|
|
}
|
|
|
|
return result;
|
2011-07-27 13:25:10 +02:00
|
|
|
}
|