Skip to content

Commit fd73e14

Browse files
committed
😅 fix selectory bugs, improve support for testing values in varsity
1 parent 1ce2447 commit fd73e14

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,8 @@ Once the plugin is aware of an element to watch, and the unique name of that ele
247247
- `--example-children`
248248
- `--example-value`
249249

250-
Test available at: [test/varsity.html](http://tomhodgins.github.io/cssplus/test/varsity.html)
250+
Test available at: [test/varsity.html](http://tomhodgins.github.io/cssplus/test/varsity.html)
251+
252+
## Demos
253+
254+
For CSSplus demos, check out the [CSSPlus demos collection](http://codepen.io/collection/XLbNKz/) on Codepen.

cursory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
44
# Cursory
5-
## version 0.0.3
5+
## version 0.0.4
66
77
Cursory is a CSS reprocessor that makes the following JS values available as CSS variables:
88

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ <h2 id=plugins>Plugins</h2>
195195
<li><a href=#varsity><strong>Varsity:</strong> scoped variables</a>
196196
</ul>
197197

198-
<h3 id=cursory>Cursory <span>v0.0.3</span></h3>
198+
<h3 id=cursory>Cursory <span>v0.0.4</span></h3>
199199
<p>Cursory is a CSS reprocessor that makes the following JS values available as CSS variables:</p>
200200
<ul>
201201
<li><code>cursorX</code>
@@ -230,7 +230,7 @@ <h3 id=cursory>Cursory <span>v0.0.3</span></h3>
230230
}</code></pre>
231231
<p>Test available at: <a href=test/cursory.html>test/cursory.html</a></p>
232232

233-
<h3 id=scrollery>Scrollery <span>v0.0.3</span></h3>
233+
<h3 id=scrollery>Scrollery <span>v0.0.4</span></h3>
234234
<p>Scrollery is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:</p>
235235
<ul>
236236
<li><code>scrollWidth</code>
@@ -253,7 +253,7 @@ <h3 id=scrollery>Scrollery <span>v0.0.3</span></h3>
253253
</ul>
254254
<p>Test available at: <a href=test/scrollery.html>test/scrollery.html</a></p>
255255

256-
<h3 id=selectory>Selectory <span>v0.0.3</span></h3>
256+
<h3 id=selectory>Selectory <span>v0.0.4</span></h3>
257257
<p>Selectory is a CSS reprocessor that resolves selectors using JS. This plugin will read CSS selectors that end with a <code>[test]</code> attribute and use JavaScript to determine whether or not to apply that style to elements matching the other part of that selector. For example, the JS test <code>1 == 1</code> will always resolve to <code>true</code>, so a selector written for <code>div[test="1 == 1"] {}</code> will always apply to each <code>div</code> element.</p>
258258
<p>By default, Selectory will reprocess selectors by watching the following events:</p>
259259
<ul>
@@ -286,7 +286,7 @@ <h3 id=selectory>Selectory <span>v0.0.3</span></h3>
286286
<p>It is limited what selectors you can use with Selectory, things like <code>:hover</code> and pseudo-classes tend not to work as well. As well the parsing only allows for 1 test per selector, and complex selectors may not work as intended. Using <code>selector[test=""] {}</code> with a simple selector is best.</p>
287287
<p>Test available at: <a href=test/selectory.html>test/selectory.html</a></p>
288288

289-
<h3 id=varsity>Varsity <span>v0.0.3</span></h3>
289+
<h3 id=varsity>Varsity <span>v0.0.4</span></h3>
290290
<p>Varsity is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:</p>
291291
<ul>
292292
<li><code>offsetWidth</code>

scrollery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
44
# Scrollery
5-
## version 0.0.3
5+
## version 0.0.4
66
77
Scrollery is a CSS reprocessor that makes the following JS values available as CSS variables for any element you tell the plugin to watch:
88

selectory.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
44
# Selectory
5-
## version 0.0.3
5+
## version 0.0.4
66
77
Selectory is a CSS reprocessor that resolves selectors using JS. This plugin will read CSS selectors that end with a `[test]` attribute and use JavaScript to determine whether or not to apply that style to elements matching the other part of that selector. For example, the JS test `1 == 1` will always resolve to `true`, so a selector written for `div[test="1 == 1"] {}` will always apply to each `div` element.
88
@@ -64,8 +64,9 @@ License: MIT
6464
// For each stylesheet
6565
Array.from(document.styleSheets, sheet => {
6666

67+
6768
// For each rule
68-
Array.from(sheet.cssRules, rule => {
69+
sheet.cssRules && Array.from(sheet.cssRules, rule => {
6970

7071
// Remember selector and rule text
7172
let selector = rule.selectorText
@@ -81,7 +82,7 @@ License: MIT
8182
ruleText = ruleText.replace(/.*\{(.*)\}/, (string, match) => {return match})
8283

8384
// If `[test=` is present anywhere in the selector
84-
if (selector.indexOf('[test=') !== -1) {
85+
if (selector && selector.indexOf('[test=') !== -1) {
8586

8687
// Extract the full selector name and test
8788
selector.replace(/^(.*)\[test=(?:"(.*)"|'(.*)')\]/i, (string, selectorText, test) => {
@@ -102,15 +103,15 @@ License: MIT
102103

103104
var newSelector = selector.replace(/^(.*\[)(test=(?:".*"|'.*'))(\])/i, (string, before, test, after) => {
104105

105-
return before + attr + after
106+
return before + attr + '="' + i + '"' + after
106107

107108
})
108109

109110
// If true, add a new attribute to our element
110111
tag.setAttribute(attr, i)
111112

112113
// And add our new attribute to the selector list for that rule
113-
const comma = selectorList.length == 0 ? '' : ',\n'
114+
const comma = selectorList.length == 0 ? '' : ',\n '
114115
selectorList += comma + newSelector
115116

116117
}

varsity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ License: MIT
107107
+ `\n --${name}-offsetLeft: ${tag.offsetLeft};`
108108
+ `\n --${name}-offsetTop: ${tag.offsetTop};`
109109
+ `\n --${name}-aspect-ratio: ${tag.offsetWidth/tag.offsetHeight};`
110-
+ `\n --${name}-characters: ${tag.innerHTML.length || (tag.value && tag.value.length) || 0};`
110+
+ `\n --${name}-characters: ${tag.textContent.length || (tag.value && tag.value.length) || 0};`
111111
+ `\n --${name}-children: ${tag.getElementsByTagName('*').length};`
112-
+ `\n --${name}-value: ${(tag.value || '')};`
112+
+ `\n --${name}-value: ${(tag.value && tag.value.length) || '')};`
113113
})
114114

115115
// Populate style tag with current CSS string

0 commit comments

Comments
 (0)