|
204 | 204 |
|
205 | 205 | throw new Error('You must provide a position');
|
206 | 206 | }
|
| 207 | + , getSideClasses = function getSideClasses(sides) { |
| 208 | + |
| 209 | + return sides.split(' ').map(function mapSideClasses(side) { |
| 210 | + |
| 211 | + return '_' + side; |
| 212 | + }).join(' '); |
| 213 | + } |
| 214 | + , directions = ['_top', '_top _left', '_left', '_bottom _left', '_bottom', '_bottom _right', '_right', '_top _right'] |
| 215 | + , smartPosition = function smartPosition(tipElement, tooltipElement, startSide) { |
| 216 | + |
| 217 | + var directionsIndex = directions.indexOf(getSideClasses(startSide)) |
| 218 | + , directionsLength = directions.length |
| 219 | + , directionsCount = 0; |
| 220 | + |
| 221 | + for (; directionsCount < directionsLength && isOutOfPage(tipElement); directionsCount += 1) { |
| 222 | + |
| 223 | + directionsIndex += 1; |
| 224 | + if (directionsIndex >= directions.length) { |
| 225 | + |
| 226 | + directionsIndex = 0; |
| 227 | + } |
| 228 | + tooltipElement.removeClass('_top _left _bottom _right'); |
| 229 | + tooltipElement.addClass(directions[directionsIndex]); |
| 230 | + } |
| 231 | + } |
207 | 232 | , tooltipConfigurationProvider = function tooltipConfigurationProvider() {
|
208 | 233 |
|
209 | 234 | var tooltipConfiguration = {
|
|
260 | 285 | throw new Error('You can not have a controller without a template or templateUrl defined');
|
261 | 286 | }
|
262 | 287 |
|
263 |
| - var oldTooltipSide = '_' + tooltipsConf.side |
| 288 | + var oldTooltipSide = getSideClasses(tooltipsConf.side) |
264 | 289 | , oldTooltipShowTrigger = tooltipsConf.showTrigger
|
265 | 290 | , oldTooltipHideTrigger = tooltipsConf.hideTrigger
|
266 | 291 | , oldTooltipClass
|
|
307 | 332 | if ($attrs.tooltipSmart) {
|
308 | 333 |
|
309 | 334 | switch ($attrs.tooltipSide) {
|
310 |
| - case 'top': { |
311 |
| - |
312 |
| - if (isOutOfPage(tipElement)) { |
313 |
| - |
314 |
| - tooltipElement.removeClass('_top'); |
315 |
| - tooltipElement.addClass('_left'); |
316 |
| - if (isOutOfPage(tipElement)) { |
317 |
| - |
318 |
| - tooltipElement.removeClass('_left'); |
319 |
| - tooltipElement.addClass('_bottom'); |
320 |
| - if (isOutOfPage(tipElement)) { |
321 |
| - |
322 |
| - tooltipElement.removeClass('_bottom'); |
323 |
| - tooltipElement.addClass('_right'); |
324 |
| - if (isOutOfPage(tipElement)) { |
325 |
| - |
326 |
| - tooltipElement.removeClass('_right'); |
327 |
| - tooltipElement.addClass('_top'); |
328 |
| - } |
329 |
| - } |
330 |
| - } |
331 |
| - } |
332 |
| - break; |
333 |
| - } |
334 |
| - |
335 |
| - case 'left': { |
336 |
| - |
337 |
| - if (isOutOfPage(tipElement)) { |
338 |
| - |
339 |
| - tooltipElement.removeClass('_left'); |
340 |
| - tooltipElement.addClass('_bottom'); |
341 |
| - if (isOutOfPage(tipElement)) { |
342 |
| - |
343 |
| - tooltipElement.removeClass('_bottom'); |
344 |
| - tooltipElement.addClass('_right'); |
345 |
| - if (isOutOfPage(tipElement)) { |
346 |
| - |
347 |
| - tooltipElement.removeClass('_right'); |
348 |
| - tooltipElement.addClass('_top'); |
349 |
| - if (isOutOfPage(tipElement)) { |
350 |
| - |
351 |
| - tooltipElement.removeClass('_top'); |
352 |
| - tooltipElement.addClass('_left'); |
353 |
| - } |
354 |
| - } |
355 |
| - } |
356 |
| - } |
357 |
| - break; |
358 |
| - } |
359 |
| - |
360 |
| - case 'bottom': { |
361 |
| - |
362 |
| - if (isOutOfPage(tipElement)) { |
363 |
| - |
364 |
| - tooltipElement.removeClass('_bottom'); |
365 |
| - tooltipElement.addClass('_left'); |
366 |
| - if (isOutOfPage(tipElement)) { |
367 |
| - |
368 |
| - tooltipElement.removeClass('_left'); |
369 |
| - tooltipElement.addClass('_top'); |
370 |
| - if (isOutOfPage(tipElement)) { |
371 |
| - |
372 |
| - tooltipElement.removeClass('_top'); |
373 |
| - tooltipElement.addClass('_right'); |
374 |
| - if (isOutOfPage(tipElement)) { |
375 |
| - |
376 |
| - tooltipElement.removeClass('_right'); |
377 |
| - tooltipElement.addClass('_bottom'); |
378 |
| - } |
379 |
| - } |
380 |
| - } |
381 |
| - } |
382 |
| - break; |
383 |
| - } |
384 |
| - |
385 |
| - case 'right': { |
386 |
| - |
387 |
| - if (isOutOfPage(tipElement)) { |
388 |
| - |
389 |
| - tooltipElement.removeClass('_right'); |
390 |
| - tooltipElement.addClass('_top'); |
391 |
| - if (isOutOfPage(tipElement)) { |
392 |
| - |
393 |
| - tooltipElement.removeClass('_top'); |
394 |
| - tooltipElement.addClass('_left'); |
395 |
| - if (isOutOfPage(tipElement)) { |
396 |
| - |
397 |
| - tooltipElement.removeClass('_left'); |
398 |
| - tooltipElement.addClass('_bottom'); |
399 |
| - if (isOutOfPage(tipElement)) { |
400 |
| - |
401 |
| - tooltipElement.removeClass('_bottom'); |
402 |
| - tooltipElement.addClass('_right'); |
403 |
| - } |
404 |
| - } |
405 |
| - } |
406 |
| - } |
| 335 | + case 'top': |
| 336 | + case 'left': |
| 337 | + case 'bottom': |
| 338 | + case 'right': |
| 339 | + case 'top left': |
| 340 | + case 'top right': |
| 341 | + case 'bottom left': |
| 342 | + case 'bottom right': { |
| 343 | + |
| 344 | + smartPosition(tipElement, tooltipElement, $attrs.tooltipSide); |
407 | 345 | break;
|
408 | 346 | }
|
| 347 | + |
409 | 348 | default: {
|
410 | 349 |
|
411 | 350 | throw new Error('Position not supported');
|
|
642 | 581 |
|
643 | 582 | if (oldTooltipSide) {
|
644 | 583 |
|
645 |
| - tooltipElement.removeAttr('_' + oldTooltipSide); |
| 584 | + tooltipElement.removeClass(oldTooltipSide); |
646 | 585 | }
|
647 |
| - tooltipElement.addClass('_' + newValue); |
| 586 | + tooltipElement.addClass(getSideClasses(newValue)); |
648 | 587 | oldTooltipSide = newValue;
|
649 | 588 | }
|
650 | 589 | }
|
|
0 commit comments