Commit ddd2fe8a authored by David Stutz's avatar David Stutz

Merge pull request #400 from kayhadrin/fix/avoid-changing-unrelatd-parent-elements

#375, #383: Avoid changing unrelated parent elements.
parents 744aa223 26ac69e6
...@@ -379,11 +379,11 @@ ...@@ -379,11 +379,11 @@
// Apply or unapply the configured selected class. // Apply or unapply the configured selected class.
if (this.options.selectedClass) { if (this.options.selectedClass) {
if (checked) { if (checked) {
$target.parents('li') $target.closest('li')
.addClass(this.options.selectedClass); .addClass(this.options.selectedClass);
} }
else { else {
$target.parents('li') $target.closest('li')
.removeClass(this.options.selectedClass); .removeClass(this.options.selectedClass);
} }
} }
...@@ -415,7 +415,7 @@ ...@@ -415,7 +415,7 @@
else { else {
// Unselect all other options and corresponding checkboxes. // Unselect all other options and corresponding checkboxes.
if (this.options.selectedClass) { if (this.options.selectedClass) {
$($checkboxesNotThis).parents('li').removeClass(this.options.selectedClass); $($checkboxesNotThis).closest('li').removeClass(this.options.selectedClass);
} }
$($checkboxesNotThis).prop('checked', false); $($checkboxesNotThis).prop('checked', false);
...@@ -426,7 +426,7 @@ ...@@ -426,7 +426,7 @@
} }
if (this.options.selectedClass === "active") { if (this.options.selectedClass === "active") {
$optionsNotThis.parents("a").css("outline", ""); $optionsNotThis.closest("a").css("outline", "");
} }
} }
else { else {
...@@ -456,15 +456,15 @@ ...@@ -456,15 +456,15 @@
var checked = $target.prop('checked') || false; var checked = $target.prop('checked') || false;
if (checked) { if (checked) {
var prev = $target.parents('li:last') var prev = $target.closest('li')
.siblings('li[class="active"]:first'); .siblings('li[class="active"]:first');
var currentIdx = $target.parents('li') var currentIdx = $target.closest('li')
.index(); .index();
var prevIdx = prev.index(); var prevIdx = prev.index();
if (currentIdx > prevIdx) { if (currentIdx > prevIdx) {
$target.parents("li:last").prevUntil(prev).each( $target.closest("li").prevUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true) $(this).find("input:first").prop("checked", true)
.trigger("change"); .trigger("change");
...@@ -472,7 +472,7 @@ ...@@ -472,7 +472,7 @@
); );
} }
else { else {
$target.parents("li:last").nextUntil(prev).each( $target.closest("li").nextUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true) $(this).find("input:first").prop("checked", true)
.trigger("change"); .trigger("change");
...@@ -597,16 +597,16 @@ ...@@ -597,16 +597,16 @@
if ($element.is(':disabled')) { if ($element.is(':disabled')) {
$checkbox.attr('disabled', 'disabled') $checkbox.attr('disabled', 'disabled')
.prop('disabled', true) .prop('disabled', true)
.parents('a') .closest('a')
.attr("tabindex", "-1") .attr("tabindex", "-1")
.parents('li') .closest('li')
.addClass('disabled'); .addClass('disabled');
} }
$checkbox.prop('checked', selected); $checkbox.prop('checked', selected);
if (selected && this.options.selectedClass) { if (selected && this.options.selectedClass) {
$checkbox.parents('li') $checkbox.closest('li')
.addClass(this.options.selectedClass); .addClass(this.options.selectedClass);
} }
}, },
...@@ -804,7 +804,7 @@ ...@@ -804,7 +804,7 @@
$input.prop('checked', true); $input.prop('checked', true);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$input.parents('li') $input.closest('li')
.addClass(this.options.selectedClass); .addClass(this.options.selectedClass);
} }
} }
...@@ -812,7 +812,7 @@ ...@@ -812,7 +812,7 @@
$input.prop('checked', false); $input.prop('checked', false);
if (this.options.selectedClass) { if (this.options.selectedClass) {
$input.parents('li') $input.closest('li')
.removeClass(this.options.selectedClass); .removeClass(this.options.selectedClass);
} }
} }
...@@ -820,12 +820,12 @@ ...@@ -820,12 +820,12 @@
if ($(element).is(":disabled")) { if ($(element).is(":disabled")) {
$input.attr('disabled', 'disabled') $input.attr('disabled', 'disabled')
.prop('disabled', true) .prop('disabled', true)
.parents('li') .closest('li')
.addClass('disabled'); .addClass('disabled');
} }
else { else {
$input.prop('disabled', false) $input.prop('disabled', false)
.parents('li') .closest('li')
.removeClass('disabled'); .removeClass('disabled');
} }
}, this)); }, this));
...@@ -863,7 +863,7 @@ ...@@ -863,7 +863,7 @@
} }
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li') $checkbox.closest('li')
.addClass(this.options.selectedClass); .addClass(this.options.selectedClass);
} }
...@@ -913,7 +913,7 @@ ...@@ -913,7 +913,7 @@
} }
if (this.options.selectedClass) { if (this.options.selectedClass) {
$checkbox.parents('li') $checkbox.closest('li')
.removeClass(this.options.selectedClass); .removeClass(this.options.selectedClass);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment