Last active
October 7, 2015 18:44
-
-
Save grapho/49db2b84999dc4ee7f9b to your computer and use it in GitHub Desktop.
table-checkboxes
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Table Checkboxes' | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
didInsertElement() { | |
this._super(...arguments); | |
Ember.$('input[type="checkbox"]').change(function(e) { | |
var checked = $(this).prop("checked"), | |
container = $(this).parent(), | |
siblings = container.siblings(); | |
container.find('input[type="checkbox"]').prop({ | |
indeterminate: false, | |
checked: checked | |
}); | |
function checkSiblings(el) { | |
var parent = el.parent().parent(), | |
all = true; | |
el.siblings().each(function() { | |
return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked); | |
}); | |
if (all && checked) { | |
parent.children('input[type="checkbox"]').prop({ | |
indeterminate: false, | |
checked: checked | |
}); | |
checkSiblings(parent); | |
} else if (all && !checked) { | |
parent.children('input[type="checkbox"]').prop("checked", checked); | |
parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0)); | |
checkSiblings(parent); | |
} else { | |
el.parents("li").children('input[type="checkbox"]').prop({ | |
indeterminate: true, | |
checked: false | |
}); | |
} | |
} | |
checkSiblings(container); | |
}); | |
} | |
}); |
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
{ | |
"version": "0.4.11", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment