<?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>dotvoid.com &#187; jquery</title>
	<atom:link href="http://www.dotvoid.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotvoid.com</link>
	<description>Experiments and thoughts in PHP and javascript</description>
	<lastBuildDate>Tue, 11 Oct 2011 12:49:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamically change z-index on Google Maps markers</title>
		<link>http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/</link>
		<comments>http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 15:12:00 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=440</guid>
		<description><![CDATA[As many have noticed Google Maps API does not include a setIndex() method on the marker. You can set the z-index when adding a marker to the map. But it is not possible to change this afterwards.
I didn&#8217;t find a good solution to the problem when searching and had to resort to my own, hacking [...]]]></description>
			<content:encoded><![CDATA[<p>As many have noticed Google Maps API does not include a setIndex() method on the marker. You can set the z-index <em>when adding a marker</em> to the map. But it is not possible to change this afterwards.</p>
<p>I didn&#8217;t find a good solution to the problem when searching and had to resort to my own, hacking away on Google Maps. As I was feeling really good about myself when I had it working really well I just remembered that <a href="http://code.google.com/apis/maps/documentation/v3/">Google Maps Javascript API V3</a> has been released in Google Labs&#8230; And of course there it was. <a href="http://code.google.com/apis/maps/documentation/v3/reference.html#Marker">The Marker class</a> has a new method, <strong><code>setZIndex(<span class="type">zIndex:number</span>)</code></strong>.</p>
<p>Well, version 3 of the API is still only released by Google Labs which is &#8220;<em>home to developer products that are still in their formative stages</em>&#8220;. So for anyone not inclined to use version 3 just yet, I&#8217;ll write down how I did it here.</p>
<p>As I use JQuery in this particular project the example is also using JQuery. If used in production I suggest using try/catch wherever appropriate as the solution depends on a specific dom structure.</p>
<p>I have the below HTML which is the container for the Google map.</p>
<pre id="line197">&lt;<span class="start-tag">div</span><span class="attribute-name"> id</span>=<span class="attribute-value">"indexmap"</span>&gt;&lt;/<span class="end-tag">div</span>&gt;</pre>
<p>The map is created as below (you&#8217;ll have to add the lat/lng variable values yourselves.</p>
<pre id="line197">var map = new GMap2($('#indexamp'));
var point = new GLatLng(lat, lng);
map.setCenter(point, zoom);</pre>
<p>This, as most know, creates the actual map. Then it is time to add the markers. In my case I have a list of locations with the latitude/longitude in the actual html. JQuery helps me loop over these locations and dynamically add markers in the correct spots. This HTML looks like below. Note how each definition list have an id no with &#8220;mm_&#8221; as prefix. (Never mind any objections you have on having many definition lists like this&#8230; Never mind that these coordinates are fiction&#8230;)</p>
<pre>&lt;dl id="mm_0"&gt;
  &lt;dt&gt;...&lt;/dt&gt;
  &lt;dd&gt;
    &lt;span class="lat"&gt;61.333&lt;/span&gt;&lt;span class="lng"&gt;31.1324&lt;/span&gt;
    Random text
  &lt;/dd&gt;
&lt;/dl&gt;
&lt;dl id="mm_1"&gt;
  &lt;dt&gt;...&lt;/dt&gt;
  &lt;dd&gt;
    &lt;span class="lat"&gt;61.333&lt;/span&gt;&lt;span class="lng"&gt;31.1324&lt;/span&gt;
    Random text
  &lt;/dd&gt;
&lt;/dl&gt;</pre>
<p>What I want is the markers to be highlighted with a different icon every time I hover over a definition list element (dl). However, both have the same coordinates and one of the markers will be hidden behind the other.</p>
<p>So to prepare we need to make sure the actual images in the Google generated map can be connected to these defintion list id:s. The Google map have many different layers on top of each other. One layer contain the foreground images, another the shadows, mouse map definitions and so on. Each of these layers (normal div elements) have their own z-index.</p>
<p>In these different layers the images used have their own z-index. However, the z-index for the marker foreground image is the same as for the transparent clickable marker image. This makes it possible to use the transparent image z-index to restore the foreground image z-index. This is important as not to confuse the user when he later click on a marker&#8230;</p>
<p>So let&#8217;s loop over these images and give them appropriate id values as well as put the markers on the map. (No &#8211; Google does not give them id&#8217;s). This is, stripped to the bare essentials, the complete code with some comments.</p>
<pre id="line197">// Create the map
var map = new GMap2($('#indexamp'));
var point = new GLatLng(lat, lng);
map.setCenter(point, zoom);

// Loop over the definition lists picking up coordinates
var n = 0;
$('dl').each(function() {
	var lat = parseFloat($('span.lat', this).text());
	var lng = parseFloat($('span.lng', this).text());
	var point = new GLatLng(lat, lng);

	// Create the marker with custom images
	var markerIcon = new GIcon(G_DEFAULT_ICON);
	markerIcon.image = 'marker_default.png';
	markerIcon.iconSize = new GSize(23, 30);
	markerIcon.shadow = "marker_shadow.png";
	markerIcon.shadowSize = new GSize(50, 30);
	markerIcon.iconAnchor = new GPoint(11, 29);
	markerIcon.infoWindowAnchor = new GPoint(11, 14);

	var marker = new GMarker(point, {icon: markerIcon});

	// Change the foreground image when hovering over a definition list
	// Note that the actual id's have not been created yet.
	var no = this.id.substring(3); // Exclude the prefix
	$(this).hover(
		function() {
			marker.setImage('marker_selected.png');
			// Bring this image to foreground
			$('#mf_' + no)[0].style.zIndex = 1;
		},
		function() {
			marker.setImage('marker_default.png');
			// Reset the z-index based on the transparent image
			// that has the same z-index
			$('#mf_' + no)[0].style.zIndex = $('#mt_' + no)[0].style.zIndex;
		}
	);
}

// Add id values to the foreground images, based on the
// dom structure created beneath the #indexmap div element used
// as the place holder for the map
n = 0;
$('#indexmap div &gt; div &gt; div:eq(6) img').each(function() {
	this.id = 'mf_' + n++;
});

// Add id values to the shadow images the same way
n = 0;
$('#indexmap div &gt; div &gt; div:eq(8) img').each(function() {
	this.id = 'mt_' + n++;
});</pre>
<p>You might have to amend the code to get it working for you as I have cut&#8217;n pasted different parts. In the real code there is a lot of other things going on that would&#8217;ve made the example above hard to read. I do think however that you should be able to understand how it works.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/&amp;title=Dynamically+change+z-index+on+Google+Maps+markers" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/&amp;t=Dynamically+change+z-index+on+Google+Maps+markers" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/&amp;title=Dynamically+change+z-index+on+Google+Maps+markers&amp;summary=As%20many%20have%20noticed%20Google%20Maps%20API%20does%20not%20include%20a%20setIndex%28%29%20method%20on%20the%20marker.%20You%20can%20set%20the%20z-index%20when%20adding%20a%20marker%20to%20the%20map.%20But%20it%20is%20not%20possible%20to%20change%20this%20afterwards.%0D%0A%0D%0AI%20didn%27t%20find%20a%20good%20solution%20to%20the%20problem%20when%20searching%20and%20had%20to%20resort%20to%20my%20own%2C%20hacking%20away&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/&amp;title=Dynamically+change+z-index+on+Google+Maps+markers" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Dynamically+change+z-index+on+Google+Maps+markers+-+http://b2l.me/fjfa4&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2010/02/dymaically-change-z-index-on-google-maps-markers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Site architecture based on Zend Framework</title>
		<link>http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/</link>
		<comments>http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 11:48:54 +0000</pubDate>
		<dc:creator>Danne</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.dotvoid.com/?p=394</guid>
		<description><![CDATA[After working on the Swedish weather site klart.se for awhile I now work on my own projects again. So I have switched Codeigniter to Zend Framework again.
After a trip to Dublin I finally launched the beginning of a new social tourist Dublin guide. It is exactly the same site as both the Swedish Fuengirola guide [...]]]></description>
			<content:encoded><![CDATA[<p>After working on the Swedish weather site klart.se for awhile I now work on my own projects again. So I have switched Codeigniter to <a href="http://framework.zend.com">Zend Framework</a> again.</p>
<p>After a trip to Dublin I finally launched the beginning of a new <a href="http://www.dublincitymap.com/">social tourist Dublin guide</a>. It is exactly the same site as both the <a href="http://www.fuengirolaguide.com">Swedish Fuengirola guide</a> as well as the <a href="http://www.fuengirolamap.com">English Fuengirola guide</a> I launched after living there for five months. The functionality is somewhat basic as of yet but every now and then I&#8217;ll add something more.</p>
<p>Basing three different sites, even though they are very similar, using two different languages gives me the possibility to try out several parts of Zend Framework. It also requires a good design both in the backend and frontend to keep it maintainable. I thought maybe some people would be interested in a basic overview of the different parts needed to put everything together.</p>
<h2>Backend</h2>
<p>The sites aren&#8217;t really that complicated. On a basic level there is a MySQL database and a database layer using Zend_Db/Zend_Db_Table, there is a Zend Framework MVC architecture using models, controllers, views, layouts with Zend_Layout as well as a few view helpers and some HTML, CSS as well as Javascript. All commonly needed. There is more needed to make it a sitethough.</p>
<p>I want as little configuration per site as possible but I naturally still use Zend_Config_Ini for settings. Zend_Registry is needed to keep the global scope clean and is used to store instantiated objects that need to be available throughtout the website logic.</p>
<p>I have been a bit particular on using ZF as often as possible on these sites. With few exceptions. Thus I also use Zend_Form, Zend_Locale, Zend_Translate, Zend_Cache and more. Zend_Cache is really a no brainer and mainly used to speed up translations. This is extremely easy as Zend_Translate and Zend_Locale both are connected to the cache with one simple method call each. It is not complete but how simple this is to setup is illustrated by the below code.</p>
<pre>$configuration = new Zend_Config_Ini(
    APPLICATION_PATH .'/config/app.ini',
    APPLICATION_ENVIRONMENT
);
$frontendOptions = array(
    'lifetime' =&gt; $config-&gt;cache-&gt;lifetime,
    'automatic_serialization' =&gt; true
);
$backendOptions = array('cache_dir' =&gt; $config-&gt;cache-&gt;dir);
$cache = Zend_Cache::factory(
    'Core',
    'File',
    $frontendOptions,
    $backendOptions
);

$conf_locale = $configuration-&gt;locale;
$locale = new Zend_Locale($conf_locale);
$locale-&gt;setCache($cache);

Zend_Translate::setCache($cache);
$translate = new Zend_Translate(
    'array',
    APPLICATION_PATH .'/config/translation-' . $conf_locale . '.php',
    $conf_locale
);
$translate-&gt;setLocale($conf_locale);</pre>
<p>Zend_Form have had a few problems in many versions of ZF. In my opinion it is also a bit bloated and limiting to be used all the way. (Even though I like the automatic connection to the translation functionality in Zend_Translate and the validation through Zend_Validate) So I have settled for a simpler way where I use Zend_Form fully for validation (with Zend_Validate) and then give the view access to the form through a Zend_Form subclass to be able to print the fields individually. I think this is easier to handle than all the overloading and coding needed to fully make Zend_Form create forms as I want them. Another good thing with the form classes is that they too are locale aware and are translated automatically by connecting them to Zend_Translate through the simple line <em>Zend_Form::setDefaultTranslator($translate);</em>. The sub classed Form utility class looks like below. The generated elements are translated automatically. Very convenient.</p>
<pre>class Custom_Form extends Zend_Form  {
    /**
     * Render a field
     * @param string $name The name of the form element
     */
    public function _e($name) {
        $e = $this-&gt;getElement($name);
        return ($e) ? $e-&gt;render() : "&lt;dt&gt;Error&lt;/dt&gt;&lt;dd&gt;Missing &lt;$name&gt; field element&lt;/dd&gt;";
    }
}</pre>
<p>Another thing needed for these sites are to keep the urls understandable and thus translated into the language used on the site. For this the routes, or paths, are kept in the translation file as well. The translated paths are then registered to the router through the use of Zend_Controller_Router_Route and Zend_Controller_Router_Route_Regex objects.</p>
<pre>$frontController = Zend_Controller_Front::getInstance();
$router = $frontController-&gt;getRouter();
$router-&gt;addRoute(
    'route_review',
    new Zend_Controller_Router_Route(
        $translate-&gt;translate('route_review'),
        array('controller' =&gt; 'review', 'action' =&gt; 'index')
    )
);</pre>
<p>For image manipulation I haven&#8217;t looked further than ImageMagick. After a bit of tweaking you get very good quality when producing different image sizes.</p>
<h2>Search</h2>
<p>Last but not least, on the backend that is, there&#8217;s the search engine. ZF have an implementation of Lucene through Zend_Search_Lucene (derived from the Apache Lucene project). This is the one time I haven&#8217;t gone with ZF as I very much like the <a href="http://www.sphinxsearch.com/">open source Sphinx search engine</a> as it is so easy to integrate with MySQL. So Sphinx get to power the search.</p>
<p>This is convenient for several reasons. MySQL is not a great full text search engine, Sphinx give you better weighted results. The main reason though is the performance. Sphinx is very fast in itself but for a site with heavier traffic it is as simple as moving the search backend to it&#8217;s own machine to get a performance increase.</p>
<h2>Frontend</h2>
<p>On the frontend there is as clean html as possible to make it easy to change the design with only CSS as well as manipulate the client side with JQuery. If it wouldn&#8217;t be for the Google map the site would actually be pretty useful even without no css style at all.</p>
<p>A good practice I learned just recently (remember I&#8217;m mostly a backend developer) is to base all javascript functionality on modules that are instantiated depending on element ids present in the html. This makes it a lot simpler to split the javascript functionality into manageble pieces and also makes it a lot easier to maintain.</p>
<p>There are functionality in the client side javascript used to display error messages and information. This makes it necessary to create one javascript file with translation stirngs for each language. The correct javascript translation file is chosen in the layout (template/view file) depending on the current locale.</p>
<p>The map used is (are there any alternatives) <a href="http://code.google.com/apis/maps/">Google Maps API</a>. I chose to completely initiate the map by scanning the actual data displayed on the page. This is possible through clean html markup and also means that if I choose to list ten reviews on a page instead of five nothing need to be changed at all in the frontend. Only a loop limit on the backend.</p>
<h2>Conclusion</h2>
<p>Well. No conclusion. This was just a very basic walkthrough of most of the different pieces needed to create a fairly simple Zend Framework based website. Mostly it was a walkthrough of the bootstrap&#8230; I still hope it is useful or at least interesting.</p>
<p>I know I find it interesting to read about other sites and the architecture and design behind them.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/&amp;title=Site+architecture+based+on+Zend+Framework" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/&amp;t=Site+architecture+based+on+Zend+Framework" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/&amp;title=Site+architecture+based+on+Zend+Framework&amp;summary=After%20working%20on%20the%20Swedish%20weather%20site%20klart.se%20for%20awhile%20I%20now%20work%20on%20my%20own%20projects%20again.%20So%20I%20have%20switched%20Codeigniter%20to%20Zend%20Framework%20again.%0D%0A%0D%0AAfter%20a%20trip%20to%20Dublin%20I%20finally%20launched%20the%20beginning%20of%20a%20new%20social%20tourist%20Dublin%20guide.%20It%20is%20exactly%20the%20same%20site%20as%20both%20the%20Swedish%20&amp;source=dotvoid.com" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
		<li class="shr-plaxo">
			<a href="http://www.plaxo.com/?share_link=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/" rel="nofollow" class="external" title="Share this on Plaxo">Share this on Plaxo</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/&amp;title=Site+architecture+based+on+Zend+Framework" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Site+architecture+based+on+Zend+Framework+-+http://b2l.me/wtxg5&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.dotvoid.com/2009/10/site-architecture-based-on-zend-framework/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

