Index: trunk/extensions/Storyboard/api/ApiStoryReview.php |
— | — | @@ -72,6 +72,6 @@ |
73 | 73 | } |
74 | 74 | |
75 | 75 | public function getVersion() { |
76 | | - return __CLASS__ . ': $Id: $'; |
| 76 | + return __CLASS__ . ': $Id$'; |
77 | 77 | } |
78 | 78 | } |
\ No newline at end of file |
Property changes on: trunk/extensions/Storyboard/api/ApiStoryReview.php |
___________________________________________________________________ |
Name: svn:keywords |
79 | 79 | + Id |
Index: trunk/extensions/Storyboard/tags/Storyboard/storyboard.js |
— | — | @@ -0,0 +1,26 @@ |
| 2 | +/** |
| 3 | + * JavaScript added for <storyboard> tags |
| 4 | + */ |
| 5 | + |
| 6 | +$j( document ).ready( function(){ |
| 7 | + $j( '#storyboard' ).ajaxScroll( { |
| 8 | + updateBatch: updateStoryboard, |
| 9 | + batchSize: 5, |
| 10 | + batchNum: 1 |
| 11 | + } ); |
| 12 | +}); |
| 13 | + |
| 14 | +function updateStoryboard( $storyboard ){ |
| 15 | + $j.getJSON( wgScriptPath + '/api.php', |
| 16 | + { |
| 17 | + 'action': 'query', |
| 18 | + 'list': 'stories', |
| 19 | + 'stcontinue': $storyboard.attr( 'offset' ), |
| 20 | + 'stlimit': 5, |
| 21 | + 'format': 'json' |
| 22 | + }, |
| 23 | + function( data ) { |
| 24 | + // TODO: use data to create stories html |
| 25 | + } |
| 26 | + ); |
| 27 | +} |
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php |
— | — | @@ -18,71 +18,39 @@ |
19 | 19 | public static function render( $input, $args, $parser, $frame ) { |
20 | 20 | global $wgOut, $wgJsMimeType, $wgScriptPath, $egStoryboardScriptPath, $egStoryboardWidth, $egStoryboardHeight; |
21 | 21 | |
22 | | - $wgOut->addStyle($egStoryboardScriptPath . '/tags/Storyboard/storyboard.css'); |
| 22 | + $wgOut->addStyle( $egStoryboardScriptPath . '/tags/Storyboard/storyboard.css' ); |
23 | 23 | $wgOut->includeJQuery(); |
24 | | - $wgOut->addScriptFile($egStoryboardScriptPath . '/tags/Storyboard/jquery.ajaxscroll.js'); |
| 24 | + // TODO: Combine+minfiy JS files, add switch to use combined+minified version |
| 25 | + $wgOut->addScriptFile( $egStoryboardScriptPath . '/tags/Storyboard/jquery.ajaxscroll.js' ); |
| 26 | + $wgOut->addScriptFile( $egStoryboardScriptPath . '/tags/Storyboard/storyboard.js' ); |
25 | 27 | |
26 | | - $widthGiven = array_key_exists('width', $args) |
27 | | - && (is_numeric($args['width']) |
28 | | - || (strlen($args['width']) > 1 |
29 | | - && is_numeric(substr($args['width'], 0, strlen($args['width']) - 1)) |
30 | | - && substr($args['width'], strlen($args['width']) == '%' |
31 | | - ) |
32 | | - ) |
33 | | - ); |
34 | | - $width = $widthGiven ? $args['width'] : $egStoryboardWidth; |
35 | | - |
36 | | - $heightGiven = array_key_exists('height', $args) |
37 | | - && (is_numeric($args['height']) |
38 | | - || (strlen($args['height']) > 1 |
39 | | - && is_numeric(substr($args['height'], 0, strlen($args['height']) - 1)) |
40 | | - && substr($args['height'], strlen($args['height']) == '%' |
41 | | - ) |
42 | | - ) |
43 | | - ); |
44 | | - $height = $heightGiven ? $args['height'] : $egStoryboardHeight; |
45 | | - |
46 | | - TagStoryboard::addPxWhenNeeded($width); |
47 | | - TagStoryboard::addPxWhenNeeded($height); |
48 | | - |
49 | | - $output = <<<EOT |
50 | | -<div class="ajaxscroll" id="storyboard" style="height: $height; width: $width;"> |
51 | | -<script type="$wgJsMimeType"> /*<![CDATA[*/ |
52 | | -jQuery(function(){ |
53 | | - jQuery('#storyboard').ajaxScroll({ |
54 | | - updateBatch: updateStoryboard, |
55 | | - batchSize: 5, |
56 | | - batchNum: 1 |
57 | | - }); |
58 | | -}); |
59 | | -function updateStoryboard(obj){ |
60 | | - jQuery.getJSON('$wgScriptPath/api.php', |
61 | | - { |
62 | | - 'action': 'query', |
63 | | - 'list': 'stories', |
64 | | - 'stcontinue': obj.attr( 'offset' ), |
65 | | - 'stlimit': '5', |
66 | | - 'format': 'json' |
67 | | - }, |
68 | | - function( data ) { |
69 | | - // TODO: use data to create stories html |
70 | | - } |
71 | | - ); |
72 | | -} |
73 | | -/*]]>*/ </script> |
74 | | -EOT; |
| 28 | + $width = self::getDimension( $args, 'width', $egStoryboardWidth ); |
| 29 | + $height = self::getDimension( $args, 'height', $egStoryboardHeight ); |
75 | 30 | |
76 | | - return array($output, 'noparse' => 'true', 'isHTML' => 'true'); |
| 31 | + $output = Html::element( 'div', array( |
| 32 | + 'class' => 'ajaxscroll', |
| 33 | + 'id' => 'storyboard', // FIXME: Causes id conflicts for multiple <storyboard> tags |
| 34 | + 'style' => "height: $height; width: $width;" |
| 35 | + ) |
| 36 | + ); |
| 37 | + return array( $output, 'noparse' => 'true', 'isHTML' => 'true' ); |
77 | 38 | } |
78 | 39 | |
79 | 40 | /** |
80 | | - * Adds 'px' to a width or height value when it's not there yet, and it's not a percentage. |
81 | | - * @param string $value |
| 41 | + * Get the width or height from an arguments array, or use the default value if not specified or not valid |
| 42 | + * @param $arr Array of arguments |
| 43 | + * @param $name Key in $array |
| 44 | + * @param $default Default value to use if $arr[$name] is not set or not valid |
82 | 45 | */ |
83 | | - private static function addPxWhenNeeded(&$value){ |
84 | | - $hasPx = strrpos( $value, 'px' ) === strlen( $value ) - 2; |
85 | | - $hasPercent = strrpos( $value, '%' ) === strlen( $value ) - 1; |
86 | | - if (!$hasPx && !$hasPercent) $value .= 'px'; |
| 46 | + private static function getDimension( $arr, $name, $default ) { |
| 47 | + $value = $default; |
| 48 | + if ( isset( $arr[$name] ) && preg_match( '/\d+(\.\d+)?%?/', $arr[$name] ) ) { |
| 49 | + $value = $arr[$name]; |
| 50 | + } |
| 51 | + if ( !preg_match( '/(px|ex|em|%)$/', $value ) ) { |
| 52 | + $value .= 'px'; |
| 53 | + } |
| 54 | + return $value; |
87 | 55 | } |
88 | 56 | |
89 | 57 | } |