jQuery()

in source/_assets/js/code-examples.js [62:113]


jQuery(document).ready(function($) {
  $('.example code div[class]').on('mouseover click', function(event) {
    var tooltips, lineNumber, content, parentElem, key, options, tooltip,
        hasTooltip;

    parentElem = $(this).closest('div.example');
    key = parentElem.attr('data-example');

    tooltips = LINE_TOOLTIPS[key];

    if (!tooltips) {
      return;
    }

    hasTooltip = $(this).attr('title') !== undefined;
    lineNumber = $(this).attr('class').replace('line-', '');
    tooltip = tooltips[lineNumber];

    if (!tooltip) {
      // No tool tip for this line.
      return;
    }

    if (hasTooltip) {
      // Popover for this line has already been created.
      if (event.type === 'click') {
        $(this).popover('toggle');
      }

      return;
    }


    if (tooltip instanceof Array) {
      content = tooltip.join('');
    }
    else {
      content = tooltip;
    }

    options = {
      'content': content,
      'placement': 'auto right',
      'html': true,
      'trigger': 'hover',
      'container': 'body'
    };

    $(this).popover(options);
    $(this).popover('show');
  });
});