-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
61 lines (48 loc) · 1.45 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;(function(win) {
function isFunction(functionToCheck) {
return functionToCheck && {}.toString.call(functionToCheck) === '[object Function]'
}
win.EditOnGithubPlugin = {}
function create(docBase, docEditBase, title) {
title = title || 'Edit on GitHub'
docEditBase = docEditBase || docBase.replace(/\/blob\//, '/edit/')
function editDoc(event, vm) {
var docName = vm.route.file
if (docName) {
var editLink = docEditBase + docName
window.open(editLink)
event.preventDefault()
return false
} else {
return true
}
}
win.EditOnGithubPlugin.editDoc = editDoc
function generateHeader(title) {
return header = [
'<div style="overflow: auto">',
'<p style="float: right"><a style="text-decoration: underline; cursor: pointer"',
'onclick="EditOnGithubPlugin.onClick(event)">',
title,
'</a></p>',
'</div>'
].join('')
}
return function(hook, vm) {
win.EditOnGithubPlugin.onClick = function(event) {
EditOnGithubPlugin.editDoc(event, vm)
}
if (isFunction(title)) {
hook.afterEach(function (html) {
return generateHeader(title(vm.route.file)) + html
})
} else {
var header = generateHeader(title)
hook.afterEach(function (html) {
return header + html
})
}
}
}
win.EditOnGithubPlugin.create = create
}) (window)