1
|
|
|
const { NodeForm } = require('./NodeForm'); |
2
|
|
|
|
3
|
|
|
class MediaForm extends NodeForm { |
4
|
|
|
constructor(id = 'prosemirror-mediaform') { |
5
|
|
|
super(id); |
6
|
|
|
|
7
|
|
|
this.name = 'Image Configuration'; |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
setSource(id = '') { |
11
|
|
|
this.$form.find('[name="mediatarget"]').val(id); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
getSource() { |
15
|
|
|
return this.$form.find('[name="mediatarget"]').val(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
setCaption(caption = '') { |
19
|
|
|
this.$form.find('[name="mediacaption"]').val(caption); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
getCaption() { |
23
|
|
|
return this.$form.find('[name="mediacaption"]').val(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
setWidth(width = '') { |
27
|
|
|
this.$form.find('[name="width"]').val(width); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
getWidth() { |
31
|
|
|
return this.$form.find('[name="width"]').val(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
setHeight(height = '') { |
35
|
|
|
this.$form.find('[name="height"]').val(height); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
getHeight() { |
39
|
|
|
return this.$form.find('[name="height"]').val(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
setAlignment(alignment = '') { |
43
|
|
|
this.$form.find('[name="alignment"]').prop('checked', ''); |
44
|
|
|
this.$form.find(`[name="alignment"][value="${alignment}"]`).prop('checked', 'checked'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
getAlignment() { |
48
|
|
|
return this.$form.find('[name="alignment"]:checked').val(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
setLinking(linking = 'details') { |
52
|
|
|
this.$form.find('[name="linking"]').prop('checked', ''); |
53
|
|
|
this.$form.find(`[name="linking"][value="${linking}"]`).prop('checked', 'checked'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
getLinking() { |
57
|
|
|
return this.$form.find('[name="linking"]:checked').val(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
setCache(cache = '') { |
61
|
|
|
this.$form.find('[name="caching"]').prop('checked', ''); |
62
|
|
|
this.$form.find(`[name="caching"][value="${cache}"]`).prop('checked', 'checked'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
getCache() { |
66
|
|
|
return this.$form.find('[name="caching"]:checked').val(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
resetForm() { |
70
|
|
|
this.setSource(); |
71
|
|
|
this.setCaption(); |
72
|
|
|
this.setWidth(); |
73
|
|
|
this.setHeight(); |
74
|
|
|
this.setAlignment(); |
75
|
|
|
this.setLinking(); |
76
|
|
|
this.setCache(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
static resolveSubmittedLinkData(initialAttrs, $mediaForm, callback) { |
80
|
|
|
return (event) => { |
81
|
|
|
event.preventDefault(); |
82
|
|
|
const newAttrs = { ...initialAttrs }; |
83
|
|
|
newAttrs.id = $mediaForm.getSource(); |
84
|
|
|
newAttrs.title = $mediaForm.getCaption(); |
85
|
|
|
newAttrs.width = $mediaForm.getWidth(); |
86
|
|
|
newAttrs.height = $mediaForm.getHeight(); |
87
|
|
|
newAttrs.align = $mediaForm.getAlignment(); |
88
|
|
|
newAttrs.linking = $mediaForm.getLinking(); |
89
|
|
|
newAttrs.cache = $mediaForm.getCache(); |
90
|
|
|
|
91
|
|
|
jQuery.get( |
92
|
|
|
`${DOKU_BASE}/lib/exe/ajax.php`, |
93
|
|
|
{ |
94
|
|
|
call: 'plugin_prosemirror', |
95
|
|
|
actions: ['resolveMedia'], |
96
|
|
|
attrs: newAttrs, |
97
|
|
|
id: JSINFO.id, |
98
|
|
|
}, |
99
|
|
|
).done((data) => { |
100
|
|
|
const parsedData = JSON.parse(data); |
101
|
|
|
newAttrs['data-resolvedHtml'] = parsedData.resolveMedia['data-resolvedHtml']; |
102
|
|
|
console.log(newAttrs); |
103
|
|
|
callback(newAttrs); |
104
|
|
|
}); |
105
|
|
|
}; |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
exports.MediaForm = MediaForm; |
109
|
|
|
|