summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/syntax_highlight.coffee
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-09-10 15:28:42 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-09-10 15:38:24 -0400
commit404a01ab148417f6314c94d213769dd72fd0589e (patch)
treec6bd24884d9ff4c87cb31857d649d43ef6c48abc /app/assets/javascripts/syntax_highlight.coffee
parent7cbf5e4d18f6ba0bf1afbddcb090fa39837e9529 (diff)
downloadgitlab-ce-404a01ab148417f6314c94d213769dd72fd0589e.tar.gz
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.
Diffstat (limited to 'app/assets/javascripts/syntax_highlight.coffee')
-rw-r--r--app/assets/javascripts/syntax_highlight.coffee10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/assets/javascripts/syntax_highlight.coffee b/app/assets/javascripts/syntax_highlight.coffee
index 71295cd4b08..980f0232d10 100644
--- a/app/assets/javascripts/syntax_highlight.coffee
+++ b/app/assets/javascripts/syntax_highlight.coffee
@@ -1,3 +1,5 @@
+# Syntax Highlighter
+#
# Applies a syntax highlighting color scheme CSS class to any element with the
# `js-syntax-highlight` class
#
@@ -6,7 +8,13 @@
# <div class="js-syntax-highlight"></div>
#
$.fn.syntaxHighlight = ->
- $(this).addClass(gon.user_color_scheme)
+ 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()