Comparing version 0.1.0 to 0.2.0
@@ -5,5 +5,7 @@ /* | ||
var $ = require("./index"), | ||
string = require("prime/shell/string"), | ||
array = require("prime/es5/array") | ||
var $ = require("./index"), | ||
clean = require("prime/string/clean"), | ||
forEach = require("prime/array/forEach"), | ||
filter = require("prime/array/filter"), | ||
indexOf = require("prime/array/indexOf") | ||
@@ -15,6 +17,5 @@ // attributes | ||
setAttribute: function(name, value){ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
node.setAttribute(name, value) | ||
}) | ||
return this | ||
}, | ||
@@ -35,7 +36,6 @@ | ||
removeAttribute: function(name){ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
var attr = node.getAttributeNode(name) | ||
if (attr) node.removeAttributeNode(attr) | ||
}) | ||
return this | ||
} | ||
@@ -47,13 +47,8 @@ | ||
array.forEach("type,value,name,href,title,id".split(","), function(name){ | ||
forEach(["type", "value", "name", "href", "title", "id"], function(name){ | ||
accessors[name] = function(value){ | ||
if (value !== undefined){ | ||
this.forEach(function(node){ | ||
node[name] = value | ||
}) | ||
return this | ||
} | ||
return this[0][name] | ||
return (value !== undefined) ? this.forEach(function(node){ | ||
node[name] = value | ||
}) : this[0][name] | ||
} | ||
@@ -65,13 +60,8 @@ | ||
array.forEach("checked,disabled,selected".split(","), function(name){ | ||
forEach(["checked", "disabled", "selected"], function(name){ | ||
accessors[name] = function(value){ | ||
if (value !== undefined){ | ||
this.forEach(function(node){ | ||
node[name] = !!value | ||
}) | ||
return this | ||
} | ||
return !!this[0][name] | ||
return (value !== undefined) ? this.forEach(function(node){ | ||
node[name] = !!value | ||
}) : !!this[0][name] | ||
} | ||
@@ -84,6 +74,6 @@ | ||
var classes = function(className){ | ||
var classNames = string.clean(className).split(" "), | ||
var classNames = clean(className).split(" "), | ||
uniques = {} | ||
return array.filter(classNames, function(className){ | ||
return filter(classNames, function(className){ | ||
if (className !== "" && !uniques[className]) return uniques[className] = className | ||
@@ -94,11 +84,5 @@ }).sort() | ||
accessors.className = function(className){ | ||
if (className !== undefined){ | ||
this.forEach(function(node){ | ||
node.className = classes(className).join(" ") | ||
}) | ||
return this | ||
} | ||
return classes(this[0].className).join(" ") | ||
return (className !== undefined) ? this.forEach(function(node){ | ||
node.className = classes(className).join(" ") | ||
}) : classes(this[0].className).join(" ") | ||
} | ||
@@ -161,7 +145,7 @@ | ||
hasClass: function(className){ | ||
return array.indexOf(this.classNames(), className) > -1 | ||
return indexOf(this.classNames(), className) > -1 | ||
}, | ||
addClass: function(className){ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
var nodeClassName = node.className | ||
@@ -171,10 +155,9 @@ var classNames = classes(nodeClassName + " " + className).join(" ") | ||
}) | ||
return this | ||
}, | ||
removeClass: function(className){ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
var classNames = classes(node.className) | ||
array.forEach(classes(className), function(className){ | ||
var index = array.indexOf(classNames, className) | ||
forEach(classes(className), function(className){ | ||
var index = indexOf(classNames, className) | ||
if (index > -1) classNames.splice(index, 1) | ||
@@ -184,3 +167,2 @@ }) | ||
}) | ||
return this | ||
} | ||
@@ -205,3 +187,3 @@ | ||
// tag, html, text | ||
// tag, html, text, data | ||
@@ -215,19 +197,15 @@ $.implement({ | ||
html: function(html){ | ||
if (html != null){ | ||
this.forEach(function(node){ | ||
node.innerHTML = html | ||
}) | ||
return this | ||
} | ||
return this[0].innerHTML | ||
return (html !== undefined) ? this.forEach(function(node){ | ||
node.innerHTML = html | ||
}) : this[0].innerHTML | ||
}, | ||
text: function(text){ | ||
if (text != undefined){ | ||
this.forEach(function(node){ | ||
node[textProperty] = text | ||
}) | ||
return this | ||
} | ||
return this[0][textProperty] | ||
return (text !== undefined) ? this.forEach(function(node){ | ||
node[textProperty] = text | ||
}) : this[0][textProperty] | ||
}, | ||
data: function(key, value){ | ||
return (value !== undefined) ? this.setAttribute("data-" + key, value) : this.getAttribute('data-' + key) | ||
} | ||
@@ -234,0 +212,0 @@ |
@@ -14,3 +14,3 @@ /* | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
@@ -26,2 +26,3 @@ var self = $(node) | ||
match = target.matches(selector) ? target : target.parent(selector) | ||
if (match) handle.call(self, e, match) | ||
@@ -36,4 +37,2 @@ } | ||
return this | ||
}, | ||
@@ -43,3 +42,3 @@ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
@@ -76,3 +75,2 @@ var self = $(node), delegation, events, map | ||
return this | ||
} | ||
@@ -79,0 +77,0 @@ |
@@ -29,3 +29,3 @@ /* | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
var self = $(node) | ||
@@ -37,7 +37,5 @@ | ||
if (!domListeners[event]) domListeners[event] = addEventListener(node, event, function(e){ | ||
self.emit(event, (e || window.event)) | ||
self.emit(event, e || window.event, Emitter.EMIT_SYNC) | ||
}) | ||
}) | ||
return this | ||
}, | ||
@@ -47,3 +45,3 @@ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
@@ -68,3 +66,7 @@ var self = $(node) | ||
for (l in domListeners) empty = false | ||
for (l in domListeners){ | ||
empty = false | ||
break | ||
} | ||
if (empty) delete self._domListeners | ||
@@ -75,4 +77,2 @@ } | ||
}) | ||
return this | ||
}, | ||
@@ -82,6 +82,5 @@ | ||
var args = arguments | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
Emitter.prototype.emit.apply($(node), args) | ||
}) | ||
return this | ||
} | ||
@@ -88,0 +87,0 @@ |
32
index.js
@@ -5,4 +5,8 @@ /* | ||
var prime = require("prime"), | ||
array = require("prime/es5/array").prototype | ||
var prime = require("prime"), | ||
forEach = require("prime/array/forEach"), | ||
map = require("prime/array/map"), | ||
filter = require("prime/array/filter"), | ||
every = require("prime/array/every"), | ||
some = require("prime/array/some") | ||
@@ -95,10 +99,24 @@ // uniqueID | ||
forEach: array.forEach, | ||
map: array.map, | ||
filter: array.filter, | ||
every: array.every, | ||
some: array.some | ||
forEach: function(method, context){ | ||
return forEach(this, method, context); | ||
}, | ||
map: function(method, context){ | ||
return map(this, method, context); | ||
}, | ||
filter: function(method, context){ | ||
return filter(this, method, context); | ||
}, | ||
every: function(method, context){ | ||
return every(this, method, context); | ||
}, | ||
some: function(method, context){ | ||
return some(this, method, context); | ||
} | ||
}) | ||
module.exports = $ |
@@ -57,6 +57,5 @@ /* | ||
element = $(element)[0] | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
element.appendChild(node) | ||
}) | ||
return this | ||
}, | ||
@@ -66,6 +65,5 @@ | ||
element = $(element)[0] | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
element.insertBefore(node, element.firstChild) | ||
}) | ||
return this | ||
} | ||
@@ -82,7 +80,6 @@ | ||
remove: function(){ | ||
this.forEach(function(node){ | ||
return this.forEach(function(node){ | ||
var parent = node.parentNode | ||
if (parent) parent.removeChild(node) | ||
}) | ||
return this | ||
}, | ||
@@ -89,0 +86,0 @@ |
{ | ||
"name": "elements", | ||
"description": "prime dom library", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT (http://mootools.net/license.txt)", | ||
@@ -22,10 +22,10 @@ "main": "./index.js", | ||
"dependencies": { | ||
"prime": "0.1", | ||
"prime": "0.2", | ||
"slick": "1.10" | ||
}, | ||
"devDependencies": { | ||
"mocha": "1.4", | ||
"expect.js": "0.1", | ||
"wrapup": "0.10", | ||
"procs": "0.0.4" | ||
"mocha": "1", | ||
"mocha-phantomjs": "2.0", | ||
"expect.js": "0.2", | ||
"wrapup": "0.12" | ||
}, | ||
@@ -32,0 +32,0 @@ "engines": { |
@@ -6,3 +6,3 @@ /* | ||
var $ = require("./index"), | ||
array = require("prime/es5/array"), | ||
map = require("prime/array/map"), | ||
slick = require("slick") | ||
@@ -15,3 +15,3 @@ | ||
expression = array.map(parts, function(part){ | ||
expression = map(parts, function(part){ | ||
return combinator + " " + part | ||
@@ -51,2 +51,6 @@ }).join(", ") | ||
contains: function(node){ | ||
return slick.contains(this[0], node) | ||
}, | ||
nextSiblings: walk("~", "search"), | ||
@@ -53,0 +57,0 @@ |
15
zen.js
@@ -5,13 +5,14 @@ /* | ||
var $ = require("./index"), | ||
parse = require("slick/parser"), | ||
array = require("prime/es5/array") | ||
var $ = require("./index"), | ||
parse = require("slick/parser"), | ||
forEach = require("prime/array/forEach"), | ||
map = require("prime/array/map") | ||
module.exports = function(expression, doc){ | ||
return $(array.map(parse(expression), function(expression){ | ||
return $(map(parse(expression), function(expression){ | ||
var previous, result | ||
array.forEach(expression, function(part, i){ | ||
forEach(expression, function(part, i){ | ||
@@ -24,7 +25,7 @@ var node = (doc || document).createElement(part.tag) | ||
if (part.attributes) array.forEach(part.attributes, function(attribute){ | ||
if (part.attributes) forEach(part.attributes, function(attribute){ | ||
node.setAttribute(attribute.name, attribute.value) | ||
}) | ||
if (part.pseudos) array.forEach(part.pseudos, function(pseudo){ | ||
if (part.pseudos) forEach(part.pseudos, function(pseudo){ | ||
var n = $(node), method = n[pseudo.name] | ||
@@ -31,0 +32,0 @@ if (method) method.call(n, pseudo.value) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
0
20451
11
579
+ Addedprime@0.2.1(transitive)
- Removedprime@0.1.0(transitive)
Updatedprime@0.2