Last active
October 7, 2015 14:59
-
-
Save grapho/a2d188f64b901e13f532 to your computer and use it in GitHub Desktop.
indeterminate-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:'Ember Twiddle' | |
}); |
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); | |
}); | |
}, | |
actions: { | |
somethingChanged(thing) { | |
console.log(thing + ' changed'); | |
} | |
} | |
}); |
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