Topic on User talk:Nicolas NALLET/Flow

FancyBoxThumbs for pdf format

5
Bennylin (talkcontribs)

No, I haven't. I tried to hack the code, to no avail. Bennylin (talk) 10:29, 6 January 2015 (UTC)

Bennylin (talkcontribs)

Hi Nicolas, in case you're still looking for a solution for this, I managed to tweak the code from version 1.0.1 to be able to display pdf thumbnail in fancyboxthumb correctly (alongside with other types)

This is my change to the code:

if ( !defined( 'MEDIAWIKI' ) )
    die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' );
 
//Register Credits
$wgExtensionCredits['other'][] = array(
    'name'        => 'FancyBoxThumbs',
    'url'         => 'http://www.mediawiki.org/wiki/Extension:FancyBoxThumbs',
    'author'      => '[http://www.gilluminate.com Jason Gill]',
    'description' => 'Displays thumbnailed images in a Mac-style "lightbox" that floats overtop of web page. A simple and fancy lightbox alternative',
    'version'     => '1.0.1'
);
 
$wgHooks['BeforePageDisplay'][] = 'efBeforePageDisplay';
 
function efBeforePageDisplay($out)
{	
    global $wgScriptPath, $wgTitle, $wgRequest;
	
	// Don't load if in the Special namespace (to prevent clobbering Semantic Forms or other extensions that load jQuery).
	// Also don't load if we're doing any sort of action on the page.
	$action = $wgRequest->getVal("action");
	if($wgTitle->getNsText() != "Special" && $action != "formedit")
	{
		$FBT_Dir = '/extensions/FancyBoxThumbs/fancybox';
		//Only load jQuery if for some reason it's not present
		$out->addScript('<script type="text/javascript">var jQueryScriptOutputted = false;function initJQuery() {if (typeof(jQuery) == "undefined") {if (! jQueryScriptOutputted) {jQueryScriptOutputted = true;document.write(\'<scr\'+\'ipt type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></scr\'+\'ipt>\');}setTimeout("initJQuery()", 50);}}initJQuery();</script>');
		$out->addScriptFile($wgScriptPath.$FBT_Dir.'/jquery.fancybox-1.3.4.js');
		$out->addScript('<link rel="stylesheet" href="'.$wgScriptPath.''.$FBT_Dir.'/jquery.fancybox-1.3.4.css" type="text/css" />');
	 
		##uses jquery to rewrite the href, rather than traditional php methods that can break the CMS nature of WikiMedia
		$out->addScript('<script type="text/javascript">'
						.'jQuery.noConflict();'
						.'(function($) {'
							.'$(document.body).ready(function() {'
								.'$("a.image").each(function(){'
									.'var img_split1 = $(this).children().first().attr("src").split("/thumb");'
									.' if(img_split1[1] == null) { img_split1[1] = img_split1[0]; img_split1[0] = \'\';};' // Not a thumb but a full image
									.' var img_type = img_split1[1].substr(img_split1[1].length -4);' // cut the last 4 (!) characters to fetch .jpg and jpeg
									.' var img_type_pdf = img_split1[1].substr(img_split1[1].length -7);' // cut the last 7 (!) characters to test if it is pdf thumbnail or not
									.' var img_split2 = img_split1[1].split(img_type);'
									.' var img_src = img_split1[0]+img_split2[0]+"."+img_type;'
									.' if(img_type_pdf == "pdf.jpg") var img_src = img_split1[0]+"/thumb"+img_split2[0]+"."+img_type;'//if pdf thumbnail, insert "/thumb" address back to the href
									.' var img_src = img_src.replace("..", ".");' // change ..jpg to .jpg but do not change .jpeg
									.' $(this).attr("href", img_src);' //href to the image source
									.' $(this).attr("rel", "group");'
								.'});'
								.'$("a.image").fancybox({"transitionIn":"elastic","transitionOut":"elastic","titlePosition":"inside"});'
							.'});'
						.'})(jQuery)'
						.'</script>');
	}
 
    return true;
}

Regards,

Deletedaccount4567435 (talkcontribs)

WOW COOL! It work for our site!

THANK YOU!

Bennylin (talkcontribs)

You're welcome, Zoglun

Reply to "FancyBoxThumbs for pdf format"