[4001] | 1 | window.dhtmlXTooltip={version:0.1};
|
---|
| 2 |
|
---|
| 3 | dhtmlXTooltip.config = {
|
---|
| 4 | className: 'dhtmlXTooltip tooltip',
|
---|
| 5 | timeout_to_display: 50,
|
---|
| 6 | delta_x: 15,
|
---|
| 7 | delta_y: -20
|
---|
| 8 | };
|
---|
| 9 |
|
---|
| 10 | dhtmlXTooltip.tooltip = document.createElement('div');
|
---|
| 11 | dhtmlXTooltip.tooltip.className = dhtmlXTooltip.config.className;
|
---|
| 12 |
|
---|
| 13 | dhtmlXTooltip.show = function(event, text) { //browser event, text to display
|
---|
| 14 | dhtmlXTooltip.tooltip.className = dhtmlXTooltip.config.className;
|
---|
| 15 | var pos=this.position(event);
|
---|
| 16 |
|
---|
| 17 | var target = event.target||event.srcElement;
|
---|
| 18 | if (this.isTooltip(target)) {return;} // if we are over tooltip -- do nothing, just return (so tooltip won't move)
|
---|
| 19 |
|
---|
| 20 | var actual_x = pos.x+dhtmlXTooltip.config.delta_x||0;
|
---|
| 21 | var actual_y = pos.y-dhtmlXTooltip.config.delta_y||0;
|
---|
| 22 |
|
---|
| 23 | this.tooltip.style.visibility = "hidden";
|
---|
| 24 |
|
---|
| 25 | if(this.tooltip.style.removeAttribute) {
|
---|
| 26 | this.tooltip.style.removeAttribute("right");
|
---|
| 27 | this.tooltip.style.removeAttribute("bottom");
|
---|
| 28 | } else {
|
---|
| 29 | this.tooltip.style.removeProperty("right");
|
---|
| 30 | this.tooltip.style.removeProperty("bottom");
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | this.tooltip.style.left = "0px";
|
---|
| 34 | this.tooltip.style.top = "0px";
|
---|
| 35 |
|
---|
| 36 | this.tooltip.innerHTML = text;
|
---|
| 37 | scheduler._obj.appendChild(this.tooltip);
|
---|
| 38 |
|
---|
| 39 | var tooltip_width = this.tooltip.offsetWidth;
|
---|
| 40 | var tooltip_height = this.tooltip.offsetHeight;
|
---|
| 41 |
|
---|
| 42 | if (document.body.offsetWidth - actual_x - tooltip_width < 0) { // tooltip is out of the right page bound
|
---|
| 43 | if(this.tooltip.style.removeAttribute)
|
---|
| 44 | this.tooltip.style.removeAttribute("left");
|
---|
| 45 | else
|
---|
| 46 | this.tooltip.style.removeProperty("left");
|
---|
| 47 | this.tooltip.style.right = (document.body.offsetWidth - actual_x + 2 * dhtmlXTooltip.config.delta_x||0) + "px";
|
---|
| 48 | } else {
|
---|
| 49 | if (actual_x < 0) { // tooltips is out of the left page bound
|
---|
| 50 | this.tooltip.style.left = (pos.x + Math.abs(dhtmlXTooltip.config.delta_x||0)) + "px";
|
---|
| 51 | } else { // normal situation
|
---|
| 52 | this.tooltip.style.left = actual_x + "px";
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | if (document.body.offsetHeight - actual_y - tooltip_height < 0) { // tooltip is below bottom of the page
|
---|
| 57 | if(this.tooltip.style.removeAttribute)
|
---|
| 58 | this.tooltip.style.removeAttribute("top");
|
---|
| 59 | else
|
---|
| 60 | this.tooltip.style.removeProperty("top");
|
---|
| 61 | this.tooltip.style.bottom = (document.body.offsetHeight - actual_y - 2 * dhtmlXTooltip.config.delta_y||0) + "px";
|
---|
| 62 | } else {
|
---|
| 63 | if (actual_y < 0) { // tooltip is higher then top of the page
|
---|
| 64 | this.tooltip.style.top = (pos.y + Math.abs(dhtmlXTooltip.config.delta_y||0)) + "px";
|
---|
| 65 | }
|
---|
| 66 | else { // normal situation
|
---|
| 67 | this.tooltip.style.top = actual_y + "px";
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | this.tooltip.style.visibility = "visible";
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | dhtmlXTooltip.hide = function() {
|
---|
| 75 | if(this.tooltip.parentNode) {
|
---|
| 76 | this.tooltip.parentNode.removeChild(this.tooltip);
|
---|
| 77 | }
|
---|
| 78 | };
|
---|
| 79 | dhtmlXTooltip.delay = function(method, object, params, delay) {
|
---|
| 80 | if(this.tooltip._timeout_id) {
|
---|
| 81 | window.clearTimeout(this.tooltip._timeout_id);
|
---|
| 82 | }
|
---|
| 83 | this.tooltip._timeout_id = setTimeout(function(){
|
---|
| 84 | var ret = method.apply(object,params);
|
---|
| 85 | method = obj = params = null;
|
---|
| 86 | return ret;
|
---|
| 87 | },delay||this.config.timeout_to_display);
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | dhtmlXTooltip.isTooltip = function(node){
|
---|
| 91 | var res = false;
|
---|
| 92 | while (node && !res) {
|
---|
| 93 | res = (node.className == this.tooltip.className);
|
---|
| 94 | node=node.parentNode;
|
---|
| 95 | }
|
---|
| 96 | return res;
|
---|
| 97 | };
|
---|
| 98 |
|
---|
| 99 | dhtmlXTooltip.position = function(ev) {
|
---|
| 100 | var ev = ev || window.event;
|
---|
| 101 | if(ev.pageX || ev.pageY) //FF, KHTML
|
---|
| 102 | return {x:ev.pageX, y:ev.pageY};
|
---|
| 103 | //IE
|
---|
| 104 | var d = ((dhtmlx._isIE)&&(document.compatMode != "BackCompat"))?document.documentElement:document.body;
|
---|
| 105 | return {
|
---|
| 106 | x:ev.clientX + d.scrollLeft - d.clientLeft,
|
---|
| 107 | y:ev.clientY + d.scrollTop - d.clientTop
|
---|
| 108 | };
|
---|
| 109 | };
|
---|
| 110 |
|
---|
| 111 | scheduler.attachEvent("onMouseMove", function(event_id, e){ // (scheduler event_id, browser event)
|
---|
| 112 | var ev = e||window.event;
|
---|
| 113 | var target = ev.target||ev.srcElement;
|
---|
| 114 |
|
---|
| 115 | if (event_id || dhtmlXTooltip.isTooltip(target)) { // if we are over event or tooltip
|
---|
| 116 | var event = scheduler.getEvent(event_id) || scheduler.getEvent(dhtmlXTooltip.tooltip.event_id);
|
---|
| 117 | dhtmlXTooltip.tooltip.event_id = event.id;
|
---|
| 118 | var text = scheduler.templates.tooltip_text(event.start_date, event.end_date, event);
|
---|
| 119 |
|
---|
| 120 | if (_isIE) { //make a copy of event, will be used in timed call
|
---|
| 121 | var evt = document.createEventObject(ev);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | dhtmlXTooltip.delay(dhtmlXTooltip.show, dhtmlXTooltip, [ evt||ev , text]); // showing tooltip
|
---|
| 125 | } else {
|
---|
| 126 | dhtmlXTooltip.delay(dhtmlXTooltip.hide, dhtmlXTooltip, []);
|
---|
| 127 | }
|
---|
| 128 | });
|
---|
| 129 |
|
---|
| 130 | /* Could be redifined */
|
---|
| 131 | scheduler.templates.tooltip_text = function(start,end,event) {
|
---|
| 132 | return "<b>Event:</b> "+event.text+"<br/><b>Start date:</b> "+scheduler.templates.tooltip_date_format(start)+"<br/><b>End date:</b> "+scheduler.templates.tooltip_date_format(end);
|
---|
| 133 | }; |
---|