forked from szerko/Respond2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.js
89 lines (67 loc) · 2.32 KB
/
messages.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
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
/*var example = {
init:function(){
$('#show').click(function(){
message.showMessage('progress', 'Something is loading, please wait.');
});
$('#switchToSuccess').click(function(){
message.showMessage('success', 'Woo hoo! You accomplished your task.');
});
$('#switchToError').click(function(){
message.showMessage('error', 'Uh oh! Something is not right. Check the form.');
});
}
}*/
// handles messaging
var message = {
// shows the progress message
showMessage:function(type, text){
// create message if it does note exist
if($('#message').length == 0){
$('body').append('<p id="message"><span></span><a class="close" href="#"></a></p>');
}
$('#message span').html(text); // set text
// center the message
var calc = $(window).width()/2; // set left
calc -= ($('#message').width()/2);
calc = calc + 'px';
$('#message').css({left:calc});
if($('#message').hasClass('visible')){ // transition
$('#message').addClass('message-'+type);
$('#message').fadeIn();
}
else{
message.removeAllClasses();
$('#message').addClass('visible ');
$('#message').addClass('message-'+type);
$('#message').animate({marginTop:'0'}, 200);
}
if(type=='success'){ // for success messages, we want to fade it out
setTimeout('message.hide()', 2000);
}
if(type=='error'){ // for error messages, we want to fade it out, but a little slower
setTimeout('message.hide()', 3000);
}
$('#message a.close').click(function(){
$('#message').fadeOut();
$('#message').removeClass('visible');
return false;
});
},
// removes all display clases
removeAllClasses:function(){
$('#message').removeClass('message-error');
$('#message').removeClass('message-success');
$('#message').removeClass('message-progress');
},
// gets the current class
getCurrentClass:function(){
if($('#message').hasClass('message-error'))return 'error';
else if($('#message').hasClass('message-success'))return 'success';
else if($('#message').hasClass('message-progress'))return 'progress';
},
// hides the message
hide:function(){
$('#message').animate({marginTop:'-46px'}, 100);
$('#message').removeClass('visible');
}
}