r63105 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63104‎ | r63105 | r63106 >
Date:23:27, 28 February 2010
Author:jeroendedauw
Status:ok
Tags:
Comment:
Modifications for getting storyboard content + support for width and height parameters
Modified paths:
  • /trunk/extensions/Storyboard/api/ApiStoryboardStoriesFeed.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php (modified) (history)
  • /trunk/extensions/Storyboard/tags/Storyboard/jquery.ajaxscroll.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Storyboard/api/ApiStoryboardStoriesFeed.php
@@ -66,9 +66,9 @@
6767 'id' => $story->story_id,
6868 'author' => $story->story_author_name,
6969 'title' => $story->story_title,
70 - 'text' => $story->story_text,
7170 'created' => wfTimestamp( TS_ISO_8601, $story->story_created ),
7271 );
 72+ ApiResult::setContent( $res, ( is_null( $story->story_text ) ? '' : $story->story_text ) );
7373 $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $res );
7474 }
7575
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php
@@ -16,23 +16,75 @@
1717 class TagStoryboard {
1818
1919 public static function render( $input, $args, $parser, $frame ) {
20 - global $wgOut, $wgJsMimeType, $egStoryboardScriptPath, $wgScriptPath;
 20+ global $wgOut, $wgJsMimeType, $wgScriptPath, $egStoryboardScriptPath, $egStoryboardWidth, $egStoryboardHeight;
2121
2222 $wgOut->addStyle($egStoryboardScriptPath . '/tags/Storyboard/storyboard.css');
2323 $wgOut->includeJQuery();
2424 $wgOut->addScriptFile($egStoryboardScriptPath . '/tags/Storyboard/jquery.ajaxscroll.js');
25 -
 25+
 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+
2649 $output = <<<EOT
27 -<div class="ajaxscroll" id="storyboard" style="height: 400px; width: 80%;">
 50+<div class="ajaxscroll" id="storyboard" style="height: $height; width: $width;">
2851 <script type="$wgJsMimeType"> /*<![CDATA[*/
29 -jQuery(function(){ jQuery('#storyboard').ajaxScroll({ updateBatch: updateStoryboard, batchSize: 5, batchNum: 2 }); });
30 -function updateStoryboard(obj){ obj.load('$wgScriptPath/api.php?action=query&list=stories&stcontinue=' + obj.attr('offset') + '&stlimit=5&format=json'); }
 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+}
3173 /*]]>*/ </script>
3274 EOT;
3375
3476 return array($output, 'noparse' => 'true', 'isHTML' => 'true');
3577 }
3678
 79+ /**
 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
 82+ */
 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';
 87+ }
 88+
3789 }
3890
3991
Index: trunk/extensions/Storyboard/tags/Storyboard/jquery.ajaxscroll.js
@@ -39,7 +39,9 @@
4040 var fnEnd,fnScroll;
4141 var offset=0;
4242 var lsp=-1;_css();
 43+
4344 opt.boxTemplate=(opt.boxTemplate||"<span class='"+opt.boxClass+"'>&nbsp</span>");
 45+
4446 if(opt.horizontal){
4547 opt.batchTemplate=(opt.batchTemplate||"<td></td>");
4648 $sp=jQuery("<table><tr></tr></table>").addClass(opt.scrollPaneClass);
@@ -59,10 +61,13 @@
6062 fnEnd=vEnd;
6163 fnScroll=vScroll;
6264 }
 65+
6366 setTimeout(monEnd,opt.endDelay);
 67+
6468 if(typeof opt.updateBatch=='function'){
6569 setTimeout(monScroll,opt.scrollDelay);
6670 }
 71+
6772 function _css(){
6873 if(opt.horizontal){
6974 $me.css({"overflow-x":"auto","overflow-y":"hidden"});
@@ -70,8 +75,10 @@
7176 $me.css({"overflow-x":"hidden","overflow-y":"auto"});
7277 }
7378 }
 79+
7480 function _ab(){
7581 var os,b;
 82+
7683 if(opt.horizontal){
7784 os=$me.find('.batch:first').next().offset().left;
7885 b=($me.width()/os+1)*os;
@@ -79,21 +86,27 @@
8087 os=$me.find('.batch:first').next().offset().top;
8188 b=($me.height()/os+1)*os;
8289 }
 90+
8391 if("auto"==opt.uBound){
8492 opt.uBound=b;
8593 }
 94+
8695 if("auto"==opt.lBound){
8796 opt.lBound=-b;
8897 }
 98+
8999 if("auto"==opt.eBound){
90100 opt.eBound=b*2;
91101 }
92102 }
 103+
93104 function _bz(){
94105 $me.scrollTop(0).scrollLeft(0);
95106 };
 107+
96108 function batch($s,o,opt){
97109 var $b,i,rp=opt.batchNum;
 110+
98111 while(rp--){
99112 $b=jQuery(opt.batchTemplate).attr({offset:o,len:opt.batchSize}).addClass(opt.batchClass+" "+opt.emptyBatchClass);
100113 i=opt.batchSize;
@@ -102,13 +115,17 @@
103116 }
104117 $s.append($b);
105118 }
 119+
106120 return o;
107121 };
 122+
108123 function vScroll(){
109124 var so=$me.scrollTop();
 125+
110126 if(lsp!=so){
111127 lsp=so;
112128 var co=$me.offset().top;
 129+
113130 $sp.find('> .'+opt.emptyBatchClass).each(function(i,obj){
114131 var $b=jQuery(obj);
115132 var p=$b.position().top-co;
@@ -117,8 +134,10 @@
118135 });
119136 }
120137 };
 138+
121139 function hScroll(){
122140 var so=$me.scrollLeft();
 141+
123142 if(lsp!=so){
124143 lsp=so;
125144 var co=$me.offset().left;
@@ -130,29 +149,36 @@
131150 });
132151 }
133152 };
 153+
134154 function vEnd(){
135155 if(ele.scrollTop>0&&ele.scrollHeight-ele.scrollTop<opt.eBound){
136156 offset=batch($sp,offset,opt);
137157 return 1;
138158 }
 159+
139160 return opt.endDelay;
140161 };
 162+
141163 function hEnd(){
142164 if(ele.scrollLeft>0&&ele.scrollWidth-ele.scrollLeft<opt.eBound){
143165 offset=batch($sp.find("tr:first"),offset,opt);
144166 return 1;
145167 }
 168+
146169 return opt.endDelay;
147170 };
 171+
148172 function monScroll(){
149173 fnScroll();
150174 setTimeout(monScroll,opt.scrollDelay);
151175 };
 176+
152177 function monEnd(){
153178 if(offset<opt.maxOffset){
154179 setTimeout(monEnd,fnEnd());
155180 }
156181 }
 182+
157183 });
158184 };
159185 })(jQuery);

Follow-up revisions

RevisionCommit summaryAuthorDate
r63120Storyboard: Cleanup for r63105...catrope15:21, 1 March 2010

Status & tagging log