Skip to content
Browse files

docs

  • Loading branch information...
1 parent e179787 commit 798595717768e7fd655f59e48d21c048895a4a23 @tj tj committed
Showing with 22 additions and 1,426 deletions.
  1. +14 −2 Makefile
  2. +8 −1 Readme.md
  3. +0 −1,423 dom.js
View
16 Makefile
@@ -6,7 +6,7 @@ components:
@component install --dev
clean:
- rm -fr build components dom.js
+ rm -fr build components dom*.js dom*.gz
test:
@mocha-phantomjs -R dot test/index.html
@@ -14,4 +14,16 @@ test:
dom.js: index.js components
@component build --standalone dom --out . --name dom
-.PHONY: clean test
+dom.js.gz: dom.js
+ @gzip --stdout $< > $@
+
+dom.min.js: dom.js
+ @uglifyjs $< > $@
+
+dom.min.js.gz: dom.min.js
+ @gzip --stdout $< > $@
+
+stats: dom.js dom.min.js dom.js.gz dom.min.js.gz
+ @du -h $^
+
+.PHONY: clean test stats
View
9 Readme.md
@@ -24,7 +24,14 @@ $ component install component/dom
This library may be used stand-alone without the component
tool, simply add ./dom.js to your application and reference
- the `dom` global. With all its dependencies dom is ~5kb gzipped.
+ the `dom` global. With all its dependencies dom is the following size:
+
+```
+ 28K dom.js
+ 16K dom.min.js
+ 8.0K dom.js.gz
+ 4.0K dom.min.js.gz
+```
## Example
View
1,423 dom.js
@@ -1,1423 +0,0 @@
-;(function(){
-
-
-/**
- * hasOwnProperty.
- */
-
-var has = Object.prototype.hasOwnProperty;
-
-/**
- * Require the given path.
- *
- * @param {String} path
- * @return {Object} exports
- * @api public
- */
-
-function require(path, parent, orig) {
- var resolved = require.resolve(path);
-
- // lookup failed
- if (null == resolved) {
- orig = orig || path;
- parent = parent || 'root';
- var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
- err.path = orig;
- err.parent = parent;
- err.require = true;
- throw err;
- }
-
- var module = require.modules[resolved];
-
- // perform real require()
- // by invoking the module's
- // registered function
- if (!module.exports) {
- module.exports = {};
- module.client = module.component = true;
- module.call(this, module.exports, require.relative(resolved), module);
- }
-
- return module.exports;
-}
-
-/**
- * Registered modules.
- */
-
-require.modules = {};
-
-/**
- * Registered aliases.
- */
-
-require.aliases = {};
-
-/**
- * Resolve `path`.
- *
- * Lookup:
- *
- * - PATH/index.js
- * - PATH.js
- * - PATH
- *
- * @param {String} path
- * @return {String} path or null
- * @api private
- */
-
-require.resolve = function(path) {
- if (path.charAt(0) === '/') path = path.slice(1);
- var index = path + '/index.js';
-
- var paths = [
- path,
- path + '.js',
- path + '.json',
- path + '/index.js',
- path + '/index.json'
- ];
-
- for (var i = 0; i < paths.length; i++) {
- var path = paths[i];
- if (has.call(require.modules, path)) return path;
- }
-
- if (has.call(require.aliases, index)) {
- return require.aliases[index];
- }
-};
-
-/**
- * Normalize `path` relative to the current path.
- *
- * @param {String} curr
- * @param {String} path
- * @return {String}
- * @api private
- */
-
-require.normalize = function(curr, path) {
- var segs = [];
-
- if ('.' != path.charAt(0)) return path;
-
- curr = curr.split('/');
- path = path.split('/');
-
- for (var i = 0; i < path.length; ++i) {
- if ('..' == path[i]) {
- curr.pop();
- } else if ('.' != path[i] && '' != path[i]) {
- segs.push(path[i]);
- }
- }
-
- return curr.concat(segs).join('/');
-};
-
-/**
- * Register module at `path` with callback `definition`.
- *
- * @param {String} path
- * @param {Function} definition
- * @api private
- */
-
-require.register = function(path, definition) {
- require.modules[path] = definition;
-};
-
-/**
- * Alias a module definition.
- *
- * @param {String} from
- * @param {String} to
- * @api private
- */
-
-require.alias = function(from, to) {
- if (!has.call(require.modules, from)) {
- throw new Error('Failed to alias "' + from + '", it does not exist');
- }
- require.aliases[to] = from;
-};
-
-/**
- * Return a require function relative to the `parent` path.
- *
- * @param {String} parent
- * @return {Function}
- * @api private
- */
-
-require.relative = function(parent) {
- var p = require.normalize(parent, '..');
-
- /**
- * lastIndexOf helper.
- */
-
- function lastIndexOf(arr, obj) {
- var i = arr.length;
- while (i--) {
- if (arr[i] === obj) return i;
- }
- return -1;
- }
-
- /**
- * The relative require() itself.
- */
-
- function localRequire(path) {
- var resolved = localRequire.resolve(path);
- return require(resolved, parent, path);
- }
-
- /**
- * Resolve relative to the parent.
- */
-
- localRequire.resolve = function(path) {
- var c = path.charAt(0);
- if ('/' == c) return path.slice(1);
- if ('.' == c) return require.normalize(p, path);
-
- // resolve deps by returning
- // the dep in the nearest "deps"
- // directory
- var segs = parent.split('/');
- var i = lastIndexOf(segs, 'deps') + 1;
- if (!i) i = 0;
- path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
- return path;
- };
-
- /**
- * Check if module is defined at `path`.
- */
-
- localRequire.exists = function(path) {
- return has.call(require.modules, localRequire.resolve(path));
- };
-
- return localRequire;
-};
-require.register("component-type/index.js", function(exports, require, module){
-
-/**
- * toString ref.
- */
-
-var toString = Object.prototype.toString;
-
-/**
- * Return the type of `val`.
- *
- * @param {Mixed} val
- * @return {String}
- * @api public
- */
-
-module.exports = function(val){
- switch (toString.call(val)) {
- case '[object Function]': return 'function';
- case '[object Date]': return 'date';
- case '[object RegExp]': return 'regexp';
- case '[object Arguments]': return 'arguments';
- case '[object Array]': return 'array';
- case '[object String]': return 'string';
- }
-
- if (val === null) return 'null';
- if (val === undefined) return 'undefined';
- if (val && val.nodeType === 1) return 'element';
- if (val === Object(val)) return 'object';
-
- return typeof val;
-};
-
-});
-require.register("component-event/index.js", function(exports, require, module){
-
-/**
- * Bind `el` event `type` to `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
-
-exports.bind = function(el, type, fn, capture){
- if (el.addEventListener) {
- el.addEventListener(type, fn, capture || false);
- } else {
- el.attachEvent('on' + type, fn);
- }
- return fn;
-};
-
-/**
- * Unbind `el` event `type`'s callback `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
-
-exports.unbind = function(el, type, fn, capture){
- if (el.removeEventListener) {
- el.removeEventListener(type, fn, capture || false);
- } else {
- el.detachEvent('on' + type, fn);
- }
- return fn;
-};
-
-});
-require.register("component-matches-selector/index.js", function(exports, require, module){
-
-/**
- * Element prototype.
- */
-
-var proto = Element.prototype;
-
-/**
- * Vendor function.
- */
-
-var vendor = proto.matchesSelector
- || proto.webkitMatchesSelector
- || proto.mozMatchesSelector
- || proto.msMatchesSelector
- || proto.oMatchesSelector;
-
-/**
- * Expose `match()`.
- */
-
-module.exports = match;
-
-/**
- * Match `el` to `selector`.
- *
- * @param {Element} el
- * @param {String} selector
- * @return {Boolean}
- * @api public
- */
-
-function match(el, selector) {
- if (vendor) return vendor.call(el, selector);
- var nodes = el.parentNode.querySelectorAll(selector);
- for (var i = 0; i < nodes.length; ++i) {
- if (nodes[i] == el) return true;
- }
- return false;
-}
-});
-require.register("component-delegate/index.js", function(exports, require, module){
-
-/**
- * Module dependencies.
- */
-
-var matches = require('matches-selector')
- , event = require('event');
-
-/**
- * Delegate event `type` to `selector`
- * and invoke `fn(e)`. A callback function
- * is returned which may be passed to `.unbind()`.
- *
- * @param {Element} el
- * @param {String} selector
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
-
-exports.bind = function(el, selector, type, fn, capture){
- return event.bind(el, type, function(e){
- if (matches(e.target, selector)) fn.call(el, e);
- }, capture);
-};
-
-/**
- * Unbind event `type`'s callback `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @api public
- */
-
-exports.unbind = function(el, type, fn, capture){
- event.unbind(el, type, fn, capture);
-};
-
-});
-require.register("component-indexof/index.js", function(exports, require, module){
-
-var indexOf = [].indexOf;
-
-module.exports = function(arr, obj){
- if (indexOf) return arr.indexOf(obj);
- for (var i = 0; i < arr.length; ++i) {
- if (arr[i] === obj) return i;
- }
- return -1;
-};
-});
-require.register("component-domify/index.js", function(exports, require, module){
-
-/**
- * Expose `parse`.
- */
-
-module.exports = parse;
-
-/**
- * Wrap map from jquery.
- */
-
-var map = {
- option: [1, '<select multiple="multiple">', '</select>'],
- optgroup: [1, '<select multiple="multiple">', '</select>'],
- legend: [1, '<fieldset>', '</fieldset>'],
- thead: [1, '<table>', '</table>'],
- tbody: [1, '<table>', '</table>'],
- tfoot: [1, '<table>', '</table>'],
- colgroup: [1, '<table>', '</table>'],
- caption: [1, '<table>', '</table>'],
- tr: [2, '<table><tbody>', '</tbody></table>'],
- td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
- th: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
- col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
- _default: [0, '', '']
-};
-
-/**
- * Parse `html` and return the children.
- *
- * @param {String} html
- * @return {Array}
- * @api private
- */
-
-function parse(html) {
- if ('string' != typeof html) throw new TypeError('String expected');
-
- // tag name
- var m = /<([\w:]+)/.exec(html);
- if (!m) throw new Error('No elements were generated.');
- var tag = m[1];
-
- // body support
- if (tag == 'body') {
- var el = document.createElement('html');
- el.innerHTML = html;
- return [el.removeChild(el.lastChild)];
- }
-
- // wrap map
- var wrap = map[tag] || map._default;
- var depth = wrap[0];
- var prefix = wrap[1];
- var suffix = wrap[2];
- var el = document.createElement('div');
- el.innerHTML = prefix + html + suffix;
- while (depth--) el = el.lastChild;
-
- return orphan(el.children);
-}
-
-/**
- * Orphan `els` and return an array.
- *
- * @param {NodeList} els
- * @return {Array}
- * @api private
- */
-
-function orphan(els) {
- var ret = [];
-
- while (els.length) {
- ret.push(els[0].parentNode.removeChild(els[0]));
- }
-
- return ret;
-}
-
-});
-require.register("component-classes/index.js", function(exports, require, module){
-
-/**
- * Module dependencies.
- */
-
-var index = require('indexof');
-
-/**
- * Whitespace regexp.
- */
-
-var re = /\s+/;
-
-/**
- * toString reference.
- */
-
-var toString = Object.prototype.toString;
-
-/**
- * Wrap `el` in a `ClassList`.
- *
- * @param {Element} el
- * @return {ClassList}
- * @api public
- */
-
-module.exports = function(el){
- return new ClassList(el);
-};
-
-/**
- * Initialize a new ClassList for `el`.
- *
- * @param {Element} el
- * @api private
- */
-
-function ClassList(el) {
- this.el = el;
- this.list = el.classList;
-}
-
-/**
- * Add class `name` if not already present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
-
-ClassList.prototype.add = function(name){
- // classList
- if (this.list) {
- this.list.add(name);
- return this;
- }
-
- // fallback
- var arr = this.array();
- var i = index(arr, name);
- if (!~i) arr.push(name);
- this.el.className = arr.join(' ');
- return this;
-};
-
-/**
- * Remove class `name` when present, or
- * pass a regular expression to remove
- * any which match.
- *
- * @param {String|RegExp} name
- * @return {ClassList}
- * @api public
- */
-
-ClassList.prototype.remove = function(name){
- if ('[object RegExp]' == toString.call(name)) {
- return this.removeMatching(name);
- }
-
- // classList
- if (this.list) {
- this.list.remove(name);
- return this;
- }
-
- // fallback
- var arr = this.array();
- var i = index(arr, name);
- if (~i) arr.splice(i, 1);
- this.el.className = arr.join(' ');
- return this;
-};
-
-/**
- * Remove all classes matching `re`.
- *
- * @param {RegExp} re
- * @return {ClassList}
- * @api private
- */
-
-ClassList.prototype.removeMatching = function(re){
- var arr = this.array();
- for (var i = 0; i < arr.length; i++) {
- if (re.test(arr[i])) {
- this.remove(arr[i]);
- }
- }
- return this;
-};
-
-/**
- * Toggle class `name`.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
-
-ClassList.prototype.toggle = function(name){
- // classList
- if (this.list) {
- this.list.toggle(name);
- return this;
- }
-
- // fallback
- if (this.has(name)) {
- this.remove(name);
- } else {
- this.add(name);
- }
- return this;
-};
-
-/**
- * Return an array of classes.
- *
- * @return {Array}
- * @api public
- */
-
-ClassList.prototype.array = function(){
- var arr = this.el.className.split(re);
- if ('' === arr[0]) arr.pop();
- return arr;
-};
-
-/**
- * Check if class `name` is present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
-
-ClassList.prototype.has =
-ClassList.prototype.contains = function(name){
- return this.list
- ? this.list.contains(name)
- : !! ~index(this.array(), name);
-};
-
-});
-require.register("component-css/index.js", function(exports, require, module){
-
-/**
- * Properties to ignore appending "px".
- */
-
-var ignore = {
- columnCount: true,
- fillOpacity: true,
- fontWeight: true,
- lineHeight: true,
- opacity: true,
- orphans: true,
- widows: true,
- zIndex: true,
- zoom: true
-};
-
-/**
- * Set `el` css values.
- *
- * @param {Element} el
- * @param {Object} obj
- * @return {Element}
- * @api public
- */
-
-module.exports = function(el, obj){
- for (var key in obj) {
- var val = obj[key];
- if ('number' == typeof val && !ignore[key]) val += 'px';
- el.style[key] = val;
- }
- return el;
-};
-
-});
-require.register("component-sort/index.js", function(exports, require, module){
-
-/**
- * Expose `sort`.
- */
-
-exports = module.exports = sort;
-
-/**
- * Sort `el`'s children with the given `fn(a, b)`.
- *
- * @param {Element} el
- * @param {Function} fn
- * @api public
- */
-
-function sort(el, fn) {
- var arr = [].slice.call(el.children).sort(fn);
- var frag = document.createDocumentFragment();
- for (var i = 0; i < arr.length; i++) {
- frag.appendChild(arr[i]);
- }
- el.appendChild(frag);
-};
-
-/**
- * Sort descending.
- *
- * @param {Element} el
- * @param {Function} fn
- * @api public
- */
-
-exports.desc = function(el, fn){
- sort(el, function(a, b){
- return ~fn(a, b) + 1;
- });
-};
-
-/**
- * Sort ascending.
- */
-
-exports.asc = sort;
-
-});
-require.register("component-query/index.js", function(exports, require, module){
-
-function one(selector, el) {
- return el.querySelector(selector);
-}
-
-exports = module.exports = function(selector, el){
- el = el || document;
- return one(selector, el);
-};
-
-exports.all = function(selector, el){
- el = el || document;
- return el.querySelectorAll(selector);
-};
-
-exports.engine = function(obj){
- if (!obj.one) throw new Error('.one callback required');
- if (!obj.all) throw new Error('.all callback required');
- one = obj.one;
- exports.all = obj.all;
-};
-
-});
-require.register("dom/index.js", function(exports, require, module){
-/**
- * Module dependencies.
- */
-
-var domify = require('domify')
- , classes = require('classes')
- , indexof = require('indexof')
- , delegate = require('delegate')
- , events = require('event')
- , query = require('query')
- , type = require('type')
- , css = require('css')
-
-/**
- * Attributes supported.
- */
-
-var attrs = [
- 'id',
- 'src',
- 'rel',
- 'cols',
- 'rows',
- 'name',
- 'href',
- 'title',
- 'style',
- 'width',
- 'height',
- 'tabindex',
- 'placeholder'
-];
-
-/**
- * Expose `dom()`.
- */
-
-exports = module.exports = dom;
-
-/**
- * Expose supported attrs.
- */
-
-exports.attrs = attrs;
-
-/**
- * Return a dom `List` for the given
- * `html`, selector, or element.
- *
- * @param {String|Element|List}
- * @return {List}
- * @api public
- */
-
-function dom(selector, context) {
- // array
- if (Array.isArray(selector)) {
- return new List(selector);
- }
-
- // List
- if (selector instanceof List) {
- return selector;
- }
-
- // node
- if (selector.nodeName) {
- return new List([selector]);
- }
-
- if ('string' != typeof selector) {
- throw new TypeError('invalid selector');
- }
-
- // html
- if ('<' == selector.charAt(0)) {
- return new List([domify(selector)[0]], selector);
- }
-
- // selector
- var ctx = context
- ? (context.els ? context.els[0] : context)
- : document;
-
- return new List(query.all(selector, ctx), selector);
-}
-
-/**
- * Expose `List` constructor.
- */
-
-exports.List = List;
-
-/**
- * Initialize a new `List` with the
- * given array-ish of `els` and `selector`
- * string.
- *
- * @param {Mixed} els
- * @param {String} selector
- * @api private
- */
-
-function List(els, selector) {
- this.els = els || [];
- this.selector = selector;
-}
-
-/**
- * Remove elements from the DOM.
- *
- * @api public
- */
-
-List.prototype.remove = function(){
- for (var i = 0; i < this.els.length; i++) {
- var el = this.els[i];
- var parent = el.parentNode;
- if (parent) parent.removeChild(el);
- }
-};
-
-/**
- * Set attribute `name` to `val`, or get attr `name`.
- *
- * @param {String} name
- * @param {String} [val]
- * @return {String|List} self
- * @api public
- */
-
-List.prototype.attr = function(name, val){
- if (1 == arguments.length) {
- return this.els[0] && this.els[0].getAttribute(name);
- }
-
- return this.forEach(function(el){
- el.setAttribute(name, val);
- });
-};
-
-/**
- * Set property `name` to `val`, or get property `name`.
- *
- * @param {String} name
- * @param {String} [val]
- * @return {Object|List} self
- * @api public
- */
-
-List.prototype.prop = function(name, val){
- if (1 == arguments.length) {
- return this.els[0] && this.els[0][name];
- }
-
- return this.forEach(function(el){
- el[name] = val;
- });
-};
-
-/**
- * Return a cloned `List` with all elements cloned.
- *
- * @return {List}
- * @api public
- */
-
-List.prototype.clone = function(){
- var arr = [];
- for (var i = 0, len = this.els.length; i < len; ++i) {
- arr.push(this.els[i].cloneNode(true));
- }
- return new List(arr);
-};
-
-/**
- * Prepend `val`.
- *
- * @param {String|Element|List} val
- * @return {List} new list
- * @api public
- */
-
-List.prototype.prepend = function(val){
- var el = this.els[0];
- if (!el) return this;
- val = dom(val);
- for (var i = 0; i < val.els.length; ++i) {
- if (el.children.length) {
- el.insertBefore(val.els[i], el.firstChild);
- } else {
- el.appendChild(val.els[i]);
- }
- }
- return val;
-};
-
-/**
- * Append `val`.
- *
- * @param {String|Element|List} val
- * @return {List} new list
- * @api public
- */
-
-List.prototype.append = function(val){
- var el = this.els[0];
- if (!el) return this;
- val = dom(val);
- for (var i = 0; i < val.els.length; ++i) {
- el.appendChild(val.els[i]);
- }
- return val;
-};
-
-/**
- * Append self's `el` to `val`
- *
- * @param {String|Element|List} val
- * @return {List} self
- * @api public
- */
-
-List.prototype.appendTo = function(val){
- dom(val).append(this);
- return this;
-};
-
-/**
- * Return a `List` containing the element at `i`.
- *
- * @param {Number} i
- * @return {List}
- * @api public
- */
-
-List.prototype.at = function(i){
- return new List([this.els[i]], this.selector);
-};
-
-/**
- * Return a `List` containing the first element.
- *
- * @param {Number} i
- * @return {List}
- * @api public
- */
-
-List.prototype.first = function(){
- return new List([this.els[0]], this.selector);
-};
-
-/**
- * Return a `List` containing the last element.
- *
- * @param {Number} i
- * @return {List}
- * @api public
- */
-
-List.prototype.last = function(){
- return new List([this.els[this.els.length - 1]], this.selector);
-};
-
-/**
- * Return an `Element` at `i`.
- *
- * @param {Number} i
- * @return {Element}
- * @api public
- */
-
-List.prototype.get = function(i){
- return this.els[i || 0];
-};
-
-/**
- * Return list length.
- *
- * @return {Number}
- * @api public
- */
-
-List.prototype.length = function(){
- return this.els.length;
-};
-
-/**
- * Return element text.
- *
- * @param {String} str
- * @return {String|List}
- * @api public
- */
-
-List.prototype.text = function(str){
- // TODO: real impl
- if (1 == arguments.length) {
- this.forEach(function(el){
- el.textContent = str;
- });
- return this;
- }
-
- var str = '';
- for (var i = 0; i < this.els.length; ++i) {
- str += this.els[i].textContent;
- }
- return str;
-};
-
-/**
- * Return element html.
- *
- * @return {String} html
- * @api public
- */
-
-List.prototype.html = function(html){
- if (1 == arguments.length) {
- this.forEach(function(el){
- el.innerHTML = html;
- });
- }
- // TODO: real impl
- return this.els[0] && this.els[0].innerHTML;
-};
-
-/**
- * Bind to `event` and invoke `fn(e)`. When
- * a `selector` is given then events are delegated.
- *
- * @param {String} event
- * @param {String} [selector]
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {List}
- * @api public
- */
-
-List.prototype.on = function(event, selector, fn, capture){
- if ('string' == typeof selector) {
- for (var i = 0; i < this.els.length; ++i) {
- fn._delegate = delegate.bind(this.els[i], selector, event, fn, capture);
- }
- return this;
- }
-
- capture = fn;
- fn = selector;
-
- for (var i = 0; i < this.els.length; ++i) {
- events.bind(this.els[i], event, fn, capture);
- }
-
- return this;
-};
-
-/**
- * Unbind to `event` and invoke `fn(e)`. When
- * a `selector` is given then delegated event
- * handlers are unbound.
- *
- * @param {String} event
- * @param {String} [selector]
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {List}
- * @api public
- */
-
-List.prototype.off = function(event, selector, fn, capture){
- if ('string' == typeof selector) {
- for (var i = 0; i < this.els.length; ++i) {
- // TODO: add selector support back
- delegate.unbind(this.els[i], event, fn._delegate, capture);
- }
- return this;
- }
-
- capture = fn;
- fn = selector;
-
- for (var i = 0; i < this.els.length; ++i) {
- events.unbind(this.els[i], event, fn, capture);
- }
- return this;
-};
-
-/**
- * Iterate elements and invoke `fn(list, i)`.
- *
- * @param {Function} fn
- * @return {List} self
- * @api public
- */
-
-List.prototype.each = function(fn){
- for (var i = 0; i < this.els.length; ++i) {
- fn(new List([this.els[i]], this.selector), i);
- }
- return this;
-};
-
-/**
- * Iterate elements and invoke `fn(el, i)`.
- *
- * @param {Function} fn
- * @return {List} self
- * @api public
- */
-
-List.prototype.forEach = function(fn){
- for (var i = 0; i < this.els.length; ++i) {
- fn(this.els[i], i);
- }
- return this;
-};
-
-/**
- * Map elements invoking `fn(list, i)`.
- *
- * @param {Function} fn
- * @return {Array}
- * @api public
- */
-
-List.prototype.map = function(fn){
- var arr = [];
- for (var i = 0; i < this.els.length; ++i) {
- arr.push(fn(new List([this.els[i]], this.selector), i));
- }
- return arr;
-};
-
-/**
- * Filter elements invoking `fn(list, i)`, returning
- * a new `List` of elements when a truthy value is returned.
- *
- * @param {Function} fn
- * @return {List}
- * @api public
- */
-
-List.prototype.select =
-List.prototype.filter = function(fn){
- var el;
- var list = new List([], this.selector);
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- if (fn(new List([el], this.selector), i)) list.els.push(el);
- }
- return list;
-};
-
-/**
- * Add the given class `name`.
- *
- * @param {String} name
- * @return {List} self
- * @api public
- */
-
-List.prototype.addClass = function(name){
- var el;
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- el._classes = el._classes || classes(el);
- el._classes.add(name);
- }
- return this;
-};
-
-/**
- * Remove the given class `name`.
- *
- * @param {String|RegExp} name
- * @return {List} self
- * @api public
- */
-
-List.prototype.removeClass = function(name){
- var el;
-
- if ('regexp' == type(name)) {
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- el._classes = el._classes || classes(el);
- var arr = el._classes.array();
- for (var j = 0; j < arr.length; j++) {
- if (name.test(arr[j])) {
- el._classes.remove(arr[j]);
- }
- }
- }
- return this;
- }
-
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- el._classes = el._classes || classes(el);
- el._classes.remove(name);
- }
-
- return this;
-};
-
-/**
- * Toggle the given class `name`,
- * optionally a `bool` may be given
- * to indicate that the class should
- * be added when truthy.
- *
- * @param {String} name
- * @param {Boolean} bool
- * @return {List} self
- * @api public
- */
-
-List.prototype.toggleClass = function(name, bool){
- var el;
- var fn = 'toggle';
-
- // toggle with boolean
- if (2 == arguments.length) {
- fn = bool ? 'add' : 'remove';
- }
-
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- el._classes = el._classes || classes(el);
- el._classes[fn](name);
- }
-
- return this;
-};
-
-/**
- * Check if the given class `name` is present.
- *
- * @param {String} name
- * @return {Boolean}
- * @api public
- */
-
-List.prototype.hasClass = function(name){
- var el;
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- el._classes = el._classes || classes(el);
- if (el._classes.has(name)) return true;
- }
- return false;
-};
-
-/**
- * Set CSS `prop` to `val` or get `prop` value.
- * Also accepts an object (`prop`: `val`)
- *
- * @param {String} prop
- * @param {Mixed} val
- * @return {List|String}
- * @api public
- */
-
-List.prototype.css = function(prop, val){
- if (2 == arguments.length) {
- var obj = {};
- obj[prop] = val;
- return this.setStyle(obj);
- }
-
- if ('object' == type(prop)) {
- return this.setStyle(prop);
- }
-
- return this.getStyle(prop);
-};
-
-/**
- * Set CSS `props`.
- *
- * @param {Object} props
- * @return {List} self
- * @api private
- */
-
-List.prototype.setStyle = function(props){
- for (var i = 0; i < this.els.length; ++i) {
- css(this.els[i], props);
- }
- return this;
-};
-
-/**
- * Get CSS `prop` value.
- *
- * @param {String} prop
- * @return {String}
- * @api private
- */
-
-List.prototype.getStyle = function(prop){
- var el = this.els[0];
- if (el) return el.style[prop];
-};
-
-/**
- * Find children matching the given `selector`.
- *
- * @param {String} selector
- * @return {List}
- * @api public
- */
-
-List.prototype.find = function(selector){
- return dom(selector, this);
-};
-
-/**
- * Empty the dom list
- *
- * @return self
- * @api public
- */
-
-List.prototype.empty = function(){
- var elem, el;
-
- for (var i = 0; i < this.els.length; ++i) {
- el = this.els[i];
- while (el.firstChild) {
- el.removeChild(el.firstChild);
- }
- }
-
- return this;
-}
-
-/**
- * Attribute accessors.
- */
-
-attrs.forEach(function(name){
- List.prototype[name] = function(val){
- if (0 == arguments.length) return this.attr(name);
- return this.attr(name, val);
- };
-});
-
-
-});
-require.alias("component-type/index.js", "dom/deps/type/index.js");
-
-require.alias("component-event/index.js", "dom/deps/event/index.js");
-
-require.alias("component-delegate/index.js", "dom/deps/delegate/index.js");
-require.alias("component-matches-selector/index.js", "component-delegate/deps/matches-selector/index.js");
-
-require.alias("component-event/index.js", "component-delegate/deps/event/index.js");
-
-require.alias("component-indexof/index.js", "dom/deps/indexof/index.js");
-
-require.alias("component-domify/index.js", "dom/deps/domify/index.js");
-
-require.alias("component-classes/index.js", "dom/deps/classes/index.js");
-require.alias("component-indexof/index.js", "component-classes/deps/indexof/index.js");
-
-require.alias("component-css/index.js", "dom/deps/css/index.js");
-
-require.alias("component-sort/index.js", "dom/deps/sort/index.js");
-
-require.alias("component-query/index.js", "dom/deps/query/index.js");
-
-if (typeof exports == "object") {
- module.exports = require("dom");
-} else if (typeof define == "function" && define.amd) {
- define(function(){ return require("dom"); });
-} else {
- window["dom"] = require("dom");
-}})();

0 comments on commit 7985957

Please sign in to comment.
Something went wrong with that request. Please try again.