Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3325021
ve.ce.MWTableNode.js
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
matmarex
Feb 8 2016, 11:56 PM
Size
2 KB
Subscribers
None
ve.ce.MWTableNode.js
View Options
/*!
* VisualEditor ContentEditable MWTableNode class.
*
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MW table node.
*
* @class
* @extends ve.ce.TableNode
* @mixins ve.ce.ClassAttributeNode
*
* @constructor
* @param {ve.dm.MWTableNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve
.
ce
.
MWTableNode
=
function
VeCeMWTableNode
()
{
// Parent constructor
ve
.
ce
.
MWTableNode
.
super
.
apply
(
this
,
arguments
);
// Mixin constructors
ve
.
ce
.
ClassAttributeNode
.
call
(
this
);
// Events
// TODO Also have to hook to any child change (cell merges or style changes), how?
this
.
connect
(
this
,
{
setup
:
'updateSortableHeaders'
}
);
this
.
model
.
connect
(
this
,
{
attributeChange
:
'updateSortableHeaders'
}
);
// DOM changes
this
.
$element
.
addClass
(
've-ce-mwTableNode'
);
};
/* Inheritance */
OO
.
inheritClass
(
ve
.
ce
.
MWTableNode
,
ve
.
ce
.
TableNode
);
OO
.
mixinClass
(
ve
.
ce
.
MWTableNode
,
ve
.
ce
.
ClassAttributeNode
);
/* Static Properties */
ve
.
ce
.
MWTableNode
.
static
.
name
=
'mwTable'
;
/**
* Update sortable headers from attributes.
*/
ve
.
ce
.
MWTableNode
.
prototype
.
updateSortableHeaders
=
function
()
{
if
(
this
.
model
.
element
.
attributes
.
sortable
)
{
var
view
,
matrix
,
i
,
row
,
longestRowLength
,
rowLength
,
headerRows
,
longestRow
,
modelNodes
,
viewNodes
;
view
=
this
;
matrix
=
this
.
model
.
getMatrix
();
i
=
0
;
longestRowLength
=
-
1
;
headerRows
=
[];
while
(
i
<
matrix
.
getRowCount
()
)
{
/*jshint loopfunc:true */
row
=
matrix
.
getRow
(
i
);
if
(
row
.
some
(
function
(
cell
)
{
return
cell
.
node
.
getAttribute
(
'style'
)
!==
'header'
;
}
)
)
{
break
;
}
rowLength
=
OO
.
unique
(
row
.
map
(
function
(
cell
)
{
return
cell
.
getOwner
();
}
)
).
length
;
if
(
rowLength
>=
longestRowLength
)
{
longestRowLength
=
rowLength
;
longestRow
=
row
;
}
i
++
;
}
modelNodes
=
longestRow
.
map
(
function
(
cell
)
{
return
cell
.
getOwner
().
node
;
}
);
viewNodes
=
modelNodes
.
map
(
function
(
cellModel
)
{
return
view
.
getNodeFromOffset
(
cellModel
.
getOffset
()
-
view
.
model
.
getOffset
()
);
}
);
$
(
viewNodes
.
map
(
function
(
cell
)
{
return
cell
.
$element
[
0
];
}
)
)
.
not
(
'.unsortable'
)
// TODO Do something smarter here
.
css
(
'background'
,
'red'
);
}
else
{
// TODO Remove the styles when table was made not sortable
}
};
/* Registration */
ve
.
ce
.
nodeFactory
.
register
(
ve
.
ce
.
MWTableNode
);
File Metadata
Details
Attached
Mime Type
text/plain
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3332201
Attached To
T139072: There should be a visual indication that setting a table's properties to 'sortable' worked
Event Timeline
Log In to Comment