We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29635
    • 361 Posts
    This is an auto-generated support/comment thread for ShowImageTVs.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Show the currently selected image for an Image TV, in the manager.
      Need MODx Ecommerce? Try FoxyCart!
      • 29635
      • 361 Posts
      Hello all.
      This may have been done before, but I just created a little plugin for Image TVs so it will display (and update) the selected image right beneath the path box. I figure this is pretty useful. (Check the link above for a screenshot if that’s not clear.)

      It works beautifully, but there’s a lot of room for improvement, so if anybody can help with the following it’d be great:

      • It’s all manual at this point. I’m sure there’s a really nice way to automatically grab all the image TVs and run this automatically for all of them.
      • Because the input is changed by javascript when you select an image from the resource browser, it doesn’t trigger the onChange event (so if you changed the image, the old image will still be displayed)... The only way I could get around this was to check the value every couple seconds. I’m not sure there’s a workaround, but if you know one, let me know.
      • I haven’t tested in IE because I don’t let my clients use it wink, so no guarantees there.

      Some other notes:
      * It’s using JQuery, because I don’t know Prototype.
      * It could very easily be hacked to display a thumbnail a la phpThumb if you have it installed.

        Need MODx Ecommerce? Try FoxyCart!
      • Very cool Brett. Thanks! (I think a mootools version of this would make a lot of sense for the manager)
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 29635
          • 361 Posts
          Thanks Ryan.
          Agreed on the mootools. I’ll see if I can refine it to automatically apply itself to all image TVs in the next week or two. And if I’m feeling really adventurous I’ll switch it to mootools as well.
            Need MODx Ecommerce? Try FoxyCart!
            • 14412
            • 74 Posts
            FIY, this wasn’t working for me as announced (using MODx 0.9.5).

            After some trial and error and debugging with Firebug, seems like the problem is that mootools and jQuery don’t get along very well.

            I had to modify the plugin:

            To reference the js files using absolute path, i.e:
            // Include the JQuery call ONLY IF IT'S NOT ALREADY INCLUDED
                $output .= '<script src="'.$modx->config['site_url'].'assets/js/jquery-1.0.1.pack.js" type="text/javascript"></script>';
                $output .= '<script src="'.$modx->config['site_url'].'assets/js/heartbeat.js" type="text/javascript"></script>';


            And replace all the [tt]$([/tt] entries with [tt]jQuery([/tt]

            I guess this should be part of MODx core, as it is much more intuitive for end-users to use image TVs if they see a preview of what they just selected.

            Any candidates for a mootools port?

            Maybe I’ll give it a try once I Mooooooo some more - don’t get too excited, tough grin

            regards, JP

              Got Music? Try XSPFjukebox - Skinnable MODx Media Player
              • 29635
              • 361 Posts
              Sorry about the 0.9.5 issues. I think I’ve been playing in 0.9.6 land for a while so I might not have noticed.

              I’ll do a MooTools port of this in the near future, unless somebody beats me to it. The jQuery heartbeat script seems to do bad things (tanking FF with this plugin, but I’ve had it tank apache as well (high traffic site, too many connections)), so it needs to be fixed in any case.

              I haven’t checked, but if anybody knows of a good heartbeat type script for MooTools, let me know.
                Need MODx Ecommerce? Try FoxyCart!
                • 4385
                • 372 Posts
                Would something like this help?


                http://docs.mootools.net/Native/Function.js#Function.periodical


                I don’t much about MooTools, but I would love to be able to add something like this to my sites.
                  DropboxUploader -- Upload files to a Dropbox account.
                  DIG -- Dynamic Image Generator
                  gus -- Google URL Shortener
                  makeQR -- Uses google chart api to make QR codes.
                  MODxTweeter -- Update your twitter status on publish.
                  • 24292
                  • 28 Posts
                  This is a rewrite using Mootools and it finds image tvs for itself so very little configuration necessary.

                  Instructions:
                  Add this as a new Plugin and tick OnDocFormRender event
                  Make sure it comes after any other plugin that could effect the template, like InheritParentTemplate.
                  That’s it. It should now show images of all image tvs

                  To configure image size: copy
                  &w=Max width;int;300 &h=Max height;int;100
                  into the plugin configuration and change values to suit
                  This sets style="max-width: ; max-height: " for the image
                  If you don’t configure w or h, the image will be fullsize but
                  you can add a css rule rule div.tvimage img {...} to the Manager Theme

                  // <?php
                  
                  //    @name       ShowImageTVs
                  //    @version    0.2, 5 Feb 2008
                  //    
                  //    
                  //    @author     Brett @ The Man Can!
                  //                rewritten by Rachael Black 
                  //                now works with MooTools and finds the image tvs itself
                  //                    
                  
                  /* --------------------------------------------------------------- 
                  Instructions:
                       Add this as a new Plugin and tick OnDocFormRender event
                       Make sure it comes after any other plugin that could effect the template, like InheritParentTemplate.
                       That's it. It should now show images of all image tvs 
                   
                       To configure image size: copy
                         &w=Max width;int;300 &h=Max height;int;100
                       into the plugin configuration and change values to suit
                       This sets style="max-width: ; max-height: " for the image
                       If you don't configure w or h, the image will be fullsize but
                       you can add a css rule rule div.tvimage img {...} to the Manager Theme
                  ------------------------------------------------------------------- */
                  
                  global $content;
                  $template = $content['template'];
                  $e = &$modx->Event;
                  
                  if ($e->name == 'OnDocFormRender' && ($template > 0)) {
                  	$site = $modx->config['site_url'];
                  	
                  	if (isset($w) || isset($h)) {
                  		$w = isset($w) ? $w : 300;
                  		$h = isset($h) ? $h : 100;
                  		$style = "'max-width:{$w}px; max-height:{$h}px'";
                  	}
                  	else
                  		$style = '';
                      
                  		// get list of all image template vars
                  	$table = $modx->getFullTableName('site_tmplvars');	
                  	$result = $modx->db->select('name', $table, "type='image'");
                  	$tvs = '';
                  	while ($row = $modx->db->getRow($result))
                  		$tvs .= ",'" . $row['name'] . "'";
                  	$tvs = substr($tvs, 1);		// remove leading ','
                  	
                  	$output = <<< EOT
                  <!-- ShowImageTVs Plugin :: Start -->  
                  
                  <script type="text/javascript" charset="utf-8">
                    var imageNames = [$tvs];
                    var pageImages = [];
                    
                    function full_url(url)
                    {
                  	 	return (url != '' && url.search(/http:\/\//i) == -1) ? ('$site' + url) : url;
                    }
                  
                    function checkImages() 
                    {
                      for (var i = 0; i < pageImages.length; i++) {
                      	var elem = pageImages[i];
                        var url = elem.value;         
                        if (url != elem.oldUrl) {   
                       	  elem.thumbnail.setProperty('src', full_url(url));  
                       	  elem.thumbnail.setStyle('display', url=='' ? 'none': 'inline');    	      
                          elem.oldUrl = url;    
                        }  
                      }
                    }
                  
                  	window.onDomReady(function() { 
                      for (var i = 0; i < imageNames.length; i++) {   
                      	var elem = $('tv' + imageNames[i]);  
                        if (elem) {  	  
                          var url = elem.value;
                          
                          	// create div and img to show thumbnail
                          var div = new Element('div').addClass('tvimage');
                          var img = new Element('img').setProperty('src', full_url(url)).setStyles($style);
                          elem.getParent().adopt(div.adopt(img));
                          
                          elem.thumbnail = img;    // direct access for when need to update
                          elem.oldUrl = url;   		 // oldUrl so change HTML only when necessary  
                          pageImages.push(elem);   // save so don't have to search each time              
                        }
                      }           
                      setInterval(checkImages, 1000);
                    })  
                  </script>	
                  
                  <!-- ShowImageTVs Plugin :: End -->	          
                  EOT;
                  
                  	$e->output($output);
                  }
                  
                  
                  
                  // ?>
                    • 29635
                    • 361 Posts
                    That’s awesome. Thanks for sharing.
                      Need MODx Ecommerce? Try FoxyCart!
                      • 24495
                      • 407 Posts
                      [SOLVED] Tried with the new 0.9.6.1p2 but no results. I think it was a problem with cookies and/or cache.

                      Great work this mod. Very helpful for content authors.