-
- 2,877 Posts
Instead of hacking the showimagetvs widget we can create our own!
- Create a new folder inside managermanager » widgets : showimagetvthumbs
- Create showimagetvthumbs.php inside that folder (see code below)
- In your mm_rules chunk call: mm_widget_showimagetvthumbs();
showimagetvthumbs.php
<?php
//---------------------------------------------------------------------------------
// mm_widget_showimagetvthumbs
// Shows a preview of image TVs
// using the CKFinder generated thumbs
//---------------------------------------------------------------------------------
function mm_widget_showimagetvthumbs($tvs='', $w=300, $h=100, $roles='', $templates='') {
global $modx, $content;
$e = &$modx->Event;
if ($e->name == 'OnDocFormRender' && useThisRule($roles, $templates)){
$output = '';
$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; margin: 4px 0; cursor: pointer;'";
} else {
$style = '';
}
// Which template is this page using?
if (isset($content['template'])) {
$page_template = $content['template'];
} else {
// If no content is set, it's likely we're adding a new page at top level.
// So use the site default template. This may need some work as it might interfere with a default template set by MM?
$page_template = $modx->config['default_template'];
}
// Does this page's template use any image TVs? If not, quit now!
$tvs = tplUseTvs($page_template, $tvs, 'image');
if ($tvs == false) {
return;
}
$output .= "// ---------------- mm_widget_showimagetvs: Add image preview ------------- \n";
// Go through each TV
foreach ($tvs as $tv) {
$new_html = '';
$output .= '// Adding preview for tv'.$tv['id'].'
$j("#tv'.$tv['id'].'").addClass("imageField").bind( "change load", function() {
// Get the new URL
var url = $j(this).val();
url = (url != "" && url.search(/http:\/\//i) == -1) ? ("'.$site.'" + url) : url;
//mrhaw
var url = url.replace("assets/images", "assets/.thumbs/images");
';
$output .= '
// Remove the old preview tv'.$tv['id'].'
$j("#tv'.$tv['id'].'PreviewContainer").remove();
if (url != "") {
// Create a new preview
$j("#tv'.$tv['id'].'").parents("td").append("<div class=\"tvimage\" id=\"tv'.$tv['id'].'PreviewContainer\"><img src=\""+url+"\" style=\""+'.$style.'+"\" id=\"tv'.$tv['id'].'Preview\"/></div>");
// Attach a browse event to the picture, so it can trigger too
$j("#tv'.$tv['id'].'Preview").click( function() {
BrowseServer("tv'.$tv['id'].'");
});
}
$j.data(this,"lastvalue", $j(this).val());
}).trigger("load"); // Trigger a change event on load
';
}
$output .= '
// Monitor the image TVs for changes
checkImageTVupdates = function () {
$j(".imageField").each( function() {
var $this = $j(this);
if ($this.val() != $this.data("lastvalue") ) {
$this.trigger("change").data("lastvalue", $this.val());
}
});
}
setInterval ( "checkImageTVupdates();", 250 );
';
$e->output($output . "\n");
}
} // end of widget
?>
-
- 2,877 Posts
Quote from: taiyo1578 at Jul 15, 2015, 03:20 PMThis is freaking awesome Mr. Haw. Per usual you are always serving up the finest tricks of the trade. My error is gone however I'm seeing a broken thumbnail image as you can see here: http://grab.by/IQos
....wondering if the .thumbs is causing this to cough? I have verified that the file is there.
Thank you!
1. Are you logged into the manager correctly!? Meaning if the site is directing to domain.com without www make sure you're not logged in using
www!
2. Can you output the thumbnails using this snippet?
http://forums.modx.com/thread/42541/tip-basic-thumbnail-solution-using-thumb-instead-of-tv-image#dis-post-246179