• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

How To: Restrict JQuery Droppable Areas To Draggable Type

You may view the code at: http://brianfalls.com/template3.cfm

I would like to know how to restrict the primary vignettes to the primary vignette droppable area and the secondary vignettes to the secondary vignette  droppable areas.

The Primary area is the larger area and the secondary areas are the smaller areas.

Is it possible to constrain what goes where?  If so, please explain how in a thorough manner.  While I certainly appreciate fixes, my real desire is to learn the how's and why's.  Thank you very much.
<!doctype html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>bf.c emTools</title>


	<script type="text/javascript" src="/ui/js/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.core.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.mouse.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.draggable.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.droppable.js"></script>
	<script type="text/javascript" src="/ui/js/jquery.ui.thumbHover.js"></script>
	<script type="text/javascript" src="/ui/js/png_fix.js"></script>
	<script type="text/javascript">
				imgSmallFlag: "_min",
				imgLargeFlag: "_med"
////////////// for draggable elements ////////////// 
			$(".imageAsset").draggable({helper: 'clone', snap: '.drop', snapMode: 'inner'});
////////////// for droppable areas (primary area(s)) with dimensions of 315px x 470px (width x height) ////////////// 
				accept: ".imageAsset",
				activeClass: 'droppable-active',
				hoverClass: 'droppable-hover',
				drop: function(ev, ui) {
				var mainContent="#".replace('#', ui.draggable.html().replace('thumbs/','').replace('_min','').replace('inline;','none;').replace('none;','block;'));
//				alert(mainContent);
				if ($(this).html() == "") {
////////////// for droppable areas (secondary area(s)) with dimensions of 315px x 225px (width x height) ////////////// 
				accept: ".imageAsset",
				activeClass: 'droppable-active',
				hoverClass: 'droppable-hover',
				drop: function(ev, ui) {
				var content="#".replace('#', ui.draggable.html().replace('thumbs/','').replace('_min','').replace('inline','none').replace('none','block'));
//				alert(mainContent);
				if ($(this).html() == "") {

	<style type="text/css">
		body { font-family: Arial, Helvetica, sans-serif; font-size: 11px; }
		.droppable-hover { outline: 2px dashed; }
		.clear { clear: both; }
		/* .png fix for early version of IE */
		img, div, input { behavior: url("/ui/js/png_fix.htc") }
		/* availableImages style - left side image library*/
		#availableImages { float: left; width: 250px; border: 1px solid #eee ; }
		#availableImages h4 { clear: both; margin: 0; padding: 0; }
		#availableImages hr { clear: both; display: block;  margin: 0 0 7px 0; color: #eee; background-color: #eee; border-color: #eee; }
		#availableImages ul { display: block; width: 250px; clear: both; margin: 0 0 7px 0; padding: 0; }
		#availableImages li { list-style: none; padding: 0; margin: 0; }
		#availableImages li div.primary { padding: 0; margin: 0; float: left; height: 85px; width: 55px; }
		#availableImages li div.secondary { padding: 0; margin: 0; float: left; height: 59px; width: 80px; }
		/* email content style - right side email content build tool*/
		#emailContent { float: left; width: 722px; }
		#emailContent .body {  background-image: url(ui/images/email_bg.png); width: 100%; height: 663px; }
		#emailContent .body .drop315x470 { width: 315px; height: 470px; float: left; border: 1px dashed #777; margin: 0; padding: 0; position: relative; top: 137px; left: 29px; }
		#emailContent .body .drop315x225 { width: 315px; height: 225px; float: left; border: 1px dashed #777; margin: 0; padding: 0; position: relative; top: 137px; left: 49px; }
		#emailContent .body .spacer { width: 315px; height: 17px; float: left; position: relative; top: 157px; left: 49px; }


	<div id="availableImages">
		<h4>Primary Area Vignettes</h4>
		<!--- Primary Area Vignettes (315x470) --->
			<li><div class="primary imageAsset"><img src="/ui/images/thumbs/image6_min.jpg" /></div></li>
		<hr />
		<!--- Secondary Area Vignettes (315x225) --->
		<h4>Secondary Area Vignettes</h4>
				<div class="secondary imageAsset">
					<div style=" display: none; ">
						<div style=" margin: 0; padding: 0; background: url(/ui/images/htmlImage1.jpg) no-repeat; width: 315px; height: 225px; border: none; " cellspacing="0" cellpadding="0">
								style=" width: 80px; background-color: #412412; font-family: Arial,Helvetica,sans-serif; color: #f0e0c7; font-size: 12px; border: none; font-weight: bold; position: relative; top: 169px; left: 202px; "
					<div style=" margin: 0 7px 0 0; padding: 0; float: left; width: 78px; display: inline; ">
						<img style=" display: block; " border="0" src="/ui/images/thumbs/htmlImage1_min.jpg" />
			<li><div class="secondary imageAsset"><img src="/ui/images/thumbs/image1_min.jpg" /></div></li>
			<li><div class="secondary imageAsset"><a href=""><img style=" border: 0px; " src="/ui/images/thumbs/image2_min.png" /></a></div></li>
	<div id="emailContent">

		<div class="body">
			<!--- Droppable Area for Primary Vignettes. (315x470) --->
			<div class="drop315x470"></div>
			<!--- Droppable Area for Secondary Vignettes. (315x225) --->
			<div class="drop315x225"></div>
			<div class="spacer"></div>
			<!--- Droppable Area for Secondary Vignettes. (315x225) --->
			<div class="drop315x225"></div>



Open in new window

1 Solution
A simple solution in your case is to change the accept option for the two droppable areas. Change one from .imageAsset to .primary and the other from .imageAsset to .secondary. This will target the different pictures depending on what type they are and is self explanatory.
brianmfallsAuthor Commented:
Awesome.  That was easy.  Thanks Zyloch.  :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now