<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BlackFade.com &#187; Modal</title>
	<atom:link href="http://www.blackfade.com/tag/modal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blackfade.com</link>
	<description>Rob Taylor - Web Developer, UK</description>
	<lastBuildDate>Wed, 18 Jan 2012 10:00:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Moodal Window for MooTools 1.2.3.1</title>
		<link>http://www.blackfade.com/2009/09/24/moodal-window-for-mootools-1-2-3-1/</link>
		<comments>http://www.blackfade.com/2009/09/24/moodal-window-for-mootools-1-2-3-1/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 11:58:12 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[Modal]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[Window]]></category>

		<guid isPermaLink="false">http://www.blackfade.com/?p=77</guid>
		<description><![CDATA[This is my first attempt at publishing one of my scripts, and my first real attempt at writing a MooTools class. I hope you enjoy it, and check out the demo: Demo &#8211; I plan on replacing this with an inline demo some time very soon (See below). Launch AJAX Demo &#8211; Not working right [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.blackfade.com/wp-content/uploads/2009/09/MoodalWindow.png" class="highslide-image" onclick="return hs.expand(this);"><img src="http://www.blackfade.com/wp-content/uploads/2009/09/MoodalWindow-150x150.png" alt="MoodalWindow" title="MoodalWindow" width="150" height="150" class="alignleft size-thumbnail wp-image-101" /></a>This is my first attempt at publishing one of my scripts, and my first real attempt at writing a MooTools class.</p>
<p>I hope you enjoy it, and check out the demo:<br />
<span id="more-77"></span><br />
<a href="/demo/MoodalWindow/" target="_blank">Demo</a> &#8211; I plan on replacing this with an inline demo some time very soon (See below).<br />
<a href='/demo/MoodalWindow/ajax-demo.html' title='AJAX Demo' class='ajax'>Launch AJAX Demo</a> &#8211; Not working right now, trying to find the out what&#8217;s not connecting. <img src='http://www.blackfade.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3 style='clear: both;'>Here are the image files you will need:</h3>
<p>I suggest you find something better, these were just temp images for me.</p>
<pre>Close:<img class="alignnone size-full wp-image-91" title="close" src="http://www.blackfade.com/wp-content/uploads/2009/09/close.png" alt="close" width="16" height="16" />
Resize: <img class="size-full wp-image-92 alignnone" title="resize" src="http://www.blackfade.com/wp-content/uploads/2009/09/resize.png" alt="resize" width="17" height="17" />
Loading: <a href="http://www.blackfade.com/wp-content/uploads/2009/09/ajax-loader.gif" class="highslide-image" onclick="return hs.expand(this);"><img class="alignnone size-full wp-image-93" title="ajax-loader" src="http://www.blackfade.com/wp-content/uploads/2009/09/ajax-loader.gif" alt="ajax-loader" width="66" height="66" /></a>
</pre>
<h3>First the Javascript</h3>
<p>I&#8217;m assuming you&#8217;ve got MooTools Code and More installed.</p>
<pre class='prettyprint lang-js'>
var MoodalWindow = new Class({

	Implements: [Options, Events],

	options : {
		container		: window,
		height			: 700,
		width			: 600,
		overlayColor		: '#000000',
		overlayTransparency	: 0.7,
		overlayClose		: true,
		move			: true,
		resize			: true,
		url			: '',
		title			: 'Modal Window'
	},

	/*
	Constructor: initialize
		Constructor

		Add event on formular and perform some stuff, you now, like settings, ...
	*/
	initialize : function( element, options ) {
		if( $(element) )
		{
			if( $(element).get('title') )
				this.options.title	= $(element).get('title');
			else if( $(element).get('text') )
				this.options.title	= $(element).get('text');

			if( $(element).get('href') )
				this.options.url	= $(element).get('href');

			this.setOptions(options);

			$(element).addEvent('click', this.createPopup.bind(this) );
			return false;
		}
	},

	createPopup : function(){
		this.killStraglers();

		this.createOverlay();
		this.createWindow();
		if( this.options.title ){
			this.createTitle();
			this.createCloser();
		}
		this.createContent();
		if( this.options.resize )
			this.createResizer();
		return false;
	},

	createOverlay : function(){
		var overlayColor		= this.options.overlayColor;
		var overlayTransparency		= this.options.overlayTransparency;
		modalOverlay = new Element( 'div', { 'id':'modalOverlay' } ).setStyles({
			backgroundColor	: this.options.overlayColor,
			position	: 'absolute',
			left		: 0,
			top		: 0,
			height		: window.getScrollSize().y,
			width		: window.getScrollSize().x,
			zIndex		: 99
		});

		if( this.options.overlayClose )
			modalOverlay.addEvent('click', this.closePopup.bind(this) );

		modalOverlay.fade('hide');

		$(document.body).grab( modalOverlay );
		modalOverlay.fade( this.options.overlayTransparency );

		window.addEvent('resize',function(){
			modalOverlay.setStyles({
				height	: window.getScrollSize().y,
				width	: window.getScrollSize().x
			});

		});

	},

	createWindow : function(){

		var modalWindowTop = ( ( this.options.container.getSize().y / 2 ) - ( this.options.height / 2 ) + window.pageYOffset );
		if( modalWindowTop &amp;amp;lt; 0 )
			var modalWindowTop = 0;

		var modalWindowLeft = ( ( this.options.container.getSize().x / 2 ) - ( this.options.width / 2 ) + window.pageXOffset );
		if( modalWindowLeft &amp;amp;lt; 0 )
			var modalWindowLeft = 0;

		modalWindow = new Element( 'div', { 'id':'modalWindow' } ).setStyles({
			position	: 'absolute',
			top		: modalWindowTop,
			left		: modalWindowLeft,
			height		: this.options.height,
			width		: this.options.width,
			zIndex		: 100
		});

		modalWindow.fade('hide');
		$(document.body).grab( modalWindow );
		modalWindow.fade( 'in' );

		if( !this.options.move )
		{
			var reposition = function(){

				var modalWindowTop = ( ( this.options.container.getSize().y / 2 ) - ( this.options.height / 2 ) + window.pageYOffset );
				if( modalWindowTop &amp;amp;lt; 0 )
					var modalWindowTop = 0;
				if( modalWindowTop &amp;amp;gt; this.options.container.getSize().y )
					var modalWindowTop = this.options.container.getSize().y;

				var modalWindowLeft = ( ( this.options.container.getSize().x / 2 ) - ( this.options.width / 2 ) + window.pageXOffset );
				if( modalWindowLeft &amp;amp;lt; 0 )
					var modalWindowLeft = 0;
				if( modalWindowLeft &amp;amp;gt; this.options.container.getSize().x )
					var modalWindowLeft = this.options.container.getSize().x;

				modalWindow.setStyles({
					top	: modalWindowTop
					//left	: modalWindowLeft
				});

			}

			window.addEvents({
				'resize' : reposition.bind(this),
				'scroll' : reposition.bind(this)
			});
		}

	},

	createTitle : function(){

		modalTitle = new Element( 'div', { 'id':'modalTitle' } ).setStyles({
			position	: 'absolute',
			top		: 0,
			left		: 0,
			width		: '100%'
		});
		modalTitle.set( 'text', this.options.title );
		modalWindow.grab( modalTitle );

		if( this.options.move )
		{
			modalWindow.makeDraggable({
				handle : modalTitle,
				limit: {
					x : [ 0, ( this.options.container.getScrollSize().x ) ],
					y : [ 0, ( this.options.container.getScrollSize().y ) ]
				}
			});
			modalTitle.setStyles({
				cursor	: 'move'
			});
		};

	},

	createContent : function(){

		modalContent = new Element( 'div', { 'id':'modalContent' } ).setStyles({
			position	: 'absolute',
			top		: ( this.options.title ? modalTitle.getStyle('height') : 0 ),
			overflow	: 'auto',
			left		: 0,
			height		: ( this.options.height - ( this.options.title ? modalTitle.getStyle('height').toInt() : 0 ) )+'px',
			width		: '100%'
		});
		modalContent.set( 'html', '&amp;amp;lt;br /&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;&amp;amp;lt;center&amp;amp;gt;&amp;amp;lt;img alt=&amp;amp;quot;Loading..&amp;amp;quot; src=&amp;amp;quot;images/ajax-loader.gif&amp;amp;quot;/&amp;amp;gt;&amp;amp;lt;br /&amp;amp;gt;Loading Content...&amp;amp;lt;/center&amp;amp;gt;' );

		modalWindow.grab( modalContent );

		modalContent.load( this.options.url );

	},

	createCloser : function(){

		modalCloser = new Element( 'div', { 'id':'modalClose' } ).setStyles({
			cursor		: 'pointer',
			position	: 'absolute',
			top		: 0,
			right		: 0
		});
		modalTitle.grab( modalCloser );
		modalCloser.addEvent('click', this.closePopup.bind(this) );

	},

	createResizer : function(){

		modalResizer = new Element( 'div', { 'id':'modalResize' } ).setStyles({
			cursor		: 'pointer',
			position	: 'absolute',
			bottom		: 0,
			right		: 0
		});
		modalWindow.grab( modalResizer );

		modalWindow.makeResizable({
			handle : modalResizer,
			onDrag : function(){
				modalContent.setStyles({
					height : ( modalWindow.clientHeight - ( this.options.title ? modalTitle.getStyle('height').toInt() : 0 ) )+'px'
				});
			}.bind(this),
			limit: {
				x : [ 100, this.options.container.getSize().x ],
				y : [ 75, this.options.container.getSize().y ]
			}
		})
		modalResizer.setStyles({
			cursor	: 'se-resize'
		});

	},

	resizePopup : function( newHeight, shift ){

		modalContent.set('tween', {
			duration: 750
		}).tween('height', ( newHeight - ( this.options.title ? modalTitle.getStyle('height').toInt() : 0 ) ) );

		var moveHeight = function(){
			modalWindow.set('tween', {
				duration: 750
			}).tween('height', newHeight );
		}.delay(0);

		if( shift ) {
			var moveTop = function(){
				modalWindow.set('tween', {
					duration: 750
				}).tween('top', ( ( window.getSize().y / 2 ) - ( newHeight / 2 ) + window.pageYOffset ) );
			}.delay(750);
		}

		return false;
	},

	killStraglers : function(){

		if( $('modalOverlay') )
			$('modalOverlay').destroy();
		if( $('modalWindow') )
			$('modalWindow').destroy();

	},

	closePopup : function(){

		modalOverlay.fade('out');
		modalWindow.fade('out');
		var killEm = function(){
			if( $('modalOverlay') )
				$('modalOverlay').destroy();
			if( $('modalWindow') )
				$('modalWindow').destroy();
		}.delay(750);

		return false;

	}

});</pre>
<h3>Second, the CSS.</h3>
<p>I&#8217;m using the CSS3 rounded borders here, but it will roll back to normal borders if the viewer is using IE.</p>
<pre class='prettyprint lang-css'>
#modalWindow{
	background-color		: #FFFFFF;
	border				: 10px solid #222;
	border-radius			: 10px;
	-moz-border-radius		: 10px;
	-webkit-border-radius		: 10px;
}

#modalTitle{
	font-size			: 14px;
	font-weight			: bold;
	color				: #FFF;
	height				: 30px;
	background-color		: #222;
}

#modalContent{
	background-color		: #FFFFFF;
}

#modalClose{
	background-image		: url(images/close.png);
	height				: 16px;
	width				: 16px;
	margin				: 5px;
}

#modalResize{
	background-image		: url(images/resize.png);
	height				: 17px;
	width				: 17px;
}
</pre>
<h3>Lastly, the calling methods.</h3>
<p>I&#8217;ve added both methods here, first attaching to a single element.</p>
<pre class='prettyprint lang-js'>
Moodal = new MoodalWindow( $( 'moobox-link' ) );
</pre>
<p>Second, attaching to any link with a class of &#8220;moobox&#8221;.</p>
<pre class='prettyprint lang-js'>
$$('a.moobox').each(function(element){
	Moodal = new MoodalWindow( element );
});</pre>
<h3>Available options:</h3>
<ul>
<li><strong>height</strong> : Pixel height of the Modal Window. (EG: 250)</li>
<li><strong>width</strong> : Pixel width of the Modal Window. (EG: 350)</li>
<li><strong>overlayColor</strong> : Hex colour of the overlay. (EG: &#8216;#AAAAAA&#8217;/'#AAA&#8217;)</li>
<li><strong>overlayTransparency</strong> : Transparency level of the overlay, from 0 to 1. (EG: 0.4)</li>
<li><strong>overlayClose</strong> : Boolean value, if you want the modal window to close when you click the overlay background. (EG: true/false)</li>
<li><strong>move</strong> : Boolean value, if you want the user to be able to move the Modal window around, using the Title Bar as a handle. (EG: true/false)</li>
<li><strong>resize</strong> : Boolean value, if you want the user to be able to resize the Modal Window, from the bottom right corner.  If this is set to true, the window will not auto position itself when the window scrolls, or resizes. (EG: true/false)</li>
<li><strong>url</strong> : URL to be opened in the modal window.  If this is not set, the class will use the HREF from the link. (EG: &#8216;users/rob/index.php&#8217;)</li>
<li><strong>title</strong> : Title bar text, if this is set to false, the title bar will not appear, disabling the close button, and the move/drag feature.  If this is not set, the code will attempt to get a &#8220;TITLE&#8221; variable from the link, or failing that, the text from inside the link.</li>
</ul>
<h3>Options Example:</h3>
<pre class='prettyprint lang-js'>
Moodal = new MoodalWindow( $('link-id'), {
	height			: 700,
	width			: 600,
	overlayColor		: '#000000',
	overlayTransparency	: 0.7,
	overlayClose		: true,
	move			: true,
	resize			: true,
	url			: '/test/hello-world.html',
	title			: 'Hello World!'
});</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.blackfade.com/2009/09/24/moodal-window-for-mootools-1-2-3-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.640 seconds -->

