Commit aa90e8ea authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Phil Hughes

Export old code into es6 modules

parent bcb14a0d
...@@ -15,7 +15,7 @@ import GroupLabelSubscription from './group_label_subscription'; ...@@ -15,7 +15,7 @@ import GroupLabelSubscription from './group_label_subscription';
import BuildArtifacts from './build_artifacts'; import BuildArtifacts from './build_artifacts';
import CILintEditor from './ci_lint_editor'; import CILintEditor from './ci_lint_editor';
import groupsSelect from './groups_select'; import groupsSelect from './groups_select';
/* global Search */ import Search from './search';
/* global Admin */ /* global Admin */
import NamespaceSelect from './namespace_select'; import NamespaceSelect from './namespace_select';
import NewCommitForm from './new_commit_form'; import NewCommitForm from './new_commit_form';
...@@ -24,7 +24,7 @@ import projectAvatar from './project_avatar'; ...@@ -24,7 +24,7 @@ import projectAvatar from './project_avatar';
/* global MergeRequest */ /* global MergeRequest */
import Compare from './compare'; import Compare from './compare';
import initCompareAutocomplete from './compare_autocomplete'; import initCompareAutocomplete from './compare_autocomplete';
/* global ProjectFindFile */ import ProjectFindFile from './project_find_file';
import ProjectNew from './project_new'; import ProjectNew from './project_new';
import projectImport from './project_import'; import projectImport from './project_import';
import Labels from './labels'; import Labels from './labels';
...@@ -91,6 +91,7 @@ import DueDateSelectors from './due_date_select'; ...@@ -91,6 +91,7 @@ import DueDateSelectors from './due_date_select';
import Diff from './diff'; import Diff from './diff';
import ProjectLabelSubscription from './project_label_subscription'; import ProjectLabelSubscription from './project_label_subscription';
import ProjectVariables from './project_variables'; import ProjectVariables from './project_variables';
import SearchAutocomplete from './search_autocomplete';
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -683,7 +684,7 @@ import ProjectVariables from './project_variables'; ...@@ -683,7 +684,7 @@ import ProjectVariables from './project_variables';
Dispatcher.prototype.initSearch = function() { Dispatcher.prototype.initSearch = function() {
// Only when search form is present // Only when search form is present
if ($('.search').length) { if ($('.search').length) {
return new gl.SearchAutocomplete(); return new SearchAutocomplete();
} }
}; };
......
...@@ -60,15 +60,10 @@ import './notifications_dropdown'; ...@@ -60,15 +60,10 @@ import './notifications_dropdown';
import './notifications_form'; import './notifications_form';
import './pager'; import './pager';
import './preview_markdown'; import './preview_markdown';
import './project_find_file';
import './project_import'; import './project_import';
import './projects_dropdown'; import './projects_dropdown';
import './projects_list';
import './syntax_highlight';
import './render_gfm'; import './render_gfm';
import './right_sidebar'; import './right_sidebar';
import './search';
import './search_autocomplete';
import initBreadcrumbs from './breadcrumb'; import initBreadcrumbs from './breadcrumb';
import './dispatcher'; import './dispatcher';
......
...@@ -10,6 +10,7 @@ import './mixins/line_conflict_actions'; ...@@ -10,6 +10,7 @@ import './mixins/line_conflict_actions';
import './components/diff_file_editor'; import './components/diff_file_editor';
import './components/inline_conflict_lines'; import './components/inline_conflict_lines';
import './components/parallel_conflict_lines'; import './components/parallel_conflict_lines';
import syntaxHighlight from '../syntax_highlight';
$(() => { $(() => {
const INTERACTIVE_RESOLVE_MODE = 'interactive'; const INTERACTIVE_RESOLVE_MODE = 'interactive';
...@@ -53,7 +54,7 @@ $(() => { ...@@ -53,7 +54,7 @@ $(() => {
mergeConflictsStore.setLoadingState(false); mergeConflictsStore.setLoadingState(false);
this.$nextTick(() => { this.$nextTick(() => {
$('.js-syntax-highlight').syntaxHighlight(); syntaxHighlight($('.js-syntax-highlight'));
}); });
}); });
}, },
......
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
import { getLocationHash } from './lib/utils/url_utility'; import { getLocationHash } from './lib/utils/url_utility';
import initDiscussionTab from './image_diff/init_discussion_tab'; import initDiscussionTab from './image_diff/init_discussion_tab';
import Diff from './diff'; import Diff from './diff';
import syntaxHighlight from './syntax_highlight';
/* eslint-disable max-len */ /* eslint-disable max-len */
// MergeRequestTabs // MergeRequestTabs
...@@ -295,7 +296,7 @@ import Diff from './diff'; ...@@ -295,7 +296,7 @@ import Diff from './diff';
} }
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs')); gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'));
$('#diffs .js-syntax-highlight').syntaxHighlight(); syntaxHighlight($('#diffs .js-syntax-highlight'));
if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction)) { if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction)) {
this.expandViewContainer(); this.expandViewContainer();
......
...@@ -2,11 +2,33 @@ ...@@ -2,11 +2,33 @@
import fuzzaldrinPlus from 'fuzzaldrin-plus'; import fuzzaldrinPlus from 'fuzzaldrin-plus';
(function() { // highlight text(awefwbwgtc -> <b>a</b>wefw<b>b</b>wgt<b>c</b> )
this.ProjectFindFile = (function() { const highlighter = function(element, text, matches) {
var highlighter; var highlightText, j, lastIndex, len, matchIndex, matchedChars, unmatched;
lastIndex = 0;
highlightText = "";
matchedChars = [];
for (j = 0, len = matches.length; j < len; j += 1) {
matchIndex = matches[j];
unmatched = text.substring(lastIndex, matchIndex);
if (unmatched) {
if (matchedChars.length) {
element.append(matchedChars.join("").bold());
}
matchedChars = [];
element.append(document.createTextNode(unmatched));
}
matchedChars.push(text[matchIndex]);
lastIndex = matchIndex + 1;
}
if (matchedChars.length) {
element.append(matchedChars.join("").bold());
}
return element.append(document.createTextNode(text.substring(lastIndex)));
};
function ProjectFindFile(element1, options) { export default class ProjectFindFile {
constructor(element1, options) {
this.element = element1; this.element = element1;
this.options = options; this.options = options;
this.goToBlob = this.goToBlob.bind(this); this.goToBlob = this.goToBlob.bind(this);
...@@ -23,7 +45,7 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -23,7 +45,7 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
this.load(this.options.url); this.load(this.options.url);
} }
ProjectFindFile.prototype.initEvent = function() { initEvent() {
this.inputElement.off("keyup"); this.inputElement.off("keyup");
this.inputElement.on("keyup", (function(_this) { this.inputElement.on("keyup", (function(_this) {
return function(event) { return function(event) {
...@@ -38,18 +60,18 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -38,18 +60,18 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
} }
}; };
})(this)); })(this));
}; }
ProjectFindFile.prototype.findFile = function() { findFile() {
var result, searchText; var result, searchText;
searchText = this.inputElement.val(); searchText = this.inputElement.val();
result = searchText.length > 0 ? fuzzaldrinPlus.filter(this.filePaths, searchText) : this.filePaths; result = searchText.length > 0 ? fuzzaldrinPlus.filter(this.filePaths, searchText) : this.filePaths;
return this.renderList(result, searchText); return this.renderList(result, searchText);
// find file // find file
}; }
// files pathes load // files pathes load
ProjectFindFile.prototype.load = function(url) { load(url) {
return $.ajax({ return $.ajax({
url: url, url: url,
method: "get", method: "get",
...@@ -63,10 +85,10 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -63,10 +85,10 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
}; };
})(this) })(this)
}); });
}; }
// render result // render result
ProjectFindFile.prototype.renderList = function(filePaths, searchText) { renderList(filePaths, searchText) {
var blobItemUrl, filePath, html, i, j, len, matches, results; var blobItemUrl, filePath, html, i, j, len, matches, results;
this.element.find(".tree-table > tbody").empty(); this.element.find(".tree-table > tbody").empty();
results = []; results = [];
...@@ -79,39 +101,14 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -79,39 +101,14 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
matches = fuzzaldrinPlus.match(filePath, searchText); matches = fuzzaldrinPlus.match(filePath, searchText);
} }
blobItemUrl = this.options.blobUrlTemplate + "/" + filePath; blobItemUrl = this.options.blobUrlTemplate + "/" + filePath;
html = this.makeHtml(filePath, matches, blobItemUrl); html = ProjectFindFile.makeHtml(filePath, matches, blobItemUrl);
results.push(this.element.find(".tree-table > tbody").append(html)); results.push(this.element.find(".tree-table > tbody").append(html));
} }
return results; return results;
};
// highlight text(awefwbwgtc -> <b>a</b>wefw<b>b</b>wgt<b>c</b> )
highlighter = function(element, text, matches) {
var highlightText, j, lastIndex, len, matchIndex, matchedChars, unmatched;
lastIndex = 0;
highlightText = "";
matchedChars = [];
for (j = 0, len = matches.length; j < len; j += 1) {
matchIndex = matches[j];
unmatched = text.substring(lastIndex, matchIndex);
if (unmatched) {
if (matchedChars.length) {
element.append(matchedChars.join("").bold());
}
matchedChars = [];
element.append(document.createTextNode(unmatched));
}
matchedChars.push(text[matchIndex]);
lastIndex = matchIndex + 1;
}
if (matchedChars.length) {
element.append(matchedChars.join("").bold());
} }
return element.append(document.createTextNode(text.substring(lastIndex)));
};
// make tbody row html // make tbody row html
ProjectFindFile.prototype.makeHtml = function(filePath, matches, blobItemUrl) { static makeHtml(filePath, matches, blobItemUrl) {
var $tr; var $tr;
$tr = $("<tr class='tree-item'><td class='tree-item-file-name link-container'><a><i class='fa fa-file-text-o fa-fw'></i><span class='str-truncated'></span></a></td></tr>"); $tr = $("<tr class='tree-item'><td class='tree-item-file-name link-container'><a><i class='fa fa-file-text-o fa-fw'></i><span class='str-truncated'></span></a></td></tr>");
if (matches) { if (matches) {
...@@ -121,9 +118,9 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -121,9 +118,9 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
$tr.find(".str-truncated").text(filePath); $tr.find(".str-truncated").text(filePath);
} }
return $tr; return $tr;
}; }
ProjectFindFile.prototype.selectRow = function(type) { selectRow(type) {
var next, rows, selectedRow; var next, rows, selectedRow;
rows = this.element.find(".files-slider tr.tree-item"); rows = this.element.find(".files-slider tr.tree-item");
selectedRow = this.element.find(".files-slider tr.tree-item.selected"); selectedRow = this.element.find(".files-slider tr.tree-item.selected");
...@@ -143,28 +140,25 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus'; ...@@ -143,28 +140,25 @@ import fuzzaldrinPlus from 'fuzzaldrin-plus';
} }
return selectedRow.addClass("selected").focus(); return selectedRow.addClass("selected").focus();
} }
}; }
ProjectFindFile.prototype.selectRowUp = function() { selectRowUp() {
return this.selectRow("UP"); return this.selectRow("UP");
}; }
ProjectFindFile.prototype.selectRowDown = function() { selectRowDown() {
return this.selectRow("DOWN"); return this.selectRow("DOWN");
}; }
ProjectFindFile.prototype.goToTree = function() { goToTree() {
return location.href = this.options.treeUrl; return location.href = this.options.treeUrl;
}; }
ProjectFindFile.prototype.goToBlob = function() { goToBlob() {
var $link = this.element.find(".tree-item.selected .tree-item-file-name a"); var $link = this.element.find(".tree-item.selected .tree-item-file-name a");
if ($link.length) { if ($link.length) {
$link.get(0).click(); $link.get(0).click();
} }
}; }
}
return ProjectFindFile;
})();
}).call(window);
import renderMath from './render_math'; import renderMath from './render_math';
import renderMermaid from './render_mermaid'; import renderMermaid from './render_mermaid';
import syntaxHighlight from './syntax_highlight';
// Render Gitlab flavoured Markdown // Render Gitlab flavoured Markdown
// //
// Delegates to syntax highlight and render math & mermaid diagrams. // Delegates to syntax highlight and render math & mermaid diagrams.
// //
$.fn.renderGFM = function renderGFM() { $.fn.renderGFM = function renderGFM() {
this.find('.js-syntax-highlight').syntaxHighlight(); syntaxHighlight(this.find('.js-syntax-highlight'));
renderMath(this.find('.js-render-math')); renderMath(this.find('.js-render-math'));
renderMermaid(this.find('.js-render-mermaid')); renderMermaid(this.find('.js-render-mermaid'));
return this; return this;
......
<script> <script>
/* global LineHighlighter */ /* global LineHighlighter */
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import syntaxHighlight from '../../syntax_highlight';
export default { export default {
computed: { computed: {
...@@ -13,7 +14,7 @@ export default { ...@@ -13,7 +14,7 @@ export default {
}, },
methods: { methods: {
highlightFile() { highlightFile() {
$(this.$el).find('.file-content').syntaxHighlight(); syntaxHighlight($(this.$el).find('.file-content'));
}, },
}, },
mounted() { mounted() {
......
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, object-shorthand, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-else-return, max-len */
import Flash from './flash'; import Flash from './flash';
import Api from './api'; import Api from './api';
(function() { export default class Search {
this.Search = (function() { constructor() {
function Search() { const $groupDropdown = $('.js-search-group-dropdown');
var $groupDropdown, $projectDropdown; const $projectDropdown = $('.js-search-project-dropdown');
$groupDropdown = $('.js-search-group-dropdown');
$projectDropdown = $('.js-search-project-dropdown'); this.searchInput = '.js-search-input';
this.searchClear = '.js-search-clear';
this.groupId = $groupDropdown.data('group-id'); this.groupId = $groupDropdown.data('group-id');
this.eventListeners(); this.eventListeners();
$groupDropdown.glDropdown({ $groupDropdown.glDropdown({
selectable: true, selectable: true,
filterable: true, filterable: true,
fieldName: 'group_id', fieldName: 'group_id',
search: { search: {
fields: ['full_name'] fields: ['full_name'],
}, },
data: function(term, callback) { data(term, callback) {
return Api.groups(term, {}, function(data) { return Api.groups(term, {}, (data) => {
data.unshift({ data.unshift({
full_name: 'Any' full_name: 'Any',
}); });
data.splice(1, 0, 'divider'); data.splice(1, 0, 'divider');
return callback(data); return callback(data);
}); });
}, },
id: function(obj) { id(obj) {
return obj.id; return obj.id;
}, },
text: function(obj) { text(obj) {
return obj.full_name; return obj.full_name;
}, },
toggleLabel: function(obj) { toggleLabel(obj) {
return ($groupDropdown.data('default-label')) + " " + obj.full_name; return `${($groupDropdown.data('default-label'))} ${obj.full_name}`;
}, },
clicked: (function(_this) { clicked: () => Search.submitSearch(),
return function() {
return _this.submitSearch();
};
})(this)
}); });
$projectDropdown.glDropdown({ $projectDropdown.glDropdown({
selectable: true, selectable: true,
filterable: true, filterable: true,
fieldName: 'project_id', fieldName: 'project_id',
search: { search: {
fields: ['name'] fields: ['name'],
}, },
data: (term, callback) => { data: (term, callback) => {
this.getProjectsData(term) this.getProjectsData(term)
.then((data) => { .then((data) => {
data.unshift({ data.unshift({
name_with_namespace: 'Any' name_with_namespace: 'Any',
}); });
data.splice(1, 0, 'divider'); data.splice(1, 0, 'divider');
...@@ -61,47 +60,46 @@ import Api from './api'; ...@@ -61,47 +60,46 @@ import Api from './api';
.then(data => callback(data)) .then(data => callback(data))
.catch(() => new Flash('Error fetching projects')); .catch(() => new Flash('Error fetching projects'));
}, },
id: function(obj) { id(obj) {
return obj.id; return obj.id;
}, },
text: function(obj) { text(obj) {
return obj.name_with_namespace; return obj.name_with_namespace;
}, },
toggleLabel: function(obj) { toggleLabel(obj) {
return ($projectDropdown.data('default-label')) + " " + obj.name_with_namespace; return `${($projectDropdown.data('default-label'))} ${obj.name_with_namespace}`;
}, },
clicked: (function(_this) { clicked: () => Search.submitSearch(),
return function() {
return _this.submitSearch();
};
})(this)
}); });
} }
Search.prototype.eventListeners = function() { eventListeners() {
$(document).off('keyup', '.js-search-input').on('keyup', '.js-search-input', this.searchKeyUp); $(document)
return $(document).off('click', '.js-search-clear').on('click', '.js-search-clear', this.clearSearchField); .off('keyup', this.searchInput)
}; .on('keyup', this.searchInput, this.searchKeyUp);
$(document)
.off('click', this.searchClear)
.on('click', this.searchClear, this.clearSearchField.bind(this));
}
Search.prototype.submitSearch = function() { static submitSearch() {
return $('.js-search-form').submit(); return $('.js-search-form').submit();
}; }
Search.prototype.searchKeyUp = function() { searchKeyUp() {
var $input; const $input = $(this);
$input = $(this);
if ($input.val() === '') { if ($input.val() === '') {
return $('.js-search-clear').addClass('hidden'); $('.js-search-clear').addClass('hidden');
} else { } else {
return $('.js-search-clear').removeClass('hidden'); $('.js-search-clear').removeClass('hidden');
}
} }
};
Search.prototype.clearSearchField = function() { clearSearchField() {
return $('.js-search-input').val('').trigger('keyup').focus(); return $(this.searchInput).val('').trigger('keyup').focus();
}; }
Search.prototype.getProjectsData = function(term) { getProjectsData(term) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (this.groupId) { if (this.groupId) {
Api.groupProjects(this.groupId, term, resolve); Api.groupProjects(this.groupId, term, resolve);
...@@ -111,8 +109,5 @@ import Api from './api'; ...@@ -111,8 +109,5 @@ import Api from './api';
}, resolve); }, resolve);
} }
}); });
}; }
}
return Search;
})();
}).call(window);
...@@ -8,17 +8,55 @@ import { isInGroupsPage, isInProjectPage, getGroupSlug, getProjectSlug } from '. ...@@ -8,17 +8,55 @@ import { isInGroupsPage, isInProjectPage, getGroupSlug, getProjectSlug } from '.
* When the user clicks `x` button it cleans the input and closes the dropdown. * When the user clicks `x` button it cleans the input and closes the dropdown.
*/ */
((global) => { const KEYCODE = {
const KEYCODE = {
ESCAPE: 27, ESCAPE: 27,
BACKSPACE: 8, BACKSPACE: 8,
ENTER: 13, ENTER: 13,
UP: 38, UP: 38,
DOWN: 40, DOWN: 40,
};
function setSearchOptions() {
var $projectOptionsDataEl = $('.js-search-project-options');
var $groupOptionsDataEl = $('.js-search-group-options');
var $dashboardOptionsDataEl = $('.js-search-dashboard-options');
if ($projectOptionsDataEl.length) {
gl.projectOptions = gl.projectOptions || {};
var projectPath = $projectOptionsDataEl.data('project-path');
gl.projectOptions[projectPath] = {
name: $projectOptionsDataEl.data('name'),
issuesPath: $projectOptionsDataEl.data('issues-path'),
issuesDisabled: $projectOptionsDataEl.data('issues-disabled'),
mrPath: $projectOptionsDataEl.data('mr-path'),
}; };
}
if ($groupOptionsDataEl.length) {
gl.groupOptions = gl.groupOptions || {};
class SearchAutocomplete { var groupPath = $groupOptionsDataEl.data('group-path');
gl.groupOptions[groupPath] = {
name: $groupOptionsDataEl.data('name'),
issuesPath: $groupOptionsDataEl.data('issues-path'),
mrPath: $groupOptionsDataEl.data('mr-path'),
};
}
if ($dashboardOptionsDataEl.length) {
gl.dashboardOptions = {
issuesPath: $dashboardOptionsDataEl.data('issues-path'),
mrPath: $dashboardOptionsDataEl.data('mr-path'),
};
}
}
export default class SearchAutocomplete {
constructor({ wrap, optsEl, autocompletePath, projectId, projectRef } = {}) { constructor({ wrap, optsEl, autocompletePath, projectId, projectRef } = {}) {
setSearchOptions();
this.bindEventContext(); this.bindEventContext();
this.wrap = wrap || $('.search'); this.wrap = wrap || $('.search');
this.optsEl = optsEl || this.wrap.find('.search-autocomplete-opts'); this.optsEl = optsEl || this.wrap.find('.search-autocomplete-opts');
...@@ -411,45 +449,4 @@ import { isInGroupsPage, isInProjectPage, getGroupSlug, getProjectSlug } from '. ...@@ -411,45 +449,4 @@ import { isInGroupsPage, isInProjectPage, getGroupSlug, getProjectSlug } from '.
return this.searchInput.val('').focus(); return this.searchInput.val('').focus();
} }
} }
} }
global.SearchAutocomplete = SearchAutocomplete;
$(function() {
var $projectOptionsDataEl = $('.js-search-project-options');
var $groupOptionsDataEl = $('.js-search-group-options');
var $dashboardOptionsDataEl = $('.js-search-dashboard-options');
if ($projectOptionsDataEl.length) {
gl.projectOptions = gl.projectOptions || {};
var projectPath = $projectOptionsDataEl.data('project-path');
gl.projectOptions[projectPath] = {
name: $projectOptionsDataEl.data('name'),
issuesPath: $projectOptionsDataEl.data('issues-path'),
issuesDisabled: $projectOptionsDataEl.data('issues-disabled'),
mrPath: $projectOptionsDataEl.data('mr-path'),
};
}
if ($groupOptionsDataEl.length) {
gl.groupOptions = gl.groupOptions || {};
var groupPath = $groupOptionsDataEl.data('group-path');
gl.groupOptions[groupPath] = {
name: $groupOptionsDataEl.data('name'),
issuesPath: $groupOptionsDataEl.data('issues-path'),
mrPath: $groupOptionsDataEl.data('mr-path'),
};
}
if ($dashboardOptionsDataEl.length) {
gl.dashboardOptions = {
issuesPath: $dashboardOptionsDataEl.data('issues-path'),
mrPath: $dashboardOptionsDataEl.data('mr-path'),
};
}
});
})(window.gl || (window.gl = {}));
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import FilesCommentButton from './files_comment_button'; import FilesCommentButton from './files_comment_button';
import imageDiffHelper from './image_diff/helpers/index'; import imageDiffHelper from './image_diff/helpers/index';
import syntaxHighlight from './syntax_highlight';
const WRAPPER = '<div class="diff-content"></div>'; const WRAPPER = '<div class="diff-content"></div>';
const LOADING_HTML = '<i class="fa fa-spinner fa-spin"></i>'; const LOADING_HTML = '<i class="fa fa-spinner fa-spin"></i>';
...@@ -64,7 +65,7 @@ export default class SingleFileDiff { ...@@ -64,7 +65,7 @@ export default class SingleFileDiff {
_this.loadingContent.hide(); _this.loadingContent.hide();
if (data.html) { if (data.html) {
_this.content = $(data.html); _this.content = $(data.html);
_this.content.syntaxHighlight(); syntaxHighlight(_this.content);
} else { } else {
_this.hasError = true; _this.hasError = true;
_this.content = $(ERROR_HTML); _this.content = $(ERROR_HTML);
......
...@@ -10,17 +10,15 @@ ...@@ -10,17 +10,15 @@
// <div class="js-syntax-highlight"></div> // <div class="js-syntax-highlight"></div>
// //
$.fn.syntaxHighlight = function() { export default function syntaxHighlight(el) {
var $children; if ($(el).hasClass('js-syntax-highlight')) {
if ($(this).hasClass('js-syntax-highlight')) {
// Given the element itself, apply highlighting // Given the element itself, apply highlighting
return $(this).addClass(gon.user_color_scheme); return $(el).addClass(gon.user_color_scheme);
} else { } else {
// Given a parent element, recurse to any of its applicable children // Given a parent element, recurse to any of its applicable children
$children = $(this).find('.js-syntax-highlight'); const $children = $(el).find('.js-syntax-highlight');
if ($children.length) { if ($children.length) {
return $children.syntaxHighlight(); return syntaxHighlight($children);
} }
} }
}; }
/* eslint-disable space-before-function-paren, max-len, no-var, one-var, one-var-declaration-per-line, no-unused-expressions, consistent-return, no-param-reassign, default-case, no-return-assign, comma-dangle, object-shorthand, prefer-template, quotes, new-parens, vars-on-top, new-cap, max-len */ /* eslint-disable space-before-function-paren, max-len, no-var, one-var, one-var-declaration-per-line, no-unused-expressions, consistent-return, no-param-reassign, default-case, no-return-assign, comma-dangle, object-shorthand, prefer-template, quotes, new-parens, vars-on-top, new-cap, max-len */
import '~/gl_dropdown'; import '~/gl_dropdown';
import '~/search_autocomplete'; import SearchAutocomplete from '~/search_autocomplete';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import * as urlUtils from '~/lib/utils/url_utility'; import * as urlUtils from '~/lib/utils/url_utility';
...@@ -128,7 +128,7 @@ import * as urlUtils from '~/lib/utils/url_utility'; ...@@ -128,7 +128,7 @@ import * as urlUtils from '~/lib/utils/url_utility';
window.gon.current_user_id = userId; window.gon.current_user_id = userId;
window.gon.current_username = userName; window.gon.current_username = userName;
return widget = new gl.SearchAutocomplete; return widget = new SearchAutocomplete();
}); });
afterEach(function() { afterEach(function() {
......
/* eslint-disable space-before-function-paren, no-var, no-return-assign, quotes */ /* eslint-disable space-before-function-paren, no-var, no-return-assign, quotes */
import '~/syntax_highlight'; import syntaxHighlight from '~/syntax_highlight';
(function() { describe('Syntax Highlighter', function() {
describe('Syntax Highlighter', function() {
var stubUserColorScheme; var stubUserColorScheme;
stubUserColorScheme = function(value) { stubUserColorScheme = function(value) {
if (window.gon == null) { if (window.gon == null) {
...@@ -17,7 +16,7 @@ import '~/syntax_highlight'; ...@@ -17,7 +16,7 @@ import '~/syntax_highlight';
}); });
return it('applies syntax highlighting', function() { return it('applies syntax highlighting', function() {
stubUserColorScheme('monokai'); stubUserColorScheme('monokai');
$('.js-syntax-highlight').syntaxHighlight(); syntaxHighlight($('.js-syntax-highlight'));
return expect($('.js-syntax-highlight')).toHaveClass('monokai'); return expect($('.js-syntax-highlight')).toHaveClass('monokai');
}); });
}); });
...@@ -27,7 +26,7 @@ import '~/syntax_highlight'; ...@@ -27,7 +26,7 @@ import '~/syntax_highlight';
}); });
it('applies highlighting to all applicable children', function() { it('applies highlighting to all applicable children', function() {
stubUserColorScheme('monokai'); stubUserColorScheme('monokai');
$('.parent').syntaxHighlight(); syntaxHighlight($('.parent'));
expect($('.parent, .foo')).not.toHaveClass('monokai'); expect($('.parent, .foo')).not.toHaveClass('monokai');
return expect($('.monokai').length).toBe(2); return expect($('.monokai').length).toBe(2);
}); });
...@@ -35,10 +34,9 @@ import '~/syntax_highlight'; ...@@ -35,10 +34,9 @@ import '~/syntax_highlight';
var highlight; var highlight;
setFixtures('<div></div>'); setFixtures('<div></div>');
highlight = function() { highlight = function() {
return $('div').syntaxHighlight(); return syntaxHighlight($('div'));
}; };
return expect(highlight).not.toThrow(); return expect(highlight).not.toThrow();
}); });
}); });
}); });
}).call(window);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment