Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
8784d362
Commit
8784d362
authored
Sep 18, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exports all the methods in the same place
parent
57c97a10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
25 deletions
+28
-25
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+28
-25
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
8784d362
window
.
gl
=
window
.
gl
||
{};
window
.
gl
.
utils
=
window
.
gl
.
utils
||
{};
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
data
(
'
page
'
).
split
(
'
:
'
)[
index
];
export
const
getPagePath
=
(
index
=
0
)
=>
$
(
'
body
'
).
data
(
'
page
'
).
split
(
'
:
'
)[
index
];
window
.
gl
.
utils
.
getPagePath
=
getPagePath
;
export
const
isInGroupsPage
=
()
=>
getPagePath
()
===
'
groups
'
;
export
const
isInGroupsPage
=
()
=>
getPagePath
()
===
'
groups
'
;
window
.
gl
.
utils
.
isInGroupsPage
=
isInGroupsPage
;
export
const
isInProjectPage
=
()
=>
getPagePath
()
===
'
projects
'
;
export
const
isInProjectPage
=
()
=>
getPagePath
()
===
'
projects
'
;
window
.
gl
.
utils
.
isInProjectPage
=
isInProjectPage
;
export
const
getProjectSlug
=
()
=>
{
export
const
getProjectSlug
=
()
=>
{
if
(
isInProjectPage
())
{
if
(
isInProjectPage
())
{
...
@@ -16,7 +11,6 @@ export const getProjectSlug = () => {
...
@@ -16,7 +11,6 @@ export const getProjectSlug = () => {
}
}
return
null
;
return
null
;
};
};
window
.
gl
.
utils
.
getProjectSlug
=
getProjectSlug
;
export
const
getGroupSlug
=
()
=>
{
export
const
getGroupSlug
=
()
=>
{
if
(
isInGroupsPage
())
{
if
(
isInGroupsPage
())
{
...
@@ -24,7 +18,6 @@ export const getGroupSlug = () => {
...
@@ -24,7 +18,6 @@ export const getGroupSlug = () => {
}
}
return
null
;
return
null
;
};
};
window
.
gl
.
utils
.
getGroupSlug
=
getGroupSlug
;
export
const
isInIssuePage
=
()
=>
{
export
const
isInIssuePage
=
()
=>
{
const
page
=
getPagePath
(
1
);
const
page
=
getPagePath
(
1
);
...
@@ -32,21 +25,18 @@ export const isInIssuePage = () => {
...
@@ -32,21 +25,18 @@ export const isInIssuePage = () => {
return
page
===
'
issues
'
&&
action
===
'
show
'
;
return
page
===
'
issues
'
&&
action
===
'
show
'
;
};
};
window
.
gl
.
utils
.
isInIssuePage
=
isInGroupsPage
;
export
const
ajaxGet
=
url
=>
$
.
ajax
({
export
const
ajaxGet
=
url
=>
$
.
ajax
({
type
:
'
GET
'
,
type
:
'
GET
'
,
url
,
url
,
dataType
:
'
script
'
,
dataType
:
'
script
'
,
});
});
window
.
gl
.
utils
.
ajaxGet
=
ajaxGet
;
export
const
ajaxPost
=
(
url
,
data
)
=>
$
.
ajax
({
export
const
ajaxPost
=
(
url
,
data
)
=>
$
.
ajax
({
type
:
'
POST
'
,
type
:
'
POST
'
,
url
,
url
,
data
,
data
,
});
});
window
.
gl
.
utils
.
ajaxPost
=
ajaxPost
;
export
const
rstrip
=
(
val
)
=>
{
export
const
rstrip
=
(
val
)
=>
{
if
(
val
)
{
if
(
val
)
{
...
@@ -54,10 +44,8 @@ export const rstrip = (val) => {
...
@@ -54,10 +44,8 @@ export const rstrip = (val) => {
}
}
return
val
;
return
val
;
};
};
window
.
gl
.
utils
.
rstrip
=
rstrip
;
export
const
updateTooltipTitle
=
(
$tooltipEl
,
newTitle
)
=>
$tooltipEl
.
attr
(
'
title
'
,
newTitle
).
tooltip
(
'
fixTitle
'
);
export
const
updateTooltipTitle
=
(
$tooltipEl
,
newTitle
)
=>
$tooltipEl
.
attr
(
'
title
'
,
newTitle
).
tooltip
(
'
fixTitle
'
);
window
.
gl
.
utils
.
updateTooltipTitle
=
updateTooltipTitle
;
export
const
disableButtonIfEmptyField
=
(
fieldSelector
,
buttonSelector
,
eventName
=
'
input
'
)
=>
{
export
const
disableButtonIfEmptyField
=
(
fieldSelector
,
buttonSelector
,
eventName
=
'
input
'
)
=>
{
const
field
=
$
(
fieldSelector
);
const
field
=
$
(
fieldSelector
);
...
@@ -73,7 +61,6 @@ export const disableButtonIfEmptyField = (fieldSelector, buttonSelector, eventNa
...
@@ -73,7 +61,6 @@ export const disableButtonIfEmptyField = (fieldSelector, buttonSelector, eventNa
return
closestSubmit
.
enable
();
return
closestSubmit
.
enable
();
});
});
};
};
window
.
gl
.
utils
.
disableButtonIfEmptyField
=
disableButtonIfEmptyField
;
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// automatically adjust scroll position for hash urls taking the height of the navbar into account
// https://github.com/twitter/bootstrap/issues/1768
// https://github.com/twitter/bootstrap/issues/1768
...
@@ -111,7 +98,6 @@ export const handleLocationHash = () => {
...
@@ -111,7 +98,6 @@ export const handleLocationHash = () => {
window
.
scrollBy
(
0
,
adjustment
);
window
.
scrollBy
(
0
,
adjustment
);
}
}
};
};
window
.
gl
.
utils
.
handleLocationHash
=
handleLocationHash
;
// Check if element scrolled into viewport from above or below
// Check if element scrolled into viewport from above or below
// Courtesy http://stackoverflow.com/a/7557433/414749
// Courtesy http://stackoverflow.com/a/7557433/414749
...
@@ -125,14 +111,12 @@ export const isInViewport = (el) => {
...
@@ -125,14 +111,12 @@ export const isInViewport = (el) => {
rect
.
right
<=
window
.
innerWidth
rect
.
right
<=
window
.
innerWidth
);
);
};
};
window
.
gl
.
utils
.
isInViewport
=
isInViewport
;
export
const
parseUrl
=
(
url
)
=>
{
export
const
parseUrl
=
(
url
)
=>
{
const
parser
=
document
.
createElement
(
'
a
'
);
const
parser
=
document
.
createElement
(
'
a
'
);
parser
.
href
=
url
;
parser
.
href
=
url
;
return
parser
;
return
parser
;
};
};
window
.
gl
.
utils
.
parseUrl
=
parseUrl
;
export
const
parseUrlPathname
=
(
url
)
=>
{
export
const
parseUrlPathname
=
(
url
)
=>
{
const
parsedUrl
=
parseUrl
(
url
);
const
parsedUrl
=
parseUrl
(
url
);
...
@@ -140,7 +124,6 @@ export const parseUrlPathname = (url) => {
...
@@ -140,7 +124,6 @@ export const parseUrlPathname = (url) => {
// We have to make sure we always have an absolute path.
// We have to make sure we always have an absolute path.
return
parsedUrl
.
pathname
.
charAt
(
0
)
===
'
/
'
?
parsedUrl
.
pathname
:
`/
${
parsedUrl
.
pathname
}
`
;
return
parsedUrl
.
pathname
.
charAt
(
0
)
===
'
/
'
?
parsedUrl
.
pathname
:
`/
${
parsedUrl
.
pathname
}
`
;
};
};
window
.
gl
.
utils
.
parseUrlPathname
=
parseUrlPathname
;
// We can trust that each param has one & since values containing & will be encoded
// We can trust that each param has one & since values containing & will be encoded
// Remove the first character of search as it is always ?
// Remove the first character of search as it is always ?
...
@@ -148,17 +131,14 @@ export const getUrlParamsArray = () => window.location.search.slice(1).split('&'
...
@@ -148,17 +131,14 @@ export const getUrlParamsArray = () => window.location.search.slice(1).split('&'
const
split
=
param
.
split
(
'
=
'
);
const
split
=
param
.
split
(
'
=
'
);
return
[
decodeURI
(
split
[
0
]),
split
[
1
]].
join
(
'
=
'
);
return
[
decodeURI
(
split
[
0
]),
split
[
1
]].
join
(
'
=
'
);
});
});
window
.
gl
.
utils
.
getUrlParamsArray
=
getUrlParamsArray
;
export
const
isMetaKey
=
e
=>
e
.
metaKey
||
e
.
ctrlKey
||
e
.
altKey
||
e
.
shiftKey
;
export
const
isMetaKey
=
e
=>
e
.
metaKey
||
e
.
ctrlKey
||
e
.
altKey
||
e
.
shiftKey
;
window
.
gl
.
utils
.
isMetaKey
=
isMetaKey
;
// Identify following special clicks
// Identify following special clicks
// 1) Cmd + Click on Mac (e.metaKey)
// 1) Cmd + Click on Mac (e.metaKey)
// 2) Ctrl + Click on PC (e.ctrlKey)
// 2) Ctrl + Click on PC (e.ctrlKey)
// 3) Middle-click or Mouse Wheel Click (e.which is 2)
// 3) Middle-click or Mouse Wheel Click (e.which is 2)
export
const
isMetaClick
=
e
=>
e
.
metaKey
||
e
.
ctrlKey
||
e
.
which
===
2
;
export
const
isMetaClick
=
e
=>
e
.
metaKey
||
e
.
ctrlKey
||
e
.
which
===
2
;
window
.
gl
.
utils
.
isMetaClick
=
isMetaClick
;
export
const
scrollToElement
=
(
$el
)
=>
{
export
const
scrollToElement
=
(
$el
)
=>
{
const
top
=
$el
.
offset
().
top
;
const
top
=
$el
.
offset
().
top
;
...
@@ -169,7 +149,6 @@ export const scrollToElement = ($el) => {
...
@@ -169,7 +149,6 @@ export const scrollToElement = ($el) => {
scrollTop
:
top
-
mrTabsHeight
-
headerHeight
,
scrollTop
:
top
-
mrTabsHeight
-
headerHeight
,
},
200
);
},
200
);
};
};
window
.
gl
.
utils
.
scrollToElement
=
scrollToElement
;
/**
/**
this will take in the `name` of the param you want to parse in the url
this will take in the `name` of the param you want to parse in the url
...
@@ -185,7 +164,6 @@ export const getParameterByName = (name, urlToParse) => {
...
@@ -185,7 +164,6 @@ export const getParameterByName = (name, urlToParse) => {
if
(
!
results
[
2
])
return
''
;
if
(
!
results
[
2
])
return
''
;
return
decodeURIComponent
(
results
[
2
].
replace
(
/
\+
/g
,
'
'
));
return
decodeURIComponent
(
results
[
2
].
replace
(
/
\+
/g
,
'
'
));
};
};
window
.
gl
.
utils
.
getParameterByName
=
getParameterByName
;
export
const
getSelectedFragment
=
()
=>
{
export
const
getSelectedFragment
=
()
=>
{
const
selection
=
window
.
getSelection
();
const
selection
=
window
.
getSelection
();
...
@@ -198,7 +176,6 @@ export const getSelectedFragment = () => {
...
@@ -198,7 +176,6 @@ export const getSelectedFragment = () => {
return
documentFragment
;
return
documentFragment
;
};
};
window
.
gl
.
utils
.
getSelectedFragment
=
getSelectedFragment
;
// TODO: Update this name, there is a gl.text.insertText function.
// TODO: Update this name, there is a gl.text.insertText function.
export
const
insertText
=
(
target
,
text
)
=>
{
export
const
insertText
=
(
target
,
text
)
=>
{
...
@@ -226,7 +203,6 @@ export const insertText = (target, text) => {
...
@@ -226,7 +203,6 @@ export const insertText = (target, text) => {
event
.
initEvent
(
'
autosize:update
'
,
true
,
false
);
event
.
initEvent
(
'
autosize:update
'
,
true
,
false
);
target
.
dispatchEvent
(
event
);
target
.
dispatchEvent
(
event
);
};
};
window
.
gl
.
utils
.
insertText
=
insertText
;
export
const
nodeMatchesSelector
=
(
node
,
selector
)
=>
{
export
const
nodeMatchesSelector
=
(
node
,
selector
)
=>
{
const
matches
=
Element
.
prototype
.
matches
||
const
matches
=
Element
.
prototype
.
matches
||
...
@@ -253,7 +229,6 @@ export const nodeMatchesSelector = (node, selector) => {
...
@@ -253,7 +229,6 @@ export const nodeMatchesSelector = (node, selector) => {
const
matchingNodes
=
parentNode
.
querySelectorAll
(
selector
);
const
matchingNodes
=
parentNode
.
querySelectorAll
(
selector
);
return
Array
.
prototype
.
indexOf
.
call
(
matchingNodes
,
node
)
!==
-
1
;
return
Array
.
prototype
.
indexOf
.
call
(
matchingNodes
,
node
)
!==
-
1
;
};
};
window
.
gl
.
utils
.
nodeMatchesSelector
=
nodeMatchesSelector
;
/**
/**
this will take in the headers from an API response and normalize them
this will take in the headers from an API response and normalize them
...
@@ -432,3 +407,31 @@ export const setCiStatusFavicon = (pageUrl) => {
...
@@ -432,3 +407,31 @@ export const setCiStatusFavicon = (pageUrl) => {
},
},
});
});
};
};
window
.
gl
=
window
.
gl
||
{};
window
.
gl
.
utils
=
{
...(
window
.
gl
.
utils
||
{}),
getPagePath
,
isInGroupsPage
,
isInProjectPage
,
getProjectSlug
,
getGroupSlug
,
isInIssuePage
,
ajaxGet
,
ajaxPost
,
rstrip
,
updateTooltipTitle
,
disableButtonIfEmptyField
,
handleLocationHash
,
isInViewport
,
parseUrl
,
parseUrlPathname
,
getUrlParamsArray
,
isMetaKey
,
isMetaClick
,
scrollToElement
,
getParameterByName
,
getSelectedFragment
,
insertText
,
nodeMatchesSelector
,
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment