2014-08-25 15:00:49 +04:00
|
|
|
/* globals ripples */
|
|
|
|
|
2014-08-18 18:25:33 +04:00
|
|
|
$(function (){
|
|
|
|
|
2014-10-03 15:03:59 +04:00
|
|
|
if (typeof ripples == "object") {
|
2014-10-12 14:27:47 +04:00
|
|
|
ripples.init( ".btn:not(.btn-link)," +
|
2014-10-13 13:58:25 +04:00
|
|
|
".card-image," +
|
2014-10-12 14:27:47 +04:00
|
|
|
".navbar a:not(.withoutripple)," +
|
|
|
|
".nav-tabs a:not(.withoutripple)," +
|
|
|
|
".withripple" );
|
2014-09-29 11:32:47 +04:00
|
|
|
}
|
2014-08-18 18:25:33 +04:00
|
|
|
|
2014-09-23 13:21:38 +04:00
|
|
|
var initInputs = function() {
|
2014-09-23 12:28:01 +04:00
|
|
|
// Add fake-checkbox to material checkboxes
|
|
|
|
$(".checkbox > label > input").not(".bs-material").addClass("bs-material").after("<span class=check></span>");
|
|
|
|
|
|
|
|
// Add fake-radio to material radios
|
|
|
|
$(".radio > label > input").not(".bs-material").addClass("bs-material").after("<span class=circle></span><span class=check></span>");
|
|
|
|
|
|
|
|
// Add elements for material inputs
|
2014-09-23 13:21:38 +04:00
|
|
|
$("input.form-control, textarea.form-control, select.form-control").not(".bs-material").each( function() {
|
2014-09-23 13:05:06 +04:00
|
|
|
if ($(this).is(".bs-material")) { return; }
|
2014-09-23 12:28:01 +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).is(":empty") || $(this).val() === null || $(this).val() == "undefined" || $(this).val() === "") {
|
|
|
|
$(this).addClass("empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($(this).parent().next().is("[type=file]")) {
|
|
|
|
$(this).parent().addClass("fileinput");
|
|
|
|
var $input = $(this).parent().next().detach();
|
|
|
|
$(this).after($input);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-09-23 13:21:38 +04:00
|
|
|
};
|
|
|
|
initInputs();
|
2014-08-18 18:25:33 +04:00
|
|
|
|
2014-09-23 13:21:38 +04:00
|
|
|
// Support for "arrive.js" to dynamically detect creation of elements
|
|
|
|
// include it before this script to take advantage of this feature
|
|
|
|
// https://github.com/uzairfarooq/arrive/
|
|
|
|
if (document.arrive) {
|
|
|
|
document.arrive("input, textarea, select", function() {
|
|
|
|
initInputs();
|
|
|
|
});
|
|
|
|
}
|
2014-09-23 12:28:01 +04:00
|
|
|
|
2014-09-29 11:32:47 +04:00
|
|
|
$(document).on("change", ".checkbox input", function() {
|
|
|
|
$(this).blur();
|
|
|
|
});
|
|
|
|
|
2014-09-08 11:39:40 +04:00
|
|
|
$(document).on("keyup change", ".form-control", function() {
|
2014-09-22 13:39:24 +04:00
|
|
|
var self = $(this);
|
|
|
|
setTimeout(function() {
|
|
|
|
if (self.val() === "") {
|
|
|
|
self.addClass("empty");
|
|
|
|
} else {
|
|
|
|
self.removeClass("empty");
|
|
|
|
}
|
|
|
|
}, 1);
|
2014-09-08 11:39:40 +04:00
|
|
|
});
|
2014-09-18 12:40:57 +04:00
|
|
|
$(document)
|
|
|
|
.on("focus", ".form-control-wrapper.fileinput", function() {
|
|
|
|
$(this).find("input").addClass("focus");
|
|
|
|
})
|
|
|
|
.on("blur", ".form-control-wrapper.fileinput", function() {
|
|
|
|
$(this).find("input").removeClass("focus");
|
|
|
|
})
|
|
|
|
.on("change", ".form-control-wrapper.fileinput [type=file]", function() {
|
|
|
|
var value = "";
|
|
|
|
$.each($(this)[0].files, function(i, file) {
|
|
|
|
console.log(file);
|
|
|
|
value += file.name + ", ";
|
|
|
|
});
|
|
|
|
value = value.substring(0, value.length - 2);
|
|
|
|
if (value) {
|
|
|
|
$(this).prev().removeClass("empty");
|
|
|
|
} else {
|
|
|
|
$(this).prev().addClass("empty");
|
|
|
|
}
|
|
|
|
$(this).prev().val(value);
|
|
|
|
});
|
2014-08-18 18:25:33 +04:00
|
|
|
});
|