Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7427274
ve.dm.CheckListItemNode.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
ve.dm.CheckListItemNode.js
View Options
/*!
* VisualEditor DataModel CheckListItemNode class.
*
* @copyright See AUTHORS.txt
*/
/**
* DataModel list item node.
*
* @class
* @extends ve.dm.BranchNode
*
* @constructor
* @param {Object} [element] Reference to element in linear model
* @param {ve.dm.Node[]} [children]
*/
ve
.
dm
.
CheckListItemNode
=
function
VeDmCheckListItemNode
()
{
// Parent constructor
ve
.
dm
.
CheckListItemNode
.
super
.
apply
(
this
,
arguments
);
};
/* Inheritance */
OO
.
inheritClass
(
ve
.
dm
.
CheckListItemNode
,
ve
.
dm
.
BranchNode
);
/* Static Properties */
ve
.
dm
.
CheckListItemNode
.
static
.
name
=
'checkListItem'
;
ve
.
dm
.
CheckListItemNode
.
static
.
parentNodeTypes
=
[
'checkList'
];
ve
.
dm
.
CheckListItemNode
.
static
.
matchTagNames
=
[
'li'
];
ve
.
dm
.
CheckListItemNode
.
static
.
matchRdfaTypes
=
[
've:checkList'
];
ve
.
dm
.
CheckListItemNode
.
static
.
handlesOwnChildren
=
true
;
ve
.
dm
.
CheckListItemNode
.
static
.
toDataElement
=
function
(
domElements
,
converter
)
{
const
checked
=
domElements
[
0
].
hasAttribute
(
'data-checked'
)
||
// Old HTML format used the invalid attribute "checked"
domElements
[
0
].
hasAttribute
(
'checked'
);
const
element
=
{
type
:
this
.
name
,
attributes
:
{
checked
:
checked
}
};
return
converter
.
getDataFromDomClean
(
domElements
[
0
],
element
);
};
ve
.
dm
.
CheckListItemNode
.
static
.
toDomElements
=
function
(
data
,
doc
,
converter
)
{
const
dataElement
=
data
[
0
];
const
listItem
=
doc
.
createElement
(
'li'
);
listItem
.
setAttribute
(
'rel'
,
've:checkList'
);
if
(
dataElement
.
attributes
.
checked
)
{
listItem
.
setAttribute
(
'data-checked'
,
'checked'
);
}
const
contents
=
data
.
slice
(
1
,
-
1
);
if
(
contents
.
length
)
{
const
wrapper
=
doc
.
createElement
(
'div'
);
converter
.
getDomSubtreeFromData
(
contents
,
wrapper
);
while
(
wrapper
.
firstChild
)
{
listItem
.
appendChild
(
wrapper
.
firstChild
);
}
}
// Formatting for external paste / preview
// * Hide the bullet list
// * Add a unicode checkbox to the text
const
checkboxText
=
document
.
createTextNode
(
dataElement
.
attributes
.
checked
?
'☑'
:
'☐'
);
let
checkbox
;
if
(
converter
.
isForParser
()
)
{
checkbox
=
checkboxText
;
}
else
{
listItem
.
style
.
listStyle
=
'none'
;
checkbox
=
document
.
createElement
(
'span'
);
checkbox
.
setAttribute
(
'data-ve-ignore'
,
'true'
);
checkbox
.
appendChild
(
checkboxText
);
}
// The first child should be the wrapper paragraph
const
textContainer
=
listItem
.
firstChild
.
nodeType
===
Node
.
TEXT_NODE
?
listItem
:
listItem
.
firstChild
;
textContainer
.
insertBefore
(
document
.
createTextNode
(
' '
),
textContainer
.
firstChild
);
textContainer
.
insertBefore
(
checkbox
,
textContainer
.
firstChild
);
return
[
listItem
];
};
ve
.
dm
.
CheckListItemNode
.
static
.
resetAttributesForClone
=
function
(
clonedElement
)
{
clonedElement
.
attributes
.
checked
=
false
;
};
/* Registration */
ve
.
dm
.
modelRegistry
.
register
(
ve
.
dm
.
CheckListItemNode
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 22, 08:52 (13 h, 50 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f0/d7/18576a8da4206f86f7834dd827ca
Default Alt Text
ve.dm.CheckListItemNode.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment