JQuery

 view release on metacpan or  search on metacpan

lib/JQuery/jquery_js/plugins/window/window.js  view on Meta::CPAN

	 * Calculates the position of the window, taking the "position" property into account.
	 * @param	DOM window object
	 * @param	hash
	 * @return	integer
	 */
	calcLeftTop: function(objWindow, hshDimensions) {
		// Initialize the new hash (with integers)
		hshTemp = {
			left: parseInt(hshDimensions.left) || 0,
			top: parseInt(hshDimensions.top) || 0,
			width: parseInt(hshDimensions.width) || 0,
			height: parseInt(hshDimensions.height) || 0
		};

		// Don't bother if the window is moved, or if the position == 0
		if (objWindow.jw.blnIsMoved || (objWindow.jw.hshOptions.intPosition == 0)) {
			return hshTemp;
		}

		// Calculate right offset
		hshClientInfo = jqWindow.getClientInfo();
		if (objWindow.jw.intWindowState == 0) {
			hshTemp.left = (hshClientInfo.documentWidth - hshTemp.width) / 2;
			hshTemp.top = (hshClientInfo.documentHeight - hshTemp.height) / 2;
		}

		// Get correct height
		if (objWindow.jw.intWindowState == -1) {
			hshTemp.height = parseInt(objElem.jw.objqTitleWrp.height()) || 0;
			hshTemp.top = (hshClientInfo.documentHeight - hshTemp.height);
		}

		// Add scroll offset
		hshTemp.top+= (objWindow.jw.hshOptions.intPosition == 1) ? hshClientInfo.scrollTop : 0;

		// Return new hash
		return hshTemp;
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Increases the ZIndex and returns the new value
	 * @return	integer
	 */
	newZIndex: function() {
		jqWindow.intZIndex+= 128;
		return jqWindow.intZIndex;
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * CHecks the ZIndex of this window and updates the objects accordingly
	 * @return	integer
	 */
	checkZIndex: function(objWindow) {
		// Update window
		jQuery(objWindow).css('zIndex', objWindow.jw.intZIndex);

		// Update overlay
		if (objWindow.jw.blnIsModal) {
			objWindow.jw.objqOverlay.css('zIndex', (objWindow.jw.intZIndex - 1));
		}
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Will be executed whenever a focus event is triggered on the document.
	 * @param	EVENT
	 * @return	boolean
	 */
	saveState: function(objWindow) {
		// Save the current window sate
		objWindow.jw.hshViewState = objWindow.jw.hshOptions.hshDimensions;
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Changes the size of the window using a transfer effect if that was enabled
	 * @param	EVENT
	 * @return	boolean
	 */
	transferDimensions: function(objWindow, hshDimensions) {
		if (objWindow.jw.hshOptions.blnTransfer) {
			// Set the dimensions of the transfer helper to match the viewport
			jqWindow.objqHelper.css({
					left: hshDimensions.left + 'px',
					top: hshDimensions.top + 'px',
					width: hshDimensions.width + 'px',
					height: hshDimensions.height + 'px'
				}).show();

			// Minimize this window to the size of the transfer helper
		 	jQuery(objWindow).TransferTo({
					to: jqWindow.objqHelper[0],
					className: 'jwTransferring',
					duration: 250,
					complete: function() {
						// Hide helper
						jqWindow.objqHelper.hide();

						// Set new dimensions
						jqWindow.setDimensions(objWindow, hshDimensions, false, true);
					}
		 		});
		} else {
			// Set new dimensions
			jqWindow.setDimensions(objWindow, hshDimensions, false, true);
		}
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Actually minimize the window
	 * @param	jQuery element
	 */
	doMinimize: function(objWindow) {

lib/JQuery/jquery_js/plugins/window/window.js  view on Meta::CPAN

	 * Sets if the window uses an IFRAME for the content.
	 * @param	object
	 * @param	boolean
	 */
	setIFrame: function(objWindow, blnValue) {
		if (blnValue) {
			if (!objWindow.jw.objqIFrame) {
				// Remove the IFrame if it exists
				if (objWindow.jw.objqContent) {
					objWindow.jw.objqContent.remove();
					objWindow.jw.objqContent = null;
				}

				// Create new content IFrame
		 		objWindow.jw.objqIFrame = jQuery('<iframe></iframe>').css({
			 										width: '100%',
			 										border: 'none'
		 										});

				// Add this to the content TD
		 		jQuery('TD.jwContentC:eq(0)', objWindow.jw.objqContentWrp)
		 			.empty()
		 			.css({
							fontSize: '1px',
							lineHeight: '1px'
						})
		 			.append(objWindow.jw.objqIFrame);
		 	}
		} else {
			if (!objWindow.jw.objqContent) {
				// Remove the IFrame if it exists
				if (objWindow.jw.objqIFrame) {
					objWindow.jw.objqIFrame.remove();
					objWindow.jw.objqIFrame = null;
				}

				// Create new content DIV
				objWindow.jw.objqContent = jQuery('<div class="jwContent">&nbsp;</div>').css({
													display: 'block',
													overflow: 'auto'
												});

				// Add this to the content TD
		 		jQuery('TD.jwContentC:eq(0)', objWindow.jw.objqContentWrp)
		 			.empty()
		 			.css({
							fontSize: '',
							lineHeight: ''
						})
		 			.append(objWindow.jw.objqContent);
			}
		}

		// Update dimensions
		jqWindow.setDimensions(objWindow, objWindow.jw.hshOptions.hshDimensions);
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Sets if the window is modal (and thus has an overlay and a restricted focus set)
	 * @param	object
	 * @param	boolean
	 */
	setIsModal: function(objWindow, blnValue) {
		// We can't set the modal state of this window if:
		// - There is an active window
		// - That window isn't thesame as this one
		// - That window is allready modal (the modal window is always on top)
		// If there is an active modal window, and this
		if (jqWindow.objqActive &&
			(blnValue == true) &&
			(jqWindow.objqActive[0].jw.hshOptions.strName != objWindow.jw.hshOptions.strName) &&
			(jqWindow.objqActive[0].jw.hshOptions.blnIsModal == true)
			) {
			blnValue = false;
		}

		// Update the new value
		if (blnValue) {
			if (!objWindow.jw.objqOverlay) {
		 		objWindow.jw.objqOverlay = jQuery(document.createElement('div'))
											.addClass('theme' + objWindow.jw.hshOptions.strTheme)
		 									.addClass('dialogOverlay')
		 									.css({
				 									zIndex: objWindow.jw.intZIndex - 1
				 								});

		 		jQuery(objWindow).before(objWindow.jw.objqOverlay);
		 	}
		} else {
			if (objWindow.jw.objqOverlay) {
				objWindow.jw.objqOverlay.remove();
				objWindow.jw.objqOverlay = null;
			}
		}

		// Save new value
		objWindow.jw.hshOptions.blnIsModal = blnValue;
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Sets if the window has a minimize button
	 * @param	object
	 * @param	boolean
	 */
	setHasMinimize: function(objWindow, blnValue) {
		if (blnValue) {
			if (!objWindow.jw.objqBtnMinimize) {
				// Create the button
		 		objWindow.jw.objqBtnMinimize = jQuery(document.createElement("div"))
		 						.html('&nbsp;')
		 						.addClass('btnMinimize')
		 						.css({
										fontSize: '1px',
										lineHeight: '1px'
									})
		 						.cssHover({
										hasMouseOver:	true,

lib/JQuery/jquery_js/plugins/window/window.js  view on Meta::CPAN

						lineHeight: ''
					});
		} else {
			objWindow.jw.objqStatus
				.html('&nbsp;')
				.css({
						fontSize: '1px',
						lineHeight: '1px'
					});
		}
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Sets a window to be the active one. Also makes sure if there is an active current window, and it is
	 * modal that it remains on top.
	 * @param	DOM element
	 */
	setActive: function(objWindow) {
		blnHasActive = (jqWindow.objqActive !== null);
		blnSetActive = (!blnHasActive);

		// Only change the active window if:
		// - There is no active window
		// - The new window isn't modal
		// - The window is different then the normal one
		if (blnHasActive) {
			if (jqWindow.objqActive[0].jw.hshOptions.strName != objWindow.jw.hshOptions.strName) {
				// Remove resizable if there is one
				if (jqWindow.objqActive[0].jw.hshOptions.blnIsResizable) {
					jqWindow.setIsResizable(jqWindow.objqActive[0], false, false);
				}

				// If the current window is modal, make sure it remains on top.
				if (jqWindow.objqActive[0].jw.hshOptions.blnIsModal) {
					// The new window has a higher zIndex, so update this window
					if (jqWindow.objqActive[0].intZIndex < jqWindow.intZIndex) {
						// Increase the zIndex
						jqWindow.objqActive[0].intZIndex = jqWindow.newZIndex();

						// Update the window
						jqWindow.checkZIndex(jqWindow.objqActive[0]);
					}
				} else {
					jqWindow.objqActive.removeClass('jwActive');
					blnSetActive = true;
				}
			}
		}

		// If we have to update this window to be the active one
		if (blnSetActive) {
			// Change active state
			jqWindow.objqActive = jQuery(objWindow);
			jqWindow.objqActive.addClass('jwActive');

			// Increase the zIndex
			objWindow.jw.intZIndex = jqWindow.newZIndex();

			// Update the overlay of needed
			jqWindow.setIsModal(objWindow, objWindow.jw.hshOptions.blnIsModal);

			// Update resizable if there is one
			jqWindow.setIsResizable(objWindow, objWindow.jw.hshOptions.blnIsResizable, false);

			// Update the window
			jqWindow.checkZIndex(objWindow);
		}

		// Show the window
		jQuery(objWindow).show();

		// Update padding
		jqWindow.updatePadding(objWindow);
		jqWindow.setOffset(objWindow, objWindow.jw.hshOptions.hshDimensions);
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Builds the window
	 * @param	object		DOM element to change
	 * @param	array		Hash with the options
	 */
	build: function(cfgOptions) {
		//----------------------------------------------------------------------------------------------------
		// Check for required plugins
		//----------------------------------------------------------------------------------------------------
		// Test for interface code
		if (!jQuery.iUtil || !jQuery.iDrag || !jQuery.iResize) {
			alert('Unable to find required the "interface" code!\nMake sure you have loaded both iUtil, iDrag and iResizable.');
			return false;
		}

		//----------------------------------------------------------------------------------------------------
		// First window to be created?
		//----------------------------------------------------------------------------------------------------
		if (jqWindow.blnInitialized == false) {
			// Set initialized flag
			jqWindow.blnInitialized = true;

			// Create helper (for resizing and transferring)
			jqWindow.objqHelper = jQuery('<div class="jwHelper">&nbsp;</div>');
			jQuery('body', document).append(jqWindow.objqHelper);

			// Assign document event handlers
			jQuery(window).scroll(jqWindow.updateWindows);
			jQuery(window).resize(jqWindow.updateWindows);
			jQuery(document).focus(jqWindow.focusHandler);
		}

		//----------------------------------------------------------------------------------------------------
		// Create the window object. We assign all functionality to this object for code simplification.
		//----------------------------------------------------------------------------------------------------
		objqElem = jQuery(document.createElement('div'));
		objElem = objqElem[0];


		//----------------------------------------------------------------------------------------------------
		// Initialize the default properties of this object
		//----------------------------------------------------------------------------------------------------
		objElem.jw = new function() {
				this.blnInitialized = false;			// To prevent multiple calls to various functions when building
				this.blnIsMoved = false;					// helper
				this.blnIsResizable = false;			// helper
				this.blnIsDraggable = false;			// helper
				this.hshViewState = null;					// Holds size information needed by maximize / minimize functions
				this.objqOverlay = null;					// Variable for the overlay object
				this.objqBtnMinimize = null;			// Variable for the minimize button
				this.objqBtnMaximize = null;			// Variable for the maximize button
				this.objqBtnClose = null;					// Variable for the close button
				this.objqIFrame = null;						// Variable for the content iFrame
				this.objqContent = null;					// Variable for the content DIV
				this.intZIndex = 500;							// Dummy value, gets overwritten
				this.intWindowState = 0;					// Window state
				this.intPadding = 0;							// For resizable

				// Define default options and override them with the passed configuration, if available
				this.hshOptions = jQuery.extend({
						strName: 'myWindow',					// The name of the window
						strTheme: 'Default',					// The theme to use
						hshDimensions: {							// An hash with initial offsets
								left: 0,
								top: 0,
								width: 500,
								height: 400
							},
						hshMinSize: null,							// A hash with a minimum size (width/height)
						hshMaxSize: null,							// A hash with a maximum size (width/height)
						blnIsModal: false,						// Show an overlay and prefect focus out of the window?
						blnHasMinimize: true,					// If the window has a minimize button
						intMimimizedWidth: 200,				// The width of the titlebar when minimized
						blnHasMaximize: true,					// If the window has a maximize button
						blnHasClose: true,						// If the window has a close button
						blnHasStatus: true,						// If the window has a status bar
						blnIsDraggable: true,					// Indicates if the window is draggable
						blnIsResizable: true,					// Indicates if the window is resizable
						blnTransfer: false,						// If the window uses the transferto effect
						intPosition: 0,								// Position untill moved: default (0), center screen (1)
						blnIsRestricted: true,				// Is the element restricted to the parent?
						intInitialSate: 0,						// Initial state: minimized (-1), default (0), maximized (1)
						dblOpacity: 1.0,							// The opacity of the dialog
						strTitle: 'Title',						// ...
						strContent: '&nbsp;',					// ...
						strStatus: ''									// ...
					}, cfgOptions || {});
			};

		//----------------------------------------------------------------------------------------------------
		// Make sure we don't build the element twice, check if there is a window object with an options hash.
		//----------------------------------------------------------------------------------------------------
		objqTemp = jqWindow.getByName(objElem.jw.hshOptions.strName);
		if (objqTemp) {
			// Move window to front
			jqWindow.setActive(objqTemp[0]);

			// Free the handle of the DOM object
			objElem = null;

			// Return the old object
			return objqTemp;
		}
		objqTemp = null;


		//----------------------------------------------------------------------------------------------------
		// Transfer effect: Check to see if it is supported and add the helper object if needed.
		//----------------------------------------------------------------------------------------------------
		objElem.jw.hshOptions.blnTransfer = (objElem.jw.hshOptions.blnTransfer && jQuery.fx.itransferTo) ? true: false;


		//----------------------------------------------------------------------------------------------------
		// Check sizes
		//----------------------------------------------------------------------------------------------------
		if (!jqWindow.isHash(objElem.jw.hshOptions.hshMinSize)) {
			objElem.jw.hshOptions.hshMinSize = null;
		}

		if (!jqWindow.isHash(objElem.jw.hshOptions.hshMaxSize)) {
			objElem.jw.hshOptions.hshMaxSize = null;
		}

		// Make sure the minimum size is not larger then the maximum size and vice versa
		if (jqWindow.isHash(objElem.jw.hshOptions.hshMinSize) && jqWindow.isHash(objElem.jw.hshOptions.hshMaxSize)) {
			// Check minimum width
			if (objElem.jw.hshOptions.hshMinSize.width > objElem.jw.hshOptions.hshMaxSize.width) {
					objElem.jw.hshOptions.hshMinSize.width = objElem.jw.hshOptions.hshMaxSize.width;
			}

			// Check minimum height

lib/JQuery/jquery_js/plugins/window/window.js  view on Meta::CPAN

		jqWindow.setIsDraggable(objElem, objElem.jw.hshOptions.blnIsDraggable);
		jqWindow.setIsResizable(objElem, objElem.jw.hshOptions.blnIsResizable);
		jqWindow.setOpacity(objElem, objElem.jw.hshOptions.dblOpacity);
		jqWindow.setPosition(objElem, objElem.jw.hshOptions.intPosition);

		// Set correct state
		if (objElem.jw.hshOptions.intInitialState == -1) {
			jqWindow.doMinimize(objWindow, false);
		} else if (objElem.jw.hshOptions.intInitialState == 1) {
			jqWindow.doMaximize(objWindow, false);
		}


		//----------------------------------------------------------------------------------------------------
		// Click handler
		//----------------------------------------------------------------------------------------------------
		objqElem.click(function() {
			// Make the dialog active
			jqWindow.setActive(this);
		});


		//----------------------------------------------------------------------------------------------------
		// Done building
		//----------------------------------------------------------------------------------------------------
		objElem.jw.blnInitialized = true;


		//----------------------------------------------------------------------------------------------------
		// Save window
		//----------------------------------------------------------------------------------------------------
		jqWindow.arrWindows[jqWindow.arrWindows.length] = objqElem;


		//----------------------------------------------------------------------------------------------------
		// Try to make this window active
		//----------------------------------------------------------------------------------------------------
		jqWindow.setActive(objElem);


		//----------------------------------------------------------------------------------------------------
		// Add iframe hack
		//----------------------------------------------------------------------------------------------------
		objqElem.bgiframe();

		return objqElem;
	},

	//----------------------------------------------------------------------------------------------------

	/**
	 * Removes the window completely
	 * @param	DOM element
	 */
	destroy: function(objWindow) {
		objqWindow = jQuery(objWindow);

		// Perform the callback
		jqWindow.doCallback(objWindow.jw.hshOptions.onClose, objWindow);

		// Remove the overlay
		jqWindow.setIsModal(objWindow, false);

		// Remove connection to the current object if that is thesame
		if (jqWindow.objqActive && (objWindow.jw.hshOptions.strName == jqWindow.objqActive[0].jw.hshOptions.strName))
			jqWindow.objqActive = null;

		// Remove the element from the array
		jqWindow.removeByName(objWindow.jw.hshOptions.strName);

		// Remove the window itself
		objqWindow.unbind().remove();
	}
};

//
// Initialize the object
jqWindow = new jqWindow();



( run in 2.879 seconds using v1.01-cache-2.11-cpan-d8267643d1d )