yoast-overlay.js
2.27 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
/* jshint -W097 */
var yoast_overlay = null;
( function( $ ) {
yoast_overlay = {
messages: [],
current_message: null,
add_message: function( title, text, autoclose ) {
this.messages.push( { title: title, text: text, autoclose: autoclose } );
this.display_message();
},
close_message: function( el ) {
$( el ).remove();
this.current_message = null;
this.display_message();
},
display_message: function() {
if ( this.current_message === null && this.messages.length > 0 ) {
// Store this in a local var.
var that = this;
// Set the current message.
this.current_message = this.messages.shift();
// Create the element.
var el = $( "<div>" );
// Set the CSS.
$( el )
.css( "position", "fixed" )
.css( "top", "20%" )
.css( "left", "50%" )
.css( "width", 350 )
.css( "min-height", 100 )
.css( "padding", "25px" )
.css( "background", "#ffffff" )
.css( "border", "2px solid #dcddde" );
// Horizontal positioning.
$( el ).css( "margin-left", "-" + ( $( el ).width() * 0.5 ) + "px" );
// The title.
$( el ).append( $( "<h2>" )
.html( this.current_message.title )
.css( "margin", 0 )
.css( "padding", "0 0 7px" )
.css( "border-bottom", "1px solid #f18500" ) );
// The text.
$( el ).append( $( "<p>" ).css( "margin-bottom", 0 ).html( this.current_message.text ) );
// The close button.
var elClose = $( "<a>" )
.css( "position", "absolute" )
.css( "top", 0 )
.css( "right", 0 )
.css( "padding", "0 5px" )
.css( "margin", "5px" )
.css( "line-height", "17px" )
.css( "cursor", "pointer" )
.css( "color", "#f18500" )
.css( "font-weight", "bold" )
.css( "border", "1px solid #f18500" );
$( elClose ).html( "X" );
$( elClose ).click( function() {
that.close_message( el );
}
);
$( el ).append( elClose );
// Append the element to body
$( "body" ).append( el );
// Check autoclose
if ( this.current_message.autoclose !== undefined &&
this.current_message.autoclose !== false &&
this.current_message.autoclose > 0 ) {
setTimeout( function() {
that.close_message( el );
}, ( this.current_message.autoclose * 1000 )
);
}
}
},
};
} )( jQuery );