Commit 47d60e38 authored by David Stutz's avatar David Stutz

Merge pull request #274 from yuripc/patch-2

Remove multiple $(event.target) object creation.
parents 382e0976 b45532b0
...@@ -320,27 +320,29 @@ ...@@ -320,27 +320,29 @@
// Bind the change event on the dropdown elements. // Bind the change event on the dropdown elements.
$('li input', this.$ul).on('change', $.proxy(function(event) { $('li input', this.$ul).on('change', $.proxy(function(event) {
var checked = $(event.target).prop('checked') || false; var $target = $(event.target);
var isSelectAllOption = $(event.target).val() === this.options.selectAllValue;
var checked = $target.prop('checked') || false;
var isSelectAllOption = $target.val() === this.options.selectAllValue;
// 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) {
$(event.target).parents('li') $target.parents('li')
.addClass(this.options.selectedClass); .addClass(this.options.selectedClass);
} }
else { else {
$(event.target).parents('li') $target.parents('li')
.removeClass(this.options.selectedClass); .removeClass(this.options.selectedClass);
} }
} }
// Get the corresponding option. // Get the corresponding option.
var value = $(event.target).val(); var value = $target.val();
var $option = this.getOptionByValue(value); var $option = this.getOptionByValue(value);
var $optionsNotThis = $('option', this.$select).not($option); var $optionsNotThis = $('option', this.$select).not($option);
var $checkboxesNotThis = $('input', this.$container).not($(event.target)); var $checkboxesNotThis = $('input', this.$container).not($target);
if (isSelectAllOption) { if (isSelectAllOption) {
if (this.$select[0][0].value === this.options.selectAllValue) { if (this.$select[0][0].value === this.options.selectAllValue) {
...@@ -408,19 +410,21 @@ ...@@ -408,19 +410,21 @@
$('li a', this.$ul).on('touchstart click', function(event) { $('li a', this.$ul).on('touchstart click', function(event) {
event.stopPropagation(); event.stopPropagation();
var $target = $(event.target);
if (event.shiftKey) { if (event.shiftKey) {
var checked = $(event.target).prop('checked') || false; var checked = $target.prop('checked') || false;
if (checked) { if (checked) {
var prev = $(event.target).parents('li:last') var prev = $target.parents('li:last')
.siblings('li[class="active"]:first'); .siblings('li[class="active"]:first');
var currentIdx = $(event.target).parents('li') var currentIdx = $target.parents('li')
.index(); .index();
var prevIdx = prev.index(); var prevIdx = prev.index();
if (currentIdx > prevIdx) { if (currentIdx > prevIdx) {
$(event.target).parents("li:last").prevUntil(prev).each( $target.parents("li:last").prevUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true) $(this).find("input:first").prop("checked", true)
.trigger("change"); .trigger("change");
...@@ -428,7 +432,7 @@ ...@@ -428,7 +432,7 @@
); );
} }
else { else {
$(event.target).parents("li:last").nextUntil(prev).each( $target.parents("li:last").nextUntil(prev).each(
function() { function() {
$(this).find("input:first").prop("checked", true) $(this).find("input:first").prop("checked", true)
.trigger("change"); .trigger("change");
...@@ -438,7 +442,7 @@ ...@@ -438,7 +442,7 @@
} }
} }
$(event.target).blur(); $target.blur();
}); });
// Keyboard support. // Keyboard support.
......
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