##// END OF EJS Templates
tooltips: use a single delegated event for tooltips
ergo -
r382:6ca0e0fb default
parent child Browse files
Show More
@@ -1,126 +1,103 b''
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
2 // #
2 // #
3 // # This program is free software: you can redistribute it and/or modify
3 // # This program is free software: you can redistribute it and/or modify
4 // # it under the terms of the GNU Affero General Public License, version 3
4 // # it under the terms of the GNU Affero General Public License, version 3
5 // # (only), as published by the Free Software Foundation.
5 // # (only), as published by the Free Software Foundation.
6 // #
6 // #
7 // # This program is distributed in the hope that it will be useful,
7 // # This program is distributed in the hope that it will be useful,
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // # GNU General Public License for more details.
10 // # GNU General Public License for more details.
11 // #
11 // #
12 // # You should have received a copy of the GNU Affero General Public License
12 // # You should have received a copy of the GNU Affero General Public License
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 // #
14 // #
15 // # This program is dual-licensed. If you wish to learn more about the
15 // # This program is dual-licensed. If you wish to learn more about the
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 /**
19 /**
20 * TOOLTIP IMPL.
20 * TOOLTIP IMPL.
21 */
21 */
22
22
23 var TTIP = {};
23 var TTIP = {};
24
24
25 TTIP.main = {
25 TTIP.main = {
26 offset: [15,15],
26 offset: [15,15],
27 maxWidth: 600,
27 maxWidth: 600,
28
28
29 set_listeners: function(tt){
29 setDeferredListeners: function(){
30 $(tt).mouseover(tt, yt.show_tip);
30 $('body').on('mouseover', '.tooltip', yt.show_tip);
31 $(tt).mousemove(tt, yt.move_tip);
31 $('body').on('mousemove', '.tooltip', yt.move_tip);
32 $(tt).mouseout(tt, yt.close_tip);
32 $('body').on('mouseout', '.tooltip', yt.close_tip);
33 },
33 },
34
34
35 init: function(){
35 init: function(){
36 $('#tip-box').remove();
36 $('#tip-box').remove();
37 yt.tipBox = document.createElement('div');
37 yt.tipBox = document.createElement('div');
38 document.body.appendChild(yt.tipBox);
38 document.body.appendChild(yt.tipBox);
39 yt.tipBox.id = 'tip-box';
39 yt.tipBox.id = 'tip-box';
40
40
41 $(yt.tipBox).hide();
41 $(yt.tipBox).hide();
42 $(yt.tipBox).css('position', 'absolute');
42 $(yt.tipBox).css('position', 'absolute');
43 if(yt.maxWidth !== null){
43 if(yt.maxWidth !== null){
44 $(yt.tipBox).css('max-width', yt.maxWidth+'px');
44 $(yt.tipBox).css('max-width', yt.maxWidth+'px');
45 }
45 }
46
46 yt.setDeferredListeners();
47 var tooltips = $('.tooltip');
48 var ttLen = tooltips.length;
49
50 for(i=0;i<ttLen;i++){
51 yt.set_listeners(tooltips[i]);
52 }
53 },
47 },
54
48
55 show_tip: function(e, el){
49 show_tip: function(e, el){
56 e.stopPropagation();
50 e.stopPropagation();
57 e.preventDefault();
51 e.preventDefault();
58 var el = e.data || el;
52 var el = e.data || e.currentTarget || el;
59 if(el.tagName.toLowerCase() === 'img'){
53 if(el.tagName.toLowerCase() === 'img'){
60 yt.tipText = el.alt ? el.alt : '';
54 yt.tipText = el.alt ? el.alt : '';
61 } else {
55 } else {
62 yt.tipText = el.title ? el.title : '';
56 yt.tipText = el.title ? el.title : '';
63 }
57 }
64
58
65 if(yt.tipText !== ''){
59 if(yt.tipText !== ''){
66 // save org title
60 // save org title
67 $(el).attr('tt_title', yt.tipText);
61 $(el).attr('tt_title', yt.tipText);
68 // reset title to not show org tooltips
62 // reset title to not show org tooltips
69 $(el).attr('title', '');
63 $(el).attr('title', '');
70
64
71 yt.tipBox.innerHTML = yt.tipText;
65 yt.tipBox.innerHTML = yt.tipText;
72 $(yt.tipBox).show();
66 $(yt.tipBox).show();
73 }
67 }
74 },
68 },
75
69
76 move_tip: function(e, el){
70 move_tip: function(e, el){
77 e.stopPropagation();
71 e.stopPropagation();
78 e.preventDefault();
72 e.preventDefault();
79 var el = e.data || el;
73 var el = e.data || e.currentTarget || el;
80 var movePos = [e.pageX, e.pageY];
74 var movePos = [e.pageX, e.pageY];
81 $(yt.tipBox).css('top', (movePos[1] + yt.offset[1]) + 'px')
75 $(yt.tipBox).css('top', (movePos[1] + yt.offset[1]) + 'px')
82 $(yt.tipBox).css('left', (movePos[0] + yt.offset[0]) + 'px')
76 $(yt.tipBox).css('left', (movePos[0] + yt.offset[0]) + 'px')
83 },
77 },
84
78
85 close_tip: function(e, el){
79 close_tip: function(e, el){
86 e.stopPropagation();
80 e.stopPropagation();
87 e.preventDefault();
81 e.preventDefault();
88 var el = e.data || el;
82 var el = e.data || e.currentTarget || el;
89 $(yt.tipBox).hide();
83 $(yt.tipBox).hide();
90 $(el).attr('title', $(el).attr('tt_title'));
84 $(el).attr('title', $(el).attr('tt_title'));
91 $('#tip-box').hide();
85 $('#tip-box').hide();
92 }
86 }
93 };
87 };
94
88
95 /**
89 /**
96 * tooltip activate
90 * tooltip activate
97 */
91 */
98 var tooltip_activate = function(){
92 var tooltip_activate = function(){
99 yt = TTIP.main;
93 yt = TTIP.main;
100 $(document).ready(yt.init);
94 if ($(document).data('activated-tooltips') !== '1'){
95 $(document).ready(yt.init);
96 $(document).data('activated-tooltips', '1');
97 }
101 };
98 };
102
99
103 /**
100 /**
104 * show changeset tooltip
101 * show changeset tooltip
105 */
102 */
106 var show_changeset_tooltip = function(){
103 var show_changeset_tooltip = function(){};
107 $('.lazy-cs').mouseover(function(e) {
108 var target = e.currentTarget;
109 var rid = $(target).attr('raw_id');
110 var repo_name = $(target).attr('repo_name');
111 var ttid = 'tt-'+rid;
112 var success = function(o){
113 $(target).addClass('tooltip')
114 $(target).attr('title', o['message']);
115 TTIP.main.show_tip(e, target);
116 }
117 if(rid && !$(target).hasClass('tooltip')){
118 $(target).attr('id', ttid);
119 $(target).attr('title', _gettext('loading ...'));
120 TTIP.main.set_listeners(target);
121 TTIP.main.show_tip(e, target);
122 var url = pyroutes.url('changeset_info', {"repo_name":repo_name, "revision": rid});
123 ajaxGET(url, success);
124 }
125 });
126 };
General Comments 0
You need to be logged in to leave comments. Login now