Advertisement
Guest User

Krusher

a guest
May 15th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.25 KB | None | 0 0
  1. <?php
  2. /*
  3.  * FancyBoxThumbsK extension
  4.  * by Jason Gill, http://www.gilluminate.com modified by Uwe Schützenmeister, http://idea-sketch.com, Modified by Krusher http://krusher.net
  5.  *
  6.  * Displays thumbnailed images in a Mac-style "lightbox" that floats overtop of web page.
  7.  *
  8.  *
  9.  * Uses: FancyBox - jQuery Plugin
  10.  * Simple and fancy lightbox alternative
  11.  *
  12.  * Examples and documentation at: http://fancybox.net
  13.  *
  14.  * Copyright (c) 2008 - 2011 Janis Skarnelis, Krusher
  15.  * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely.
  16.  * Their support is greatly appreciated.
  17.  *
  18.  * Version: 1.3.4 (11/11/2010)
  19.  * Requires: jQuery v1.3+
  20.  *
  21.  * Dual licensed under the MIT and GPL licenses:
  22.  *   http://www.opensource.org/licenses/mit-license.php
  23.  *   http://www.gnu.org/licenses/gpl.html
  24.  */
  25.  
  26. if ( !defined( 'MEDIAWIKI' ) )
  27.     die( 'This is a MediaWiki extension, and must be run from within MediaWiki.' );
  28.  
  29. //Register Credits
  30. $wgExtensionCredits['other'][] = array(
  31.     'name'        => 'FancyBoxThumbsK',
  32.     'url'         => 'http://www.mediawiki.org/wiki/Extension:FancyBoxThumbs',
  33.     'author'      => '[http://www.gilluminate.com Jason Gill], [http://krusher.net]',
  34.     'description' => 'Displays thumbnailed images in a Mac-style "lightbox" that floats overtop of web page. A simple and fancy lightbox alternative',
  35.     'version'     => '0.4.K'
  36. );
  37.  
  38. $wgHooks['BeforePageDisplay'][] = 'efBeforePageDisplay';
  39.  
  40. function efBeforePageDisplay($out)
  41. {  
  42.     global $wgScriptPath;
  43.     $FBT_Dir = '/extensions/FancyBoxThumbs/fancybox';
  44.     //$out->addScript('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>');
  45.     $out->addScriptFile($wgScriptPath.$FBT_Dir.'/jquery.fancybox-1.3.4.js');
  46.     $out->addScript('<link rel="stylesheet" href="'.$FBT_Dir.'/jquery.fancybox-1.3.4.css" type="text/css" />');
  47.  
  48.     ##uses jquery to rewrite the href, rather than traditional php methods that can break the CMS nature of WikiMedia
  49.     $out->addScript('<script type="text/javascript">'
  50.                     .'jQuery.noConflict();'
  51.                     .'(function($) {'
  52.                         .'$(document.body).ready(function() {'
  53.                             .'$("a.image").each(function(){'
  54.                                 .'var img_split1 = $(this).children().first().attr("src").split("/thumb");'
  55.                                 .' if(img_split1[1] == null) { img_split1[1] = img_split1[0]; img_split1[0] = \'\';};' // Not a thumb but a full image
  56.                                 .' var img_type = img_split1[1].substr(img_split1[1].length -4);' // cut the last 4 (!) characters to fetch .jpg and jpeg
  57.                                 .' var img_split2 = img_split1[1].split(img_type);'
  58.                                 .' var img_src = img_split1[0]+img_split2[0]+"."+img_type;'
  59.                                 .' var img_src = img_src.replace("..", ".");' // change ..jpg to .jpg but do not change .jpeg
  60.                                 .' var pieces = img_src.split(\'/\');'
  61.                                 .' $(this).attr("title", $(this).attr("title") + "<br />Origen: <a style=\"color:#888888;\" href=\"http://www.frikipedia.es/friki/Archivo:"+pieces[pieces.length-1]+"\">" + pieces[pieces.length-1] + "</a>");'
  62.                                 .' $(this).attr("href", img_src);'
  63.                             .'});'
  64.                             .'$("a.image").fancybox({"transitionIn":"elastic","transitionOut":"elastic","titlePosition":"inside"});'
  65.                         .'});'
  66.                     .'})(jQuery)'
  67.                     .'</script>');
  68.  
  69.     return true;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement