BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
5f7b4cb5
Commit
5f7b4cb5
authored
Apr 21, 2017
by
Eric Eastwood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use jQuery niceness on blob_fork_suggestion
Fix
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10602#note_27871752
parent
9c35162f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
44 deletions
+43
-44
blob_fork_suggestion.js
app/assets/javascripts/blob/blob_fork_suggestion.js
+25
-28
dispatcher.js
app/assets/javascripts/dispatcher.js
+2
-1
blob_fork_suggestion_spec.js
spec/javascripts/blob/blob_fork_suggestion_spec.js
+16
-15
No files found.
app/assets/javascripts/blob/blob_fork_suggestion.js
View file @
5f7b4cb5
...
...
@@ -16,47 +16,44 @@ const defaults = {
class
BlobForkSuggestion
{
constructor
(
options
)
{
this
.
elementMap
=
Object
.
assign
({},
defaults
,
options
);
this
.
onClickWrapper
=
this
.
onClick
.
bind
(
this
);
document
.
addEventListener
(
'click'
,
this
.
onClickWrapper
);
this
.
onOpenButtonClick
=
this
.
onOpenButtonClick
.
bind
(
this
);
this
.
onCancelButtonClick
=
this
.
onCancelButtonClick
.
bind
(
this
);
}
showSuggestionSection
(
forkPath
,
action
=
'edit'
)
{
[].
forEach
.
call
(
this
.
elementMap
.
suggestionSections
,
(
suggestionSection
)
=>
{
suggestionSection
.
classList
.
remove
(
'hidden'
);
});
init
()
{
this
.
bindEvents
();
[].
forEach
.
call
(
this
.
elementMap
.
forkButtons
,
(
forkButton
)
=>
{
forkButton
.
setAttribute
(
'href'
,
forkPath
);
});
return
this
;
}
[].
forEach
.
call
(
this
.
elementMap
.
actionTextPieces
,
(
actionTextPiece
)
=>
{
// eslint-disable-next-line no-param-reassign
actionTextPiece
.
textContent
=
action
;
});
bindEvents
()
{
$
(
this
.
elementMap
.
openButtons
).
on
(
'click'
,
this
.
onOpenButtonClick
);
$
(
this
.
elementMap
.
cancelButtons
).
on
(
'click'
,
this
.
onCancelButtonClick
);
}
hideSuggestionSection
(
)
{
[].
forEach
.
call
(
this
.
elementMap
.
suggestionSections
,
(
suggestionSection
)
=>
{
suggestionSection
.
classList
.
add
(
'hidden'
);
}
);
showSuggestionSection
(
forkPath
,
action
=
'edit'
)
{
$
(
this
.
elementMap
.
suggestionSections
).
removeClass
(
'hidden'
);
$
(
this
.
elementMap
.
forkButtons
).
attr
(
'href'
,
forkPath
);
$
(
this
.
elementMap
.
actionTextPieces
).
text
(
action
);
}
onClick
(
e
)
{
const
el
=
e
.
target
;
hideSuggestionSection
()
{
$
(
this
.
elementMap
.
suggestionSections
).
addClass
(
'hidden'
);
}
if
([].
includes
.
call
(
this
.
elementMap
.
openButtons
,
el
))
{
const
{
forkPath
,
action
}
=
el
.
dataset
;
this
.
showSuggestionSection
(
forkPath
,
action
);
}
onOpenButtonClick
(
e
)
{
const
forkPath
=
$
(
e
.
currentTarget
).
attr
(
'data-fork-path'
);
const
action
=
$
(
e
.
currentTarget
).
attr
(
'data-action'
);
this
.
showSuggestionSection
(
forkPath
,
action
);
}
if
([].
includes
.
call
(
this
.
elementMap
.
cancelButtons
,
el
))
{
this
.
hideSuggestionSection
();
}
onCancelButtonClick
()
{
this
.
hideSuggestionSection
();
}
destroy
()
{
document
.
removeEventListener
(
'click'
,
this
.
onClickWrapper
);
$
(
this
.
elementMap
.
openButtons
).
off
(
'click'
,
this
.
onOpenButtonClick
);
$
(
this
.
elementMap
.
cancelButtons
).
off
(
'click'
,
this
.
onCancelButtonClick
);
}
}
...
...
app/assets/javascripts/dispatcher.js
View file @
5f7b4cb5
...
...
@@ -97,7 +97,8 @@ const ShortcutsBlob = require('./shortcuts_blob');
cancelButtons
:
document
.
querySelectorAll
(
'.js-cancel-fork-suggestion-button'
),
suggestionSections
:
document
.
querySelectorAll
(
'.js-file-fork-suggestion-section'
),
actionTextPieces
:
document
.
querySelectorAll
(
'.js-file-fork-suggestion-section-action'
),
});
})
.
init
();
}
switch
(
page
)
{
...
...
spec/javascripts/blob/blob_fork_suggestion_spec.js
View file @
5f7b4cb5
...
...
@@ -3,20 +3,21 @@ import BlobForkSuggestion from '~/blob/blob_fork_suggestion';
describe
(
'BlobForkSuggestion'
,
()
=>
{
let
blobForkSuggestion
;
const
openButton
s
=
[
document
.
createElement
(
'div'
)]
;
const
forkButton
s
=
[
document
.
createElement
(
'a'
)]
;
const
cancelButton
s
=
[
document
.
createElement
(
'div'
)]
;
const
suggestionSection
s
=
[
document
.
createElement
(
'div'
)]
;
const
actionTextPiece
s
=
[
document
.
createElement
(
'div'
)]
;
const
openButton
=
document
.
createElement
(
'div'
)
;
const
forkButton
=
document
.
createElement
(
'a'
)
;
const
cancelButton
=
document
.
createElement
(
'div'
)
;
const
suggestionSection
=
document
.
createElement
(
'div'
)
;
const
actionTextPiece
=
document
.
createElement
(
'div'
)
;
beforeEach
(()
=>
{
blobForkSuggestion
=
new
BlobForkSuggestion
({
openButtons
,
forkButtons
,
cancelButtons
,
suggestionSections
,
actionTextPieces
,
});
openButtons
:
openButton
,
forkButtons
:
forkButton
,
cancelButtons
:
cancelButton
,
suggestionSections
:
suggestionSection
,
actionTextPieces
:
actionTextPiece
,
})
.
init
();
});
afterEach
(()
=>
{
...
...
@@ -25,13 +26,13 @@ describe('BlobForkSuggestion', () => {
it
(
'showSuggestionSection'
,
()
=>
{
blobForkSuggestion
.
showSuggestionSection
(
'/foo'
,
'foo'
);
expect
(
suggestionSection
s
[
0
]
.
classList
.
contains
(
'hidden'
)).
toEqual
(
false
);
expect
(
forkButton
s
[
0
]
.
getAttribute
(
'href'
)).
toEqual
(
'/foo'
);
expect
(
actionTextPiece
s
[
0
]
.
textContent
).
toEqual
(
'foo'
);
expect
(
suggestionSection
.
classList
.
contains
(
'hidden'
)).
toEqual
(
false
);
expect
(
forkButton
.
getAttribute
(
'href'
)).
toEqual
(
'/foo'
);
expect
(
actionTextPiece
.
textContent
).
toEqual
(
'foo'
);
});
it
(
'hideSuggestionSection'
,
()
=>
{
blobForkSuggestion
.
hideSuggestionSection
();
expect
(
suggestionSection
s
[
0
]
.
classList
.
contains
(
'hidden'
)).
toEqual
(
true
);
expect
(
suggestionSection
.
classList
.
contains
(
'hidden'
)).
toEqual
(
true
);
});
});
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