r68444 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68443‎ | r68444 | r68445 >
Date:06:30, 23 June 2010
Author:dale
Status:deferred
Tags:
Comment:
* some smil animate player improvements
* stubs for playback
Modified paths:
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.EmbedPlayerSmil.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilAnimate.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilBody.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilLayout.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilBody.js
@@ -88,7 +88,7 @@
8989
9090 /**
9191 * getElementsForTimeRecurse
92 - * @param {Object} $node NOde to recursively search for elements in the given time range
 92+ * @param {Object} $node Node to recursively search for elements in the given time range
9393 */
9494 getElementsForTimeRecurse: function( $node, time, startOffset){
9595 // Setup local pointers:
@@ -102,13 +102,13 @@
103103 startOffset = 0;
104104 }
105105
106 - mw.log( "getElementsForTimeRecurse::" +
 106+ /*mw.log( "getElementsForTimeRecurse::" +
107107 ' time: ' + time +
108108 ' nodeName: ' + $j( $node ).get(0).nodeName +
109109 ' nodeType: ' + nodeType +
110110 ' nodeDur: ' + nodeDuration +
111111 ' offset: ' + startOffset
112 - );
 112+ );*/
113113
114114 // If startOffset is > time skip node and all its children
115115 if( startOffset > time ){
@@ -143,7 +143,7 @@
144144 $node.data('parentStartOffset', startOffset );
145145 // Ref type get the
146146 this.elementsInRange.push( $node );
147 - mw.log("Add ref to elementsInRange:: " + nodeType + " length:" + this.elementsInRange.length);
 147+ //mw.log("Add ref to elementsInRange:: " + nodeType + " length:" + this.elementsInRange.length);
148148 }
149149
150150 // Return the node Duration for tracking startOffset
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilLayout.js
@@ -43,12 +43,12 @@
4444 mw.log( "SmilLayout::getRootLayout:" );
4545 if( !this.$rootLayout ){
4646 this.$rootLayout = $j('<div />' )
47 - .attr('rel', 'root-layout' )
48 - .css( {
49 - 'position': 'absolute',
50 - 'width' : '100%',
51 - 'height' : '100%'
52 - });
 47+ .addClass( 'smilRootLayout' )
 48+ .css( {
 49+ 'position': 'absolute',
 50+ 'width' : '100%',
 51+ 'height' : '100%'
 52+ });
5353
5454 // Update the root layout css
5555 this.$rootLayout.css( _this.getRootLayoutCss() )
@@ -236,8 +236,10 @@
237237 this.$dom.find( 'region' ).each( function( inx, regionElement ) {
238238 $layoutContainer.append(
239239 $j( '<div />' )
240 - .attr('rel', 'region' )
241 - .css( 'position', 'absolute' )
 240+ .addClass('smilRegion' )
 241+ .css({
 242+ 'position' : 'absolute'
 243+ })
242244 // Transform the smil attributes into html attributes
243245 .attr( _this.transformSmilAttributes( regionElement ) )
244246 // Transform the css attributes into percentages
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilAnimate.js
@@ -94,9 +94,9 @@
9595 mw.log( "b:" + begin +" < " + animateTime + " && b+d: " + ( begin + duration ) + " > " + animateTime );
9696
9797 // Check if the animate element is in range
98 - var cssTransform = {};
99 - if( begin < animateTime && ( begin + duration ) > animateTime ) {
100 - // Get the tranform type:
 98+ var cssTransform = {};
 99+ if( begin <= animateTime && ( begin + duration ) >= animateTime ) {
 100+ // Get the transform type:
101101 switch( $j( animateElement ).attr('attributeName') ){
102102 case 'panZoom':
103103 // Get the pan zoom css for "this" time
@@ -129,12 +129,12 @@
130130 // Get target panZoom for given animateTime
131131 var animatePoints = $j( animateElement ).attr('values').split( ';' );
132132
133 - // Get the target intepreted value
134 - var targetValue = this.getInterpetedPointsValue( animatePoints, relativeAnimationTime, duration );
 133+ // Get the target interpreted value
 134+ var targetValue = this.getInterpolatePointsValue( animatePoints, relativeAnimationTime, duration );
135135
136136 // Let Top Width Height
137137 // translate values into % values
138 - // NOTE this is depenent on the media being "loaded" and having natural width and height
 138+ // NOTE this is dependent on the media being "loaded" and having natural width and height
139139 var namedValueOrder = ['left', 'top', 'width', 'height' ];
140140 var htmlAsset = $j( '#' + this.smil.getAssetId( smilImgElement ) ).get(0);
141141
@@ -157,8 +157,7 @@
158158 }
159159
160160 // Now we have "hard" layout info try and render it.
161 - this.updateElementLayout( smilImgElement, percentValues );
162 - debugger;
 161+ this.updateElementLayout( smilImgElement, percentValues );
163162
164163 // Now set the target value
165164
@@ -171,9 +170,9 @@
172171 "scale mode"?
173172
174173 fit:
175 - "width or height dominiate"?
 174+ "width or height dominate"?
176175
177 - width X percetnage "virtualPixles"
 176+ width X percentage "virtualPixles"
178177 height relative to width
179178
180179 layout:
@@ -181,25 +180,35 @@
182181 */
183182 },
184183
185 - // xxx need to refactor
186 - updateElementLayout: function( smilEmelent, percentValues ){
187 - // get a pointer to the hmtl target:
188 - var $target = $j( '#' + this.smil.getAssetId( smilEmelent ));
 184+ // xxx need to refactor move to "smilLayout"
 185+ updateElementLayout: function( smilElement, percentValues ){
189186
190 - // get the scale via width ( need to think about this might need to support either )
191 - // width is 20% of orginal means we have to scale up 1/ .2
192 -
193 -
 187+ mw.log("updateElementLayout::" + percentValues.top + ' ' + percentValues.left + ' ' + percentValues.width + ' ' + percentValues.height );
 188+ // get a pointer to the html target:
 189+ var $target = $j( '#' + this.smil.getAssetId( smilElement ));
 190+
 191+ var htmlAsset = $j( '#' + this.smil.getAssetId( smilElement ) ).get(0);
 192+
 193+ // find if we are height or width bound
 194+
 195+ // Setup target height width based target region size
 196+ var fullWidth = $target.parents('.smilRegion').width() ;
 197+ var fullHeight = $target.parents('.smilRegion').height() ;
 198+ var targetWidth = fullWidth;
 199+ var targetHeight = targetWidth * (
 200+ ( percentValues['height'] * htmlAsset.naturalHeight )
 201+ /
 202+ ( percentValues['width'] * htmlAsset.naturalWidth )
 203+ )
 204+ // Check if it exceeds the height constraint:
 205+ var sourceScale = ( targetHeight < fullHeight )
 206+ ? (1 / percentValues['width'] )
 207+ : (1 / percentValues['height'] )
 208+
 209+
194210 // Wrap the target and absolute the image layout ( if not already )
195211 if( $target.parent('.refTransformWrap').length === 0 ){
196 - $target
197 - .css({
198 - 'position' : 'abolute',
199 - 'width' : (1 / percentValues['width'])*100 + '%',
200 - 'height' : (1 / percentValues['height'])*100 + '%',
201 - 'top' : (-1 * percentValues['top'])*100 + '%',
202 - 'left' : (-1 * percentValues['left'])*100 + '%',
203 - })
 212+ $target
204213 .wrap(
205214 $j( '<div />' )
206215 .css( {
@@ -210,29 +219,45 @@
211220 } )
212221 .addClass('refTransformWrap')
213222 )
214 - }
215 - debugger;
 223+ }
 224+ // run the css transform
 225+ $target.css({
 226+ 'position' : 'absolute',
 227+ 'width' : sourceScale *100 + '%',
 228+ 'height': sourceScale *100 + '%',
 229+ 'top' : (-1 * percentValues['top'])*100 + '%',
 230+ 'left' : (-1 * percentValues['left'])*100 + '%',
 231+ })
 232+
216233 // set up the offsets for the percentage wrap.
217234
218235 // scale the
219236 },
220237
221238 /**
222 - * getInterpetedPointsValue
 239+ * getInterpolatePointsValue
 240+ * @param animatePoints Set of points to be interpolated
223241 */
224 - getInterpetedPointsValue: function( animatePoints, relativeAnimationTime, duration){
 242+ getInterpolatePointsValue: function( animatePoints, relativeAnimationTime, duration ){
225243 // For now only support "linear" transforms
226244 // What two points are we animating between:
227245 var timeInx = ( relativeAnimationTime / duration ) * animatePoints.length ;
228 - var startPointSet = animatePoints[ Math.floor( timeInx ) -1 ].split( ',' );
229 - var endPointSet = animatePoints[ Math.ceil( timeInx) - 1 ].split( ',' );
 246+ // if timeInx is zero just return the first point:
 247+ if( timeInx == 0 ){
 248+ return animatePoints[0].split(',');
 249+ }
 250+ // make sure we are in bounds:
 251+ var startInx = ( Math.floor( timeInx ) -1 );
 252+ startInx = ( startInx < 0 ) ? 0 : startInx;
 253+ var startPointSet = animatePoints[ startInx ].split( ',' );
 254+ var endPointSet = animatePoints[ Math.ceil( timeInx) -1 ].split( ',' );
230255
231256 var interptPercent = ( relativeAnimationTime / duration ) / ( animatePoints.length -1 );
232257 // Interpolate between start and end points to get target "value"
233258 var targetValue = [];
234259 for( var i = 0 ; i < startPointSet.length ; i++ ){
235260 targetValue[ i ] = parseFloat( startPointSet[i] ) + ( parseFloat( endPointSet[i] ) - parseFloat( startPointSet[i] ) ) * interptPercent;
236 - // Retain percent messurment
 261+ // Retain percent measurement
237262 targetValue[ i ] += ( startPointSet[i].indexOf('%') != -1 ) ? '%' : '';
238263 }
239264 return targetValue;
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.EmbedPlayerSmil.js
@@ -46,14 +46,15 @@
4747 mw.log('EmbedPlayerSmil::setCurrentTime: ' + time );
4848 // Set "loading" spinner here)
4949 $j( this ).append(
50 - $j( '<div />')
 50+ $j( '<div />')
5151 .attr('id', 'loadingSpinner_' + this.id )
5252 .loadingSpinner()
5353 );
5454 var _this = this;
5555 this.getSmil( function( smil ){
5656 smil.renderTime( time, function(){
57 - $j('#loadingSpinner_' + _this.id ).hide();
 57+ mw.log("renderTime callback");
 58+ $j('#loadingSpinner_' + _this.id ).remove();
5859 callback();
5960 } );
6061 });
@@ -82,9 +83,51 @@
8384 },
8485
8586 play: function(){
86 - mw.log("EmbedPlayerSmil::play (not yet supported)" );
 87+ mw.log(" EmbedPlayerSmil::play " );
 88+ // call the parent
 89+ this.parent_play();
 90+
 91+ this.clockStartTime = new Date().getTime();
 92+
 93+
 94+ this.getSmil( function( smil ){
 95+ this.smil = smil;
 96+ })
 97+ // Start up monitor:
 98+ this.monitor();
8799 },
 100+
88101 /**
 102+ * Preserves the pause time across for timed playback
 103+ */
 104+ pause:function() {
 105+ mw.log( 'EmbedPlayerSmil::pause at time' + this.currentTime);
 106+ var ct = new Date();
 107+ this.pauseTime = this.currentTime;
 108+ mw.log( 'pause time: ' + this.pauseTime );
 109+ },
 110+
 111+ /**
 112+ * Get the embed player time
 113+ */
 114+ getPlayerElementTime: function() {
 115+ mw.log('html:monitor: '+ this.currentTime + ' ct:' + new Date().getTime() + ' - ' + this.clockStartTime);
 116+ this.currentTime = ( ( new Date().getTime() - this.clockStartTime ) / 1000 ) + this.pauseTime;
 117+ return this.currentTime;
 118+ },
 119+
 120+ /**
 121+ * Monitor function render a given time
 122+ */
 123+ monitor: function(){
 124+ mw.log("time::" + this.getPlayerElementTime());
 125+ /*this.smil.renderTime( , function(){
 126+
 127+ });*/
 128+ this.parent_monitor();
 129+ },
 130+
 131+ /**
89132 * Get the smil object. If the smil object does not exist create one with the source url:
90133 * @param callback
91134 */

Status & tagging log