widgets.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. (function ($) {
  2. var csscls = PhpDebugBar.utils.makecsscls('phpdebugbar-');
  3. /**
  4. * TooltipIndicator
  5. *
  6. * A customised indicator class that will provide a better tooltip.
  7. *
  8. * Options:
  9. * - icon
  10. * - title
  11. * - tooltip: array('html' => '', 'class' => '')
  12. * - data: alias of title
  13. */
  14. var TooltipIndicator = PhpDebugBar.DebugBar.TooltipIndicator = PhpDebugBar.DebugBar.Indicator.extend({
  15. render: function() {
  16. this.$icon = $('<i />').appendTo(this.$el);
  17. this.bindAttr('icon', function(icon) {
  18. if (icon) {
  19. this.$icon.attr('class', 'fa fa-' + icon);
  20. } else {
  21. this.$icon.attr('class', '');
  22. }
  23. });
  24. this.bindAttr(['title', 'data'], $('<span />').addClass(csscls('text')).appendTo(this.$el));
  25. this.$tooltip = $('<span />').addClass(csscls('tooltip disabled')).appendTo(this.$el);
  26. this.bindAttr('tooltip', function(tooltip) {
  27. if (tooltip['html']) {
  28. tooltipHTML = $('<span />').html(tooltip['html']).addClass(csscls('tooltip-html'));
  29. this.$tooltip.html(tooltipHTML).removeClass(csscls('disabled'));
  30. if (tooltip['class']) {
  31. this.$tooltip.addClass(csscls(tooltip['class']));
  32. }
  33. } else {
  34. this.$tooltip.addClass(csscls('disabled'));
  35. }
  36. });
  37. }
  38. });
  39. /**
  40. * LinkIndicator
  41. *
  42. * A customised indicator class that will allow "click" behaviour.
  43. *
  44. * Options:
  45. * - icon
  46. * - title
  47. * - tooltip
  48. * - data: alias of title
  49. * - href
  50. * - target
  51. */
  52. var LinkIndicator = PhpDebugBar.DebugBar.LinkIndicator = PhpDebugBar.DebugBar.Indicator.extend({
  53. tagName: 'a',
  54. render: function() {
  55. LinkIndicator.__super__.render.apply(this);
  56. this.bindAttr('href', function(href) {
  57. this.$el.attr('href', href);
  58. });
  59. this.bindAttr('target', function(target) {
  60. this.$el.attr('target', target);
  61. });
  62. }
  63. });
  64. })(PhpDebugBar.$);