mdb-ui-kit/scripts/material.js

49 lines
1.8 KiB
JavaScript
Raw Normal View History

/* globals ripples */
2014-08-18 18:25:33 +04:00
$(function (){
ripples.init(".btn:not(.btn-link), .navbar a, .nav-tabs a, .withripple");
2014-08-18 18:25:33 +04:00
// Add fake-checkbox to material checkboxes
$(".checkbox label input").after("<span class=ripple></span><span class=check></span><span class=box></span>");
2014-08-18 18:25:33 +04:00
// Add fake-radio to material radios
$(".radio label input").after("<span class=ripple></span><span class=circle></span><span class=check></span>");
2014-08-18 18:25:33 +04:00
// Add elements for material inputs
$("input.form-control, textarea.form-control, select.form-control").each( function() {
2014-08-18 18:25:33 +04:00
$(this).wrap("<div class=form-control-wrapper></div>");
$(this).after("<span class=material-input></span>");
if ($(this).hasClass("floating-label")) {
var placeholder = $(this).attr("placeholder");
$(this).attr("placeholder", null).removeClass("floating-label");
$(this).after("<div class=floating-label>" + placeholder + "</div>");
}
if ($(this).val() === "") {
$(this).addClass("empty");
}
});
// Material inputs engine (ripple effect)
2014-08-18 18:25:33 +04:00
$(document).on("click", ".checkbox label, .radio label", function() {
var $ripple = $(this).find(".ripple"),
2014-08-18 18:25:33 +04:00
timestamp = "t" + new Date().getTime();
$ripple.attr("class", "ripple");
$ripple.addClass("animate").addClass(timestamp);
2014-08-18 18:25:33 +04:00
setTimeout(function() {
if ($ripple.hasClass(timestamp)) {
$ripple.removeClass("animate").removeClass(timestamp);
2014-08-18 18:25:33 +04:00
}
}, 800);
2014-08-18 18:25:33 +04:00
});
$(document).on("change", ".form-control", function() {
if ($(this).val() !== "") {
$(this).removeClass("empty");
} else {
$(this).addClass("empty");
}
});
});