main.js
10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
'use strict';
$(document).ready(function () {
Waves.init();
Waves.attach('.flat-icon', ['waves-circle']);
Waves.attach('.button', ['waves-button', 'waves-float']);
$('#btn-mobile').click(function(event) {
$('.overlay-mobile').fadeIn('fast');
});
$('.overlay-mobile').click(function(){
$(this).fadeOut('fast');
$('body').removeClass('active');
$('#btn-mobile .material-icon').removeClass('arrow')
$('#btn-mobile .material-icon').addClass('hamburger');
});
$('form .form-control').each(function () {
if ($(this).val() !== '') $(this).parents('.form-group').addClass('active');
});
$('.trigger').trigger('click');
$('form .form-control').focus(function () {
$(this).parents('.form-group').addClass('active');
});
$('form .form-control').blur(function () {
if ($(this).val() === '') {
$(this).parents('.form-group').removeClass('active');
}
});
$('.menu .dropdown a').click(function () {
$(this).siblings('ul').slideToggle('fast');
});
$('.search').click(function () {
$(this).siblings('form').toggleClass('active');
setTimeout(function () {
$('.form-search.active input').focus();
}, 500);
});
$('.material-grid').click(function () {
$('body').toggleClass('active');
});
$("section.material-green").mouseup(function () {
if ($(".material-green div.material-icon").hasClass("hamburger")) {
$(".material-green div.material-icon").removeClass("hamburger").addClass("arrow");
} else {
$(".material-green div.material-icon").removeClass("arrow").addClass("hamburger");
}
});
$('.selectpicker').on('loaded.bs.select', function (e) {
$('form .bootstrap-select').click(function () {
$(this).parents('.form-group').addClass('active');
});
});
$('.selectpicker').on('hidden.bs.select', function (e) {
$(this).parents('.form-group').removeClass('active');
});
$('.count').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
duration: 4000,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
}
});
});
function notify() {
Notification.requestPermission(function() {
var notification = new Notification("Título", {
icon: 'http://i.stack.imgur.com/dmHl0.png',
body: "Texto da notificação"
});
notification.onclick = function() {
window.open("http://stackoverflow.com");
}
});
}
});
//checkbox
var ripples = {
init : function(withRipple) {
"use strict";
// Cross browser matches function
function matchesSelector(dom_element, selector) {
var matches = dom_element.matches || dom_element.matchesSelector || dom_element.webkitMatchesSelector || dom_element.mozMatchesSelector || dom_element.msMatchesSelector || dom_element.oMatchesSelector;
return matches.call(dom_element, selector);
}
// animations time
var rippleOutTime = 100,
rippleStartTime = 500;
// Helper to bind events on dynamically created elements
var bind = function(event, selector, callback) {
document.addEventListener(event, function(e) {
var target = (typeof e.detail !== "number") ? e.detail : e.target;
if (matchesSelector(target, selector)) {
callback(e, target);
}
});
};
var rippleStart = function(e, target) {
// Init variables
var $rippleWrapper = target,
$el = $rippleWrapper.parentNode,
$ripple = document.createElement("div"),
elPos = $el.getBoundingClientRect(),
mousePos = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
scale = "transform:scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
rippleEnd = new CustomEvent("rippleEnd", {detail: $ripple}),
refreshElementStyle;
$ripplecache = $ripple;
// Set ripple class
$ripple.className = "ripple";
// Move ripple to the mouse position
$ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
// Insert new ripple into ripple wrapper
$rippleWrapper.appendChild($ripple);
// Make sure the ripple has the class applied (ugly hack but it works)
refreshElementStyle = window.getComputedStyle($ripple).opacity;
// Let other funtions know that this element is animating
$ripple.dataset.animating = 1;
// Set scale value to ripple and animate it
$ripple.className = "ripple ripple-on";
$ripple.setAttribute("style", $ripple.getAttribute("style") + ["-ms-" + scale,"-moz-" + scale,"-webkit-" + scale,scale].join(";"));
// This function is called when the animation is finished
setTimeout(function() {
// Let know to other functions that this element has finished the animation
$ripple.dataset.animating = 0;
document.dispatchEvent(rippleEnd);
}, rippleStartTime);
};
var rippleOut = function($ripple) {
// Clear previous animation
$ripple.className = "ripple ripple-on ripple-out";
// Let ripple fade out (with CSS)
setTimeout(function() {
$ripple.remove();
}, rippleOutTime);
};
// Helper, need to know if mouse is up or down
var mouseDown = false;
document.body.onmousedown = function() {
mouseDown = true;
};
document.body.onmouseup = function() {
mouseDown = false;
};
// Append ripple wrapper if not exists already
var rippleInit = function(e, target) {
if (target.getElementsByClassName("ripple-wrapper").length === 0) {
target.className += " withripple";
var $rippleWrapper = document.createElement("div");
$rippleWrapper.className = "ripple-wrapper";
target.appendChild($rippleWrapper);
}
};
var $ripplecache;
// Events handler
// init RippleJS and start ripple effect on mousedown
bind("mouseover", withRipple, rippleInit);
// start ripple effect on mousedown
bind("mousedown", ".ripple-wrapper", rippleStart);
// if animation ends and user is not holding mouse then destroy the ripple
bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
if (!mouseDown) {
rippleOut($ripple);
}
});
// Destroy ripple when mouse is not holded anymore if the ripple still exists
bind("mouseup", ".ripple-wrapper", function() {
var $ripple = $ripplecache;
if ($ripple.dataset.animating != 1) {
rippleOut($ripple);
}
});
}
};
/* globals ripples */
$(function (){
if (ripples) {
ripples.init(".btn:not(.btn-link), .navbar a, .nav-tabs a, .withripple");
}
var initInputs = function() {
// 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
$("input.form-control, textarea.form-control, select.form-control").not(".bs-material").each( function() {
if ($(this).is(".bs-material")) { return; }
$(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);
}
});
};
initInputs();
// 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();
});
}
$(document).on("change", ".checkbox input", function() {
$(this).blur();
});
$(document).on("keyup change", ".form-control", function() {
var self = $(this);
setTimeout(function() {
if (self.val() === "") {
self.addClass("empty");
} else {
self.removeClass("empty");
}
}, 1);
});
$(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) {
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);
});
});
$(window).load(function() {
setTimeout(function(){
$("#loading").fadeOut('slow');
}, 500);
});
//# sourceMappingURL=main.js.map