1
|
//<![CDATA[
|
2
|
var browser = '';
|
3
|
var version = '';
|
4
|
var entrance = '';
|
5
|
var cond = '';
|
6
|
|
7
|
// BROWSER?
|
8
|
if (browser == '')
|
9
|
{
|
10
|
if (navigator.appName.indexOf('Microsoft') != -1)
|
11
|
browser = 'IE';
|
12
|
else if (navigator.appName.indexOf('Netscape') != -1)
|
13
|
browser = 'Netscape';
|
14
|
else
|
15
|
browser = 'IE';
|
16
|
}
|
17
|
if (version == '')
|
18
|
{
|
19
|
version= navigator.appVersion;
|
20
|
paren = version.indexOf('(');
|
21
|
whole_version = navigator.appVersion.substring(0,paren-1);
|
22
|
version = parseInt(whole_version);
|
23
|
}
|
24
|
|
25
|
if (browser == 'IE' && version < 7)
|
26
|
document.write('<script type="text/javascript" src="/themes/pfsense_ng/javascript/ie7/ie7-standard-p.js"></script>');
|
27
|
|
28
|
document.write('<script type="text/javascript" src="/themes/pfsense_ng/javascript/niftyjsCode.js"></script>');
|
29
|
|
30
|
///////////////////////////////////////////
|
31
|
// jQuery code for columns / widgets part 1
|
32
|
///////////////////////////////////////////
|
33
|
|
34
|
var noCols = 2;
|
35
|
var printed3 = false;
|
36
|
var printed4 = false;
|
37
|
var printed5 = false;
|
38
|
var printed6 = false;
|
39
|
var printed7 = false;
|
40
|
var printed8 = false;
|
41
|
var printed9 = false;
|
42
|
var printed10 = false;
|
43
|
var id;
|
44
|
var noColsOnLoad = noCols; // holds a reference to the number of displayed columns on load
|
45
|
var existing =[]; // array to hold each columns contents
|
46
|
var specifiedColWidth = 350; // width of columns for resizing
|
47
|
|
48
|
///////////////////////////////////////////
|
49
|
// jQuery Widget functions
|
50
|
///////////////////////////////////////////
|
51
|
|
52
|
// function to connect all columns to each other to allow jQuery interaction (drag and droppable)
|
53
|
function connectColumns()
|
54
|
{
|
55
|
jQuery('.ui-sortable').sortable({connectWith: '.ui-sortable', dropOnEmpty: true, handle: '.widgetheader', change: showSave});
|
56
|
}
|
57
|
|
58
|
// function to add columns due to a window resize
|
59
|
function resizeAddColumns()
|
60
|
{
|
61
|
if(noColsOnLoad > noCols) // if a column has previously been deleted
|
62
|
{
|
63
|
var maxCols = maxColsToDisplay(); // the maximum we can display
|
64
|
|
65
|
if(noColsOnLoad < maxCols) // if the number of columns on load is less then the maximum number of columns we can display
|
66
|
maxCols = noColsOnLoad; // change the maximum number of columns as we do not want to display them all
|
67
|
if( (maxCols - noCols) > 0 ) // if we need to add more columns
|
68
|
{
|
69
|
replaceColumn();
|
70
|
|
71
|
for(var i=noCols; i<maxCols; i++)
|
72
|
{
|
73
|
var addCols = i +1;
|
74
|
jQuery('#col' + (i).toString() ).after("<div id=\"col" + addCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
|
75
|
jQuery(existing[i]).appendTo('#col' + addCols ); // append onLoad contents
|
76
|
}
|
77
|
noCols = maxCols;
|
78
|
for(var i=noCols; i<noColsOnLoad ; i++)
|
79
|
{
|
80
|
jQuery(existing[i]).appendTo('#col' + maxCols ); // append widgets from stored array to columns
|
81
|
}
|
82
|
correctWidgetDisplay(noCols);
|
83
|
connectColumns();
|
84
|
showSave();
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
|
89
|
|
90
|
// function to remove columns due to a window resize
|
91
|
function resizeRmColumns()
|
92
|
{
|
93
|
if( noCols > 1 ) // keep at least 1 column displayed at all times
|
94
|
{
|
95
|
var maxCols = maxColsToDisplay();
|
96
|
var noColsToDel = noCols - maxCols;
|
97
|
|
98
|
if(noColsToDel>0) // if columns need deleteing
|
99
|
{
|
100
|
for(var i=(noCols-noColsToDel); i<noColsOnLoad; i++)
|
101
|
{
|
102
|
jQuery(existing[i]).appendTo('#col' + maxCols ); // append widgets from stored array to columns
|
103
|
}
|
104
|
for(var i=0; i<noColsToDel; i++ )
|
105
|
{
|
106
|
var del = noCols -i;
|
107
|
jQuery('#col' + del ).remove(); // remove columns
|
108
|
}
|
109
|
noCols = maxCols;
|
110
|
correctWidgetDisplay(noCols);
|
111
|
showSave();
|
112
|
}
|
113
|
}
|
114
|
};
|
115
|
|
116
|
|
117
|
// functions to removes the highest value column current displayed and replaces it with the same column number on load ie before any resizing took place
|
118
|
function replaceColumn()
|
119
|
{
|
120
|
var tmpReplace = noCols -1;
|
121
|
jQuery('#col' + noCols ).remove();
|
122
|
|
123
|
// prepend column1 as we can't add it AFTER a column as none will exist
|
124
|
if(tmpReplace==0)
|
125
|
jQuery("#niftyOutter").prepend("<div id=\"col1\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
|
126
|
else
|
127
|
jQuery('#col' + (tmpReplace).toString() ).after("<div id=\"col" + noCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
|
128
|
jQuery(existing[tmpReplace]).appendTo('#col' + noCols);
|
129
|
}
|
130
|
|
131
|
|
132
|
// function to calculate & return the maximum number of columns we can display
|
133
|
function maxColsToDisplay()
|
134
|
{
|
135
|
var niftyWidth = jQuery('#niftyOutter.fakeClass').width();
|
136
|
return Math.round(niftyWidth / specifiedColWidth);
|
137
|
}
|
138
|
|
139
|
// function to amend the widget width
|
140
|
function correctWidgetDisplay(noCols)
|
141
|
{
|
142
|
var percent = ( 100 / noCols ) - 0.1;
|
143
|
var percentStr = percent.toString() + '%';
|
144
|
|
145
|
// set all column widths
|
146
|
jQuery('.ui-sortable').width(percentStr);
|
147
|
}
|
148
|
|
149
|
// function to insert a new column we can place content into (from saved state)
|
150
|
function printColumn(newNum)
|
151
|
{
|
152
|
if(newNum > noCols)
|
153
|
{
|
154
|
noCols = newNum;
|
155
|
noColsOnLoad = noCols;
|
156
|
}
|
157
|
|
158
|
document.write("</div><div id=\"col" + newNum + "\" style=\"float:left; padding-bottom:40px\" class=\"ui-sortable\">");
|
159
|
correctWidgetDisplay(noCols);
|
160
|
connectColumns();
|
161
|
}
|
162
|
|
163
|
// function to create the columns
|
164
|
function createColumn(colPos)
|
165
|
{
|
166
|
if (colpos == "col3" && printed3 == false){
|
167
|
printColumn(3);
|
168
|
printed3=true;
|
169
|
}
|
170
|
else if (colpos == "col4" && printed4 == false){
|
171
|
printColumn(4);
|
172
|
printed4=true;
|
173
|
}
|
174
|
else if (colpos == "col5" && printed5 == false){
|
175
|
printColumn(5);
|
176
|
printed5=true;
|
177
|
}
|
178
|
else if (colpos == "col6" && printed6 == false){
|
179
|
printColumn(6);
|
180
|
printed6=true;
|
181
|
}
|
182
|
else if (colpos == "col7" && printed7 == false){
|
183
|
printColumn(7);
|
184
|
printed7=true;
|
185
|
}
|
186
|
else if (colpos == "col8" && printed8 == false){
|
187
|
printColumn(8);
|
188
|
printed8=true;
|
189
|
}
|
190
|
else if (colpos == "col9" && printed9 == false){
|
191
|
printColumn(9);
|
192
|
printed9=true;
|
193
|
}
|
194
|
else if (colpos == "col10" && printed10 == false){
|
195
|
printColumn(10);
|
196
|
printed10=true;
|
197
|
}
|
198
|
}
|
199
|
|
200
|
// function which is called when the broswer window is resized
|
201
|
jQuery( window ).resize(function()
|
202
|
{
|
203
|
// stop resize firing twice: http://stackoverflow.com/questions/4298612/jquery-how-to-call-resize-event-only-once-its-finished-resizing
|
204
|
clearTimeout(id);
|
205
|
id = setTimeout(finishedResizing, 500);
|
206
|
});
|
207
|
|
208
|
// function called after the browser has finished resizing
|
209
|
function finishedResizing()
|
210
|
{
|
211
|
var colWidth = jQuery("#col1").width();
|
212
|
if( colWidth < specifiedColWidth ) // Columns width is too small to display all the columns properly so we delete some columns and resize the remaining columns
|
213
|
resizeRmColumns(); // Check if we can delete any columns
|
214
|
else if( colWidth > specifiedColWidth ) // Columns width COULD display more columns properly
|
215
|
resizeAddColumns(); // Check if we can add any columns
|
216
|
}
|
217
|
|
218
|
///////////////// end widget code part 1 /////////////////////////
|
219
|
|
220
|
// jQuery function to define dropdown menu size
|
221
|
jQuery(document).ready(function ()
|
222
|
{
|
223
|
var hwindow = '';
|
224
|
hwindow = (jQuery(window).height()-35);
|
225
|
// Force the size dropdown menu
|
226
|
jQuery('#navigation ul li ul').css('max-height', hwindow);
|
227
|
|
228
|
///////////////////////////////////////////
|
229
|
// jQuery code for columns / widgets part 2
|
230
|
///////////////////////////////////////////
|
231
|
|
232
|
// insert add/delete column buttons
|
233
|
jQuery('<br /><br /><div id=\"columnModifier\"><div style=\"float:left\"><div id =\"addCol\" style=\"float:left\"><img src=\"./themes/pfsense_ng_fs/images/icons/icon_plus.gif\" style=\"cursor:pointer\" alt=\"Click here to add a column\"/></div> Add column </div><div style=\"float:left\"><div id =\"delCol\" style=\"float:left\"><img src=\"./themes/pfsense_ng_fs/images/icons/icon_x.gif\" style=\"cursor:pointer\" alt=\"Click here to delete a column\"/></div> Delete column</div><div id=\"columnWarningText\" style=\"float:left; margin-left:5em\"></div><br /><br />').insertBefore('#niftyOutter.fakeClass');
|
234
|
|
235
|
if ( jQuery('#columnModifier').length > 0 ) // only perform resizing on the dashboard page
|
236
|
{
|
237
|
// correct the css for column 2
|
238
|
jQuery('#col2').css("float","left");
|
239
|
|
240
|
// Make a copy of the current state of columns on page load
|
241
|
for ( var i = 1; i <= noCols; i = i + 1 )
|
242
|
{
|
243
|
var contents = jQuery('#col' + i ).html();
|
244
|
existing.push( contents );
|
245
|
}
|
246
|
|
247
|
finishedResizing(); // on page load correct display of columns to fit
|
248
|
}
|
249
|
|
250
|
// on click add a new column and change column widths
|
251
|
jQuery('#addCol').click(function()
|
252
|
{
|
253
|
var maxCols = maxColsToDisplay();
|
254
|
if( (noCols < maxCols) && (noCols < 10) )
|
255
|
{
|
256
|
var colAfter = noCols;
|
257
|
noCols++;
|
258
|
|
259
|
// insert new column
|
260
|
jQuery('#col' + (colAfter).toString() ).after("<div id=\"col" + noCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
|
261
|
|
262
|
correctWidgetDisplay(noCols);
|
263
|
connectColumns();
|
264
|
}
|
265
|
else
|
266
|
jQuery('#columnWarningText').html('<b>Maximum number of columns reached for the current window size</b>').show().delay(1000).fadeOut(1000);
|
267
|
});
|
268
|
|
269
|
// on click delete a columns and change column widths
|
270
|
jQuery('#delCol').click(function()
|
271
|
{
|
272
|
if( noCols > 1 )
|
273
|
{
|
274
|
var colToDel = noCols;
|
275
|
noCols -= 1;
|
276
|
|
277
|
correctWidgetDisplay(noCols);
|
278
|
|
279
|
// get column contents before deletion
|
280
|
var colContent = jQuery('#col' + colToDel ).html();
|
281
|
|
282
|
// remove column
|
283
|
jQuery('#col' + colToDel ).remove();
|
284
|
|
285
|
// append deleted columns content to preceeding column
|
286
|
jQuery(colContent).appendTo('#col' + noCols );
|
287
|
|
288
|
showSave();
|
289
|
}
|
290
|
else
|
291
|
jQuery('#columnWarningText').html('<b>Minimum number of columns reached for the current window size</b>').show().delay(1000).fadeOut(1000);
|
292
|
});
|
293
|
});
|
294
|
//]]>
|