Skip to content

Commit

Permalink
dal updated
Browse files Browse the repository at this point in the history
  • Loading branch information
pfraces committed Dec 22, 2012
1 parent 0d55d80 commit 686844e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -2,8 +2,8 @@

Split html in divs

**html-split** only depends on [DAL](https://github.com/pfraces/dal), a micro
library for dealing with the DOM
**html-split** only depends on [DAL](https://github.com/pfraces/dal), a
micro-library for dealing with the DOM

**DAL** has been created explicitly for this project, so more than a
dependency is its standard library
Expand Down Expand Up @@ -78,7 +78,7 @@ Finally, the expected **example.js:**
run = function () {
var size = { width: '20em', height: '10em' }
, tokens = split(dal('content').innerHTML, size)
, original = dal().color('red', 'white').size(size);
, original = dal().color({ bg: 'red', fg: 'white' }).size(size);
for (var i = 0; i < tokens.length; i++)
dal('split').add(original.clone().html(tokens[tokens.length - (1 + i)]));
Expand All @@ -104,10 +104,11 @@ this time.
## split(html, opts)
`opts` is an object with the following properties:
`html`: _[String: HTML]_ Content to be splitted
`opts`: _[Object]_
* **width:** Determines the width of the wrapper
* **height:** Determines the height of the wrapper
* `opts.width`: Determines the width of the wrapper
* `opts.height`: Determines the height of the wrapper
# Contribute
Expand Down
12 changes: 6 additions & 6 deletions lib/index.js
@@ -1,20 +1,20 @@
split = function (html, opts) {
var split = function (html, opts) {
function removeScriptTags () {
var nodetree = dal().html(html)
, scriptNodes = nodetree.getElementsByTagName('script');
while (scriptNodes.length) dal(scriptNodes[0]).del();
while (scriptNodes.length) dal(scriptNodes[0]).detach();
return nodetree;
}

var nodes = removeScriptTags().getElementsByTagName('*')
, wrapper = dal().clear().move(0, 0).size(opts)
, wrap = wrapper.clone().draw()
, wrapper = dal().hide().move(0, 0).size(opts)
, wrap = wrapper.clone().attach()
, divs = [];

for (var i = 0; i < nodes.length; i++) {
if (wrap.overflow()) {
if (wrap.full()) {
divs.push(wrap.innerHTML);
wrap = wrapper.clone().draw();
wrap = wrapper.clone().attach();
}

wrap.add(dal(nodes[i]).copy());
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "html-split",
"version": "0.2.7",
"version": "0.2.8",
"description": "Split html in divs",
"main": "./lib/index.js",
"dependencies": {
Expand Down

0 comments on commit 686844e

Please sign in to comment.