Index: trunk/extensions/Storyboard/api/ApiStoryboardStoriesFeed.php |
— | — | @@ -66,9 +66,9 @@ |
67 | 67 | 'id' => $story->story_id, |
68 | 68 | 'author' => $story->story_author_name, |
69 | 69 | 'title' => $story->story_title, |
70 | | - 'text' => $story->story_text, |
71 | 70 | 'created' => wfTimestamp( TS_ISO_8601, $story->story_created ), |
72 | 71 | ); |
| 72 | + ApiResult::setContent( $res, ( is_null( $story->story_text ) ? '' : $story->story_text ) ); |
73 | 73 | $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $res ); |
74 | 74 | } |
75 | 75 | |
Index: trunk/extensions/Storyboard/tags/Storyboard/Storyboard_body.php |
— | — | @@ -16,23 +16,75 @@ |
17 | 17 | class TagStoryboard { |
18 | 18 | |
19 | 19 | public static function render( $input, $args, $parser, $frame ) { |
20 | | - global $wgOut, $wgJsMimeType, $egStoryboardScriptPath, $wgScriptPath; |
| 20 | + global $wgOut, $wgJsMimeType, $wgScriptPath, $egStoryboardScriptPath, $egStoryboardWidth, $egStoryboardHeight; |
21 | 21 | |
22 | 22 | $wgOut->addStyle($egStoryboardScriptPath . '/tags/Storyboard/storyboard.css'); |
23 | 23 | $wgOut->includeJQuery(); |
24 | 24 | $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 | + |
26 | 49 | $output = <<<EOT |
27 | | -<div class="ajaxscroll" id="storyboard" style="height: 400px; width: 80%;"> |
| 50 | +<div class="ajaxscroll" id="storyboard" style="height: $height; width: $width;"> |
28 | 51 | <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 | +} |
31 | 73 | /*]]>*/ </script> |
32 | 74 | EOT; |
33 | 75 | |
34 | 76 | return array($output, 'noparse' => 'true', 'isHTML' => 'true'); |
35 | 77 | } |
36 | 78 | |
| 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 | + |
37 | 89 | } |
38 | 90 | |
39 | 91 | |
Index: trunk/extensions/Storyboard/tags/Storyboard/jquery.ajaxscroll.js |
— | — | @@ -39,7 +39,9 @@ |
40 | 40 | var fnEnd,fnScroll; |
41 | 41 | var offset=0; |
42 | 42 | var lsp=-1;_css(); |
| 43 | + |
43 | 44 | opt.boxTemplate=(opt.boxTemplate||"<span class='"+opt.boxClass+"'> </span>"); |
| 45 | + |
44 | 46 | if(opt.horizontal){ |
45 | 47 | opt.batchTemplate=(opt.batchTemplate||"<td></td>"); |
46 | 48 | $sp=jQuery("<table><tr></tr></table>").addClass(opt.scrollPaneClass); |
— | — | @@ -59,10 +61,13 @@ |
60 | 62 | fnEnd=vEnd; |
61 | 63 | fnScroll=vScroll; |
62 | 64 | } |
| 65 | + |
63 | 66 | setTimeout(monEnd,opt.endDelay); |
| 67 | + |
64 | 68 | if(typeof opt.updateBatch=='function'){ |
65 | 69 | setTimeout(monScroll,opt.scrollDelay); |
66 | 70 | } |
| 71 | + |
67 | 72 | function _css(){ |
68 | 73 | if(opt.horizontal){ |
69 | 74 | $me.css({"overflow-x":"auto","overflow-y":"hidden"}); |
— | — | @@ -70,8 +75,10 @@ |
71 | 76 | $me.css({"overflow-x":"hidden","overflow-y":"auto"}); |
72 | 77 | } |
73 | 78 | } |
| 79 | + |
74 | 80 | function _ab(){ |
75 | 81 | var os,b; |
| 82 | + |
76 | 83 | if(opt.horizontal){ |
77 | 84 | os=$me.find('.batch:first').next().offset().left; |
78 | 85 | b=($me.width()/os+1)*os; |
— | — | @@ -79,21 +86,27 @@ |
80 | 87 | os=$me.find('.batch:first').next().offset().top; |
81 | 88 | b=($me.height()/os+1)*os; |
82 | 89 | } |
| 90 | + |
83 | 91 | if("auto"==opt.uBound){ |
84 | 92 | opt.uBound=b; |
85 | 93 | } |
| 94 | + |
86 | 95 | if("auto"==opt.lBound){ |
87 | 96 | opt.lBound=-b; |
88 | 97 | } |
| 98 | + |
89 | 99 | if("auto"==opt.eBound){ |
90 | 100 | opt.eBound=b*2; |
91 | 101 | } |
92 | 102 | } |
| 103 | + |
93 | 104 | function _bz(){ |
94 | 105 | $me.scrollTop(0).scrollLeft(0); |
95 | 106 | }; |
| 107 | + |
96 | 108 | function batch($s,o,opt){ |
97 | 109 | var $b,i,rp=opt.batchNum; |
| 110 | + |
98 | 111 | while(rp--){ |
99 | 112 | $b=jQuery(opt.batchTemplate).attr({offset:o,len:opt.batchSize}).addClass(opt.batchClass+" "+opt.emptyBatchClass); |
100 | 113 | i=opt.batchSize; |
— | — | @@ -102,13 +115,17 @@ |
103 | 116 | } |
104 | 117 | $s.append($b); |
105 | 118 | } |
| 119 | + |
106 | 120 | return o; |
107 | 121 | }; |
| 122 | + |
108 | 123 | function vScroll(){ |
109 | 124 | var so=$me.scrollTop(); |
| 125 | + |
110 | 126 | if(lsp!=so){ |
111 | 127 | lsp=so; |
112 | 128 | var co=$me.offset().top; |
| 129 | + |
113 | 130 | $sp.find('> .'+opt.emptyBatchClass).each(function(i,obj){ |
114 | 131 | var $b=jQuery(obj); |
115 | 132 | var p=$b.position().top-co; |
— | — | @@ -117,8 +134,10 @@ |
118 | 135 | }); |
119 | 136 | } |
120 | 137 | }; |
| 138 | + |
121 | 139 | function hScroll(){ |
122 | 140 | var so=$me.scrollLeft(); |
| 141 | + |
123 | 142 | if(lsp!=so){ |
124 | 143 | lsp=so; |
125 | 144 | var co=$me.offset().left; |
— | — | @@ -130,29 +149,36 @@ |
131 | 150 | }); |
132 | 151 | } |
133 | 152 | }; |
| 153 | + |
134 | 154 | function vEnd(){ |
135 | 155 | if(ele.scrollTop>0&&ele.scrollHeight-ele.scrollTop<opt.eBound){ |
136 | 156 | offset=batch($sp,offset,opt); |
137 | 157 | return 1; |
138 | 158 | } |
| 159 | + |
139 | 160 | return opt.endDelay; |
140 | 161 | }; |
| 162 | + |
141 | 163 | function hEnd(){ |
142 | 164 | if(ele.scrollLeft>0&&ele.scrollWidth-ele.scrollLeft<opt.eBound){ |
143 | 165 | offset=batch($sp.find("tr:first"),offset,opt); |
144 | 166 | return 1; |
145 | 167 | } |
| 168 | + |
146 | 169 | return opt.endDelay; |
147 | 170 | }; |
| 171 | + |
148 | 172 | function monScroll(){ |
149 | 173 | fnScroll(); |
150 | 174 | setTimeout(monScroll,opt.scrollDelay); |
151 | 175 | }; |
| 176 | + |
152 | 177 | function monEnd(){ |
153 | 178 | if(offset<opt.maxOffset){ |
154 | 179 | setTimeout(monEnd,fnEnd()); |
155 | 180 | } |
156 | 181 | } |
| 182 | + |
157 | 183 | }); |
158 | 184 | }; |
159 | 185 | })(jQuery); |