An open API service indexing awesome lists of open source software.

https://github.com/naugtur/ripper

Ripper.js - copy fragments of DOM and insert to another document preserving the CSS styles of elements
https://github.com/naugtur/ripper

Last synced: 7 months ago
JSON representation

Ripper.js - copy fragments of DOM and insert to another document preserving the CSS styles of elements

Awesome Lists containing this project

README

          

Ripper.js
======

Copy and compress fragments of html document and insert to another document preserving the CSS applied to elements.

The `copy(node,,)` method serializes all content of given DOM node and CSS style set on elements inside to a string containing only letters provided as the dictionary. The default dictionary contains all characters that are allowed in HTTP GET request. Optional attributes: perprocess - function to run on node copy before serializing; skipCSS - set to true to not sotre information about styles.

The `paste(data,)` method returns a node with deserialized content from the `data` string. Optional: target - node to use for output.

##Usage:

//without setup, default dictionary will be used
var ripper=Ripper();

//or with setup object
var ripper=Ripper({dictionary:'abcdefghijklmnopqrstuvwxyz'});

//copy a node
var data=ripper.copy(DOMnode);
//send data to the server

//load data from the server on another page
ripper.paste(data,domNode);
//domNode is optional. ripper.paste will work on a newly created node if domNode is not given. It is recommended to work on a node that is not in the visible document.

##Avaliable options

- dictionary - characters avaliable for output, default = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!~*;:/$,-_"
- numberLength - length of a number in base{dictionary.length} encoding, default = 2
- heuristic - use heuristic compression before LZW, default = false
- keepJS - when set to false ripper removes all javascript from ripped content, default = false

You can also pass a preprocessing function as a second argument to `.copy()`, eg.

ripper.copy(node,function(domCopy){
//modify domCopy before it gets serialized.
//original document is not affected
},skipCSS);

skipCSS - if true, css is not mirrored (it actually copies just the HTML and compresses it then). Useful when grabbing whole document.

##Unit tests

http://naugtur.github.io/ripper/testrunner.html

##Demo

http://naugtur.github.io/ripper/