Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 57 additions & 7 deletions lib/zest.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ var nth = function(param, test, last) {
};
};

/**
* Handle :column pseudo-classes
*/
function calc_cols (td, cache) {
while (td = td.parentNode) if (td.nodeName === 'TABLE') break;

var cols = td.getElementsByTagName('col')
var col_list = []
, col
, col_pos = 0
, td_pos = 1
, spans

for (; col = cols[col_pos]; col_pos++) {
spans = parseInt(col.getAttribute('span')) || 1

td_pos += spans

while (spans) {
col_list[td_pos - spans] = col
spans--
}
}

return col_list
}

/**
* Simple Selectors
*/
Expand Down Expand Up @@ -412,14 +439,37 @@ var selectors = {
':visited': function() {
throw new Error(':visited is not supported.');
},
':column': function() {
throw new Error(':column is not supported.');
},
':nth-column': function() {
throw new Error(':nth-column is not supported.');
':column': function(selector) {
var test = zest.compile(selector)

return function(el) {
if (el.parentNode.nodeType !== 1 || el.nodeName !== 'TD') return;

var rel = child(el.parentNode)
, pos = 0
, temp_pos
, cols = calc_cols(el)
, spans

while (rel) {
spans = parseInt(rel.getAttribute('span')) || 1
if (rel.nodeName === 'TD') pos += spans
if (rel === el) {
while (spans--) {
temp_pos = pos - spans
if (cols[temp_pos] && test(cols[temp_pos])) return true
}
return false;
}
rel = next(rel);
}
};
};,
':nth-column': function(param) {
return selectors[':column'](':nth-child(' + param + ')')
},
':nth-last-column': function() {
throw new Error(':nth-last-column is not supported.');
':nth-last-column': function(param) {
return selectors[':column'](':nth-last-child(' + param + ')')
},
':current': function() {
throw new Error(':current is not supported.');
Expand Down