Comparing version 0.0.6-alpha to 0.0.7-alpha
/* | ||
nodes attributes | ||
elements attributes | ||
*/"use strict" | ||
@@ -42,48 +42,37 @@ | ||
// common properties | ||
var accessors = {} | ||
$.implement((function(){ | ||
array.forEach("type,value,name,href,title,id".split(","), function(name){ | ||
var properties = {} | ||
array.forEach("type,value,name,href,title".split(","), function(name){ | ||
properties[name] = function(value){ | ||
if (arguments.length){ | ||
this.forEach(function(node){ | ||
node[name] = value | ||
}) | ||
return this | ||
} | ||
return this[0][name] | ||
accessors[name] = function(value){ | ||
if (value !== undefined){ | ||
this.forEach(function(node){ | ||
node[name] = value | ||
}) | ||
return this | ||
} | ||
}) | ||
return properties | ||
return this[0][name] | ||
} | ||
})()) | ||
}) | ||
// booleans | ||
$.implement((function(){ | ||
array.forEach("checked,disabled,selected".split(","), function(name){ | ||
var booleans = {} | ||
array.forEach("checked,disabled,selected".split(","), function(name){ | ||
booleans[name] = function(value){ | ||
if (arguments.length){ | ||
this.forEach(function(node){ | ||
node[name] = !!value | ||
}) | ||
return this | ||
} | ||
return !!this[0][name] | ||
accessors[name] = function(value){ | ||
if (value !== undefined){ | ||
this.forEach(function(node){ | ||
node[name] = !!value | ||
}) | ||
return this | ||
} | ||
}) | ||
return booleans | ||
return !!this[0][name] | ||
} | ||
})()) | ||
}) | ||
// className, classNames, id, tag | ||
// className | ||
@@ -99,28 +88,56 @@ var classes = function(className){ | ||
accessors.className = function(className){ | ||
if (className !== undefined){ | ||
this.forEach(function(node){ | ||
node.className = classes(className).join(" ") | ||
}) | ||
return this | ||
} | ||
return classes(this[0].className).join(" ") | ||
} | ||
// attribute | ||
$.implement({ | ||
classNames: function(){ | ||
return classes(this[0].className) | ||
attribute: function(name, value){ | ||
var accessor = accessors[name] | ||
if (accessor) return accessor.call(this, value) | ||
if (value != null) return this.setAttribute(name, value) | ||
else if (value === null) return this.removeAttribute(name) | ||
else if (value === undefined) return this.getAttribute(name) | ||
} | ||
}) | ||
$.implement(accessors) | ||
// shortcuts | ||
$.implement({ | ||
check: function(){ | ||
return this.checked(true) | ||
}, | ||
className: function(className){ | ||
if (arguments.length){ | ||
this.forEach(function(node){ | ||
node.className = classes(className).join(" ") | ||
}) | ||
return this | ||
} | ||
uncheck: function(){ | ||
return this.checked(false) | ||
}, | ||
return this.classNames().join(" ") | ||
disable: function(){ | ||
return this.disabled(true) | ||
}, | ||
id: function(id){ | ||
var node = this[0] | ||
if (arguments.length) node.id = id | ||
else return node.id | ||
return this | ||
enable: function(){ | ||
return this.disabled(false) | ||
}, | ||
tag: function(){ | ||
return this[0].tagName.toLowerCase() | ||
select: function(){ | ||
return this.selected(true) | ||
}, | ||
deselect: function(){ | ||
return this.selected(false) | ||
} | ||
@@ -130,6 +147,10 @@ | ||
// has / add / remove Class | ||
// classNames, has / add / remove Class | ||
$.implement({ | ||
classNames: function(){ | ||
return classes(this[0].className) | ||
}, | ||
hasClass: function(className){ | ||
@@ -162,3 +183,2 @@ return array.indexOf(this.classNames(), className) > -1 | ||
// toString | ||
@@ -177,2 +197,34 @@ | ||
var textProperty = (document.createElement('div').textContent == null) ? 'innerText': 'textContent' | ||
// tag, html, text | ||
$.implement({ | ||
tag: function(){ | ||
return this[0].tagName.toLowerCase() | ||
}, | ||
html: function(html){ | ||
if (html != null){ | ||
this.forEach(function(node){ | ||
node.innerHTML = html | ||
}) | ||
return this | ||
} | ||
return this[0].innerHTML | ||
}, | ||
text: function(text){ | ||
if (text != undefined){ | ||
this.forEach(function(node){ | ||
node[textProperty] = text | ||
}) | ||
return this | ||
} | ||
return this[0][textProperty] | ||
} | ||
}) | ||
module.exports = $ |
@@ -25,3 +25,2 @@ /* | ||
if (readystatechange) doc.off('readystatechange', check) | ||
doc.off('DOMContentLoaded', domready) | ||
@@ -32,3 +31,3 @@ win.off('load', domready) | ||
for (var i = 0; ready = readys[i++];) ready.call($) | ||
for (var i = 0; ready = readys[i++];) ready() | ||
} | ||
@@ -98,7 +97,5 @@ | ||
$.ready = function(ready){ | ||
(loaded) ? ready.call($) : readys.push(ready) | ||
return $ | ||
module.exports = function(ready){ | ||
(loaded) ? ready() : readys.push(ready) | ||
return null | ||
} | ||
module.exports = $ |
/* | ||
nodes events | ||
elements events | ||
*/"use strict" | ||
var $ = require("./nodes"), | ||
var $ = require("./elements"), | ||
prime = require("prime/prime"), | ||
@@ -46,8 +46,23 @@ Emitter = require("prime/util/emitter") | ||
this.handle(function(node){ | ||
NodesEmitter.parent.off.call(this, event, handle) | ||
var domListeners = this._domListeners, domEvent, listeners = this._listeners, events | ||
if (domListeners && (domEvent = domListeners[event]) && listeners && (events = listeners[event]) && !events.length){ | ||
removeEventListener(node, event, domEvent) | ||
delete domListeners[event] | ||
if (domListeners && (domEvent = domListeners[event]) && listeners && (events = listeners[event])){ | ||
NodesEmitter.parent.off.call(this, event, handle) | ||
var empty = true, k, l | ||
for (k in events){ | ||
empty = false | ||
break | ||
} | ||
if (empty){ | ||
removeEventListener(node, event, domEvent) | ||
delete domListeners[event] | ||
for (l in domListeners) empty = false | ||
if (empty) delete this._domListeners | ||
} | ||
} | ||
@@ -54,0 +69,0 @@ }) |
/* | ||
nodes insertion | ||
elements insertion | ||
*/"use strict" | ||
@@ -73,3 +73,3 @@ | ||
// insert, remove, replace | ||
// insert, replace | ||
@@ -80,10 +80,2 @@ $.implement({ | ||
remove: function(){ | ||
this.forEach(function(node){ | ||
var parent = node.parentNode | ||
if (parent) parent.removeChild(node) | ||
}) | ||
return this | ||
}, | ||
replace: function(element){ | ||
@@ -90,0 +82,0 @@ element = $(element)[0] |
/* | ||
nodes events | ||
elements events | ||
*/"use strict" | ||
var $ = require("./nodes"), | ||
list = require("prime/es5/array").prototype | ||
var $ = require("./elements"), | ||
array = require("prime/es5/array").prototype | ||
@@ -12,8 +12,8 @@ module.exports = $.implement({ | ||
forEach: list.forEach, | ||
map: list.map, | ||
filter: list.filter, | ||
every: list.every, | ||
some: list.some | ||
forEach: array.forEach, | ||
map: array.map, | ||
filter: array.filter, | ||
every: array.every, | ||
some: array.some | ||
}) |
@@ -5,3 +5,3 @@ /* | ||
var $ = require("./nodes") | ||
var $ = require("./elements") | ||
@@ -12,4 +12,3 @@ require("./attributes") | ||
require("./list") | ||
require("./domready") | ||
module.exports = $ |
@@ -5,3 +5,3 @@ /* | ||
var $ = require("./nodes"), | ||
var $ = require("./elements"), | ||
array = require("prime/es5/array"), | ||
@@ -8,0 +8,0 @@ slick = require("slick") |
@@ -7,3 +7,3 @@ /* | ||
array = require("prime/es5/array"), | ||
$ = require("./nodes") | ||
$ = require("./elements") | ||
@@ -10,0 +10,0 @@ module.exports = function(expression, doc){ |
{ | ||
"name": "elements", | ||
"description": "prime dom library", | ||
"version": "0.0.6-alpha", | ||
"version": "0.0.7-alpha", | ||
"license": "MIT (http://mootools.net/license.txt)", | ||
@@ -25,8 +25,10 @@ "main": "./lib/main.js", | ||
"devDependencies": { | ||
"mocha": "1.0", | ||
"mocha": "1.4", | ||
"expect.js": "0.1", | ||
"wrapup": "0.9" | ||
"wrapup": "0.9", | ||
"robotskirt": "0.2", | ||
"highlight.js": "7" | ||
}, | ||
"optionalDependencies": { | ||
"slick": "1.9.1-alpha" | ||
"slick": "1.9.1-alpha" | ||
}, | ||
@@ -33,0 +35,0 @@ "engines": { |
@@ -1,5 +0,5 @@ | ||
Nodes | ||
===== | ||
Elements | ||
======== | ||
[![Build Status](https://secure.travis-ci.org/mootools/nodes.png?branch=master)](http://travis-ci.org/mootools/nodes) | ||
[![Build Status](https://secure.travis-ci.org/mootools/elements.png?branch=master)](http://travis-ci.org/mootools/elements) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
22434
5
16
616