r70279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70278‎ | r70279 | r70280 >
Date:16:56, 1 August 2010
Author:dale
Status:deferred
Tags:
Comment:
* improved undo redo support
* timeline "draw" methods insert or update dom state.
* removed some debug statements
Modified paths:
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTimeline.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilBody.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.SmilBody.js
@@ -366,8 +366,7 @@
367367 $node.data( 'implictDuration', childDuration);
368368 }
369369 }
370 - });
371 - alert( 'getting duration for ' + $node.children().length + ' children ');
 370+ });
372371 }
373372
374373 // Check the explicit duration attribute:
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js
@@ -86,34 +86,38 @@
8787 * @param {string}
8888 * SmilXmlString Xml string of smil to be loaded
8989 */
90 - loadFromString : function( smilXmlString ) {
 90+ loadFromString: function( smilXmlString ) {
9191 // Load the parsed string into the local "dom"
9292 this.$dom = $j( smilXmlString );
93 -
9493 mw.log("Smil::loadFromString: loaded smil dom: " + this.$dom.length + "\n" + smilXmlString );
95 - /*
96 - // Clear out the layout
97 - this.layout = null;
98 -
99 - // Clear out the body
100 - this.body = null;
101 -
102 - // Clear out the top level duration
103 - this.duration = null;
104 -
105 - // Clear out the "buffer" object
106 - this.buffer = null;
107 - */
10894 },
10995 updateFromString: function( smilXmlString ){
11096 delete this.$dom;
111 - this.$dom = $j( smilXmlString );
 97+ // jQuery strips some html native tags when parsing xml passed into jQuery
 98+ // since smil has html tags ( "body" "head" ) we need to first convert it to
 99+ // an xml object::
 100+ this.$dom = $j( this.getXMLDomObject( smilXmlString ) );
112101 },
 102+ // simple XML DOMParser object parser wrapper
 103+ // xxx Add error handling
 104+ getXMLDomObject: function( smilXmlString ){
 105+ if (window.DOMParser){
 106+ parser=new DOMParser();
 107+ xmlDoc=parser.parseFromString(smilXmlString, "text/xml");
 108+ } else // Internet Explorer
 109+ {
 110+ xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
 111+ xmlDoc.async="false";
 112+ xmlDoc.loadXML( smilXmlString );
 113+ }
 114+ return xmlDoc;
 115+ },
 116+
113117 /**
114118 * Internal function to get the jQuery smil dom
115119 */
116120 getDom : function() {
117 - if (this.$dom) {
 121+ if ( this.$dom ) {
118122 return this.$dom;
119123 }
120124 mw.log("Error SMIL Dom not available");
@@ -132,7 +136,7 @@
133137 this.getLayout().setupLayout(this.embedPlayer.getRenderTarget());
134138
135139 // Update the render target with bodyElements for the requested time
136 - this.getBody().renderTime(time);
 140+ this.getBody().renderTime( time );
137141
138142 // Wait until buffer is ready and run the callback
139143 this.getBuffer().addAssetsReadyCallback(callback);
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js
@@ -97,19 +97,14 @@
9898 */
9999 updateSmilXML: function( smilXML ){
100100 mw.log("Sequencer::updateSmilXML" + smilXML);
101 - var _this = this;
102 - alert( 'before Dur:' + this.getEmbedPlayer().getDuration( true ) + ' update seq len: ' + this.getSmil().$dom.find('seq').children().length )
 101+ var _this = this;
103102 // Update the embedPlayer smil:
104 - this.getSmil().updateFromString( smilXML );
105 - debugger;
106 - alert( 'after Dur:' + this.getEmbedPlayer().getDuration( true ) + ' update seq len: ' + this.getSmil().$dom.find('seq').children().length )
 103+ this.getSmil().updateFromString( smilXML );
107104 // Get a duration ( forceRefresh to clear the cache )
108 - var dur = this.getEmbedPlayer().getDuration( true );
109 - alert( 'restored dur should be: ' + dur);
110 - /*
111 - // redraw the timeline
112 - this.getTimeline().drawTimeline();
113 - */
 105+ this.getEmbedPlayer().getDuration( true );
 106+
 107+ // Redraw the timeline
 108+ this.getTimeline().drawTimeline();
114109 },
115110
116111 /**
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTimeline.js
@@ -27,9 +27,11 @@
2828 getTimelineContainer: function(){
2929 return this.sequencer.getContainer().find('.mwseq-timeline');
3030 },
31 -
32 - getTracksContainer: function(){
33 - if( ! this.$timelineTracksContainer ){
 31+ /**
 32+ * xxx needs to support multiple tracks
 33+ */
 34+ getTracksContainer: function( trackId ){
 35+ if( this.getTimelineContainer().find( '.timelineTrackContainer' ).length == 0 ){
3436 // getTimelineContainer
3537 this.getTimelineContainer().append(
3638 $j('<div />')
@@ -43,8 +45,7 @@
4446 )
4547 )
4648 // Apply layout control to track name / clipTrackSet division
47 - this.$timelineTracksContainer = this.getTimelineContainer().find( '.timelineTrackContainer');
48 - this.trackLayout = this.$timelineTracksContainer
 49+ this.getTimelineContainer().find( '.timelineTrackContainer')
4950 .layout( {
5051 'applyDefaultStyles': true,
5152 'west__size' : 150,
@@ -52,56 +53,52 @@
5354 'west__maxSize' : 300
5455 } );
5556 }
56 - return this.$timelineTracksContainer;
 57+ return this.getTimelineContainer().find( '.timelineTrackContainer');
5758 },
5859 resizeTimeline: function(){
59 - if( this.trackLayout ){
60 - this.trackLayout.resizeAll();
61 - }
 60+ this.getTimelineContainer().find( '.timelineTrackContainer').resizeAll();
6261 },
6362
6463 // Draw the timeline
6564 drawTimeline: function(){
6665 // Empty the timeline container
67 - this.getTimelineContainer().empty();
 66+ //this.getTimelineContainer().empty();
6867
6968 // Get the top level sequence tracks
7069 var seqTracks = this.sequencer.getSmil().getBody().getSeqElements();
71 - var trackType = 'video';
72 - // For now just two tracks first is video second is audio
73 - for( var trackIndex=0; trackIndex < seqTracks.length; trackIndex++){
74 -
75 - if( trackType == 'audio' ){
76 - mw.log("SequencerTimeline::Error only two tracks presently suppoted");
77 - break;
78 - }
79 - // Draw the sequence track
80 - this.drawSequenceTrack( trackIndex, seqTracks[ trackIndex ], trackType);
81 - trackType = 'audio';
82 - }
 70+ // For now just one video track:
 71+ this.drawSequenceTrack( 0, seqTracks[ 0 ], 'video');
8372 },
8473
8574 drawSequenceTrack: function( trackIndex, sequenceNode, trackType ){
8675 var _this = this;
87 - mw.log(" drawSequenceTrack: Track inx: " + trackIndex + ' trackType:' + trackType );
88 - // Check if we already have a container for this track set
 76+ mw.log("SequenceTimeline::drawSequenceTrack: Track inx: " + trackIndex + ' trackType:' + trackType );
 77+ // Check if we already have a container for this track set
8978
90 - // Add a sequence track Name
91 - this.getTracksContainer().find('.trackNamesContainer').append(
92 - this.getTrackNameInterface( trackIndex, sequenceNode, trackType )
93 - )
 79+ // Add / update the sequence track name if not present
 80+ // xxx check for specific sequenceTrack updates that require interface update
 81+ if( this.getTracksContainer().find('.trackNamesContainer').children().length == 0 ){
 82+ this.getTracksContainer().find('.trackNamesContainer').append(
 83+ this.getTrackNameInterface( trackIndex, sequenceNode, trackType )
 84+ )
 85+ };
9486
95 - // Add Sequence clips
96 - this.getTracksContainer().find('.clipTrackSetContainer').append(
97 - this.getTrackClipInterface( trackIndex ,sequenceNode , trackType )
98 - ).click( function(){
99 - // xxx todo catch de-select clicks in clipTrackSetContainer that are not a click in the timeline
100 - //_this.getTracksContainer().find('.timelineClip').removeClass( 'selectedClip' );
101 - })
 87+ // Add Sequence track clips
 88+ // xxx check for specific sequenceTrack updates that require interface update
 89+ this.drawTrackClipsInterface( trackIndex ,sequenceNode , trackType )
 90+ /*if( this.getTracksContainer().find('.clipTrackSetContainer').childrend().length == 0 ){
 91+ this.getTracksContainer().find('.clipTrackSetContainer').append(
 92+
 93+ ).click( function(){
 94+ // xxx todo catch de-select clicks in clipTrackSetContainer that are not a click in the timeline
 95+ //_this.getTracksContainer().find('.timelineClip').removeClass( 'selectedClip' );
 96+ })
 97+ }
 98+ */
10299 // Load and display all clip thumbnails
103100 this.drawTrackThumbs( trackIndex, sequenceNode, trackType );
104101 },
105 -
 102+
106103 drawTrackThumbs: function( trackIndex, sequenceNode, trackType ){
107104 var _this = this;
108105 var smil = this.sequencer.getSmil();
@@ -121,67 +118,80 @@
122119 });
123120 },
124121 /**
125 - * Get Track Clip Interface
 122+ * add Track Clips and Interface binding
126123 */
127 - getTrackClipInterface: function( trackIndex, sequenceNode, trackType ){
 124+ drawTrackClipsInterface: function( trackIndex, sequenceNode, trackType ){
128125 var _this = this;
129 - // setup a local pointer to the smil engine:
 126+ // Setup a local pointer to the smil engine:
130127 var smil = this.sequencer.getSmil();
 128+
131129 // Get all the refs that are children of the sequenceNode with associated offsets and durations
132130 // for now assume all tracks start at zero:
133131 var startOffset = 0;
134132 var clipTrackSetId = this.sequencer.getId() + '_clipTrackSet_' + trackIndex;
135133
136 - var $clipTrackSet =
137 - $j('<ul />')
138 - .attr('id', clipTrackSetId)
139 - .addClass('clipTrackSet ui-corner-all')
140 - // Add "sortable
141 - .sortable({
142 - placeholder: "clipSortTarget timelineClip ui-corner-all",
143 - opacity: 0.6,
144 - cursor: 'move',
145 - helper: function( event, helper ){
146 - // xxxx might need some fixes for multi-track
147 - var $selected = _this.getTimelineContainer().find( '.selectedClip' )
148 - if ( $selected.length === 0 || $selected.length == 1) {
149 - return $j( helper );
150 - }
151 -
152 - return $j('<ul />')
153 - .css({
154 - 'width' : (_this.timelineThumbSize.width + 16) * $selected.length
155 - })
156 - .append( $selected.clone() );
157 - },
158 - scroll: true,
159 - update: function( event, ui ) {
160 - // Update the html dom
161 - _this.handleReorder( ui.item );
162 - }
163 - })
164 -
165 - smil.getBody().getRefElementsRecurse( sequenceNode, startOffset, function( $node ){
166 - // Draw the node onto the timeline:
167 -
168 - // xxx would be good to support both "storyboard" and "timeline" view modes.
169 - // for now just "storyboard"
170 -
171 - // add a clip float left box container
172 - $clipTrackSet.append(
173 - $j('<li />')
174 - .attr('id', _this.getTimelineClipId( $node ) )
175 - .data( {
176 - 'smilId': $node.attr('id'),
177 - 'prevIndex' : $clipTrackSet.length
 134+ var $clipTrackSet = this.getTracksContainer().find('.clipTrackSetContainer').find( '.clipTrackSet' );
 135+ // Add the $clipTrackSet if not already in dom:
 136+ if( $clipTrackSet.length == 0 ){
 137+ $clipTrackSet = this.getTracksContainer().find('.clipTrackSetContainer').append(
 138+ $j('<ul />')
 139+ .attr('id', clipTrackSetId)
 140+ .addClass('clipTrackSet ui-corner-all')
 141+ // Add "sortable
 142+ .sortable({
 143+ placeholder: "clipSortTarget timelineClip ui-corner-all",
 144+ opacity: 0.6,
 145+ cursor: 'move',
 146+ helper: function( event, helper ){
 147+ // xxxx might need some fixes for multi-track
 148+ var $selected = _this.getTimelineContainer().find( '.selectedClip' )
 149+ if ( $selected.length === 0 || $selected.length == 1) {
 150+ return $j( helper );
 151+ }
 152+
 153+ return $j('<ul />')
 154+ .css({
 155+ 'width' : (_this.timelineThumbSize.width + 16) * $selected.length
 156+ })
 157+ .append( $selected.clone() );
 158+ },
 159+ scroll: true,
 160+ update: function( event, ui ) {
 161+ // Update the html dom
 162+ _this.handleReorder( ui.item );
 163+ }
178164 })
179 - .addClass('timelineClip ui-corner-all')
180 - .loadingSpinner()
181 - .click(function(){
182 - //Add clip to selection
183 - _this.handleMultiSelect( this );
184 - })
185 - );
 165+ ).find( '.clipTrackSet' )
 166+ }
 167+ var $previusClip = null;
 168+ smil.getBody().getRefElementsRecurse( sequenceNode, startOffset, function( $node ){
 169+ // Draw the node onto the timeline if the clip is not already there:
 170+ if( $clipTrackSet.find('#' + _this.getTimelineClipId( $node ) ).length == 0 ){
 171+ var $timelineClip = $j('<li />')
 172+ .attr('id', _this.getTimelineClipId( $node ) )
 173+ .data( {
 174+ 'smilId': $node.attr('id'),
 175+ 'prevIndex' : $clipTrackSet.length
 176+ })
 177+ .addClass('timelineClip ui-corner-all')
 178+ .loadingSpinner()
 179+ .click(function(){
 180+ //Add clip to selection
 181+ _this.handleMultiSelect( this );
 182+ })
 183+ if( $previusClip ){
 184+ $previusClip.after(
 185+ $timelineClip
 186+ )
 187+ } else {
 188+ // Add to the start of the track set:
 189+ $clipTrackSet.prepend(
 190+ $timelineClip
 191+ );
 192+ }
 193+ }
 194+ // Update the $previusClip
 195+ $previusClip = $clipTrackSet.find('#' + _this.getTimelineClipId( $node ) );
186196 })
187197 // Give the track set a width relative to the number of clips
188198 $clipTrackSet.css('width', ($clipTrackSet.find( '.timelineClip' ).length + 1) *
@@ -197,8 +207,7 @@
198208 'delete': function(){
199209 _this.removeSelectedClips();
200210 }
201 - })
202 - return $clipTrackSet;
 211+ })
203212 },
204213 // calls the edit interface passing in the selected clip:
205214 editClip: function( selectedClip ){
@@ -410,18 +419,24 @@
411420 .css( {
412421 'top': '0px',
413422 'position' : 'absolute',
414 - 'opacity' : '.8',
 423+ 'opacity' : '.9',
415424 'left': '0px',
416425 'height': _this.timelineThumbSize.height
417426 })
418427 .attr( 'src', smil.getAssetUrl( $node.attr('poster') ) )
419 - .load( function(){
 428+ .load( function(){
420429 if( $thumbTarget.children().length == 0 ){
421 - $thumbTarget.html(this);
 430+ $thumbTarget.html( img );
422431 }
423 - })
 432+ });
 433+
 434+ // Sometimes the load event does not fire force the fallback image after 5 seconds
 435+ setTimeout( function(){
 436+ if( $thumbTarget.children().length == 0 ){
 437+ $thumbTarget.html( img );
 438+ }
 439+ }, 5000);
424440 }
425 -
426441 // Buffer the asset then render it into the layout target:
427442 smil.getBuffer().bufferedSeek( $node, relativeTime, function(){
428443 // Add the seek, add to canvas and draw thumb request

Status & tagging log