-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
50 lines (47 loc) · 1.77 KB
/
Utils.js
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
// Configurar estilos que vienen como parametros a un elemento
var addStyles = function(element, defaultStyles={}, paramStyles={}){
var styles = {}
Object.assign(styles, defaultStyles, paramStyles)
Object.keys(styles).map(
function(style){
element.css(style, styles[style])
}
)
}
// Asignar eventos que vienen como parametros a un elemento
var addEventHandlers = function(element, eventHandlersDefault={}, eventHandlersParam={}){
// Agregamos manejadores por parametros
Object.keys(eventHandlersParam).map(
function(event){
if (event == "load"){
eventHandlersParam[event]()
} else {
element.on(event, eventHandlersParam[event]);
}
}
)
// Agregamos manejadores por default
Object.keys(eventHandlersDefault).map(
function(event){
element.on(event, eventHandlersDefault[event]);
}
)
}
var addInputStyles = function(div){
var $element = $("#" + div)
$("input, select, option, button", $element).addClass("ui-state-default")
.css("padding", "5px")
var focus = function(){$(this).off("mouseenter mouseleave")
$(this).removeClass()
$(this).addClass("ui-state-active")}
var mouseenter = function(){$(this).removeClass();$(this).addClass("ui-state-hover")}
var mouseleave = function(){$(this).removeClass();$(this).addClass("ui-state-default")}
var blur = function(){
$(this).removeClass()
$(this).addClass("ui-state-default")
.on("mouseenter", mouseenter).on("mouseleave", mouseleave)}
$("input, select, option, button", $element).on("focus", focus)
$("input, select, option, button", $element).on("mouseenter", mouseenter)
$("input, select, option, button", $element).on("mouseleave", mouseleave)
$("input, select, option, button", $element).on("blur", blur)
}