# loaf

> Sheaf bundles DOM elements together, similar to a document fragment.

Latest version **0.2.6** (published 2014-09-24) · BSD license · 0 weekly downloads

## Install

```sh
npm install loaf
pnpm add loaf
yarn add loaf
bun add loaf
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2014-09-24 |
| First published | 2013-07-26 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | architectd |

## Links

- npm: https://www.npmjs.com/package/loaf
- Repository: https://github.com/classdojo/loaf.js
- Issues: https://github.com/classdojo/loaf.js/issues
- npm.io page: https://npm.io/package/loaf

## Dependencies (2)

- [nofactor](https://npm.io/package/nofactor.md) 0.0.x
- [protoclass](https://npm.io/package/protoclass.md) 0.0.x

## Recent versions

- 0.2.6 (latest) — 2014-09-24
- 0.2.5 — 2014-09-02
- 0.2.4 — 2014-08-01
- 0.2.3 — 2014-08-01
- 0.2.2 — 2014-03-06
- 0.2.1 — 2014-03-04
- 0.2.0 — 2014-01-06
- 0.1.3 — 2014-01-04
- 0.1.0 — 2013-12-19
- 0.0.15 — 2013-12-05
- 0.0.12 — 2013-12-03
- 0.0.11 — 2013-12-02
- 0.0.10 — 2013-10-18
- 0.0.9 — 2013-10-18
- 0.0.8 — 2013-08-23
- … 6 more at https://npm.io/package/loaf/versions

## README

## Loaf.js [![Alt ci](https://travis-ci.org/classdojo/loaf.js.png)](https://travis-ci.org/classdojo/loaf.js)

Loaf creates virtual "sections" of DOM elements - a sort of document fragment that can be referenced anytime it's attached to the DOM. Loaf is used in:

- [mojo.js](https://github.com/classdojo/mojo.js) - javascript framework
- [paperclip.js](https://github.com/classdojo/paperclip.js) - template engine.



Input:
```html
<html>
  <head>
    
  </head>
  <body>
    
    <!-- give loaf something to look for -->
    <div id="application"></div>
  </body>
</html>
```

Bundle:

```javascript
var helloSection = loaf(), buttonSection = loaf(), buttonElement;

// add multiple items - this demonstrates how multiple nodes are controlled by one
// section
helloSection.append(document.createTextNode("Hello "));
helloSection.append(document.createTextNode("World!"));

// setup the button which toggles the message visibility
buttonSection.append(buttonElement = $("<div><a href='#'>Toggle Message Visibility</a></div>")[0]);

// create a toggle for the "Hello World!" message.
$(buttonElement).click(function () {
    if(helloSection.visible) {
        helloSection.hide();
    } else {
        helloSection.show();
    }
});

// convert the sections into controlled document fragments.
$("#application").append(helloSection.toFragment());
$("#application").append(buttonSection.toFragment());
```

Output:
```html
<html>
  <head>
    
  </head>
  <body>
    <div id="application">
      Hello World!
      <div>
        <a href="#">Toggle Message Visibility</a>
      </div>
    </div>
  </body>
</html>
```


Here's a live example: http://jsfiddle.net/4L8wy/1/. Be sure to inspect the DOM as you're toggling the message visibility!

## API

### section loaf(nodeFactory = document)

creates a new block of dom elements

### section.replace(node)

inserts as child at the end of the target node.

### section.hide()

hides the section - replaces all bundled nodes with a placeholder node

### section.show()

displays the section if it's hidden

### section.append(children...)

appends a node to the section

### section.prepend(children...)

prepends a node to the section

### section.replaceChildNodes(children...)

disposes the loaf

### section.toFragment()

returns the section as a document fragment

### section.dispose()

removes all child nodes

### section.getChildNodes()

returns an array of the child nodes

### section.start

the start marker for the section

### section.end

the stop marker for the section

---
_Source: https://npm.io/package/loaf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
