Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
footnotes-3486079
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
footnotes-3486079
Commits
80d92e69
Commit
80d92e69
authored
4 months ago
by
Scott Euser
Browse files
Options
Downloads
Patches
Plain Diff
Merge
parent
d2cc40df
Branches
2.0.x
Branches containing commit
Tags
2.0.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
assets/js/build/footnotes.js
+1
-1
1 addition, 1 deletion
assets/js/build/footnotes.js
assets/js/ckeditor5_plugins/footnotes/src/footnotesediting.js
+11
-17
11 additions, 17 deletions
...ts/js/ckeditor5_plugins/footnotes/src/footnotesediting.js
with
12 additions
and
18 deletions
assets/js/build/footnotes.js
+
1
−
1
View file @
80d92e69
!
function
(
e
,
t
){
"
object
"
==
typeof
exports
&&
"
object
"
==
typeof
module
?
module
.
exports
=
t
():
"
function
"
==
typeof
define
&&
define
.
amd
?
define
([],
t
):
"
object
"
==
typeof
exports
?
exports
.
CKEditor5
=
t
():(
e
.
CKEditor5
=
e
.
CKEditor5
||
{},
e
.
CKEditor5
.
footnotes
=
t
())}(
self
,(()
=>
(()
=>
{
var
e
=
{
"
ckeditor5/src/core.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/core.js
"
)},
"
ckeditor5/src/engine.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/engine.js
"
)},
"
ckeditor5/src/ui.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/ui.js
"
)},
"
ckeditor5/src/widget.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/widget.js
"
)},
"
dll-reference CKEditor5.dll
"
:
e
=>
{
"
use strict
"
;
e
.
exports
=
CKEditor5
.
dll
}},
t
=
{};
function
o
(
n
){
var
r
=
t
[
n
];
if
(
void
0
!==
r
)
return
r
.
exports
;
var
s
=
t
[
n
]
=
{
exports
:{}};
return
e
[
n
](
s
,
s
.
exports
,
o
),
s
.
exports
}
o
.
d
=
(
e
,
t
)
=>
{
for
(
var
n
in
t
)
o
.
o
(
t
,
n
)
&&!
o
.
o
(
e
,
n
)
&&
Object
.
defineProperty
(
e
,
n
,{
enumerable
:
!
0
,
get
:
t
[
n
]})},
o
.
o
=
(
e
,
t
)
=>
Object
.
prototype
.
hasOwnProperty
.
call
(
e
,
t
);
var
n
=
{};
return
(()
=>
{
"
use strict
"
;
o
.
d
(
n
,{
default
:()
=>
m
});
var
e
=
o
(
"
ckeditor5/src/core.js
"
),
t
=
o
(
"
ckeditor5/src/widget.js
"
);
class
r
extends
e
.
Command
{
execute
(
e
){
const
t
=
this
.
editor
.
plugins
.
get
(
"
footnotesEditing
"
),
o
=
Object
.
entries
(
t
.
attrs
).
reduce
(((
e
,[
t
,
o
])
=>
(
e
[
o
]
=
t
,
e
)),{}),
n
=
Object
.
keys
(
e
).
reduce
(((
t
,
n
)
=>
(
o
[
n
]
&&
(
void
0
!==
e
[
n
].
value
?
t
[
o
[
n
]]
=
e
[
n
].
value
:
t
[
o
[
n
]]
=
e
[
n
]),
t
)),{});
this
.
editor
.
model
.
change
((
e
=>
{
this
.
editor
.
model
.
insertContent
(
function
(
e
,
t
){
return
e
.
createElement
(
"
footnotes
"
,
t
)}(
e
,
n
))}))}
refresh
(){
const
{
model
:
e
}
=
this
.
editor
,{
selection
:
t
}
=
e
.
document
,
o
=
e
.
schema
.
findAllowedParent
(
t
.
getFirstPosition
(),
"
footnotes
"
);
this
.
isEnabled
=
null
!==
o
}}
function
s
(){
return
new
URLSearchParams
(
window
.
location
.
search
).
has
(
"
debug
"
)}
function
i
(
e
){
s
()
&&
(
console
.
log
(
"
Content received from paste pipeline:
"
),
console
.
log
(
e
));
e
.
querySelectorAll
(
'
.sdfootnote, [id*="ftn"] > p, [id*="sdfootnote"] > p
'
).
forEach
((
t
=>
{
let
o
=
function
(
e
){
if
(
"
string
"
!=
typeof
e
)
throw
new
Error
(
"
Expected a string as input, got:
"
+
typeof
e
);
const
t
=
(
new
DOMParser
).
parseFromString
(
e
,
"
text/html
"
),
o
=
document
.
createDocumentFragment
();
Array
.
from
(
t
.
body
.
childNodes
).
forEach
((
function
e
(
t
){
if
(
t
.
nodeType
===
Node
.
ELEMENT_NODE
){
const
n
=
t
.
tagName
.
toLowerCase
();
if
(
"
b
"
===
n
||
"
strong
"
===
n
){
const
e
=
document
.
createElement
(
"
b
"
);
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}
else
if
(
"
i
"
===
n
||
"
em
"
===
n
){
const
e
=
document
.
createElement
(
"
i
"
);
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}
else
if
(
"
a
"
===
n
){
const
e
=
t
.
href
.
split
(
"
#
"
)[
1
]
||
""
;
if
(
!
e
.
startsWith
(
"
sdfootnote
"
)
&&!
e
.
startsWith
(
"
ftn
"
)
&&!
e
.
startsWith
(
"
_ftn
"
)){
const
e
=
document
.
createElement
(
"
a
"
);
e
.
href
=
t
.
href
,
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}}
else
Array
.
from
(
t
.
childNodes
).
forEach
(
e
)}
else
t
.
nodeType
===
Node
.
TEXT_NODE
&&
o
.
appendChild
(
document
.
createTextNode
(
t
.
textContent
))}));
const
n
=
document
.
createElement
(
"
div
"
);
return
n
.
appendChild
(
o
),
n
.
innerHTML
.
trim
()}(
t
.
innerHTML
);
const
n
=
t
.
querySelector
(
'
.sdfootnotesym, [ href*="_ftnref"]
'
);
if
(
n
){
let
t
=
n
.
getAttribute
(
"
href
"
).
replace
(
/anc|ref|_/g
,
""
);
t
=
`#
${
t
.
split
(
"
#
"
).
pop
()}
`
;
const
r
=
e
.
querySelector
(
`.sdfootnoteanc[href*="
${
t
}
sym"], [href*="_ftn"]`
),
i
=
e
.
querySelector
(
`div
${
t
}
`
),
c
=
""
;
if
(
r
){
if
(
!
o
&&
i
.
querySelector
(
"
.MsoFootnoteReference
"
)){
const
e
=
i
.
querySelector
(
"
.MsoFootnoteReference
"
).
parentNode
;
void
0
!==
e
&&
e
.
parentNode
.
removeChild
(
e
);
const
t
=
i
.
querySelector
(
"
.MsoFootnoteText
"
);
t
&&
(
o
=
t
.
innerHTML
)}
if
(
o
){
const
e
=
function
(
e
,
t
){
const
o
=
document
.
createElement
(
"
footnotes
"
);
return
o
.
setAttribute
(
"
data-value
"
,
e
),
o
.
setAttribute
(
"
data-text
"
,
t
),
o
.
innerHTML
=
"
"
,
o
}(
c
,
o
);
s
()
&&
(
console
.
log
(
"
Created footnotes element:
"
),
console
.
log
(
e
),
console
.
log
(
"
Replacing citation element:
"
),
console
.
log
(
r
),
console
.
log
(
"
Removing anchor div:
"
),
console
.
log
(
i
)),
r
.
parentNode
.
replaceChild
(
e
,
r
),
i
.
parentNode
.
removeChild
(
i
)}}}}));
const
t
=
e
.
querySelectorAll
(
'
div[style*="mso-element:footnote-list;"]
'
);
t
&&
t
.
length
>
0
&&
t
.
forEach
((
e
=>
{
e
.
parentNode
.
removeChild
(
e
)}));
return
e
.
querySelectorAll
(
"
footnotes
"
).
forEach
((
e
=>
{
e
.
setAttribute
(
"
data-value
"
,
""
)})),
s
()
&&
(
console
.
log
(
"
Returning document fragment:
"
),
console
.
log
(
e
)),
e
}
class
c
extends
e
.
Plugin
{
static
get
requires
(){
return
[
t
.
Widget
]}
static
get
pluginName
(){
return
"
footnotesEditing
"
}
init
(){
this
.
attrs
=
{
footnotesText
:
"
data-text
"
,
footnotesValue
:
"
data-value
"
};
const
e
=
this
.
editor
.
config
.
get
(
"
footnotes
"
);
if
(
!
e
)
return
;
const
{
previewURL
:
t
,
themeError
:
o
}
=
e
;
this
.
previewUrl
=
t
,
this
.
themeError
=
o
||
`\n <p>
${
Drupal
.
t
(
"
An error occurred while trying to preview the embedded content. Please save your work and reload this page.
"
)}
<p>\n `
,
this
.
_defineSchema
(),
this
.
_defineConverters
(),
this
.
editor
.
commands
.
add
(
"
footnotes
"
,
new
r
(
this
.
editor
)),
this
.
editor
.
plugins
.
get
(
"
ClipboardPipeline
"
).
on
(
"
inputTransformation
"
,((
e
,
t
)
=>
{
const
o
=
t
.
content
,
n
=
i
(
this
.
editor
.
editing
.
view
.
domConverter
.
viewToDom
(
o
)),
r
=
this
.
editor
.
editing
.
view
.
domConverter
.
domToView
(
n
);
s
()
&&
(
console
.
log
(
"
Transformed view fragment:
"
),
console
.
log
(
r
));
const
c
=
this
.
editor
.
data
.
toModel
(
r
);
this
.
editor
.
model
.
change
((
e
=>
{
const
t
=
this
.
editor
.
model
.
document
.
selection
;
t
&&!
t
.
isCollapsed
&&
e
.
remove
(
t
.
getFirstRange
()),
this
.
editor
.
model
.
insertContent
(
c
,
t
)})),
e
.
stop
()}),{
priority
:
"
highest
"
})}
async
_fetchPreview
(
e
){
const
t
=
{
text
:
e
.
getAttribute
(
"
footnotesText
"
),
value
:
e
.
getAttribute
(
"
footnotesValue
"
)},
o
=
await
fetch
(
`
${
this
.
previewUrl
}
?
${
new
URLSearchParams
(
t
)}
`
);
return
o
.
ok
?
o
.
text
():
this
.
themeError
}
_defineSchema
(){
const
{
schema
:
e
}
=
this
.
editor
.
model
;
e
.
register
(
"
footnotes
"
,{
allowWhere
:
"
$inlineObject
"
,
blockObject
:
!
1
,
isObject
:
!
0
,
isContent
:
!
0
,
isBlock
:
!
1
,
isInline
:
!
0
,
inlineObject
:
!
0
,
allowAttributes
:
Object
.
keys
(
this
.
attrs
)}),
this
.
editor
.
editing
.
view
.
domConverter
.
blockElements
.
push
(
"
footnotes
"
)}
_defineConverters
(){
const
{
conversion
:
e
}
=
this
.
editor
;
e
.
for
(
"
upcast
"
).
elementToElement
({
view
:{
name
:
"
footnotes
"
},
model
:
"
footnotes
"
}),
e
.
for
(
"
dataDowncast
"
).
elementToElement
({
model
:
"
footnotes
"
,
view
:{
name
:
"
footnotes
"
}}),
e
.
for
(
"
editingDowncast
"
).
elementToElement
({
model
:
"
footnotes
"
,
view
:(
e
,{
writer
:
o
})
=>
{
const
n
=
o
.
createContainerElement
(
"
span
"
);
return
(
0
,
t
.
toWidget
)(
n
,
o
,{
label
:
Drupal
.
t
(
"
Footnotes
"
)})}}).
add
((
e
=>
(
e
.
on
(
"
attribute:footnotesValue:footnotes
"
,((
e
,
t
,
o
)
=>
{
const
n
=
o
.
writer
,
r
=
t
.
item
,
s
=
o
.
mapper
.
toViewElement
(
t
.
item
),
i
=
n
.
createRawElement
(
"
span
"
,{
"
data-footnotes-preview
"
:
"
loading
"
,
class
:
"
footnotes-preview
"
});
n
.
insert
(
n
.
createPositionAt
(
s
,
0
),
i
),
this
.
_fetchPreview
(
r
).
then
((
e
=>
{
i
&&
this
.
editor
.
editing
.
view
.
change
((
t
=>
{
const
o
=
t
.
createRawElement
(
"
span
"
,{
class
:
"
footnotes-preview
"
,
"
data-footnotes-preview
"
:
"
ready
"
},(
t
=>
{
t
.
innerHTML
=
e
}));
t
.
insert
(
t
.
createPositionBefore
(
i
),
o
),
t
.
remove
(
i
)}))}))})),
e
))),
Object
.
keys
(
this
.
attrs
).
forEach
((
t
=>
{
const
o
=
{
model
:{
key
:
t
,
name
:
"
footnotes
"
},
view
:{
name
:
"
footnotes
"
,
key
:
this
.
attrs
[
t
]}};
e
.
for
(
"
dataDowncast
"
).
attributeToAttribute
(
o
),
e
.
for
(
"
upcast
"
).
attributeToAttribute
(
o
)}))}}
var
a
=
o
(
"
ckeditor5/src/ui.js
"
),
d
=
o
(
"
ckeditor5/src/engine.js
"
);
class
l
extends
d
.
DomEventObserver
{
constructor
(
e
){
super
(
e
),
this
.
domEventType
=
"
dblclick
"
}
onDomEvent
(
e
){
this
.
fire
(
e
.
type
,
e
)}}
class
f
extends
e
.
Plugin
{
init
(){
const
{
editor
:
e
}
=
this
,
t
=
this
.
editor
.
config
.
get
(
"
footnotes
"
);
if
(
!
t
)
return
;
const
{
dialogURL
:
o
,
openDialog
:
n
,
dialogSettings
:
r
=
{}}
=
t
;
if
(
!
o
||
"
function
"
!=
typeof
n
)
return
;
e
.
ui
.
componentFactory
.
add
(
"
footnotes
"
,(
t
=>
{
const
s
=
e
.
commands
.
get
(
"
footnotes
"
),
i
=
new
a
.
ButtonView
(
t
);
return
i
.
set
({
label
:
Drupal
.
t
(
"
Footnotes
"
),
icon
:
'
<?xml version="1.0" standalone="no"?>
\n
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
\n
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
\n
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
\n
width="16.000000pt" height="16.000000pt" viewBox="0 0 16.000000 16.000000"
\n
preserveAspectRatio="xMidYMid meet">
\n\n
<g transform="translate(0.000000,16.000000) scale(0.100000,-0.100000)"
\n
fill="#000000" stroke="none">
\n
<path d="M115 115 c0 -14 5 -25 11 -25 7 0 9 10 6 25 -2 14 -7 25 -11 25 -3 0
\n
-6 -11 -6 -25z"/>
\n
<path d="M35 110 c-4 -6 5 -10 19 -10 14 0 26 -4 26 -10 0 -5 -8 -10 -19 -10
\n
-24 0 -45 -25 -38 -45 4 -9 19 -14 42 -13 33 1 35 3 35 38 0 20 -5 41 -12 48
\n
-15 15 -45 16 -53 2z m45 -60 c0 -5 -9 -10 -20 -10 -11 0 -20 5 -20 10 0 6 9
\n
10 20 10 11 0 20 -4 20 -10z"/>
\n
</g>
\n
</svg>
\n
'
,
tooltip
:
!
0
}),
i
.
bind
(
"
isOn
"
,
"
isEnabled
"
).
to
(
s
,
"
value
"
,
"
isEnabled
"
),
this
.
listenTo
(
i
,
"
execute
"
,(()
=>
{
const
t
=
e
.
model
.
document
.
selection
.
getSelectedElement
(),
s
=
new
URL
(
o
,
document
.
baseURI
);
t
&&
void
0
!==
t
.
name
&&
"
footnotes
"
===
t
.
name
&&
(
s
.
searchParams
.
append
(
"
text
"
,
t
.
getAttribute
(
"
footnotesText
"
)),
s
.
searchParams
.
append
(
"
value
"
,
t
.
getAttribute
(
"
footnotesValue
"
))),
n
(
s
.
toString
(),(({
attributes
:
t
})
=>
{
e
.
execute
(
"
footnotes
"
,
t
)}),
r
)})),
i
}));
const
{
view
:
s
}
=
e
.
editing
,
i
=
s
.
document
;
s
.
addObserver
(
l
),
e
.
listenTo
(
i
,
"
dblclick
"
,((
t
,
s
)
=>
{
const
i
=
e
.
editing
.
mapper
.
toModelElement
(
s
.
target
.
parent
);
if
(
i
&&
void
0
!==
i
.
name
&&
"
footnotes
"
===
i
.
name
){
const
t
=
{
text
:
i
.
getAttribute
(
"
footnotesText
"
),
value
:
i
.
getAttribute
(
"
footnotesValue
"
)};
n
(
`
${
o
}
?
${
new
URLSearchParams
(
t
)}
`
,(({
attributes
:
t
})
=>
{
e
.
execute
(
"
footnotes
"
,
t
)}),
r
)}}))}}
class
u
extends
e
.
Plugin
{
static
get
requires
(){
return
[
c
,
f
]}
static
get
pluginName
(){
return
"
footnotes
"
}}
const
m
=
{
Footnotes
:
u
}})(),
n
=
n
.
default
})()));
\ No newline at end of file
!
function
(
e
,
t
){
"
object
"
==
typeof
exports
&&
"
object
"
==
typeof
module
?
module
.
exports
=
t
():
"
function
"
==
typeof
define
&&
define
.
amd
?
define
([],
t
):
"
object
"
==
typeof
exports
?
exports
.
CKEditor5
=
t
():(
e
.
CKEditor5
=
e
.
CKEditor5
||
{},
e
.
CKEditor5
.
footnotes
=
t
())}(
self
,(()
=>
(()
=>
{
var
e
=
{
"
ckeditor5/src/core.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/core.js
"
)},
"
ckeditor5/src/engine.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/engine.js
"
)},
"
ckeditor5/src/ui.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/ui.js
"
)},
"
ckeditor5/src/widget.js
"
:(
e
,
t
,
o
)
=>
{
e
.
exports
=
o
(
"
dll-reference CKEditor5.dll
"
)(
"
./src/widget.js
"
)},
"
dll-reference CKEditor5.dll
"
:
e
=>
{
"
use strict
"
;
e
.
exports
=
CKEditor5
.
dll
}},
t
=
{};
function
o
(
n
){
var
r
=
t
[
n
];
if
(
void
0
!==
r
)
return
r
.
exports
;
var
i
=
t
[
n
]
=
{
exports
:{}};
return
e
[
n
](
i
,
i
.
exports
,
o
),
i
.
exports
}
o
.
d
=
(
e
,
t
)
=>
{
for
(
var
n
in
t
)
o
.
o
(
t
,
n
)
&&!
o
.
o
(
e
,
n
)
&&
Object
.
defineProperty
(
e
,
n
,{
enumerable
:
!
0
,
get
:
t
[
n
]})},
o
.
o
=
(
e
,
t
)
=>
Object
.
prototype
.
hasOwnProperty
.
call
(
e
,
t
);
var
n
=
{};
return
(()
=>
{
"
use strict
"
;
o
.
d
(
n
,{
default
:()
=>
m
});
var
e
=
o
(
"
ckeditor5/src/core.js
"
),
t
=
o
(
"
ckeditor5/src/widget.js
"
);
class
r
extends
e
.
Command
{
execute
(
e
){
const
t
=
this
.
editor
.
plugins
.
get
(
"
footnotesEditing
"
),
o
=
Object
.
entries
(
t
.
attrs
).
reduce
(((
e
,[
t
,
o
])
=>
(
e
[
o
]
=
t
,
e
)),{}),
n
=
Object
.
keys
(
e
).
reduce
(((
t
,
n
)
=>
(
o
[
n
]
&&
(
void
0
!==
e
[
n
].
value
?
t
[
o
[
n
]]
=
e
[
n
].
value
:
t
[
o
[
n
]]
=
e
[
n
]),
t
)),{});
this
.
editor
.
model
.
change
((
e
=>
{
this
.
editor
.
model
.
insertContent
(
function
(
e
,
t
){
return
e
.
createElement
(
"
footnotes
"
,
t
)}(
e
,
n
))}))}
refresh
(){
const
{
model
:
e
}
=
this
.
editor
,{
selection
:
t
}
=
e
.
document
,
o
=
e
.
schema
.
findAllowedParent
(
t
.
getFirstPosition
(),
"
footnotes
"
);
this
.
isEnabled
=
null
!==
o
}}
function
i
(){
return
new
URLSearchParams
(
window
.
location
.
search
).
has
(
"
debug
"
)}
function
s
(
e
){
i
()
&&
(
console
.
log
(
"
Content received from paste pipeline:
"
),
console
.
log
(
e
));
e
.
querySelectorAll
(
'
.sdfootnote, [id*="ftn"] > p, [id*="sdfootnote"] > p
'
).
forEach
((
t
=>
{
let
o
=
function
(
e
){
if
(
"
string
"
!=
typeof
e
)
throw
new
Error
(
"
Expected a string as input, got:
"
+
typeof
e
);
const
t
=
(
new
DOMParser
).
parseFromString
(
e
,
"
text/html
"
),
o
=
document
.
createDocumentFragment
();
Array
.
from
(
t
.
body
.
childNodes
).
forEach
((
function
e
(
t
){
if
(
t
.
nodeType
===
Node
.
ELEMENT_NODE
){
const
n
=
t
.
tagName
.
toLowerCase
();
if
(
"
b
"
===
n
||
"
strong
"
===
n
){
const
e
=
document
.
createElement
(
"
b
"
);
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}
else
if
(
"
i
"
===
n
||
"
em
"
===
n
){
const
e
=
document
.
createElement
(
"
i
"
);
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}
else
if
(
"
a
"
===
n
){
const
e
=
t
.
href
.
split
(
"
#
"
)[
1
]
||
""
;
if
(
!
e
.
startsWith
(
"
sdfootnote
"
)
&&!
e
.
startsWith
(
"
ftn
"
)
&&!
e
.
startsWith
(
"
_ftn
"
)){
const
e
=
document
.
createElement
(
"
a
"
);
e
.
href
=
t
.
href
,
e
.
innerHTML
=
t
.
innerHTML
,
o
.
appendChild
(
e
)}}
else
Array
.
from
(
t
.
childNodes
).
forEach
(
e
)}
else
t
.
nodeType
===
Node
.
TEXT_NODE
&&
o
.
appendChild
(
document
.
createTextNode
(
t
.
textContent
))}));
const
n
=
document
.
createElement
(
"
div
"
);
return
n
.
appendChild
(
o
),
n
.
innerHTML
.
trim
()}(
t
.
innerHTML
);
const
n
=
t
.
querySelector
(
'
.sdfootnotesym, [ href*="_ftnref"]
'
);
if
(
n
){
let
t
=
n
.
getAttribute
(
"
href
"
).
replace
(
/anc|ref|_/g
,
""
);
t
=
`#
${
t
.
split
(
"
#
"
).
pop
()}
`
;
const
r
=
e
.
querySelector
(
`.sdfootnoteanc[href*="
${
t
}
sym"], [href*="_ftn"]`
),
s
=
e
.
querySelector
(
`div
${
t
}
`
),
c
=
""
;
if
(
r
){
if
(
!
o
&&
s
.
querySelector
(
"
.MsoFootnoteReference
"
)){
const
e
=
s
.
querySelector
(
"
.MsoFootnoteReference
"
).
parentNode
;
void
0
!==
e
&&
e
.
parentNode
.
removeChild
(
e
);
const
t
=
s
.
querySelector
(
"
.MsoFootnoteText
"
);
t
&&
(
o
=
t
.
innerHTML
)}
if
(
o
){
const
e
=
function
(
e
,
t
){
const
o
=
document
.
createElement
(
"
footnotes
"
);
return
o
.
setAttribute
(
"
data-value
"
,
e
),
o
.
setAttribute
(
"
data-text
"
,
t
),
o
.
innerHTML
=
"
"
,
o
}(
c
,
o
);
i
()
&&
(
console
.
log
(
"
Created footnotes element:
"
),
console
.
log
(
e
),
console
.
log
(
"
Replacing citation element:
"
),
console
.
log
(
r
),
console
.
log
(
"
Removing anchor div:
"
),
console
.
log
(
s
)),
r
.
parentNode
.
replaceChild
(
e
,
r
),
s
.
parentNode
.
removeChild
(
s
)}}}}));
const
t
=
e
.
querySelectorAll
(
'
div[style*="mso-element:footnote-list;"]
'
);
t
&&
t
.
length
>
0
&&
t
.
forEach
((
e
=>
{
e
.
parentNode
.
removeChild
(
e
)}));
return
e
.
querySelectorAll
(
"
footnotes
"
).
forEach
((
e
=>
{
e
.
setAttribute
(
"
data-value
"
,
""
)})),
i
()
&&
(
console
.
log
(
"
Returning document fragment:
"
),
console
.
log
(
e
)),
e
}
class
c
extends
e
.
Plugin
{
static
get
requires
(){
return
[
t
.
Widget
]}
static
get
pluginName
(){
return
"
footnotesEditing
"
}
init
(){
this
.
attrs
=
{
footnotesText
:
"
data-text
"
,
footnotesValue
:
"
data-value
"
};
const
e
=
this
.
editor
.
config
.
get
(
"
footnotes
"
);
if
(
!
e
)
return
;
const
{
previewURL
:
t
,
themeError
:
o
}
=
e
;
this
.
previewUrl
=
t
,
this
.
themeError
=
o
||
`\n <p>
${
Drupal
.
t
(
"
An error occurred while trying to preview the embedded content. Please save your work and reload this page.
"
)}
<p>\n `
,
this
.
_defineSchema
(),
this
.
_defineConverters
(),
this
.
editor
.
commands
.
add
(
"
footnotes
"
,
new
r
(
this
.
editor
)),
this
.
editor
.
plugins
.
get
(
"
ClipboardPipeline
"
).
on
(
"
inputTransformation
"
,((
e
,
t
)
=>
{
if
((
t
.
content
.
getChild
(
0
).
data
||
""
).
includes
(
"
<footnote
"
))
return
;
const
o
=
t
.
content
,
n
=
s
(
this
.
editor
.
editing
.
view
.
domConverter
.
viewToDom
(
o
)),
r
=
this
.
editor
.
editing
.
view
.
domConverter
.
domToView
(
n
);
i
()
&&
(
console
.
log
(
"
Original view fragment:
"
),
console
.
log
(
o
),
console
.
log
(
"
Transformed view fragment:
"
),
console
.
log
(
r
)),
t
.
content
=
r
}),{
priority
:
"
highest
"
})}
async
_fetchPreview
(
e
){
const
t
=
{
text
:
e
.
getAttribute
(
"
footnotesText
"
),
value
:
e
.
getAttribute
(
"
footnotesValue
"
)},
o
=
await
fetch
(
`
${
this
.
previewUrl
}
?
${
new
URLSearchParams
(
t
)}
`
);
return
o
.
ok
?
o
.
text
():
this
.
themeError
}
_defineSchema
(){
const
{
schema
:
e
}
=
this
.
editor
.
model
;
e
.
register
(
"
footnotes
"
,{
allowWhere
:
"
$inlineObject
"
,
blockObject
:
!
1
,
isObject
:
!
0
,
isContent
:
!
0
,
isBlock
:
!
1
,
isInline
:
!
0
,
inlineObject
:
!
0
,
allowAttributes
:
Object
.
keys
(
this
.
attrs
)}),
this
.
editor
.
editing
.
view
.
domConverter
.
blockElements
.
push
(
"
footnotes
"
)}
_defineConverters
(){
const
{
conversion
:
e
}
=
this
.
editor
;
e
.
for
(
"
upcast
"
).
elementToElement
({
view
:{
name
:
"
footnotes
"
},
model
:
"
footnotes
"
}),
e
.
for
(
"
dataDowncast
"
).
elementToElement
({
model
:
"
footnotes
"
,
view
:{
name
:
"
footnotes
"
}}),
e
.
for
(
"
editingDowncast
"
).
elementToElement
({
model
:
"
footnotes
"
,
view
:(
e
,{
writer
:
o
})
=>
{
const
n
=
o
.
createContainerElement
(
"
span
"
);
return
(
0
,
t
.
toWidget
)(
n
,
o
,{
label
:
Drupal
.
t
(
"
Footnotes
"
)})}}).
add
((
e
=>
(
e
.
on
(
"
attribute:footnotesValue:footnotes
"
,((
e
,
t
,
o
)
=>
{
const
n
=
o
.
writer
,
r
=
t
.
item
,
i
=
o
.
mapper
.
toViewElement
(
t
.
item
),
s
=
n
.
createRawElement
(
"
span
"
,{
"
data-footnotes-preview
"
:
"
loading
"
,
class
:
"
footnotes-preview
"
});
n
.
insert
(
n
.
createPositionAt
(
i
,
0
),
s
),
this
.
_fetchPreview
(
r
).
then
((
e
=>
{
s
&&
this
.
editor
.
editing
.
view
.
change
((
t
=>
{
const
o
=
t
.
createRawElement
(
"
span
"
,{
class
:
"
footnotes-preview
"
,
"
data-footnotes-preview
"
:
"
ready
"
},(
t
=>
{
t
.
innerHTML
=
e
}));
t
.
insert
(
t
.
createPositionBefore
(
s
),
o
),
t
.
remove
(
s
)}))}))})),
e
))),
Object
.
keys
(
this
.
attrs
).
forEach
((
t
=>
{
const
o
=
{
model
:{
key
:
t
,
name
:
"
footnotes
"
},
view
:{
name
:
"
footnotes
"
,
key
:
this
.
attrs
[
t
]}};
e
.
for
(
"
dataDowncast
"
).
attributeToAttribute
(
o
),
e
.
for
(
"
upcast
"
).
attributeToAttribute
(
o
)}))}}
var
a
=
o
(
"
ckeditor5/src/ui.js
"
),
l
=
o
(
"
ckeditor5/src/engine.js
"
);
class
d
extends
l
.
DomEventObserver
{
constructor
(
e
){
super
(
e
),
this
.
domEventType
=
"
dblclick
"
}
onDomEvent
(
e
){
this
.
fire
(
e
.
type
,
e
)}}
class
f
extends
e
.
Plugin
{
init
(){
const
{
editor
:
e
}
=
this
,
t
=
this
.
editor
.
config
.
get
(
"
footnotes
"
);
if
(
!
t
)
return
;
const
{
dialogURL
:
o
,
openDialog
:
n
,
dialogSettings
:
r
=
{}}
=
t
;
if
(
!
o
||
"
function
"
!=
typeof
n
)
return
;
e
.
ui
.
componentFactory
.
add
(
"
footnotes
"
,(
t
=>
{
const
i
=
e
.
commands
.
get
(
"
footnotes
"
),
s
=
new
a
.
ButtonView
(
t
);
return
s
.
set
({
label
:
Drupal
.
t
(
"
Footnotes
"
),
icon
:
'
<?xml version="1.0" standalone="no"?>
\n
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
\n
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
\n
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
\n
width="16.000000pt" height="16.000000pt" viewBox="0 0 16.000000 16.000000"
\n
preserveAspectRatio="xMidYMid meet">
\n\n
<g transform="translate(0.000000,16.000000) scale(0.100000,-0.100000)"
\n
fill="#000000" stroke="none">
\n
<path d="M115 115 c0 -14 5 -25 11 -25 7 0 9 10 6 25 -2 14 -7 25 -11 25 -3 0
\n
-6 -11 -6 -25z"/>
\n
<path d="M35 110 c-4 -6 5 -10 19 -10 14 0 26 -4 26 -10 0 -5 -8 -10 -19 -10
\n
-24 0 -45 -25 -38 -45 4 -9 19 -14 42 -13 33 1 35 3 35 38 0 20 -5 41 -12 48
\n
-15 15 -45 16 -53 2z m45 -60 c0 -5 -9 -10 -20 -10 -11 0 -20 5 -20 10 0 6 9
\n
10 20 10 11 0 20 -4 20 -10z"/>
\n
</g>
\n
</svg>
\n
'
,
tooltip
:
!
0
}),
s
.
bind
(
"
isOn
"
,
"
isEnabled
"
).
to
(
i
,
"
value
"
,
"
isEnabled
"
),
this
.
listenTo
(
s
,
"
execute
"
,(()
=>
{
const
t
=
e
.
model
.
document
.
selection
.
getSelectedElement
(),
i
=
new
URL
(
o
,
document
.
baseURI
);
t
&&
void
0
!==
t
.
name
&&
"
footnotes
"
===
t
.
name
&&
(
i
.
searchParams
.
append
(
"
text
"
,
t
.
getAttribute
(
"
footnotesText
"
)),
i
.
searchParams
.
append
(
"
value
"
,
t
.
getAttribute
(
"
footnotesValue
"
))),
n
(
i
.
toString
(),(({
attributes
:
t
})
=>
{
e
.
execute
(
"
footnotes
"
,
t
)}),
r
)})),
s
}));
const
{
view
:
i
}
=
e
.
editing
,
s
=
i
.
document
;
i
.
addObserver
(
d
),
e
.
listenTo
(
s
,
"
dblclick
"
,((
t
,
i
)
=>
{
const
s
=
e
.
editing
.
mapper
.
toModelElement
(
i
.
target
.
parent
);
if
(
s
&&
void
0
!==
s
.
name
&&
"
footnotes
"
===
s
.
name
){
const
t
=
{
text
:
s
.
getAttribute
(
"
footnotesText
"
),
value
:
s
.
getAttribute
(
"
footnotesValue
"
)};
n
(
`
${
o
}
?
${
new
URLSearchParams
(
t
)}
`
,(({
attributes
:
t
})
=>
{
e
.
execute
(
"
footnotes
"
,
t
)}),
r
)}}))}}
class
u
extends
e
.
Plugin
{
static
get
requires
(){
return
[
c
,
f
]}
static
get
pluginName
(){
return
"
footnotes
"
}}
const
m
=
{
Footnotes
:
u
}})(),
n
=
n
.
default
})()));
\ No newline at end of file
This diff is collapsed.
Click to expand it.
assets/js/ckeditor5_plugins/footnotes/src/footnotesediting.js
+
11
−
17
View file @
80d92e69
...
...
@@ -233,6 +233,12 @@ export default class Footnotesediting extends Plugin {
this
.
editor
.
plugins
.
get
(
'
ClipboardPipeline
'
).
on
(
'
inputTransformation
'
,
(
evt
,
data
)
=>
{
// Already completed.
const
contentString
=
data
.
content
.
getChild
(
0
).
data
||
''
;
if
(
contentString
.
includes
(
'
<footnote
'
))
{
return
;
}
// Convert the view document fragment to a DOM document fragment.
const
viewFragment
=
data
.
content
;
const
domFragment
=
...
...
@@ -246,27 +252,15 @@ export default class Footnotesediting extends Plugin {
);
if
(
isDebugMode
())
{
console
.
log
(
'
Original view fragment:
'
);
console
.
log
(
viewFragment
);
console
.
log
(
'
Transformed view fragment:
'
);
console
.
log
(
transformedViewFragment
);
}
// Convert the transformed view fragment to a model fragment.
const
modelFragment
=
this
.
editor
.
data
.
toModel
(
transformedViewFragment
);
this
.
editor
.
model
.
change
((
writer
)
=>
{
const
selection
=
this
.
editor
.
model
.
document
.
selection
;
// If there is a selection, replace the selected content.
if
(
selection
&&
!
selection
.
isCollapsed
)
{
writer
.
remove
(
selection
.
getFirstRange
());
}
// Insert the transformed content at the selection position.
this
.
editor
.
model
.
insertContent
(
modelFragment
,
selection
);
});
// Prevent default content handling, as we've already updated the model.
evt
.
stop
();
// Update `data.content` with the transformed view fragment.
// This will allow further listeners to receive the updated data.
data
.
content
=
transformedViewFragment
;
},
{
priority
:
'
highest
'
},
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment