GitXplorerGitXplorer
t

dom-data-map

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
2c58c616714bab42d75d287493d440820d6d7927

Release 0.0.5

ttimoxley committed 12 years ago
Unverified
955b20dcbe8a7b817dc2969645d5326176ff97b7

Remove log statements.

ttimoxley committed 12 years ago
Unverified
0bb445d4a9f98ff557674585a15b91fd2f7dfd84

Release 0.0.4

ttimoxley committed 12 years ago
Unverified
d39f761958eb0699c6ebbe6a503f75f6699d80ae

Ensure to save data back to el

ttimoxley committed 12 years ago
Unverified
43a200006ee9cb007654f9f4fa73b697e99700a3

Release 0.0.3

ttimoxley committed 12 years ago
Unverified
dd01569c86b5531bd446ec9a62bf20951095425b

Add experiemental data inheritance

ttimoxley committed 12 years ago

README

The README file for this repository.

dom-data-map

Associate arbitrary data with DOM Elements via NodeList or a selector String.

Simple wrapper around yields/data to add multiple element/selector interface.

Installation

$ component install timoxley/dom-data-map

Example

var DDM = require('dom-data-map')

// Arbitrary Data
var appData = {
	users: [{
		name: 'Tim'
	}, {
		name: 'Bob'
	}]
}

// set the context for the domData callbacks
var domData = DDM(appData)

// apply a callback to each matching element
// passing the element and its associated data.
// return a new object to set/update the element's
// data.
domData('[data-user]', function(el, data) {
	var userName = el.attributes['data-user'].value
	var foundUsers = this.users.filter(function(user) {
		return user.name == userName
	})
	var foundUser = foundUsers.pop()
	data.user = foundUser
	return data
})

domData('[data-userview]', function(el, data) {
	el.innerHTML = '<h2>User:'+data.user.name+'</h2>'
})

License

MIT