summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/syntax_highlight.js
blob: 7c063fae045480771db5d9339ab448ddb2fe4067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* eslint-disable func-names, space-before-function-paren, consistent-return, no-var, no-else-return, prefer-arrow-callback, max-len */

// Syntax Highlighter
//
// Applies a syntax highlighting color scheme CSS class to any element with the
// `js-syntax-highlight` class
//
// ### Example Markup
//
//   <div class="js-syntax-highlight"></div>
//
(function() {
  $.fn.syntaxHighlight = function() {
    var $children;

    if ($(this).hasClass('js-syntax-highlight')) {
      // Given the element itself, apply highlighting
      return $(this).addClass(gon.user_color_scheme);
    } else {
      // Given a parent element, recurse to any of its applicable children
      $children = $(this).find('.js-syntax-highlight');
      if ($children.length) {
        return $children.syntaxHighlight();
      }
    }
  };
}).call(window);