gitlab-org--gitlab-foss/app/assets/javascripts/syntax_highlight.coffee
Robert Speicher 404a01ab14 Add specs for syntax_highlight JS
Also makes it work when given a parent element containing a
`.js-syntax-highlight` element so for dynamically-added things like
notes or Markdown previews, we can more accurately target just the
element we care about.
2015-09-10 15:38:24 -04:00

20 lines
637 B
CoffeeScript

# 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>
#
$.fn.syntaxHighlight = ->
if $(this).hasClass('js-syntax-highlight')
# Given the element itself, apply highlighting
$(this).addClass(gon.user_color_scheme)
else
# Given a parent element, recurse to any of its applicable children
$children = $(this).find('.js-syntax-highlight')
$children.syntaxHighlight() if $children.length
$(document).on 'ready page:load', ->
$('.js-syntax-highlight').syntaxHighlight()