summaryrefslogtreecommitdiffstats
path: root/usr/local/www/themes/pfsense_ng_fs/loader.js
blob: c8ebe6039d9f958f622efd583ad6081b3ddc0b46 (plain)
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
//<![CDATA[
var browser     = '';
var version     = '';
var entrance    = '';
var cond        = '';

// BROWSER?
if (browser == '')
{
	if (navigator.appName.indexOf('Microsoft') != -1)
		browser = 'IE';
	else if (navigator.appName.indexOf('Netscape') != -1)
		browser = 'Netscape';
	else
		browser = 'IE';
}
if (version == '')
{
	version= navigator.appVersion;
	paren = version.indexOf('(');
	whole_version = navigator.appVersion.substring(0,paren-1);
	version = parseInt(whole_version);
}

if (browser == 'IE' && version < 7)
	document.write('<script type="text/javascript" src="/themes/pfsense_ng/javascript/ie7/ie7-standard-p.js"></script>');

document.write('<script type="text/javascript" src="/themes/pfsense_ng/javascript/niftyjsCode.js"></script>');

///////////////////////////////////////////
// jQuery code for columns / widgets part 1
///////////////////////////////////////////

var noCols = 2;
var printed3 = false;
var printed4 = false;
var printed5 = false;
var printed6 = false;
var printed7 = false;
var printed8 = false;
var printed9 = false;
var printed10 = false;
var id;
var noColsOnLoad = noCols; // holds a reference to the number of displayed columns on load
var existing =[]; // array to hold each columns contents
var specifiedColWidth = 350; // width of columns for resizing

///////////////////////////////////////////
// jQuery Widget functions
///////////////////////////////////////////

// function to connect all columns to each other to allow jQuery interaction (drag and droppable)
function connectColumns()
{
	jQuery('.ui-sortable').sortable({connectWith: '.ui-sortable', dropOnEmpty: true, handle: '.widgetheader', change: showSave});
}

// function to add columns due to a window resize
function resizeAddColumns()
{
	if(noColsOnLoad > noCols) // if a column has previously been deleted
	{
		var maxCols = maxColsToDisplay(); // the maximum we can display
		
		if(noColsOnLoad < maxCols) // if the number of columns on load is less then the maximum number of columns we can display
			maxCols = noColsOnLoad; // change the maximum number of columns as we do not want to display them all
		if( (maxCols - noCols) > 0 ) // if we need to add more columns
		{
			replaceColumn();
			
			for(var i=noCols; i<maxCols; i++)
			{
				var addCols = i +1;
				jQuery('#col' + (i).toString() ).after("<div id=\"col" + addCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>"); 
				jQuery(existing[i]).appendTo('#col' + addCols ); // append onLoad contents
			}
			noCols = maxCols;
			for(var i=noCols; i<noColsOnLoad ; i++)
			{
				jQuery(existing[i]).appendTo('#col' + maxCols ); // append widgets from stored array to columns
			}
		correctWidgetDisplay(noCols);
		connectColumns();
		showSave();
		}
	}
}


// function to remove columns due to a window resize 
function resizeRmColumns()
{
	if( noCols > 1 ) // keep at least 1 column displayed at all times
	{
		var maxCols = maxColsToDisplay();
		var noColsToDel = noCols - maxCols;
		
		if(noColsToDel>0) // if columns need deleteing
		{
			for(var i=(noCols-noColsToDel); i<noColsOnLoad; i++)
			{
				jQuery(existing[i]).appendTo('#col' + maxCols ); // append widgets from stored array to columns
			}
			for(var i=0; i<noColsToDel; i++ )
			{
				var del = noCols -i;
				jQuery('#col' + del ).remove(); // remove columns
			}
		noCols = maxCols;
		correctWidgetDisplay(noCols);
		showSave();
		}
	}
};


// 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
function replaceColumn()
{
	var tmpReplace = noCols -1;
	jQuery('#col' + noCols ).remove();

	// prepend column1 as we can't add it AFTER a column as none will exist           
	if(tmpReplace==0)
		jQuery("#niftyOutter").prepend("<div id=\"col1\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
	else
		jQuery('#col' + (tmpReplace).toString() ).after("<div id=\"col" + noCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");
	jQuery(existing[tmpReplace]).appendTo('#col' +  noCols);
}


// function to calculate & return the maximum number of columns we can display
function maxColsToDisplay()
{
	var niftyWidth = jQuery('#niftyOutter.fakeClass').width();
	return Math.round(niftyWidth / specifiedColWidth);	    
}

// function to amend the widget width  
function correctWidgetDisplay(noCols)
{
	var percent = ( 100 / noCols ) - 0.1;
	var percentStr = percent.toString() + '%';

	// set all column widths
	jQuery('.ui-sortable').width(percentStr);
}

// function to insert a new column we can place content into (from saved state)
function printColumn(newNum)
{
	if(newNum > noCols)
        {
		noCols = newNum;
		noColsOnLoad = noCols;
	}
	
	document.write("</div><div id=\"col" + newNum + "\" style=\"float:left; padding-bottom:40px\" class=\"ui-sortable\">");
	correctWidgetDisplay(noCols);
	connectColumns();
}

// function to create the columns
function createColumn(colPos)
{
	if (colpos == "col3" && printed3 == false){
		printColumn(3);
		printed3=true;
	}
	else if (colpos == "col4" && printed4 == false){
		printColumn(4);
		printed4=true;
	}
	else if (colpos == "col5" && printed5 == false){
		printColumn(5);
		printed5=true;
	}
	else if (colpos == "col6" && printed6 == false){
		printColumn(6);
		printed6=true;
	}
	else if (colpos == "col7" && printed7 == false){
		printColumn(7);
		printed7=true;
	}
	else if (colpos == "col8" && printed8 == false){
		printColumn(8);
		printed8=true;
	}
	else if (colpos == "col9" && printed9 == false){
		printColumn(9);
		printed9=true;
	}
	else if (colpos == "col10" && printed10 == false){
		printColumn(10);
		printed10=true;
	}
}

// function which is called when the broswer window is resized
jQuery( window ).resize(function()
{  
    // stop resize firing twice: http://stackoverflow.com/questions/4298612/jquery-how-to-call-resize-event-only-once-its-finished-resizing
    clearTimeout(id);
    id = setTimeout(finishedResizing, 500);
});

// function called after the browser has finished resizing
function finishedResizing()
{
	var colWidth = jQuery("#col1").width();
	if( colWidth < specifiedColWidth ) // Columns width is too small to display all the columns properly so we delete some columns and resize the remaining columns    
		resizeRmColumns(); // Check if we can delete any columns
	else if( colWidth > specifiedColWidth ) // Columns width COULD display more columns properly    
		resizeAddColumns(); // Check if we can add any columns
}

///////////////// end widget code part 1 /////////////////////////

// jQuery function to define dropdown menu size
jQuery(document).ready(function ()
{
    var hwindow  = '';
    hwindow = (jQuery(window).height()-35);
    // Force the size dropdown menu 
    jQuery('#navigation ul li ul').css('max-height', hwindow);
    
    ///////////////////////////////////////////
    // jQuery code for columns / widgets part 2    
    ///////////////////////////////////////////
    
    // insert add/delete column buttons
    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>&nbsp;Add column&nbsp;</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>&nbsp;Delete column</div><div id=\"columnWarningText\" style=\"float:left; margin-left:5em\"></div><br /><br />').insertBefore('#niftyOutter.fakeClass');
    
    if ( jQuery('#columnModifier').length > 0 ) // only perform resizing on the dashboard page
    {
        // correct the css for column 2
        jQuery('#col2').css("float","left");

        // Make a copy of the current state of columns on page load
        for ( var i = 1; i <= noCols; i = i + 1 )
        {
	    var contents = jQuery('#col' + i ).html();
	    existing.push( contents );
        }  
    
        finishedResizing(); // on page load correct display of columns to fit
    }
    
    // on click add a new column and change column widths
    jQuery('#addCol').click(function()
    {
	var maxCols = maxColsToDisplay();
	if( (noCols < maxCols) && (noCols < 10) )
        {
		var colAfter = noCols;
		noCols++;

		// insert new column
		jQuery('#col' + (colAfter).toString() ).after("<div id=\"col" + noCols + "\" style=\"float: left; padding-bottom: 40px\" class=\"ui-sortable\"> </div>");

		correctWidgetDisplay(noCols);
		connectColumns();
	}
	else
		jQuery('#columnWarningText').html('<b>Maximum number of columns reached for the current window size</b>').show().delay(1000).fadeOut(1000);
    });

    // on click delete a columns and change column widths
    jQuery('#delCol').click(function()
    {
	if( noCols > 1 )
        {
		var colToDel = noCols;
		noCols -= 1;

		correctWidgetDisplay(noCols);

		// get column contents before deletion
		var colContent = jQuery('#col' + colToDel ).html();

		// remove column
		jQuery('#col' + colToDel ).remove();

		// append deleted columns content to preceeding column
		jQuery(colContent).appendTo('#col' + noCols );

		showSave();
	}
	else
		jQuery('#columnWarningText').html('<b>Minimum number of columns reached for the current window size</b>').show().delay(1000).fadeOut(1000);
    });
});
//]]>
OpenPOWER on IntegriCloud