r20420 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r20419‎ | r20420 | r20421 >
Date:00:06, 14 March 2007
Author:daniel
Status:old
Tags:
Comment:
fall back to plain old gallery if JS is not supported
Modified paths:
  • /trunk/extensions/SmoothGallery/SmoothGallery.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SmoothGallery/SmoothGallery.php
@@ -34,6 +34,8 @@
3535
3636 $wgHooks['BeforePageDisplay'][] = 'addSmoothGalleryJavascriptAndCSS';
3737
 38+$wgSmoothGalleryExtensionPath = $wgScriptPath . '/extensions/SmoothGallery'; //sane default
 39+
3840 function wfSmoothGallery() {
3941 global $wgParser;
4042
@@ -206,7 +208,7 @@
207209 }
208210
209211 //Open the outer div of the gallery
210 - $output = '<div id="' . $name . '" class="myGallery" style="width: ' . $width . ';height: ' . $height . '">';
 212+ $output = '<div id="' . $name . '" class="myGallery" style="width: ' . $width . ';height: ' . $height . '; display:none;">';
211213
212214 //Expand templates in the input
213215 $input = $parser->replaceVariables( $input );
@@ -219,6 +221,8 @@
220222 //can report them later
221223 $missing_img = "";
222224
 225+ $plain_gallery = new ImageGallery();
 226+
223227 foreach ( $img_arr as $img ) {
224228 //Get the image object from the database
225229 #$img_obj = Image::newFromName( $wgContLang->ucfirst($img) );
@@ -288,6 +292,8 @@
289293 }
290294
291295 $output .= '</div>';
 296+
 297+ $plain_gallery->add( $img_obj ); //TODO: use text
292298 }
293299
294300 //Make sure we have something to output
@@ -311,10 +317,22 @@
312318 //Close the outer div of the gallery
313319 $output .= '</div>';
314320
 321+ //Wrapper div for plain old gallery, to be shown per default, if JS is off.
 322+ $output .= '<div id="' . $name . '-plain">';
 323+
 324+ $output .= $plain_gallery->toHTML();
 325+
 326+ //Close the wrappe div for the plain old gallery
 327+ $output .= '</div>';
 328+
315329 //Output the javascript needed for the gallery with any
316330 //options the user requested
317331 $output .= '<script type="text/javascript">';
318 - $output .= 'function startGallery() {';
 332+
 333+ $output .= 'document.getElementById("' . $name . '-plain").style.display = "none";'; //hide plain gallery
 334+ $output .= 'document.getElementById("' . $name . '").style.display = "block";'; //show smooth gallery
 335+
 336+ $output .= 'function startGallery_' . $name . '() {';
319337 $output .= "var myGallery = new gallery($('" . $name . "'), {";
320338
321339 //A boolean to tell whether or not we need a comma before
@@ -356,7 +374,7 @@
357375
358376 $output .= '});';
359377 $output .= '}';
360 - $output .= 'window.onDomReady(startGallery);';
 378+ $output .= 'addOnloadHook(startGallery_' . $name . ');';
361379 $output .= '</script>';
362380
363381 //Finished, let's send it out