debian-mirror-gitlab/app/assets/javascripts/syntax_highlight.js

28 lines
834 B
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable func-names, space-before-function-paren, consistent-return, no-var, no-else-return, prefer-arrow-callback, max-len */
2016-09-29 09:46:39 +05:30
// 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>
//
2016-09-13 17:45:13 +05:30
(function() {
$.fn.syntaxHighlight = function() {
var $children;
2017-08-17 22:00:37 +05:30
2016-09-13 17:45:13 +05:30
if ($(this).hasClass('js-syntax-highlight')) {
2016-09-29 09:46:39 +05:30
// Given the element itself, apply highlighting
2016-09-13 17:45:13 +05:30
return $(this).addClass(gon.user_color_scheme);
} else {
2016-09-29 09:46:39 +05:30
// Given a parent element, recurse to any of its applicable children
2016-09-13 17:45:13 +05:30
$children = $(this).find('.js-syntax-highlight');
if ($children.length) {
return $children.syntaxHighlight();
}
}
};
2017-08-17 22:00:37 +05:30
}).call(window);