");
correctWidgetDisplay(noCols);
-
- // connect new column with other columns
- jQuery('.ui-sortable').sortable({connectWith: '.ui-sortable', dropOnEmpty: true, handle: '.widgetheader', change: showSave});
+ connectColumns();
}
-function createColumn(colPos){
+// function to create the columns
+function createColumn(colPos)
+{
if (colpos == "col3" && printed3 == false){
printColumn(3);
printed3=true;
@@ -94,10 +196,30 @@ function createColumn(colPos){
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 () {
+jQuery(document).ready(function ()
+{
var hwindow = '';
hwindow = (jQuery(window).height()-35);
// Force the size dropdown menu
@@ -107,14 +229,27 @@ jQuery(document).ready(function () {
// jQuery code for columns / widgets part 2
///////////////////////////////////////////
+ // correct the css for column 2
jQuery('#col2').css("float","left");
// insert add/delete column buttons
jQuery('
').insertBefore('#niftyOutter.fakeClass');
+ // 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(){
- if( noCols < 10 ){
+ jQuery('#addCol').click(function()
+ {
+ var maxCols = maxColsToDisplay();
+ if( (noCols < maxCols) && (noCols < 10) )
+ {
var colAfter = noCols;
noCols++;
@@ -122,18 +257,17 @@ jQuery(document).ready(function () {
jQuery('#col' + (colAfter).toString() ).after("
");
correctWidgetDisplay(noCols);
-
- // connect new column with other columns
- jQuery('.ui-sortable').sortable({connectWith: '.ui-sortable', dropOnEmpty: true, handle: '.widgetheader', change: showSave});
- }
- else{
- jQuery('#columnWarningText').html('
Maximum number of columns reached').show().delay(1000).fadeOut(1000);
+ connectColumns();
}
+ else
+ jQuery('#columnWarningText').html('
Maximum number of columns reached for the current window size').show().delay(1000).fadeOut(1000);
});
// on click delete a columns and change column widths
- jQuery('#delCol').click(function(){
- if( noCols > 2 ){
+ jQuery('#delCol').click(function()
+ {
+ if( noCols > 1 )
+ {
var colToDel = noCols;
noCols -= 1;
@@ -147,12 +281,11 @@ jQuery(document).ready(function () {
// append deleted columns content to preceeding column
jQuery(colContent).appendTo('#col' + noCols );
-
- showSave();
- }
- else{
- jQuery('#columnWarningText').html('
Minimum number of columns reached').show().delay(1000).fadeOut(1000);
+
+ showSave();
}
+ else
+ jQuery('#columnWarningText').html('
Minimum number of columns reached for the current window size').show().delay(1000).fadeOut(1000);
});
});
//]]>