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
Jérome Perrin
gitlab-ce
Commits
796acbe1
Commit
796acbe1
authored
Apr 13, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add BlobViewer JS
parent
3079a2d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
135 additions
and
0 deletions
+135
-0
app/assets/javascripts/blob/viewer/index.js
app/assets/javascripts/blob/viewer/index.js
+130
-0
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+2
-0
app/views/projects/blob/show.html.haml
app/views/projects/blob/show.html.haml
+3
-0
No files found.
app/assets/javascripts/blob/viewer/index.js
0 → 100644
View file @
796acbe1
``
/* eslint-disable no-new */
/* global Flash */
export
default
class
BlobViewer
{
constructor
()
{
this
.
switcherBtns
=
document
.
querySelectorAll
(
'
.js-blob-viewer-switcher
'
);
this
.
copySourceBtn
=
document
.
querySelector
(
'
.js-copy-blob-source-btn
'
);
this
.
simpleViewer
=
document
.
querySelector
(
'
.blob-viewer[data-type="simple"]
'
);
this
.
richViewer
=
document
.
querySelector
(
'
.blob-viewer[data-type="rich"]
'
);
this
.
$blobContentHolder
=
$
(
'
#blob-content-holder
'
);
let
initialViewerName
=
document
.
querySelector
(
'
.blob-viewer:not(.hidden)
'
).
getAttribute
(
'
data-type
'
);
if
(
this
.
switcherBtns
.
length
)
{
this
.
initBindings
();
if
(
location
.
hash
.
indexOf
(
'
#L
'
)
===
0
)
{
initialViewerName
=
'
simple
'
;
}
}
this
.
switchToViewer
(
initialViewerName
);
}
initBindings
()
{
Array
.
from
(
this
.
switcherBtns
)
.
forEach
((
el
)
=>
{
el
.
addEventListener
(
'
click
'
,
this
.
switchViewHandler
.
bind
(
this
));
});
if
(
this
.
copySourceBtn
)
{
this
.
copySourceBtn
.
addEventListener
(
'
click
'
,
()
=>
{
if
(
this
.
copySourceBtn
.
classList
.
contains
(
'
disabled
'
))
return
;
this
.
switchToViewer
(
'
simple
'
);
});
}
}
switchViewHandler
(
e
)
{
const
target
=
e
.
currentTarget
;
e
.
preventDefault
();
this
.
switchToViewer
(
target
.
getAttribute
(
'
data-viewer
'
));
}
toggleCopyButtonState
()
{
if
(
!
this
.
copySourceBtn
)
return
;
if
(
this
.
simpleViewer
.
getAttribute
(
'
data-loaded
'
))
{
this
.
copySourceBtn
.
setAttribute
(
'
title
'
,
'
Copy source to clipboard
'
);
this
.
copySourceBtn
.
classList
.
remove
(
'
disabled
'
);
}
else
if
(
this
.
activeViewer
==
this
.
simpleViewer
)
{
this
.
copySourceBtn
.
setAttribute
(
'
title
'
,
'
Wait for the source to load to copy it to the clipboard
'
);
this
.
copySourceBtn
.
classList
.
add
(
'
disabled
'
);
}
else
{
this
.
copySourceBtn
.
setAttribute
(
'
title
'
,
'
Switch to the source to copy it to the clipboard
'
);
this
.
copySourceBtn
.
classList
.
add
(
'
disabled
'
);
}
$
(
this
.
copySourceBtn
).
tooltip
(
'
fixTitle
'
);
}
loadViewer
(
viewerParam
,
resolve
,
reject
)
{
const
viewer
=
viewerParam
;
const
url
=
viewer
.
getAttribute
(
'
data-url
'
);
if
(
!
url
||
viewer
.
getAttribute
(
'
data-loaded
'
)
||
viewer
.
getAttribute
(
'
data-loading
'
))
{
if
(
resolve
)
resolve
();
return
;
}
viewer
.
setAttribute
(
'
data-loading
'
,
'
true
'
);
$
.
ajax
({
url
,
dataType
:
'
JSON
'
,
})
.
fail
(()
=>
{
if
(
reject
)
reject
();
})
.
done
((
data
)
=>
{
viewer
.
innerHTML
=
data
.
html
;
$
(
viewer
).
syntaxHighlight
();
viewer
.
setAttribute
(
'
data-loaded
'
,
'
true
'
);
this
.
$blobContentHolder
.
trigger
(
'
highlight:line
'
);
this
.
toggleCopyButtonState
();
if
(
resolve
)
resolve
();
});
}
switchToViewer
(
name
)
{
const
newViewer
=
document
.
querySelector
(
`.blob-viewer[data-type='
${
name
}
']`
);
if
(
this
.
activeViewer
==
newViewer
)
return
;
const
oldButton
=
document
.
querySelector
(
'
.js-blob-viewer-switcher.active
'
)
const
newButton
=
document
.
querySelector
(
`.js-blob-viewer-switcher[data-viewer='
${
name
}
']`
);
const
oldViewer
=
document
.
querySelector
(
`.blob-viewer:not([data-type='
${
name
}
'])`
);
if
(
oldButton
)
{
oldButton
.
classList
.
remove
(
'
active
'
);
}
if
(
newButton
)
{
newButton
.
classList
.
add
(
'
active
'
);
newButton
.
blur
();
}
if
(
oldViewer
)
{
oldViewer
.
classList
.
add
(
'
hidden
'
);
}
newViewer
.
classList
.
remove
(
'
hidden
'
);
this
.
activeViewer
=
newViewer
;
this
.
toggleCopyButtonState
();
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
loadViewer
(
newViewer
,
resolve
,
reject
);
})
.
catch
(()
=>
{
new
Flash
(
'
Error loading file
'
);
});
}
}
app/assets/javascripts/dispatcher.js
View file @
796acbe1
...
@@ -48,6 +48,7 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion';
...
@@ -48,6 +48,7 @@ import BlobForkSuggestion from './blob/blob_fork_suggestion';
import
UserCallout
from
'
./user_callout
'
;
import
UserCallout
from
'
./user_callout
'
;
import
{
ProtectedTagCreate
,
ProtectedTagEditList
}
from
'
./protected_tags
'
;
import
{
ProtectedTagCreate
,
ProtectedTagEditList
}
from
'
./protected_tags
'
;
import
ShortcutsWiki
from
'
./shortcuts_wiki
'
;
import
ShortcutsWiki
from
'
./shortcuts_wiki
'
;
import
BlobViewer
from
'
./blob/viewer/index
'
;
const
ShortcutsBlob
=
require
(
'
./shortcuts_blob
'
);
const
ShortcutsBlob
=
require
(
'
./shortcuts_blob
'
);
...
@@ -299,6 +300,7 @@ const ShortcutsBlob = require('./shortcuts_blob');
...
@@ -299,6 +300,7 @@ const ShortcutsBlob = require('./shortcuts_blob');
gl
.
TargetBranchDropDown
.
bootstrap
();
gl
.
TargetBranchDropDown
.
bootstrap
();
break
;
break
;
case
'
projects:blob:show
'
:
case
'
projects:blob:show
'
:
new
BlobViewer
();
gl
.
TargetBranchDropDown
.
bootstrap
();
gl
.
TargetBranchDropDown
.
bootstrap
();
initBlob
();
initBlob
();
break
;
break
;
...
...
app/views/projects/blob/show.html.haml
View file @
796acbe1
...
@@ -2,6 +2,9 @@
...
@@ -2,6 +2,9 @@
-
page_title
@blob
.
path
,
@ref
-
page_title
@blob
.
path
,
@ref
=
render
"projects/commits/head"
=
render
"projects/commits/head"
-
content_for
:page_specific_javascripts
do
=
page_specific_javascript_bundle_tag
(
'blob'
)
%div
{
class:
container_class
}
%div
{
class:
container_class
}
=
render
'projects/last_push'
=
render
'projects/last_push'
...
...
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