Add -no-wrapify

This commit is contained in:
Rico Sta. Cruz 2017-10-25 18:37:48 +08:00
parent 73ccc139a9
commit 95314a8512
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
5 changed files with 94 additions and 63 deletions

View File

@ -204,6 +204,50 @@ exports[`multiple h2s 1`] = `
</div> </div>
`; `;
exports[`no-wrapify mode 1`] = `
<div>
<div
class="h2-section -versus -no-wrapify"
>
<h2
class="-versus -no-wrapify"
>
versus
</h2>
<div
class="body -versus -no-wrapify"
>
<h3>
install
</h3>
<p>
(install)
</p>
<h3>
usage
</h3>
<p>
(usage)
</p>
</div>
</div>
</div>
`;
exports[`simple usage 1`] = ` exports[`simple usage 1`] = `
<div> <div>
@ -260,47 +304,3 @@ exports[`simple usage 1`] = `
</div> </div>
</div> </div>
`; `;
exports[`versus mode 1`] = `
<div>
<div
class="h2-section -versus"
>
<h2
class="-versus"
>
versus
</h2>
<div
class="body -versus"
>
<h3>
install
</h3>
<p>
(install)
</p>
<h3>
usage
</h3>
<p>
(usage)
</p>
</div>
</div>
</div>
`;

View File

@ -51,9 +51,9 @@ it('h2 + pre', run(`
</div> </div>
`)) `))
it('versus mode', run(` it('no-wrapify mode', run(`
<div> <div>
<h2 class='-versus'>versus</h2> <h2 class='-versus -no-wrapify'>versus</h2>
<h3>install</h3> <h3>install</h3>
<p>(install)</p> <p>(install)</p>
@ -62,7 +62,7 @@ it('versus mode', run(`
<p>(usage)</p> <p>(usage)</p>
</div> </div>
`, $div => { `, $div => {
expect($div.find('h2 + div.body.-versus').length).toEqual(1) expect($div.find('h2 + div.body.-versus.-no-wrapify').length).toEqual(1)
})) }))
/* /*

View File

@ -57,7 +57,7 @@ function wrapifyH2 (root) {
*/ */
function isExcempted (h2) { function isExcempted (h2) {
return h2.classList.contains('-versus') return h2.classList.contains('-no-wrapify')
} }
/** /**

View File

@ -50,6 +50,7 @@
* One column * One column
*/ */
.h3-section-list.-versus,
.h3-section-list.-one-column { .h3-section-list.-one-column {
& > .h3-section { & > .h3-section {
width: 100%; width: 100%;

60
dom.md
View File

@ -1,11 +1,11 @@
--- ---
title: DOM without jQuery title: DOM vs. jQuery
category: JavaScript libraries category: JavaScript libraries
layout: 2017/sheet layout: 2017/sheet
--- ---
## Selectors ## Selectors
{: .-one-column} {: .-versus.-no-hide}
### Selectors ### Selectors
@ -35,7 +35,7 @@ Array.from(elements).forEach(el => {
``` ```
## Classes ## Classes
{: .-one-column} {: .-versus}
### Add class ### Add class
@ -91,7 +91,7 @@ el.classList.replace('collapsed', 'expanded')
``` ```
## Events ## Events
{: .-one-column} {: .-versus}
### Document ready ### Document ready
@ -116,7 +116,7 @@ ready(() => {
``` ```
## Attributes ## Attributes
{: .-one-column} {: .-versus}
### Get attribute ### Get attribute
@ -149,7 +149,7 @@ el.removeAttribute('hidden')
``` ```
## Properties ## Properties
{: .-one-column} {: .-versus}
### Get checked ### Get checked
@ -192,7 +192,7 @@ el.disabled = true
``` ```
## Traversing ## Traversing
{: .-one-column} {: .-versus}
### Children ### Children
@ -214,6 +214,26 @@ $(el).parent()
el.parentNode el.parentNode
``` ```
### Closest match
```js
$(el).closest('div')
```
```js
el.closest('div')
```
### Match check
```js
$(el).is(':checked')
```
```js
el.matches(':checked')
```
### Finding ### Finding
```js ```js
@ -226,7 +246,7 @@ el.querySelectorAll('button')
``` ```
## Inputs ## Inputs
{: .-one-column} {: .-versus}
### Blur ### Blur
@ -249,7 +269,7 @@ el.focus()
``` ```
## DOM operations ## DOM operations
{: .-one-column} {: .-versus}
### Remove ### Remove
@ -261,6 +281,16 @@ $(el).remove()
el.parentNode.removeChild(el) el.parentNode.removeChild(el)
``` ```
### Append
```js
$(el).append(newEl)
```
```js
el.appendChild(newEl)
```
### Before ### Before
```js ```js
@ -316,7 +346,7 @@ el.textContent
<!-- needs polyfill for IE8 below --> <!-- needs polyfill for IE8 below -->
## Events ## Events
{: .-one-column} {: .-versus}
### Attach event ### Attach event
@ -349,19 +379,19 @@ el.dispatchEvent(ev)
<style> <style>
.h3-section .body { .-versus .body {
display: flex; display: flex;
} }
.h3-section .body > pre { .-versus .body > pre {
flex: 0 0 50%; flex: 0 0 50%;
} }
.h3-section .body > pre + pre { .-versus .body > pre + pre {
background: #faf7ff; background: #faf7ff;
} }
.h3-section .body > pre ~ p { .-versus .body > pre ~ p {
display: none; display: none;
} }
.h3-section h3 { .-versus h3 {
display: none; display: none;
} }
</style> </style>