-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrorDisplay.js
More file actions
266 lines (216 loc) · 12.1 KB
/
errorDisplay.js
File metadata and controls
266 lines (216 loc) · 12.1 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
(function ($) {
"use strict";
var errorDisplayHtml = (
''
+ '<div class="errorDisplay">'
+ '<span class="errorDisplayOptions">'
+ '<button class="errorDisplayDetailsButton">See Details</button>'
+ '<a href="" class="errorDisplayXButton">✖</a>'
+ '</span>'
+ '<span class="errorDisplaySummary"></span>'
+ '<span class="errorDisplayOverflow">...</span>'
+ '</div>'
+ '<div class="errorDisplayRetrieverOuter">'
+ '<span class="errorDisplayRetriever"></span>'
+ '</div>'
);
var detailDisplayHtml = (
'' + '<div class="errorDisplayDetailsOuter">'
+ '<a href="" class="errorDisplayDetailsXButton">✖</a>'
+ '<div class="errorDisplayDetails">'
+ '<span class="errorDisplayFullMessageArea"></span>'
+ '</div>'
+ '</div>'
);
var detailDisplayListHtml = (
''
+ '<ul class="errorDisplayFullMessageList">'
+ '</ul>'
);
/** templates **/
var singleLineMessageTemplate = (
' <div class="errorDisplayDetailsListItem">' +
' <span class ="{{class}}">{{bullet}}</span><span> {{message}}</span>' +
' </div>'
);
var multiLineMessageOuterTemplate = (
' <div class="errorDisplayDetailsListItem">' +
' <div class="errorDisplayDetailsListItemCollapsed"></div>' +
' <div class="errorDisplayDetailsListItemExpanded"></div>' +
' </div>'
);
var multiLineMessageAdditionalLineTemplate = (
' <div class="errorDisplayDetailsListItem"><span class="additional">{{{bullet}}}</span><span>{{message}}</span></div>'
);
var multiLineMessageFirstLineTemplate = (
' <div class="errorDisplayDetailsListItem">' +
' <span class ={{class}}>{{{bullet}}}</span><span> {{message}}</span>' +
' </div>'
);
//span classes used: plain, collapsed, expanded, and additional
//bullets used: -, +, o
var methods = {
init : function(options) {
return this.each(function() {
var $this = $(this),
data = $this.data('errorDisplay'),
settings = $.extend({
'displayFontColor' : '#ff0000',
'displayBackgroundColor' : '#ffffff',
'displayTime' : 1000,
'displayIndicatorColor' : '#ff0000',
'displayLocation' : 'bottom',
'displayDetailsSize' : 200
}, options);
if ( ! data ) {
$this.append(errorDisplayHtml);
$this.find('.errorDisplay').width($this.width()-6);
var detailDisplay = $(detailDisplayHtml).appendTo($("body"));
var detailDisplayList = $(detailDisplayListHtml);
var errorDisplayFlag = 0; //set error display flag to off (for mouseleave function)
$this.data('errorDisplay', {
'detailDisplay' : detailDisplay,
'detailDisplayList' : detailDisplayList,
'displayFontColor' : settings.displayFontColor,
'displayBackgroundColor' : settings.displayBackgroundColor,
'displayTime' : settings.displayTime,
'displayIndicatorColor' : settings.displayIndicatorColor,
'displayLocation' : settings.displayLocation,
'displayDetailsSize' : settings.displayDetailsSize
});
$this.find('.errorDisplayXButton').click(function(event) {
event.preventDefault();
$this.find('.errorDisplayOptions').hide();
$this.find('.errorDisplay').hide(0, function(){
$this.find('.errorDisplayRetriever').show();
});
});
$this.find('.errorDisplayDetailsButton').click(function(event) {
event.preventDefault();
$this.find('.errorDisplay').hide();
$this.find('.errorDisplayRetriever').hide();
$(detailDisplay).find('.errorDisplayFullMessageArea').append($(detailDisplayList));
$(detailDisplay).show();
});
$(detailDisplay).find('.errorDisplayDetailsXButton').click(function(event) {
event.preventDefault();
$(detailDisplay).hide();
$this.find('.errorDisplayRetriever').show();
});
$this.find('.errorDisplayRetrieverOuter').hover(function(event){
event.preventDefault();
$this.find('.errorDisplayRetriever').hide();
$this.find('.errorDisplay').show(0, function(){
$this.find('.errorDisplayOptions').show();
errorDisplayFlag = 1; //turn on error display flag after show function is complete (for mouseleave function)
});
});
$this.find('.errorDisplay').mouseleave(function(event){
if(errorDisplayFlag){
$this.find('.errorDisplay').hide();
if( $(detailDisplay).css("display") == 'none' ){
$this.find('.errorDisplayRetriever').show()
}
errorDisplayFlag = 0; //turn off error display flag after hide function is complete
}
});
}
return this;
});
}, // init() method
displayError : function(message, summary, options) {
return this.each(function() {
var $this = $(this),
data = $this.data('errorDisplay'),
settings = $.extend({
'displayFontColor' : data.displayFontColor,
'displayBackgroundColor' : data.displayBackgroundColor,
'displayTime' : data.displayTime,
'displayIndicatorColor' : data.displayIndicatorColor,
'displayLocation' : data.displayLocation,
'displayDetailsSize' : data.displayDetailsSize
}, options);
//process for multi-line messages
var splitMsg = message.split("\n");
var errorDisplaySummary = (!summary) ? splitMsg[0] : summary; //use first line of full message if short message does not
var errorDisplayTimestamp = new Date();
errorDisplayTimestamp = (errorDisplayTimestamp.getMonth() + 1) + "/" + errorDisplayTimestamp.getDate() + "/" + errorDisplayTimestamp.getFullYear() + " " + errorDisplayTimestamp.toTimeString().substr(0,8);
var obj;
function setupClickHandlers(obj){
obj.find('span.expanded').click(function(){
obj.find('.errorDisplayDetailsListItemExpanded').hide();
obj.find('.errorDisplayDetailsListItemCollapsed').show();
});
obj.find('span.collapsed').click(function(){
obj.find('.errorDisplayDetailsListItemExpanded').show();
obj.find('.errorDisplayDetailsListItemCollapsed').hide();
});
}
if (splitMsg.length == 1){
obj = $(Mustache.to_html(singleLineMessageTemplate, {'class' : 'plain', 'bullet' : 'o', 'message' : errorDisplayTimestamp + ' ' + splitMsg[0] })).css('color', settings.displayFontColor).appendTo($(data.detailDisplayList));
}
else{
obj = $(multiLineMessageOuterTemplate).appendTo($(data.detailDisplayList));
obj.find('.errorDisplayDetailsListItemCollapsed').append(Mustache.to_html(multiLineMessageFirstLineTemplate, {'class' : 'collapsed', 'bullet' : '+', 'message' : errorDisplayTimestamp + ' ' + errorDisplaySummary })).css('color', settings.displayFontColor);
obj.find('.errorDisplayDetailsListItemExpanded').append(Mustache.to_html(multiLineMessageFirstLineTemplate, {'class' : 'expanded', 'bullet' : '-', 'message' : errorDisplayTimestamp + ' ' + splitMsg[0] })).css('color', settings.displayFontColor);
for (var i=1; i<splitMsg.length; i++){
obj.find('.errorDisplayDetailsListItemExpanded').append(Mustache.to_html(multiLineMessageAdditionalLineTemplate, {'message' : splitMsg[i], 'bullet' : ' ' })).css('color', settings.displayFontColor);
}
setupClickHandlers(obj);
}
$('.errorDisplayDetails').css('height', settings.displayDetailsSize); //set details display size according to specifications
$('.errorDisplayFullMessageList').css('height', settings.displayDetailsSize*.9); //set message list size to 90% of details display size
if(settings.displayLocation == 'top'){
$this.find('.errorDisplay').removeClass('errorDisplayBottom').addClass('errorDisplayTop');
$this.find('.errorDisplayRetriever').removeClass('errorDisplayRetrieverBottom').addClass('errorDisplayRetrieverTop').css('background-color', settings.displayIndicatorColor);
//attributes for ease with mobile devices
$this.find('.errorDisplayRetrieverOuter').removeClass('errorDisplayRetrieverBottom').addClass('errorDisplayRetrieverTop');
$this.find('.errorDisplayRetrieverOuter').removeClass('errorDisplayBottom').addClass('errorDisplayTop');
}
else{
$this.find('.errorDisplay').removeClass('errorDisplayTop').addClass('errorDisplayBottom');
$this.find('.errorDisplayRetriever').removeClass('errorDisplayRetrieverTop').addClass('errorDisplayRetrieverBottom').css('background-color', settings.displayIndicatorColor);;
//attributes for ease with mobile devices
$this.find('.errorDisplayRetrieverOuter').removeClass('errorDisplayTop').addClass('errorDisplayBottom');
$this.find('.errorDisplayRetrieverOuter').removeClass('errorDisplayRetrieverTop').addClass('errorDisplayRetrieverBottom');
}
$this.find('.errorDisplayRetriever').hide();
$this.find('.errorDisplayOptions').hide();
$this.find('.errorDisplaySummary').css('color', settings.displayFontColor).html(errorDisplaySummary);
//set background color as configured, also sets options div background color for space around button
$this.find('.errorDisplayOptions').css('background-color', settings.displayBackgroundColor);
$this.find('.errorDisplay').css('background-color', settings.displayBackgroundColor);
if( $('.errorDisplayDetailsOuter').css("display") == 'none' ){ //only show error display div if details are not open
$this.find('.errorDisplay').show();
//using height + 2 as a workaround due to inexplicable differences between scrollheight and height in some browsers
if(($('.errorDisplaySummary').height()+ 2) < $('.errorDisplaySummary')[0].scrollHeight){
$this.find('.errorDisplayOverflow').show();
}
else{
$this.find('.errorDisplayOverflow').hide();
}
if(settings.displayTime != -1){
$this.find('.errorDisplay').slideUp(settings.displayTime, function(){
$this.find('.errorDisplayRetriever').show();
});
}
else{
$this.find('.errorDisplay').show(0, function(){
$this.find('.errorDisplayOptions').show();
});
}
}
});
} // displayError() method
};
$.fn.errorDisplay = function( method ) {
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.errorDisplay' );
return null;
}
};
}(jQuery));