|
1 | 1 | /*
|
2 | 2 | * angular-tooltips
|
3 |
| - * 1.1.12 |
| 3 | + * 1.2.0 |
4 | 4 | *
|
5 | 5 | * Angular.js tooltips module.
|
6 | 6 | * http://720kb.github.io/angular-tooltips
|
7 | 7 | *
|
8 | 8 | * MIT license
|
9 |
| - * Sat May 20 2017 |
| 9 | + * Sun May 21 2017 |
10 | 10 | */
|
11 | 11 | /*global angular,window*/
|
12 | 12 | (function withAngular(angular, window) {
|
|
214 | 214 |
|
215 | 215 | throw new Error('You must provide a position');
|
216 | 216 | }
|
| 217 | + , getSideClasses = function getSideClasses(sides) { |
| 218 | + |
| 219 | + return sides.split(' ').map(function mapSideClasses(side) { |
| 220 | + |
| 221 | + return '_' + side; |
| 222 | + }).join(' '); |
| 223 | + } |
| 224 | + , directions = ['_top', '_top _left', '_left', '_bottom _left', '_bottom', '_bottom _right', '_right', '_top _right'] |
| 225 | + , smartPosition = function smartPosition(tipElement, tooltipElement, startSide) { |
| 226 | + |
| 227 | + var directionsIndex = directions.indexOf(getSideClasses(startSide)) |
| 228 | + , directionsLength = directions.length |
| 229 | + , directionsCount = 0; |
| 230 | + |
| 231 | + for (; directionsCount < directionsLength && isOutOfPage(tipElement); directionsCount += 1) { |
| 232 | + |
| 233 | + directionsIndex += 1; |
| 234 | + if (directionsIndex >= directions.length) { |
| 235 | + |
| 236 | + directionsIndex = 0; |
| 237 | + } |
| 238 | + tooltipElement.removeClass('_top _left _bottom _right'); |
| 239 | + tooltipElement.addClass(directions[directionsIndex]); |
| 240 | + } |
| 241 | + } |
217 | 242 | , tooltipConfigurationProvider = function tooltipConfigurationProvider() {
|
218 | 243 |
|
219 | 244 | var tooltipConfiguration = {
|
|
270 | 295 | throw new Error('You can not have a controller without a template or templateUrl defined');
|
271 | 296 | }
|
272 | 297 |
|
273 |
| - var oldTooltipSide = '_' + tooltipsConf.side |
| 298 | + var oldTooltipSide = getSideClasses(tooltipsConf.side) |
274 | 299 | , oldTooltipShowTrigger = tooltipsConf.showTrigger
|
275 | 300 | , oldTooltipHideTrigger = tooltipsConf.hideTrigger
|
276 | 301 | , oldTooltipClass
|
|
317 | 342 | if ($attrs.tooltipSmart) {
|
318 | 343 |
|
319 | 344 | switch ($attrs.tooltipSide) {
|
320 |
| - case 'top': { |
321 |
| - |
322 |
| - if (isOutOfPage(tipElement)) { |
323 |
| - |
324 |
| - tooltipElement.removeClass('_top'); |
325 |
| - tooltipElement.addClass('_left'); |
326 |
| - if (isOutOfPage(tipElement)) { |
327 |
| - |
328 |
| - tooltipElement.removeClass('_left'); |
329 |
| - tooltipElement.addClass('_bottom'); |
330 |
| - if (isOutOfPage(tipElement)) { |
331 |
| - |
332 |
| - tooltipElement.removeClass('_bottom'); |
333 |
| - tooltipElement.addClass('_right'); |
334 |
| - if (isOutOfPage(tipElement)) { |
335 |
| - |
336 |
| - tooltipElement.removeClass('_right'); |
337 |
| - tooltipElement.addClass('_top'); |
338 |
| - } |
339 |
| - } |
340 |
| - } |
341 |
| - } |
342 |
| - break; |
343 |
| - } |
344 |
| - |
345 |
| - case 'left': { |
346 |
| - |
347 |
| - if (isOutOfPage(tipElement)) { |
348 |
| - |
349 |
| - tooltipElement.removeClass('_left'); |
350 |
| - tooltipElement.addClass('_bottom'); |
351 |
| - if (isOutOfPage(tipElement)) { |
352 |
| - |
353 |
| - tooltipElement.removeClass('_bottom'); |
354 |
| - tooltipElement.addClass('_right'); |
355 |
| - if (isOutOfPage(tipElement)) { |
356 |
| - |
357 |
| - tooltipElement.removeClass('_right'); |
358 |
| - tooltipElement.addClass('_top'); |
359 |
| - if (isOutOfPage(tipElement)) { |
360 |
| - |
361 |
| - tooltipElement.removeClass('_top'); |
362 |
| - tooltipElement.addClass('_left'); |
363 |
| - } |
364 |
| - } |
365 |
| - } |
366 |
| - } |
367 |
| - break; |
368 |
| - } |
369 |
| - |
370 |
| - case 'bottom': { |
371 |
| - |
372 |
| - if (isOutOfPage(tipElement)) { |
373 |
| - |
374 |
| - tooltipElement.removeClass('_bottom'); |
375 |
| - tooltipElement.addClass('_left'); |
376 |
| - if (isOutOfPage(tipElement)) { |
377 |
| - |
378 |
| - tooltipElement.removeClass('_left'); |
379 |
| - tooltipElement.addClass('_top'); |
380 |
| - if (isOutOfPage(tipElement)) { |
381 |
| - |
382 |
| - tooltipElement.removeClass('_top'); |
383 |
| - tooltipElement.addClass('_right'); |
384 |
| - if (isOutOfPage(tipElement)) { |
385 |
| - |
386 |
| - tooltipElement.removeClass('_right'); |
387 |
| - tooltipElement.addClass('_bottom'); |
388 |
| - } |
389 |
| - } |
390 |
| - } |
391 |
| - } |
392 |
| - break; |
393 |
| - } |
394 |
| - |
395 |
| - case 'right': { |
396 |
| - |
397 |
| - if (isOutOfPage(tipElement)) { |
398 |
| - |
399 |
| - tooltipElement.removeClass('_right'); |
400 |
| - tooltipElement.addClass('_top'); |
401 |
| - if (isOutOfPage(tipElement)) { |
402 |
| - |
403 |
| - tooltipElement.removeClass('_top'); |
404 |
| - tooltipElement.addClass('_left'); |
405 |
| - if (isOutOfPage(tipElement)) { |
406 |
| - |
407 |
| - tooltipElement.removeClass('_left'); |
408 |
| - tooltipElement.addClass('_bottom'); |
409 |
| - if (isOutOfPage(tipElement)) { |
410 |
| - |
411 |
| - tooltipElement.removeClass('_bottom'); |
412 |
| - tooltipElement.addClass('_right'); |
413 |
| - } |
414 |
| - } |
415 |
| - } |
416 |
| - } |
| 345 | + case 'top': |
| 346 | + case 'left': |
| 347 | + case 'bottom': |
| 348 | + case 'right': |
| 349 | + case 'top left': |
| 350 | + case 'top right': |
| 351 | + case 'bottom left': |
| 352 | + case 'bottom right': { |
| 353 | + |
| 354 | + smartPosition(tipElement, tooltipElement, $attrs.tooltipSide); |
417 | 355 | break;
|
418 | 356 | }
|
| 357 | + |
419 | 358 | default: {
|
420 | 359 |
|
421 | 360 | throw new Error('Position not supported');
|
|
652 | 591 |
|
653 | 592 | if (oldTooltipSide) {
|
654 | 593 |
|
655 |
| - tooltipElement.removeAttr('_' + oldTooltipSide); |
| 594 | + tooltipElement.removeClass(oldTooltipSide); |
656 | 595 | }
|
657 |
| - tooltipElement.addClass('_' + newValue); |
| 596 | + tooltipElement.addClass(getSideClasses(newValue)); |
658 | 597 | oldTooltipSide = newValue;
|
659 | 598 | }
|
660 | 599 | }
|
|
0 commit comments