4 // Selector to select only not already processed elements
5 $.expr[":"].notmdproc = function(obj){
6 if ($(obj).data("mdproc")) {
13 function _isChar(evt) {
14 if (typeof evt.which == "undefined") {
16 } else if (typeof evt.which == "number" && evt.which > 0) {
17 return !evt.ctrlKey && !evt.metaKey && !evt.altKey && evt.which != 8 && evt.which != 9;
24 // These options set what will be started by $.material.init()
34 ".btn:not(.btn-link)",
36 ".navbar a:not(.withoutripple)",
38 ".nav-tabs a:not(.withoutripple)",
40 ".pagination li:not(.active, .disabled) a:not(.withoutripple)"
42 "inputElements": "input.form-control, textarea.form-control, select.form-control",
43 "checkboxElements": ".checkbox > label > input[type=checkbox]",
44 "togglebuttonElements": ".togglebutton > label > input[type=checkbox]",
45 "radioElements": ".radio > label > input[type=radio]"
47 "checkbox": function(selector) {
48 // Add fake-checkbox to material checkboxes
49 $((selector) ? selector : this.options.checkboxElements)
52 .after("<span class=checkbox-material><span class=check></span></span>");
54 "togglebutton": function(selector) {
55 // Add fake-checkbox to material checkboxes
56 $((selector) ? selector : this.options.togglebuttonElements)
59 .after("<span class=toggle></span>");
61 "radio": function(selector) {
62 // Add fake-radio to material radios
63 $((selector) ? selector : this.options.radioElements)
66 .after("<span class=circle></span><span class=check></span>");
68 "input": function(selector) {
69 $((selector) ? selector : this.options.inputElements)
75 if (!$(this).attr("data-hint") && !$this.hasClass("floating-label")) {
78 $this.wrap("<div class=form-control-wrapper></div>");
79 $this.after("<span class=material-input></span>");
81 // Add floating label if required
82 if ($this.hasClass("floating-label")) {
83 var placeholder = $this.attr("placeholder");
84 $this.attr("placeholder", null).removeClass("floating-label");
85 $this.after("<div class=floating-label>" + placeholder + "</div>");
88 // Add hint label if required
89 if ($this.attr("data-hint")) {
90 $this.after("<div class=hint>" + $this.attr("data-hint") + "</div>");
93 // Set as empty if is empty (damn I must improve this...)
94 if ($this.val() === null || $this.val() == "undefined" || $this.val() === "") {
95 $this.addClass("empty");
98 // Support for file input
99 if ($this.parent().next().is("[type=file]")) {
100 $this.parent().addClass("fileinput");
101 var $input = $this.parent().next().detach();
107 .on("change", ".checkbox input[type=checkbox]", function() { $(this).blur(); })
108 .on("keydown paste", ".form-control", function(e) {
110 $(this).removeClass("empty");
113 .on("keyup change", ".form-control", function() {
115 if ($this.val() === "" && (typeof $this[0].checkValidity != "undefined" && !$this[0].checkValidity())) {
116 $this.addClass("empty");
118 $this.removeClass("empty");
121 .on("focus", ".form-control-wrapper.fileinput", function() {
122 $(this).find("input").addClass("focus");
124 .on("blur", ".form-control-wrapper.fileinput", function() {
125 $(this).find("input").removeClass("focus");
127 .on("change", ".form-control-wrapper.fileinput [type=file]", function() {
129 $.each($(this)[0].files, function(i, file) {
130 value += file.name + ", ";
132 value = value.substring(0, value.length - 2);
134 $(this).prev().removeClass("empty");
136 $(this).prev().addClass("empty");
138 $(this).prev().val(value);
141 "ripples": function(selector) {
142 $((selector) ? selector : this.options.withRipples).ripples();
144 "autofill": function() {
146 // This part of code will detect autofill when the page is loading (username and password inputs for example)
147 var loading = setInterval(function() {
148 $("input[type!=checkbox]").each(function() {
149 if ($(this).val() && $(this).val() !== $(this).attr("value")) {
150 $(this).trigger("change");
155 // After 10 seconds we are quite sure all the needed inputs are autofilled then we can stop checking them
156 setTimeout(function() {
157 clearInterval(loading);
159 // Now we just listen on inputs of the focused form (because user can select from the autofill dropdown only when the input has focus)
162 .on("focus", "input", function() {
163 var $inputs = $(this).parents("form").find("input").not("[type=file]");
164 focused = setInterval(function() {
165 $inputs.each(function() {
166 if ($(this).val() !== $(this).attr("value")) {
167 $(this).trigger("change");
172 .on("blur", "input", function() {
173 clearInterval(focused);
177 if ($.fn.ripples && this.options.ripples) {
180 if (this.options.input) {
183 if (this.options.checkbox) {
186 if (this.options.togglebutton) {
189 if (this.options.radio) {
192 if (this.options.autofill) {
196 if (document.arrive && this.options.arrive) {
197 if ($.fn.ripples && this.options.ripples) {
198 $(document).arrive(this.options.withRipples, function() {
199 $.material.ripples($(this));
202 if (this.options.input) {
203 $(document).arrive(this.options.inputElements, function() {
204 $.material.input($(this));
207 if (this.options.checkbox) {
208 $(document).arrive(this.options.checkboxElements, function() {
209 $.material.checkbox($(this));
212 if (this.options.radio) {
213 $(document).arrive(this.options.radioElements, function() {
214 $.material.radio($(this));
217 if (this.options.togglebutton) {
218 $(document).arrive(this.options.togglebuttonElements, function() {
219 $.material.togglebutton($(this));