Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pagedjs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cy Z
pagedjs
Commits
cfda8c14
Commit
cfda8c14
authored
Jun 07, 2020
by
Nellie McKesson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding initial handling for nth-of-type selectors
parent
01ee33ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
nth-of-type.js
src/modules/paged-media/nth-of-type.js
+73
-0
No files found.
src/modules/paged-media/nth-of-type.js
0 → 100644
View file @
cfda8c14
import
Handler
from
"
../handler
"
;
import
csstree
from
"
css-tree
"
;
import
{
UUID
}
from
"
../../utils/utils
"
;
class
NthOfType
extends
Handler
{
constructor
(
chunker
,
polisher
,
caller
)
{
super
(
chunker
,
polisher
,
caller
);
this
.
styleSheet
=
polisher
.
styleSheet
;
this
.
selectors
=
{};
}
onRule
(
ruleNode
,
ruleItem
,
rulelist
)
{
let
selector
=
csstree
.
generate
(
ruleNode
.
prelude
);
if
(
selector
.
match
(
/:
(
first|last|nth
)
-of-type/
))
{
// process it
console
.
log
(
ruleNode
);
console
.
log
(
selector
);
let
declarations
=
csstree
.
generate
(
ruleNode
.
block
);
declarations
=
declarations
.
replace
(
/
[
{}
]
/g
,
""
);
console
.
log
(
"
DECLART
"
);
console
.
log
(
declarations
);
let
uuid
=
UUID
();
// does this selector already exist in the hash?
// if yes, just create a new rule using the existing random string.
// if no, create a random string for it and then create the new rule
selector
.
split
(
"
,
"
).
forEach
((
s
)
=>
{
if
(
!
this
.
selectors
[
s
])
{
this
.
selectors
[
s
]
=
[
uuid
,
declarations
];
// make the new rule
}
else
{
this
.
selectors
[
s
][
1
]
=
`
${
this
.
selectors
[
s
][
1
]}
;
${
declarations
}
`
;
// make the new rule
// makeRule(this.selectors[s])
}
});
rulelist
.
remove
(
ruleItem
);
console
.
log
(
this
.
selectors
);
}
}
afterParsed
(
parsed
)
{
this
.
processSelectors
(
parsed
,
this
.
selectors
);
}
processSelectors
(
parsed
,
selectors
)
{
// add the new attributes to matching elements
for
(
let
s
in
selectors
)
{
// Find elements
let
elements
=
parsed
.
querySelectorAll
(
s
);
for
(
var
i
=
0
;
i
<
elements
.
length
;
i
++
)
{
elements
[
i
].
setAttribute
(
"
data-css-rule
"
,
selectors
[
s
][
0
]);
}
let
rule
=
`*[data-css-rule='
${
selectors
[
s
][
0
]}
'] {
${
selectors
[
s
][
1
]}
; }`
;
this
.
styleSheet
.
insertRule
(
rule
,
this
.
styleSheet
.
cssRules
.
length
);
}
console
.
log
(
this
.
styleSheet
);
}
}
export
default
NthOfType
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment