-
Notifications
You must be signed in to change notification settings - Fork 4
/
jquery.bugme.js
160 lines (135 loc) · 6.57 KB
/
jquery.bugme.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
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
/**
* jQuery bugMe v1.0.7
* Copyright (C) 2013 Chris Wharton ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT
* HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR
* FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE
* OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS,
* COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.COPYRIGHT HOLDERS WILL NOT
* BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL
* DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://gnu.org/licenses/>.
*
* View the demo at http://weare2ndfloor.com/bugmebar
*
*/
(function ($) {
$.fn.bugme = function (options) {
var defaults = {
target: jQuery(this), // target of where you want the bugme bar to go
message: "Super duper exciting announcement goes in here! You can even have a link <a href='http://weare2ndfloor.com'>weare2ndfloor.com</a>", // message that goes inside the bug me bar
align: "left", // align the message left, right, center or justify
close: true, // have the close button on or off
closeText: "X", // for the little dismiss cross in the top right
closeAlign: "right", // align close button left or right
remember: true, // this stores a cookie to remember cancellation of bugme bar
expireIn: 7, // set expiry of remember cookie (in days)
cookieName: "bugmebar", // this will allow you set a cookie name
colours: true, // this will traverse through the colours in the CSS - CSS3 browsers only
animate: true, // this will animate in and out the bugme bar - CSS3 browsers only
fixed: false, // this will fix bugmebar to the top of the page
fixedSpacer: false, // want to create a bit of space for a fixed bar? Set to true
zindex: 99999 // this will allow you control the z-index of bugmebar
};
var options = $.extend(defaults, options);
return this.each(function () {
var target = options.target;
var align = options.align;
var message = options.message;
var close = options.close;
var closeText = options.closeText;
var closeAlign = options.closeAlign;
var remember = options.remember;
var expireIn = options.expireIn;
var cookieName = options.cookieName;
var colours = options.colours;
var animate = options.animate;
var fixed = options.fixed;
var fixedSpacer = options.fixedSpacer;
var zindex = options.zindex;
// lets get going
function bugMe() {
if ( closeAlign == "left" ) {
closeme = " bugme-close-left";
} else {
closeme = "";
}
if ( close ) {
closer = '<a class="bugme-close' + closeme + '" href="#">' + closeText + '</a>';
} else {
closer = "";
}
if ( animate ) {
animateme = ' bugmebar-animated bugmebar-bounceInDown';
} else {
animateme = "";
}
if ( fixed ) {
fixme = ' bugme-fixed';
} else {
fixme = "";
}
zindexme = "z-index:" + zindex;
//check for cookie present...
var bugCookieExist = jQuery.cookie(cookieName) == "close";
if ( !bugCookieExist || !remember ) {
jQuery('body').addClass('bugmebar');
jQuery(target).prepend('<div class="bugme' + animateme + fixme + '" style="text-align:'+ align +';' + zindexme + '">' + message + closer + '</div>');
// grab height of bar if its fixed and fixedSpacer is true
if ( fixedSpacer && fixed ) {
var bugmeHeight = jQuery('.bugme' , target).outerHeight();
// add to the targets margin
jQuery(target).animate({ marginTop: '+=' + bugmeHeight }, 500);
}
// slide content as it animates in
jQuery('.bugme').hide().slideDown();
if ( colours ) {
var timeoutId;
function addColourTimeout() {
timeoutId = window.setTimeout(addColour, 2000);
}
function addColour() {
jQuery('.bugme' , target).addClass("colours");
}
addColourTimeout();
}
jQuery('a.bugme-close').on( "click" , function (e) {
e.preventDefault();
jQuery('.bugme' , target).removeClass("colours").addClass("bugmebar-bounceOutUp");
if ( remember ) {
jQuery.cookie(cookieName, 'close', { expires: expireIn, path: '/' });
}
var timeoutId;
function bodyUpTimeout() {
timeoutId = window.setTimeout(bodyUp, 1000);
timeoutId = window.setTimeout(bugMeRemove, 2000);
}
function bodyUp() {
if ( fixedSpacer && fixed ) {
// animate margin back up again
jQuery(target).animate({ marginTop: '-=' + bugmeHeight }, 500);
}
jQuery('.bugme' , target).slideUp();
}
function bugMeRemove() {
jQuery('.bugme' , target).remove();
jQuery('body').removeClass('bugmebar');
}
bodyUpTimeout();
});
}
}
// run main bugMe function on load
bugMe();
});
};
})(jQuery);