Skip to content
Snippets Groups Projects
Verified Commit e0bbadc2 authored by Phil Hughes's avatar Phil Hughes
Browse files

use exported methods instead of gl.utils

parent 13df7a85
No related branches found
No related tags found
No related merge requests found
Showing
with 49 additions and 51 deletions
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, no-unused-vars, no-else-return, prefer-arrow-callback, camelcase, quotes, comma-dangle, max-len */
import { refreshCurrentPage } from './lib/utils/url_utility';
 
window.Admin = (function() {
function Admin() {
Loading
Loading
@@ -40,10 +41,10 @@ window.Admin = (function() {
return $('.change-owner-link').show();
});
$('li.project_member').bind('ajax:success', function() {
return gl.utils.refreshCurrentPage();
return refreshCurrentPage();
});
$('li.group_member').bind('ajax:success', function() {
return gl.utils.refreshCurrentPage();
return refreshCurrentPage();
});
showBlacklistType = function() {
if ($("input[name='blacklist_type']:checked").val() === 'file') {
Loading
Loading
Loading
Loading
@@ -5,6 +5,7 @@
// %button.js-toggle-button
// %div.js-toggle-content
//
import { getLocationHash } from '../lib/utils/url_utility';
 
$(() => {
function toggleContainer(container, toggleState) {
Loading
Loading
@@ -32,7 +33,7 @@ $(() => {
 
// If we're accessing a permalink, ensure it is not inside a
// closed js-toggle-container!
const hash = window.gl.utils.getLocationHash();
const hash = getLocationHash();
const anchor = hash && document.getElementById(hash);
const container = anchor && $(anchor).closest('.js-toggle-container');
 
Loading
Loading
/* eslint-disable func-names, object-shorthand, prefer-arrow-callback */
import Dropzone from 'dropzone';
import '../lib/utils/url_utility';
import { visitUrl } from '../lib/utils/url_utility';
import { HIDDEN_CLASS } from '../lib/utils/constants';
import csrf from '../lib/utils/csrf';
 
Loading
Loading
@@ -49,7 +49,7 @@ export default class BlobFileDropzone {
});
this.on('success', function (header, response) {
$('#modal-upload-blob').modal('hide');
window.gl.utils.visitUrl(response.filePath);
visitUrl(response.filePath);
});
this.on('maxfilesexceeded', function (file) {
dropzoneMessage.addClass(HIDDEN_CLASS);
Loading
Loading
import { getLocationHash } from '../lib/utils/url_utility';
const lineNumberRe = /^L[0-9]+/;
 
const updateLineNumbersOnBlobPermalinks = (linksToUpdate) => {
const hash = gl.utils.getLocationHash();
const hash = getLocationHash();
if (hash && lineNumberRe.test(hash)) {
const hashUrlString = `#${hash}`;
 
Loading
Loading
import './lib/utils/url_utility';
import { getLocationHash } from './lib/utils/url_utility';
import FilesCommentButton from './files_comment_button';
import SingleFileDiff from './single_file_diff';
import imageDiffHelper from './image_diff/helpers/index';
Loading
Loading
@@ -31,7 +31,7 @@ export default class Diff {
isBound = true;
}
 
if (gl.utils.getLocationHash()) {
if (getLocationHash()) {
this.highlightSelectedLine();
}
 
Loading
Loading
@@ -73,7 +73,7 @@ export default class Diff {
}
 
openAnchoredDiff(cb) {
const locationHash = gl.utils.getLocationHash();
const locationHash = getLocationHash();
const anchoredDiff = locationHash && locationHash.split('_')[0];
 
if (!anchoredDiff) return;
Loading
Loading
@@ -128,7 +128,7 @@ export default class Diff {
}
// eslint-disable-next-line class-methods-use-this
highlightSelectedLine() {
const hash = gl.utils.getLocationHash();
const hash = getLocationHash();
const $diffFiles = $('.diff-file');
$diffFiles.find('.hll').removeClass('hll');
 
Loading
Loading
import * as urlUtils from '../lib/utils/url_utility';
import Flash from '../flash';
import FilteredSearchContainer from './container';
import RecentSearchesRoot from './recent_searches_root';
Loading
Loading
@@ -566,7 +567,7 @@ class FilteredSearchManager {
if (this.updateObject) {
this.updateObject(parameterizedUrl);
} else {
gl.utils.visitUrl(parameterizedUrl);
urlUtils.visitUrl(parameterizedUrl);
}
}
 
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@
/* global fuzzaldrinPlus */
import _ from 'underscore';
import fuzzaldrinPlus from 'fuzzaldrin-plus';
import * as urlUtils from './lib/utils/url_utility';
import { isObject } from './lib/utils/type_utility';
 
var GitLabDropdown, GitLabDropdownFilter, GitLabDropdownRemote, GitLabDropdownInput;
Loading
Loading
@@ -852,7 +853,7 @@ GitLabDropdown = (function() {
if ($el.length) {
var href = $el.attr('href');
if (href && href !== '#') {
gl.utils.visitUrl(href);
urlUtils.visitUrl(href);
} else {
$el.trigger('click');
}
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ import eventHub from '../event_hub';
import { getParameterByName } from '../../lib/utils/common_utils';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import { COMMON_STR } from '../constants';
import * as utils from '../../lib/utils/url_utility';
import groupsComponent from './groups.vue';
 
export default {
Loading
Loading
@@ -93,7 +93,7 @@ export default {
this.isLoading = false;
$.scrollTo(0);
 
const currentPath = gl.utils.mergeUrlParams({ page }, window.location.href);
const currentPath = utils.mergeUrlParams({ page }, window.location.href);
window.history.replaceState({
page: currentPath,
}, document.title, currentPath);
Loading
Loading
<script>
import * as urlUtils from '../../lib/utils/url_utility';
import tooltip from '../../vue_shared/directives/tooltip';
import identicon from '../../vue_shared/components/identicon.vue';
import eventHub from '../event_hub';
Loading
Loading
@@ -60,7 +61,7 @@ export default {
if (this.hasChildren) {
eventHub.$emit('toggleChildren', this.group);
} else {
gl.utils.visitUrl(this.group.relativePath);
urlUtils.visitUrl(this.group.relativePath);
}
}
},
Loading
Loading
import { visitUrl } from '../lib/utils/url_utility';
import DropLab from '../droplab/drop_lab';
import ISetter from '../droplab/plugins/input_setter';
 
Loading
Loading
@@ -54,9 +55,9 @@ export default class NewGroupChild {
 
onClickNewGroupChildButton(e) {
if (e.target.dataset.action === NEW_PROJECT) {
gl.utils.visitUrl(this.newGroupPath);
visitUrl(this.newGroupPath);
} else if (e.target.dataset.action === NEW_SUBGROUP) {
gl.utils.visitUrl(this.subgroupPath);
visitUrl(this.subgroupPath);
}
}
}
<script>
import Visibility from 'visibilityjs';
import * as urlUtils from '../../lib/utils/url_utility';
import Poll from '../../lib/utils/poll';
import eventHub from '../event_hub';
import Service from '../services/index';
Loading
Loading
@@ -8,7 +9,6 @@ import titleComponent from './title.vue';
import descriptionComponent from './description.vue';
import editedComponent from './edited.vue';
import formComponent from './form.vue';
import '../../lib/utils/url_utility';
 
export default {
props: {
Loading
Loading
@@ -169,7 +169,7 @@ export default {
.then(res => res.json())
.then((data) => {
if (location.pathname !== data.web_url) {
gl.utils.visitUrl(data.web_url);
urlUtils.visitUrl(data.web_url);
}
 
return this.service.getData();
Loading
Loading
@@ -191,7 +191,7 @@ export default {
// Stop the poll so we don't get 404's with the issuable not existing
this.poll.stop();
 
gl.utils.visitUrl(data.web_url);
urlUtils.visitUrl(data.web_url);
})
.catch(() => {
eventHub.$emit('close.form');
Loading
Loading
import _ from 'underscore';
import * as urlUtils from './lib/utils/url_utility';
import bp from './breakpoints';
import { bytesToKiB } from './lib/utils/number_utils';
import { setCiStatusFavicon } from './lib/utils/common_utils';
Loading
Loading
@@ -209,7 +210,7 @@ export default class Job {
}
 
if (log.status !== this.buildStatus) {
gl.utils.visitUrl(this.pagePath);
urlUtils.visitUrl(this.pagePath);
}
})
.fail(() => {
Loading
Loading
import { getLocationHash } from './url_utility';
 
export const getPagePath = (index = 0) => $('body').attr('data-page').split(':')[index];
 
Loading
Loading
@@ -65,7 +66,7 @@ export const disableButtonIfEmptyField = (fieldSelector, buttonSelector, eventNa
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// https://github.com/twitter/bootstrap/issues/1768
export const handleLocationHash = () => {
let hash = window.gl.utils.getLocationHash();
let hash = getLocationHash();
if (!hash) return;
 
// This is required to handle non-unicode characters in hash
Loading
Loading
Loading
Loading
@@ -17,20 +17,17 @@ export function getParameterValues(sParam) {
// @param {Object} params - url keys and value to merge
// @param {String} url
export function mergeUrlParams(params, url) {
let newUrl = Object.keys(params).reduce((accParam, paramName) => {
let newUrl = Object.keys(params).reduce((acc, paramName) => {
const paramValue = params[paramName];
const pattern = new RegExp(`\\b(${paramName}=).*?(&|$)`);
let acc = accParam;
 
if (paramValue === null) {
acc = acc.replace(pattern, '');
return acc.replace(pattern, '');
} else if (url.search(pattern) !== -1) {
acc = acc.replace(pattern, `$1${paramValue}$2`);
} else {
acc = `${accParam}${accParam.indexOf('?') > 0 ? '&' : '?'}${paramName}=${paramValue}`;
return acc.replace(pattern, `$1${paramValue}$2`);
}
 
return acc;
return `${acc}${acc.indexOf('?') > 0 ? '&' : '?'}${paramName}=${paramValue}`;
}, decodeURIComponent(url));
 
// Remove a trailing ampersand
Loading
Loading
@@ -86,15 +83,3 @@ export function refreshCurrentPage() {
export function redirectTo(url) {
return window.location.assign(url);
}
window.gl = window.gl || {};
window.gl.utils = {
...(window.gl.utils || {}),
mergeUrlParams,
getLocationHash,
getParameterValues,
redirectTo,
refreshCurrentPage,
removeParams,
visitUrl,
};
Loading
Loading
@@ -29,7 +29,7 @@ import './commit/image_file';
// lib/utils
import { handleLocationHash } from './lib/utils/common_utils';
import './lib/utils/datetime_utility';
import './lib/utils/url_utility';
import { getLocationHash, visitUrl } from './lib/utils/url_utility';
 
// behaviors
import './behaviors/';
Loading
Loading
@@ -122,7 +122,7 @@ $(function () {
// `hashchange` is not triggered when link target is already in window.location
$body.on('click', 'a[href^="#"]', function() {
var href = this.getAttribute('href');
if (href.substr(1) === gl.utils.getLocationHash()) {
if (href.substr(1) === getLocationHash()) {
setTimeout(handleLocationHash, 1);
}
});
Loading
Loading
@@ -294,7 +294,7 @@ $(function () {
const action = `${this.action}${link.search === '' ? '?' : '&'}`;
 
event.preventDefault();
gl.utils.visitUrl(`${action}${$(this).serialize()}`);
visitUrl(`${action}${$(this).serialize()}`);
});
 
const flashContainer = document.querySelector('.flash-container');
Loading
Loading
Loading
Loading
@@ -11,6 +11,7 @@ import {
handleLocationHash,
isMetaClick,
} from './lib/utils/common_utils';
import * as urlUtils from './lib/utils/url_utility';
import initDiscussionTab from './image_diff/init_discussion_tab';
import Diff from './diff';
 
Loading
Loading
@@ -317,7 +318,7 @@ import Diff from './diff';
 
// Scroll any linked note into view
// Similar to `toggler_behavior` in the discussion tab
const hash = window.gl.utils.getLocationHash();
const hash = urlUtils.getLocationHash();
const anchor = hash && $container.find(`.note[id="${hash}"]`);
if (anchor && anchor.length > 0) {
const notesContent = anchor.closest('.notes_content');
Loading
Loading
/* eslint-disable func-names, space-before-function-paren, no-var, comma-dangle, object-shorthand, no-else-return, prefer-template, quotes, prefer-arrow-callback, max-len */
import Api from './api';
import './lib/utils/url_utility';
import { mergeUrlParams } from './lib/utils/url_utility';
 
export default class NamespaceSelect {
constructor(opts) {
Loading
Loading
@@ -50,7 +50,7 @@ export default class NamespaceSelect {
}
},
url(namespace) {
return gl.utils.mergeUrlParams({ [fieldName]: namespace.id }, window.location.href);
return mergeUrlParams({ [fieldName]: namespace.id }, window.location.href);
},
});
}
Loading
Loading
Loading
Loading
@@ -16,6 +16,7 @@ import Autosize from 'autosize';
import 'vendor/jquery.caret'; // required by jquery.atwho
import 'vendor/jquery.atwho';
import AjaxCache from '~/lib/utils/ajax_cache';
import * as urlUtils from './lib/utils/url_utility';
import Flash from './flash';
import CommentTypeToggle from './comment_type_toggle';
import GLForm from './gl_form';
Loading
Loading
@@ -330,7 +331,7 @@ export default class Notes {
}
 
static updateNoteTargetSelector($note) {
const hash = gl.utils.getLocationHash();
const hash = urlUtils.getLocationHash();
// Needs to be an explicit true/false for the jQuery `toggleClass(force)`
const addTargetClass = Boolean(hash && $note.filter(`#${hash}`).length > 0);
$note.toggleClass('target', addTargetClass);
Loading
Loading
<script>
import { mapGetters, mapActions } from 'vuex';
import { getLocationHash } from '../../lib/utils/url_utility';
import Flash from '../../flash';
import store from '../stores/';
import * as constants from '../constants';
Loading
Loading
@@ -95,7 +96,7 @@
this.poll();
},
checkLocationHash() {
const hash = gl.utils.getLocationHash();
const hash = getLocationHash();
const element = document.getElementById(hash);
 
if (hash && element) {
Loading
Loading
import { getParameterByName } from '~/lib/utils/common_utils';
import '~/lib/utils/url_utility';
import * as utils from './lib/utils/url_utility';
 
(() => {
const ENDLESS_SCROLL_BOTTOM_PX = 400;
Loading
Loading
@@ -7,7 +7,7 @@ import '~/lib/utils/url_utility';
 
const Pager = {
init(limit = 0, preload = false, disable = false, prepareData = $.noop, callback = $.noop) {
this.url = $('.content_list').data('href') || gl.utils.removeParams(['limit', 'offset']);
this.url = $('.content_list').data('href') || utils.removeParams(['limit', 'offset']);
this.limit = limit;
this.offset = parseInt(getParameterByName('offset'), 10) || this.limit;
this.disable = disable;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment