Merge pull request #659 from dciccale/patch-1

more $(this) caching
This commit is contained in:
Fez Vrasta 2015-08-04 13:59:19 +02:00
commit c6352f3606

View File

@ -72,7 +72,7 @@
.each( function() { .each( function() {
var $this = $(this); var $this = $(this);
if (!$(this).attr("data-hint") && !$this.hasClass("floating-label")) { if (!$this.attr("data-hint") && !$this.hasClass("floating-label")) {
return; return;
} }
$this.wrap("<div class=form-control-wrapper></div>"); $this.wrap("<div class=form-control-wrapper></div>");
@ -125,17 +125,18 @@
$(this).find("input").removeClass("focus"); $(this).find("input").removeClass("focus");
}) })
.on("change", ".form-control-wrapper.fileinput [type=file]", function() { .on("change", ".form-control-wrapper.fileinput [type=file]", function() {
var $this = $(this);
var value = ""; var value = "";
$.each($(this)[0].files, function(i, file) { $.each(this.files, function(i, file) {
value += file.name + ", "; value += file.name + ", ";
}); });
value = value.substring(0, value.length - 2); value = value.substring(0, value.length - 2);
if (value) { if (value) {
$(this).prev().removeClass("empty"); $this.prev().removeClass("empty");
} else { } else {
$(this).prev().addClass("empty"); $this.prev().addClass("empty");
} }
$(this).prev().val(value); $this.prev().val(value);
}); });
}, },
"ripples": function(selector) { "ripples": function(selector) {
@ -146,8 +147,9 @@
// This part of code will detect autofill when the page is loading (username and password inputs for example) // This part of code will detect autofill when the page is loading (username and password inputs for example)
var loading = setInterval(function() { var loading = setInterval(function() {
$("input[type!=checkbox]").each(function() { $("input[type!=checkbox]").each(function() {
if ($(this).val() && $(this).val() !== $(this).attr("value")) { var $this = $(this);
$(this).trigger("change"); if ($this.val() && $this.val() !== $this.attr("value")) {
$this.trigger("change");
} }
}); });
}, 100); }, 100);
@ -163,8 +165,9 @@
var $inputs = $(this).parents("form").find("input").not("[type=file]"); var $inputs = $(this).parents("form").find("input").not("[type=file]");
focused = setInterval(function() { focused = setInterval(function() {
$inputs.each(function() { $inputs.each(function() {
if ($(this).val() !== $(this).attr("value")) { var $this = $(this);
$(this).trigger("change"); if ($this.val() !== $this.attr("value")) {
$this.trigger("change");
} }
}); });
}, 100); }, 100);
@ -174,6 +177,8 @@
}); });
}, },
"init": function() { "init": function() {
var $document = $(document);
if ($.fn.ripples && this.options.ripples) { if ($.fn.ripples && this.options.ripples) {
this.ripples(); this.ripples();
} }
@ -195,27 +200,27 @@
if (document.arrive && this.options.arrive) { if (document.arrive && this.options.arrive) {
if ($.fn.ripples && this.options.ripples) { if ($.fn.ripples && this.options.ripples) {
$(document).arrive(this.options.withRipples, function() { $document.arrive(this.options.withRipples, function() {
$.material.ripples($(this)); $.material.ripples($(this));
}); });
} }
if (this.options.input) { if (this.options.input) {
$(document).arrive(this.options.inputElements, function() { $document.arrive(this.options.inputElements, function() {
$.material.input($(this)); $.material.input($(this));
}); });
} }
if (this.options.checkbox) { if (this.options.checkbox) {
$(document).arrive(this.options.checkboxElements, function() { $document.arrive(this.options.checkboxElements, function() {
$.material.checkbox($(this)); $.material.checkbox($(this));
}); });
} }
if (this.options.radio) { if (this.options.radio) {
$(document).arrive(this.options.radioElements, function() { $document.arrive(this.options.radioElements, function() {
$.material.radio($(this)); $.material.radio($(this));
}); });
} }
if (this.options.togglebutton) { if (this.options.togglebutton) {
$(document).arrive(this.options.togglebuttonElements, function() { $document.arrive(this.options.togglebuttonElements, function() {
$.material.togglebutton($(this)); $.material.togglebutton($(this));
}); });
} }