Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
2
node_modules/dom-serialize/.npmignore
generated
vendored
Normal file
2
node_modules/dom-serialize/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/npm-debug.log
|
||||
/node_modules
|
26
node_modules/dom-serialize/.travis.yml
generated
vendored
Normal file
26
node_modules/dom-serialize/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- '0.10'
|
||||
env:
|
||||
global:
|
||||
- secure: VEtxOvO70QprLOKcRNFaEGoWMFXzUJ6D6/lmS8Iw+wlSuXMZVYb/vxqM3Fgp6WR5NaFoJ9drgTmIIR1jqlzN6vDpVh1NKAxYm6YAajJn8hFxQlbbagoM7E3Zx1A+YKldk8UygD3Tldj231ZLc8We+ZBWdoVWM3Si/bLO8O6rBVU=
|
||||
- secure: ZBLLYhAqGdP6R5z4ZJb/9OOmqlRasMn2lynzYKn/VO6RNgG0gqDtWOh9M+9LaGNkRGrUOyjkhnh+6FI1vmBpGwmapCq5voagzc34+4vz/CWhHM3P0/axr9kSNtWZ5Oj57PiOuvbBoMUWZcDsv8vomhm/K/c6LIxlC3Z6sJ55l78=
|
||||
matrix:
|
||||
- BROWSER_NAME=chrome BROWSER_VERSION=latest
|
||||
- BROWSER_NAME=chrome BROWSER_VERSION=35
|
||||
- BROWSER_NAME=chrome BROWSER_VERSION=34
|
||||
- BROWSER_NAME=firefox BROWSER_VERSION=latest
|
||||
- BROWSER_NAME=firefox BROWSER_VERSION=30
|
||||
- BROWSER_NAME=firefox BROWSER_VERSION=29
|
||||
- BROWSER_NAME=opera BROWSER_VERSION=latest
|
||||
- BROWSER_NAME=opera BROWSER_VERSION=11
|
||||
- BROWSER_NAME=safari BROWSER_VERSION=latest
|
||||
- BROWSER_NAME=safari BROWSER_VERSION=7
|
||||
- BROWSER_NAME=safari BROWSER_VERSION=6
|
||||
- BROWSER_NAME=safari BROWSER_VERSION=5
|
||||
- BROWSER_NAME=ie BROWSER_VERSION=11
|
||||
- BROWSER_NAME=ie BROWSER_VERSION=10
|
||||
- BROWSER_NAME=ie BROWSER_VERSION=9
|
||||
- BROWSER_NAME=iphone BROWSER_VERSION=7.1
|
||||
- BROWSER_NAME=iphone BROWSER_VERSION=7.0
|
||||
- BROWSER_NAME=iphone BROWSER_VERSION=6.1
|
73
node_modules/dom-serialize/History.md
generated
vendored
Normal file
73
node_modules/dom-serialize/History.md
generated
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
2.2.1 / 2015-11-05
|
||||
==================
|
||||
|
||||
* bump extend and void-elements (@shinnn, #1)
|
||||
|
||||
2.2.0 / 2015-02-13
|
||||
==================
|
||||
|
||||
* add support for passing `encode()` options in to `serializeAttribute()` and `serializeTextNode()`
|
||||
|
||||
2.1.0 / 2015-02-10
|
||||
==================
|
||||
|
||||
* if `e.detail.serialize` is set and the event is cancelled, still use the `e.detail.serialize` value
|
||||
* attempting to get 100% test code coverage
|
||||
* package: allow any "zuul" v1
|
||||
* test: add HTML5 Doctype test, for 100% test code coverage!
|
||||
* test: remove `console.log()` call
|
||||
|
||||
2.0.1 / 2015-02-03
|
||||
==================
|
||||
|
||||
* index: support Nodes with children for `e.detail.serialize`
|
||||
|
||||
2.0.0 / 2015-02-03
|
||||
==================
|
||||
|
||||
* README: update for `serializeTarget`
|
||||
* index: emit the "serialize" event on the node that we know is in the DOM
|
||||
|
||||
1.2.1 / 2015-02-03
|
||||
==================
|
||||
|
||||
* fix one-time callback functions on NodeLists / Arrays
|
||||
* README: fix weird spacing
|
||||
* README: add "inspect" example to readme
|
||||
|
||||
1.2.0 / 2015-02-02
|
||||
==================
|
||||
|
||||
* add support for one-time "serialize" callback functions
|
||||
* add support for a "context" argument
|
||||
* index: make `serializeDoctype()` more readable
|
||||
* README: fix typo in example output
|
||||
* README: better description
|
||||
|
||||
1.1.0 / 2015-01-16
|
||||
==================
|
||||
|
||||
* add support for Comment, Document, Doctype, DocumentFragment and NodeList types to be serialized
|
||||
* add .travis.yml file
|
||||
* add Makefile for zuul tests
|
||||
* add README.md file
|
||||
* index: run `e.detail.serialize` through all the serialize() logic
|
||||
* index: use += operator for String concatentation (faster)
|
||||
* index: use `require('ent/encode')` syntax
|
||||
* package: update "ent" to v2.2.0
|
||||
* package: rename to "dom-serialize"
|
||||
* test: add Array serialize test
|
||||
|
||||
1.0.0 / 2015-01-15
|
||||
==================
|
||||
|
||||
* index: add support for Nodes to be set on `e.data.serialize`
|
||||
* index: remove redundant `break` statements
|
||||
* test: add `e.detail.serialize` Node and Number tests
|
||||
* test: add "serialize" event tests
|
||||
* test: add initial test cases
|
||||
* package: add "string" as a keyword
|
||||
* package: add "zuul" as a dev dependency
|
||||
* package: use ~ for dep versions
|
||||
* initial commit
|
29
node_modules/dom-serialize/Makefile
generated
vendored
Normal file
29
node_modules/dom-serialize/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
|
||||
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
|
||||
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
|
||||
|
||||
# BIN directory
|
||||
BIN := $(THIS_DIR)/node_modules/.bin
|
||||
|
||||
# applications
|
||||
NODE ?= node
|
||||
ZUUL ?= $(NODE) $(BIN)/zuul
|
||||
|
||||
test:
|
||||
@if [ "x$(BROWSER_PLATFORM)" = "x" ]; then \
|
||||
$(ZUUL) \
|
||||
--ui mocha-bdd \
|
||||
--browser-name $(BROWSER_NAME) \
|
||||
--browser-version $(BROWSER_VERSION) \
|
||||
test/*.js; \
|
||||
else \
|
||||
$(ZUUL) \
|
||||
--ui mocha-bdd \
|
||||
--browser-name $(BROWSER_NAME) \
|
||||
--browser-version $(BROWSER_VERSION) \
|
||||
--browser-platform "$(BROWSER_PLATFORM)" \
|
||||
test/*.js; \
|
||||
fi
|
||||
|
||||
.PHONY: test
|
81
node_modules/dom-serialize/README.md
generated
vendored
Normal file
81
node_modules/dom-serialize/README.md
generated
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
dom-serialize
|
||||
=============
|
||||
### Serializes any DOM node into a String
|
||||
|
||||
[](https://saucelabs.com/u/dom-serialize)
|
||||
|
||||
[](https://travis-ci.org/webmodules/dom-serialize)
|
||||
|
||||
It's like `outerHTML`, but it works with:
|
||||
|
||||
* DOM elements
|
||||
* Text nodes
|
||||
* Attributes
|
||||
* Comment nodes
|
||||
* Documents
|
||||
* DocumentFragments
|
||||
* Doctypes
|
||||
* NodeLists / Arrays
|
||||
|
||||
For custom serialization logic, a "serialize" event is dispatched on
|
||||
every `Node` which event listeners can override the default behavior on by
|
||||
setting the `event.detail.serialize` property to a String or other Node.
|
||||
|
||||
The "serialize" event bubbles, so it could be a good idea to utilize
|
||||
event delegation on a known root node that will be serialized.
|
||||
Check the `event.serializeTarget` property to check which `Node` is
|
||||
currently being serialized.
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
``` bash
|
||||
$ npm install dom-serialize
|
||||
```
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
``` js
|
||||
var serialize = require('dom-serialize');
|
||||
var node;
|
||||
|
||||
// works with Text nodes
|
||||
node = document.createTextNode('foo & <bar>');
|
||||
console.log(serialize(node));
|
||||
|
||||
|
||||
// works with DOM elements
|
||||
node = document.createElement('body');
|
||||
node.appendChild(document.createElement('strong'));
|
||||
node.firstChild.appendChild(document.createTextNode('hello'));
|
||||
console.log(serialize(node));
|
||||
|
||||
|
||||
// custom "serialize" event
|
||||
node.firstChild.addEventListener('serialize', function (event) {
|
||||
event.detail.serialize = 'pwn';
|
||||
}, false);
|
||||
console.log(serialize(node));
|
||||
|
||||
|
||||
// you can also just pass a function in for a one-time serializer
|
||||
console.log(serialize(node, function (event) {
|
||||
if (event.serializeTarget === node.firstChild) {
|
||||
// for the first child, output an ellipsis to summarize "content"
|
||||
event.detail.serialze = '…';
|
||||
} else if (event.serializeTarget !== node) {
|
||||
// any other child
|
||||
event.preventDefault();
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
```
|
||||
foo & <bar>
|
||||
<body><strong>hello</strong></body>
|
||||
<body>pwn</body>
|
||||
<body>…</body>
|
||||
```
|
230
node_modules/dom-serialize/index.js
generated
vendored
Normal file
230
node_modules/dom-serialize/index.js
generated
vendored
Normal file
|
@ -0,0 +1,230 @@
|
|||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var extend = require('extend');
|
||||
var encode = require('ent/encode');
|
||||
var CustomEvent = require('custom-event');
|
||||
var voidElements = require('void-elements');
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
exports = module.exports = serialize;
|
||||
exports.serializeElement = serializeElement;
|
||||
exports.serializeAttribute = serializeAttribute;
|
||||
exports.serializeText = serializeText;
|
||||
exports.serializeComment = serializeComment;
|
||||
exports.serializeDocument = serializeDocument;
|
||||
exports.serializeDoctype = serializeDoctype;
|
||||
exports.serializeDocumentFragment = serializeDocumentFragment;
|
||||
exports.serializeNodeList = serializeNodeList;
|
||||
|
||||
/**
|
||||
* Serializes any DOM node. Returns a string.
|
||||
*
|
||||
* @param {Node} node - DOM Node to serialize
|
||||
* @param {String} [context] - optional arbitrary "context" string to use (useful for event listeners)
|
||||
* @param {Function} [fn] - optional callback function to use in the "serialize" event for this call
|
||||
* @param {EventTarget} [eventTarget] - optional EventTarget instance to emit the "serialize" event on (defaults to `node`)
|
||||
* return {String}
|
||||
* @public
|
||||
*/
|
||||
|
||||
function serialize (node, context, fn, eventTarget) {
|
||||
if (!node) return '';
|
||||
if ('function' === typeof context) {
|
||||
fn = context;
|
||||
context = null;
|
||||
}
|
||||
if (!context) context = null;
|
||||
|
||||
var rtn;
|
||||
var nodeType = node.nodeType;
|
||||
|
||||
if (!nodeType && 'number' === typeof node.length) {
|
||||
// assume it's a NodeList or Array of Nodes
|
||||
rtn = exports.serializeNodeList(node, context, fn);
|
||||
} else {
|
||||
|
||||
if ('function' === typeof fn) {
|
||||
// one-time "serialize" event listener
|
||||
node.addEventListener('serialize', fn, false);
|
||||
}
|
||||
|
||||
// emit a custom "serialize" event on `node`, in case there
|
||||
// are event listeners for custom serialization of this node
|
||||
var e = new CustomEvent('serialize', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
detail: {
|
||||
serialize: null,
|
||||
context: context
|
||||
}
|
||||
});
|
||||
|
||||
e.serializeTarget = node;
|
||||
|
||||
var target = eventTarget || node;
|
||||
var cancelled = !target.dispatchEvent(e);
|
||||
|
||||
// `e.detail.serialize` can be set to a:
|
||||
// String - returned directly
|
||||
// Node - goes through serializer logic instead of `node`
|
||||
// Anything else - get Stringified first, and then returned directly
|
||||
var s = e.detail.serialize;
|
||||
if (s != null) {
|
||||
if ('string' === typeof s) {
|
||||
rtn = s;
|
||||
} else if ('number' === typeof s.nodeType) {
|
||||
// make it go through the serialization logic
|
||||
rtn = serialize(s, context, null, target);
|
||||
} else {
|
||||
rtn = String(s);
|
||||
}
|
||||
} else if (!cancelled) {
|
||||
// default serialization logic
|
||||
switch (nodeType) {
|
||||
case 1 /* element */:
|
||||
rtn = exports.serializeElement(node, context, eventTarget);
|
||||
break;
|
||||
case 2 /* attribute */:
|
||||
rtn = exports.serializeAttribute(node);
|
||||
break;
|
||||
case 3 /* text */:
|
||||
rtn = exports.serializeText(node);
|
||||
break;
|
||||
case 8 /* comment */:
|
||||
rtn = exports.serializeComment(node);
|
||||
break;
|
||||
case 9 /* document */:
|
||||
rtn = exports.serializeDocument(node, context, eventTarget);
|
||||
break;
|
||||
case 10 /* doctype */:
|
||||
rtn = exports.serializeDoctype(node);
|
||||
break;
|
||||
case 11 /* document fragment */:
|
||||
rtn = exports.serializeDocumentFragment(node, context, eventTarget);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ('function' === typeof fn) {
|
||||
node.removeEventListener('serialize', fn, false);
|
||||
}
|
||||
}
|
||||
|
||||
return rtn || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize an Attribute node.
|
||||
*/
|
||||
|
||||
function serializeAttribute (node, opts) {
|
||||
return node.name + '="' + encode(node.value, extend({
|
||||
named: true
|
||||
}, opts)) + '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a DOM element.
|
||||
*/
|
||||
|
||||
function serializeElement (node, context, eventTarget) {
|
||||
var c, i, l;
|
||||
var name = node.nodeName.toLowerCase();
|
||||
|
||||
// opening tag
|
||||
var r = '<' + name;
|
||||
|
||||
// attributes
|
||||
for (i = 0, c = node.attributes, l = c.length; i < l; i++) {
|
||||
r += ' ' + exports.serializeAttribute(c[i]);
|
||||
}
|
||||
|
||||
r += '>';
|
||||
|
||||
// child nodes
|
||||
r += exports.serializeNodeList(node.childNodes, context, null, eventTarget);
|
||||
|
||||
// closing tag, only for non-void elements
|
||||
if (!voidElements[name]) {
|
||||
r += '</' + name + '>';
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a text node.
|
||||
*/
|
||||
|
||||
function serializeText (node, opts) {
|
||||
return encode(node.nodeValue, extend({
|
||||
named: true,
|
||||
special: { '<': true, '>': true, '&': true }
|
||||
}, opts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a comment node.
|
||||
*/
|
||||
|
||||
function serializeComment (node) {
|
||||
return '<!--' + node.nodeValue + '-->';
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a Document node.
|
||||
*/
|
||||
|
||||
function serializeDocument (node, context, eventTarget) {
|
||||
return exports.serializeNodeList(node.childNodes, context, null, eventTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a DOCTYPE node.
|
||||
* See: http://stackoverflow.com/a/10162353
|
||||
*/
|
||||
|
||||
function serializeDoctype (node) {
|
||||
var r = '<!DOCTYPE ' + node.name;
|
||||
|
||||
if (node.publicId) {
|
||||
r += ' PUBLIC "' + node.publicId + '"';
|
||||
}
|
||||
|
||||
if (!node.publicId && node.systemId) {
|
||||
r += ' SYSTEM';
|
||||
}
|
||||
|
||||
if (node.systemId) {
|
||||
r += ' "' + node.systemId + '"';
|
||||
}
|
||||
|
||||
r += '>';
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a DocumentFragment instance.
|
||||
*/
|
||||
|
||||
function serializeDocumentFragment (node, context, eventTarget) {
|
||||
return exports.serializeNodeList(node.childNodes, context, null, eventTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a NodeList/Array of nodes.
|
||||
*/
|
||||
|
||||
function serializeNodeList (list, context, fn, eventTarget) {
|
||||
var r = '';
|
||||
for (var i = 0, l = list.length; i < l; i++) {
|
||||
r += serialize(list[i], context, fn, eventTarget);
|
||||
}
|
||||
return r;
|
||||
}
|
35
node_modules/dom-serialize/package.json
generated
vendored
Normal file
35
node_modules/dom-serialize/package.json
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "dom-serialize",
|
||||
"version": "2.2.1",
|
||||
"description": "Serializes any DOM node into a String",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/webmodules/dom-serialize.git"
|
||||
},
|
||||
"keywords": [
|
||||
"browser",
|
||||
"node",
|
||||
"dom",
|
||||
"serialize",
|
||||
"string"
|
||||
],
|
||||
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/webmodules/dom-serialize/issues"
|
||||
},
|
||||
"homepage": "https://github.com/webmodules/dom-serialize",
|
||||
"dependencies": {
|
||||
"custom-event": "~1.0.0",
|
||||
"ent": "~2.2.0",
|
||||
"extend": "^3.0.0",
|
||||
"void-elements": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"zuul": "1"
|
||||
}
|
||||
}
|
377
node_modules/dom-serialize/test/test.js
generated
vendored
Normal file
377
node_modules/dom-serialize/test/test.js
generated
vendored
Normal file
|
@ -0,0 +1,377 @@
|
|||
|
||||
var assert = require('assert');
|
||||
var serialize = require('../');
|
||||
|
||||
describe('node-serialize', function () {
|
||||
var node;
|
||||
|
||||
afterEach(function () {
|
||||
if (node) {
|
||||
// clean up...
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
node = null;
|
||||
}
|
||||
});
|
||||
|
||||
it('should return an empty string on invalid input', function () {
|
||||
assert.strictEqual('', serialize(null));
|
||||
});
|
||||
|
||||
it('should serialize a SPAN element', function () {
|
||||
node = document.createElement('span');
|
||||
assert.equal('<span></span>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a BR element', function () {
|
||||
node = document.createElement('br');
|
||||
assert.equal('<br>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a text node', function () {
|
||||
node = document.createTextNode('test');
|
||||
assert.equal('test', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a text node with special HTML characters', function () {
|
||||
node = document.createTextNode('<>\'"&');
|
||||
assert.equal('<>\'"&', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a DIV element with child nodes', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createTextNode('hello '));
|
||||
var b = document.createElement('b');
|
||||
b.appendChild(document.createTextNode('world'));
|
||||
node.appendChild(b);
|
||||
node.appendChild(document.createTextNode('!'));
|
||||
node.appendChild(document.createElement('br'));
|
||||
assert.equal('<div>hello <b>world</b>!<br></div>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a DIV element with attributes', function () {
|
||||
node = document.createElement('div');
|
||||
node.setAttribute('foo', 'bar');
|
||||
node.setAttribute('escape', '<>&"\'');
|
||||
assert.equal('<div foo="bar" escape="<>&"'"></div>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize an Attribute node', function () {
|
||||
var div = document.createElement('div');
|
||||
div.setAttribute('foo', 'bar');
|
||||
node = div.attributes[0];
|
||||
assert.equal('foo="bar"', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a Comment node', function () {
|
||||
node = document.createComment('test');
|
||||
assert.equal('<!--test-->', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a Document node', function () {
|
||||
node = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
|
||||
assert.equal('<html></html>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a Doctype node', function () {
|
||||
node = document.implementation.createDocumentType(
|
||||
'html',
|
||||
'-//W3C//DTD XHTML 1.0 Strict//EN',
|
||||
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
||||
);
|
||||
|
||||
// Some older browsers require the DOCTYPE to be within a Document,
|
||||
// otherwise the "serialize" custom event is considered "cancelled".
|
||||
// See: https://travis-ci.org/webmodules/dom-serialize/builds/47307749
|
||||
var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', node);
|
||||
|
||||
assert.equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', serialize(node));
|
||||
assert.equal('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html></html>', serialize(doc));
|
||||
});
|
||||
|
||||
it('should serialize a Doctype node with systemId', function () {
|
||||
node = document.implementation.createDocumentType(
|
||||
'root-element',
|
||||
'',
|
||||
'http://www.w3.org/1999/xhtml'
|
||||
);
|
||||
document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'root-element', node);
|
||||
|
||||
assert.equal('<!DOCTYPE root-element SYSTEM "http://www.w3.org/1999/xhtml">', serialize(node));
|
||||
});
|
||||
|
||||
|
||||
it('should serialize an HTML5 Doctype node', function () {
|
||||
node = document.implementation.createDocumentType(
|
||||
'html',
|
||||
'',
|
||||
''
|
||||
);
|
||||
document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'node', node);
|
||||
|
||||
assert.equal('<!DOCTYPE html>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize a DocumentFragment node', function () {
|
||||
node = document.createDocumentFragment();
|
||||
node.appendChild(document.createElement('b'));
|
||||
node.appendChild(document.createElement('i'));
|
||||
node.lastChild.appendChild(document.createTextNode('foo'));
|
||||
assert.equal('<b></b><i>foo</i>', serialize(node));
|
||||
});
|
||||
|
||||
it('should serialize an Array of nodes', function () {
|
||||
var array = [];
|
||||
array.push(document.createTextNode('foo'));
|
||||
array.push(document.createElement('div'));
|
||||
array[1].appendChild(document.createTextNode('bar'));
|
||||
assert.equal('foo<div>bar</div>', serialize(array));
|
||||
});
|
||||
|
||||
describe('serializeText()', function () {
|
||||
|
||||
it('should serialize an Attribute node', function () {
|
||||
var d = document.createElement('div');
|
||||
d.setAttribute('foo', '<>"&');
|
||||
assert.equal('foo="<>"&"', serialize.serializeAttribute(d.attributes[0]));
|
||||
});
|
||||
|
||||
it('should allow an "options" object to be passed in', function () {
|
||||
var d = document.createElement('div');
|
||||
d.setAttribute('foo', '<>"&');
|
||||
assert.equal('foo="<>"&"', serialize.serializeAttribute(d.attributes[0], { named: false }));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('serializeText()', function () {
|
||||
|
||||
it('should serialize a TextNode instance', function () {
|
||||
node = document.createTextNode('<b>&');
|
||||
assert.equal('<b>&', serialize.serializeText(node));
|
||||
});
|
||||
|
||||
it('should allow an "options" object to be passed in', function () {
|
||||
node = document.createTextNode('<b>&');
|
||||
assert.equal('<b>&', serialize.serializeText(node, { named: false }));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('"serialize" event', function () {
|
||||
|
||||
it('should emit a "serialize" event on a DIV node', function () {
|
||||
node = document.createElement('div');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
e.detail.serialize = 'MEOW';
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('MEOW', serialize(node));
|
||||
assert.equal(1, count);
|
||||
});
|
||||
|
||||
it('should emit a "serialize" event on a Text node', function () {
|
||||
node = document.createTextNode('whaaaaa!!!!!!');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
e.detail.serialize = 'MEOW';
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('MEOW', serialize(node));
|
||||
assert.equal(1, count);
|
||||
});
|
||||
|
||||
it('should output an empty string when event is cancelled', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createTextNode('!'));
|
||||
var count = 0;
|
||||
node.firstChild.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
e.preventDefault();
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('<div></div>', serialize(node));
|
||||
assert.equal(1, count);
|
||||
});
|
||||
|
||||
it('should render a Number when set as `e.detail.serialize`', function () {
|
||||
node = document.createTextNode('whaaaaa!!!!!!');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
e.detail.serialize = 123;
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('123', serialize(node));
|
||||
assert.equal(1, count);
|
||||
});
|
||||
|
||||
it('should render a Node when set as `e.detail.serialize`', function () {
|
||||
node = document.createTextNode('whaaaaa!!!!!!');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
if (count === 1) {
|
||||
e.detail.serialize = document.createTextNode('foo');
|
||||
}
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('foo', serialize(node));
|
||||
assert.equal(2, count);
|
||||
});
|
||||
|
||||
it('should render a Node when set as `e.detail.serialize` and event is cancelled', function () {
|
||||
node = document.createTextNode('whaaaaa!!!!!!');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
if (count === 1) {
|
||||
e.preventDefault();
|
||||
e.detail.serialize = document.createTextNode('foo');
|
||||
}
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('foo', serialize(node));
|
||||
assert.equal(2, count);
|
||||
});
|
||||
|
||||
it('should have `context` set on the event', function () {
|
||||
node = document.createTextNode('');
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
e.detail.serialize = e.detail.context;
|
||||
});
|
||||
assert.equal(0, count);
|
||||
assert.equal('foo', serialize(node, 'foo'));
|
||||
assert.equal(1, count);
|
||||
assert.equal('bar', serialize(node, 'bar'));
|
||||
assert.equal(2, count);
|
||||
assert.equal('baz', serialize(node, 'baz'));
|
||||
assert.equal(3, count);
|
||||
});
|
||||
|
||||
it('should bubble', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createTextNode('foo'));
|
||||
node.appendChild(document.createTextNode(' '));
|
||||
node.appendChild(document.createTextNode('bar'));
|
||||
|
||||
// `node` must be inside the DOM for the "serialize" event to bubble
|
||||
document.body.appendChild(node);
|
||||
|
||||
var count = 0;
|
||||
node.addEventListener('serialize', function (e) {
|
||||
count++;
|
||||
assert.equal('foo', e.detail.context);
|
||||
if (e.serializeTarget === node)
|
||||
return;
|
||||
else if (e.serializeTarget.nodeValue === 'foo')
|
||||
e.detail.serialize = '…';
|
||||
else
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
|
||||
assert.equal(0, count);
|
||||
assert.equal('<div>…</div>', serialize(node, 'foo'));
|
||||
assert.equal(4, count);
|
||||
});
|
||||
|
||||
it('should support one-time callback function on Elements', function () {
|
||||
node = document.createElement('div');
|
||||
var count = 0;
|
||||
|
||||
function callback (e) {
|
||||
count++;
|
||||
e.detail.serialize = count;
|
||||
}
|
||||
|
||||
assert.equal(0, count);
|
||||
assert.equal('1', serialize(node, callback));
|
||||
assert.equal(1, count);
|
||||
assert.equal('<div></div>', serialize(node));
|
||||
assert.equal(1, count);
|
||||
});
|
||||
|
||||
it('should support one-time callback function on NodeLists', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createElement('strong'));
|
||||
node.appendChild(document.createTextNode('foo'));
|
||||
node.appendChild(document.createElement('em'));
|
||||
node.appendChild(document.createTextNode('bar'));
|
||||
|
||||
var count = 0;
|
||||
|
||||
function callback (e) {
|
||||
count++;
|
||||
e.detail.serialize = count;
|
||||
}
|
||||
|
||||
assert.equal(0, count);
|
||||
assert.equal('1234', serialize(node.childNodes, callback));
|
||||
assert.equal(4, count);
|
||||
assert.equal('<strong></strong>foo<em></em>bar', serialize(node.childNodes));
|
||||
assert.equal(4, count);
|
||||
});
|
||||
|
||||
it('should support one-time callback function on Nodes set in `e.detail.serialize`', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createTextNode('foo'));
|
||||
|
||||
// `node` must be inside the DOM for the "serialize" event to bubble
|
||||
document.body.appendChild(node);
|
||||
|
||||
var count = 0;
|
||||
|
||||
function callback (e) {
|
||||
count++;
|
||||
|
||||
if (2 === count) {
|
||||
assert.equal('foo', e.serializeTarget.nodeValue);
|
||||
var text = document.createTextNode('bar');
|
||||
e.detail.serialize = text;
|
||||
} else if (3 === count) {
|
||||
assert.equal('bar', e.serializeTarget.nodeValue);
|
||||
var text = document.createTextNode('baz');
|
||||
e.detail.serialize = text;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(0, count);
|
||||
assert.equal('<div>baz</div>', serialize(node, callback));
|
||||
assert.equal(4, count);
|
||||
});
|
||||
|
||||
it('should support one-time callback function on complex Nodes set in `e.detail.serialize`', function () {
|
||||
node = document.createElement('div');
|
||||
node.appendChild(document.createTextNode('foo'));
|
||||
|
||||
// `node` must be inside the DOM for the "serialize" event to bubble
|
||||
document.body.appendChild(node);
|
||||
|
||||
var count = 0;
|
||||
|
||||
function callback (e) {
|
||||
count++;
|
||||
if (e.serializeTarget.nodeValue === 'foo') {
|
||||
var el = document.createElement('p');
|
||||
el.appendChild(document.createTextNode('x '));
|
||||
el.appendChild(document.createElement('i'));
|
||||
el.lastChild.appendChild(document.createTextNode('bar'));
|
||||
|
||||
e.detail.serialize = el;
|
||||
}
|
||||
}
|
||||
|
||||
assert.equal(0, count);
|
||||
assert.equal('<div><p>x <i>bar</i></p></div>', serialize(node, callback));
|
||||
assert.equal(6, count);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue