|
29 | 29 | position: ['top', 'center'], |
30 | 30 | offset: [0, 0], |
31 | 31 | relative: false, |
32 | | - calculateInlineOffset: false, |
| 32 | + calculateInlineOffset: false, //If need to handle multilines inline elements |
33 | 33 | cancelDefault: true, |
34 | 34 |
|
35 | 35 | // type to event mapping |
|
79 | 79 | }; |
80 | 80 |
|
81 | 81 |
|
82 | | - /* calculate tip position relative to the trigger */ |
83 | | - function getPosition(trigger, tip, conf) { |
| 82 | + /* calculate tip position relative to the trigger */ |
| 83 | + function getPosition(trigger, tip, conf) { |
84 | 84 |
|
85 | | - |
86 | | - // get origin top/left position |
87 | | - var top = conf.relative ? trigger.position().top : trigger.offset().top, |
88 | | - left = conf.relative ? trigger.position().left : trigger.offset().left, |
89 | | - pos = conf.position[0]; |
90 | | - |
91 | | - //If relative is false and calculateInlineOffset flag is on then only go for it. |
92 | | - if (!conf.relative && conf.calculateInlineOffset) { |
93 | | - //Get the actual inline offset of triggered elem |
94 | | - var iOffset = $(trigger).inlineOffset(); |
95 | | - |
96 | | - //If element is spans multilines then compare the left positions. |
97 | | - if (left < iOffset.left){ |
98 | | - left = iOffset.left; |
99 | | - } |
100 | | - } |
| 85 | + |
| 86 | + // get origin top/left position |
| 87 | + var top = conf.relative ? trigger.position().top : trigger.offset().top, |
| 88 | + left = conf.relative ? trigger.position().left : trigger.offset().left, |
| 89 | + pos = conf.position[0]; |
| 90 | + |
| 91 | + var orgLeftOffset = left; //Keeping original offset |
| 92 | + top -= tip.outerHeight() - conf.offset[0]; |
| 93 | + left += trigger.outerWidth() + conf.offset[1]; |
| 94 | + |
| 95 | + var isInlineOffsetSet = false; |
| 96 | + //If relative is false and calculateInlineOffset flag is on then only go for it. |
| 97 | + if (!conf.relative && conf.calculateInlineOffset) { |
| 98 | + //Get the actual inline offset of triggered elem |
| 99 | + var iOffset = $(trigger).inlineOffset(); |
101 | 100 |
|
102 | | - top -= tip.outerHeight() - conf.offset[0]; |
103 | | - left += trigger.outerWidth() + conf.offset[1]; |
104 | | - |
105 | | - // iPad position fix |
106 | | - if (/iPad/i.test(navigator.userAgent)) { |
107 | | - top -= $(window).scrollTop(); |
108 | | - } |
109 | | - |
110 | | - // adjust Y |
111 | | - var height = tip.outerHeight() + trigger.outerHeight(); |
112 | | - if (pos == 'center') { top += height / 2; } |
113 | | - if (pos == 'bottom') { top += height; } |
114 | | - |
115 | | - |
116 | | - // adjust X |
117 | | - pos = conf.position[1]; |
118 | | - var width = tip.outerWidth() + trigger.outerWidth(); |
119 | | - if (pos == 'center') { left -= width / 2; } |
120 | | - if (pos == 'left') { left -= width; } |
121 | | - |
122 | | - return {top: top, left: left}; |
123 | | - } |
| 101 | + //If element is spans multilines then compare the left positions. |
| 102 | + if (orgLeftOffset < iOffset.left){ |
| 103 | + left = iOffset.left; |
| 104 | + isInlineOffsetSet = true; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + // iPad position fix |
| 109 | + if (/iPad/i.test(navigator.userAgent)) { |
| 110 | + top -= $(window).scrollTop(); |
| 111 | + } |
| 112 | + |
| 113 | + // adjust Y |
| 114 | + var height = tip.outerHeight() + trigger.outerHeight(); |
| 115 | + if (pos == 'center') { top += height / 2; } |
| 116 | + if (pos == 'bottom') { top += height; } |
| 117 | + |
| 118 | + |
| 119 | + // adjust X |
| 120 | + pos = conf.position[1]; |
| 121 | + var width = tip.outerWidth() + trigger.outerWidth(); |
| 122 | + |
| 123 | + //don't apply 'center' in case of setting inline offset value |
| 124 | + if (pos == 'center' && !isInlineOffsetSet) { left -= width / 2;} |
| 125 | + if (pos == 'left') { left -= width; } |
| 126 | + |
| 127 | + return {top: top, left: left}; |
| 128 | + } |
124 | 129 |
|
125 | 130 |
|
126 | 131 |
|
|
0 commit comments