Comparing version 2.1.0 to 2.2.0
@@ -7,2 +7,9 @@ # Change Log | ||
## 2.2.0 - 2017-11-06 | ||
### Added | ||
* If the second argument of `d.data()` is an array of keys, returns an object with all {key: value} | ||
* If the second argument of `d.data()` is undefined, returns an object with all values | ||
## 2.1.0 - 2017-10-20 | ||
@@ -9,0 +16,0 @@ |
21
d.js
@@ -189,5 +189,24 @@ 'use strict'; | ||
data: function(query, name, value) { | ||
if (arguments.length < 3 && typeof name !== 'object') { | ||
if ( | ||
arguments.length < 3 && | ||
(typeof name !== 'object' || Array.isArray(name)) | ||
) { | ||
var element = d.get(query); | ||
if (!name) { | ||
name = Object.keys(element.dataset); | ||
} | ||
if (Array.isArray(name)) { | ||
var values = {}; | ||
name.forEach(function(name) { | ||
if (element.dataset[name]) { | ||
values[name] = dataValue(element.dataset[name]); | ||
} | ||
}); | ||
return values; | ||
} | ||
if (!element || !element.dataset[name]) { | ||
@@ -194,0 +213,0 @@ return; |
{ | ||
"name": "d_js", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "DOM manipulation micro-library", | ||
@@ -5,0 +5,0 @@ "main": "d.js", |
@@ -129,3 +129,3 @@ # d.js | ||
* **query** A string with the selector, array of elements or a Node/NodeList/HTMLCollection instance | ||
* **name** A string with the name of the data attribute or an object with name/values | ||
* **name** A string with the name of the data attribute, an array of names or an object with name/values | ||
* **value** The new value of the property | ||
@@ -148,2 +148,9 @@ | ||
}); | ||
//Get some values | ||
var someValues = d.data('.button', ['clicked', 'boolean', 'array']); | ||
//Get all values | ||
var allValues = d.data('.button'); | ||
``` | ||
@@ -150,0 +157,0 @@ |
Sorry, the diff of this file is not supported yet
32337
422
210