{"id":69,"date":"2009-06-24T21:13:56","date_gmt":"2009-06-25T01:13:56","guid":{"rendered":"http:\/\/www.carolinamantis.com\/wordpress\/?p=69"},"modified":"2009-06-24T21:13:56","modified_gmt":"2009-06-25T01:13:56","slug":"adding-dynamic-behavior-when-using-tabbedmaxcontent","status":"publish","type":"post","link":"http:\/\/www.carolinamantis.com\/wordpress\/?p=69","title":{"rendered":"Adding Dynamic Behavior When Using TabbedMaxContent"},"content":{"rendered":"<div class=\"wp_plus_one_button\" style=\"margin: 0 8px 8px 0; float:left; \"><g:plusone href=\"http:\/\/www.carolinamantis.com\/wordpress\/?p=69\" callback=\"wp_plus_one_handler\"><\/g:plusone><\/div><p>Last time I promised a continuation of the series describing how I used the Tabbed Max Content JavaScript class for some Google Maps at ECU.  One of the inspirations I used was the many examples in the <a href=\"http:\/\/code.google.com\/apis\/maps\/documentation\/demogallery.html\">Google Maps API Demo Gallery<\/a>.  Specifically, I used code snippets from the <a href=\"http:\/\/gmaps-utility-library.googlecode.com\/svn\/trunk\/tabbedmaxcontent\/1.0\/examples\/ajaxmaxtabs.html\">Tabbed Max InfoWindow + Dynamic Content<\/a> example.  Thanks to Nianwei Liu for the Tabbed Max InfoWindow example posted there.<\/p>\n<p>The <a href=\"http:\/\/www.carolinamantis.com\/demo\/tabbedmaxcontent\/ex01.html\">simple example<\/a> from my last posting didn&#8217;t need any dynamic actions; all of the rendering was handled by the Tabbed Max Content itself.  If the contents of the Tabbed Max Content may change, though, we need additional actions.<\/p>\n<pre name=\"code\" class=\"js\">\r\nGEvent.addListener(map.getTabbedMaxContent(), 'selecttab', function(tab) {\r\n   switch (tab.getLabel()) {\r\n      case 'Availability':\r\n         \/\/ Generate the dynamic HTML as strings\r\n         \/\/ Set the html content  of the div, p, or other block element to be that string\r\n      break;\r\n   }\r\n});\r\n<\/pre>\n<p>In the code above we have the outline of our basic tab selection event listener.  The method that will fire is selecttab, generated by the map&#8217;s current Tabbed Max Content instance.  We only have to do this once in the entire map, not once per marker.<\/p>\n<p>I have created a simple example that generates a random value and sets the image data for a Google chart to graph the value:<\/p>\n<p><a href=\"http:\/\/www.carolinamantis.com\/demo\/tabbedmaxcontent\/ex02.html\">http:\/\/www.carolinamantis.com\/demo\/tabbedmaxcontent\/ex02.html<\/a><\/p>\n<p>My example adds this block of code for the dynamic aspect:<\/p>\n<pre name=\"code\" class=\"js:firstline[75]\">\r\nGEvent.addListener(map.getTabbedMaxContent(), 'selecttab', function(tab) {\r\n   switch (tab.getLabel()) {\r\n      \/\/ We could also have used case 1 below (tabs are numbered from 0 and increase as they go left to right)\r\n      \/\/ Here I choose to switch on the actual text of the tab, note it is enclosed in quotes but the numeric 1\r\n     \/\/ is not.\r\n     case 'Tab 2':\r\n        \/\/ Everything needed for a Google chart but the final value\r\n        var url = 'http:\/\/chart.apis.google.com\/chart?chs=170x170&amp;chtt=Power%20Reading&amp;cht=gom&amp;chd=t:';\r\n        \/\/ Generate a random number between 0 and 100\r\n       var randomnumber=Math.floor(Math.random()*101);\r\n       url += randomnumber;\r\n       var htmlsrc = '<img decoding=\"async\" src=\"' + url + '\" width=\"170\" heigh=\"170\"\/>';\r\n       \/\/ Use jQuery to set the HTML for the paragraph.\r\n       $('#tab2image').html(htmlsrc);\r\n    break;\r\n    }\r\n});\t\t\t\r\n<\/pre>\n<p>If you visit the example page, you can click on the point and then expand the Tabbed Max Content.  Every time you switch between Tab 1 and Tab 2, a new random value will be generated and the graphic will be updated.<\/p>\n<p>Next time I will post about how to manage the case where you have many points on your map, and must generate separate dynamic content on a tab for each one.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"wp_plus_one_button\" style=\"margin: 0 8px 8px 0; float:left; \"><g:plusone href=\"http:\/\/www.carolinamantis.com\/wordpress\/?p=69\" callback=\"wp_plus_one_handler\"><\/g:plusone><\/div><p>Last time I promised a continuation of the series describing how I used the Tabbed Max Content JavaScript class for some Google Maps at ECU. One of the inspirations I used was the many examples in the Google Maps API Demo Gallery. Specifically, I used code snippets from the Tabbed Max InfoWindow + Dynamic Content [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,4,5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/69"}],"collection":[{"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":8,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":77,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/77"}],"wp:attachment":[{"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.carolinamantis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}