Created
July 5, 2011 15:59
-
-
Save ryanflorence/1065115 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new List.Checkbox(element, options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--- | |
name: List.CheckBox | |
license: MIT-style license. | |
copyright: Copyright (c) 2011 [Ryan Florence](http://ryanflorence.com/). | |
author: Ryan Florence | |
requires: | |
- /List | |
provides: [List.Checkbox] | |
... | |
*/ | |
List.Checkbox = new Class({ | |
Extends: List, | |
selectOne: function (event, target){ | |
var input = document.id(target.get('data-only')); | |
if (!input || input.disabled) return; | |
// selecting every click so it can have dynamic contents | |
this.inputs.set('checked', false); | |
input.set('checked', true); | |
this.fireEvent('selectOne', [input]); | |
}, | |
selectAll: function (event, target){ | |
this.inputs.set('checked', true); | |
this.fireEvent('selectAll'); | |
}, | |
deselectAll: function (){ | |
this.inputs.set('checked', false); | |
this.fireEvent('deselectAll'); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
--- | |
name: List | |
license: MIT-style license. | |
copyright: Copyright (c) 2011 [Ryan Florence](http://ryanflorence.com/). | |
author: Ryan Florence | |
requires: | |
- Core/Element.Event | |
- Core/Class.Extras | |
- More/Element.Delegation | |
provides: [List] | |
... | |
*/ | |
(function (){ | |
var empty = function (){}; | |
var List = this.List = new Class({ | |
Implements: [Options, Events], | |
options: { | |
input: 'input[type=checkbox]', | |
only: '[data-only]', | |
'select-all': '[data-select-all]', | |
'deselect-all': '[data-deselect-all]' | |
}, | |
events: {}, | |
initialize: function (element, options){ | |
this.setOptions(options); | |
this.element = document.id(element); | |
this.events['click:relay('+this.options.only+')'] = this.selectOne.bind(this); | |
this.events['click:relay('+this.options['select-all']+')'] = this.selectAll.bind(this); | |
this.events['click:relay('+this.options['deselect-all']+')'] = this.deselectAll.bind(this); | |
this.inputs = this.element.getElements(this.options.input); | |
this.attach(); | |
}, | |
attach: function (detach){ | |
this.element[(detach ? 'remove' : 'add') + 'Events'](this.events); | |
}, | |
selectOne: empty, | |
selectAll: empty, | |
deselectAll: empty | |
}); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment