r70362 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70361‎ | r70362 | r70363 >
Date:22:03, 2 August 2010
Author:dale
Status:deferred
Tags:
Comment:
* undo redo supported for clip re order edits
* fixes to jquery menu plugin ( don't remove id from selected menu item )
* added createMenuCallback for keeping menuConfig in sync with elements not yet in the dom
Modified paths:
  • /branches/MwEmbedStandAlone/libraries/jquery/plugins/jquery.menu/jquery.menu.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerActionsEdit.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerMenu.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTimeline.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.Sequencer.js
@@ -97,7 +97,7 @@
9898 * Update the smil xml and then update the interface
9999 */
100100 updateSmilXML: function( smilXML ){
101 - mw.log("Sequencer::updateSmilXML" + smilXML);
 101+ mw.log( "Sequencer::updateSmilXML" );
102102 var _this = this;
103103 // Update the embedPlayer smil:
104104 this.getSmil().updateFromString( smilXML );
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerMenu.js
@@ -97,46 +97,33 @@
9898 var $menuTarget = this.sequencer.getMenuTarget();
9999 $menuTarget.empty();
100100
101 - for( var topMenuKey in this.menuConfig ){
102 - // Create a function to preserve topMenuKey binding scope
103 - function drawTopMenu( topMenuKey ){
 101+ for( var menuKey in this.menuConfig ){
 102+ // Create a function to preserve menuKey binding scope
 103+ function drawTopMenu( menuKey ){
104104 // Add the menu target
105105 $menuTarget
106106 .append(
107107 $j('<span />')
108 - .html( gM('mwe-sequencer-menu-' + topMenuKey ) )
 108+ .html( gM('mwe-sequencer-menu-' + menuKey ) )
109109 .css({
110110 'padding': '7px',
111111 'cursor' : 'default'
112112 })
113 - .attr( 'id', _this.sequencer.id + '_' + topMenuKey + '_topMenuItem')
 113+ .attr( 'id', _this.sequencer.id + '_' + menuKey + '_topMenuItem')
114114 .addClass( 'ui-state-default' )
115115 .buttonHover()
116116 // Add menu binding:
117117 .menu({
118 - content: _this.getMenuSet( _this.menuConfig, topMenuKey ),
119 - showSpeed: 100
120 - })
121 - // should fire post jquery.fn.menu() mousedown binding ::
122 - .mousedown(function(){
123 - // sync the disabled enabled state to menu
124 - for( var menuItemKey in _this.menuConfig[ topMenuKey ] ){
125 - var $menuItem = $j( '#' + _this.getMenuItemId( topMenuKey, menuItemKey ) );
126 - var isDisabled = _this.menuConfig[ topMenuKey ][menuItemKey].disabled;
127 - if( $menuItem.hasClass( 'disabled') ){
128 - if( ! isDisabled ){
129 - $menuItem.removeClass( 'disabled' )
130 - }
131 - } else {
132 - if( isDisabled ){
133 - $menuItem.addClass( 'disabled' );
134 - }
135 - }
136 - }
137 - })
 118+ content: _this.getMenuSet( menuKey ),
 119+ showSpeed: 100,
 120+ createMenuCallback: function(){
 121+ // Sync the disabled enabled state to menu
 122+ _this.syncMenuState( menuKey )
 123+ }
 124+ })
138125 )
139126 }
140 - drawTopMenu( topMenuKey );
 127+ drawTopMenu( menuKey );
141128 }
142129
143130 // Check if we should include kaltura credits
@@ -156,9 +143,31 @@
157144 )
158145 }
159146 },
 147+ /**
 148+ * Sync an in-dom menu with the menuConfig state
 149+ */
 150+ syncMenuState: function( menuKey ){
 151+ var _this = this;
 152+ var menuConfig = this.menuConfig;
 153+ for( var menuItemKey in _this.menuConfig[ menuKey ] ){
 154+ var $menuItem = $j( '#' + _this.getMenuItemId( menuKey, menuItemKey ) );
 155+ var isDisabled = _this.menuConfig[ menuKey ][ menuItemKey ].disabled;
 156+ mw.log('sync: ' + menuItemKey + ' in-dom:' + $menuItem.length + ' isd:' + isDisabled);
 157+ if( $menuItem.hasClass( 'disabled') ){
 158+ if( ! isDisabled ){
 159+ $menuItem.removeClass( 'disabled' )
 160+ }
 161+ } else {
 162+ if( isDisabled ){
 163+ $menuItem.addClass( 'disabled' );
 164+ }
 165+ }
 166+ }
 167+ },
160168 /* return a top menuItem with all its associated menuItems */
161 - getMenuSet: function( menuConfig, menuKey ){
 169+ getMenuSet: function( menuKey ){
162170 var _this = this;
 171+ var menuConfig = this.menuConfig;
163172 // Build out the ul for the given menu
164173 var $menu = $j( '<ul />' )
165174 .attr({
@@ -199,6 +208,10 @@
200209 }
201210 );
202211
 212+ if( menuItem.disabled === true ){
 213+ $li.addClass( 'disabled' );
 214+ }
 215+
203216 // Set the ID for easy reference
204217 $li.attr( 'id', _this.getMenuItemId( menuKey, menuItemKey ) )
205218
@@ -210,42 +223,24 @@
211224 return $li;
212225 },
213226
214 - disableMenuItem: function( menuKey, menuItemKey ){
215 -
 227+ disableMenuItem: function( menuKey, menuItemKey ){
216228 this.menuConfig[ menuKey ][ menuItemKey ].disabled = true;
217 - $menuItemTarget = $j('#' + this.getMenuItemId(menuKey, menuItemKey ) );
 229+ $menuItemTarget = $j('#' + this.getMenuItemId( menuKey, menuItemKey ) );
 230+
 231+ mw.log("SequencerMenu::disable:" + ' ' + menuKey + ' ' + menuItemKey + ' in-dom:' + $menuItemTarget.length );
218232 if( $menuItemTarget.length && ! $menuItemTarget.hasClass( 'disabled' ) ){
219233 $menuItemTarget.addClass( 'disabled' );
220234 }
221 -
222 - /*this.menuConfig[ menuKey ][ menuItemKey ].enabled = false;
223 -
224 - $j('#' + this.getMenuItemId(menuKey, menuItemKey ) )
225 - // remove menu role
226 - .attr( 'role', '')
227 - // Set to faded out
228 - .css({
229 - 'opacity' : .5
230 - })*/
231 -
232235 },
233236
234 - enableMenuItem: function( menuKey, menuItemKey ){
235 - this.menuConfig[ menuKey ][ menuItemKey ].disabled = false;
236 - alert( 'EnableMenuItem' + menuKey + ' key:' + menuItemKey );
 237+ enableMenuItem: function( menuKey, menuItemKey ){
 238+ this.menuConfig[ menuKey ][ menuItemKey ].disabled = false;
237239 $menuItemTarget = $j('#' + this.getMenuItemId( menuKey, menuItemKey ) );
238 - if( $menuItemTarget.hasClass( 'disabled' ) ){
239 - $menuItemTarget.removeClass( 'disabled' );
240 - }
241240
242 - /*
243 - $j('#' + this.getMenuItemId(menuKey, menuItemKey ) )
244 - // remove menu role
245 - .attr( 'role', 'menuitem')
246 - // Set to faded out
247 - .css({
248 - 'opacity' : 1
249 - })*/
 241+ mw.log("SequencerMenu::enable:" + menuKey + ' ' + menuItemKey + ' in-dom:' + $menuItemTarget.length );
 242+ if( $menuItemTarget.length && $menuItemTarget.hasClass( 'disabled' ) ){
 243+ $menuItemTarget.removeClass( 'disabled' );
 244+ }
250245 },
251246
252247 getMenuItemId: function( menuKey, menuItemKey ){
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTimeline.js
@@ -60,7 +60,7 @@
6161 },
6262
6363 // Draw the timeline
64 - drawTimeline: function(){
 64+ drawTimeline: function(){
6565 // xxx TODO support multiple tracks :::
6666 var seqTracks = this.sequencer.getSmil().getBody().getSeqElements();
6767 // For now just one video track:
@@ -91,9 +91,7 @@
9292 var _this = this;
9393 // Setup a local pointer to the smil engine:
9494 var smil = this.sequencer.getSmil();
95 -
96 -
97 -
 95+
9896 var $clipTrackSet = this.getTracksContainer().find('.clipTrackSetContainer').find( '.clipTrackSet' );
9997 // Add the $clipTrackSet if not already in dom:
10098 if( $clipTrackSet.length == 0 ){
@@ -113,8 +111,7 @@
114112 var reRenderThumbFlag = false;
115113 // Draw the node onto the timeline if the clip is not already there:
116114 var $timelineClip = $clipTrackSet.find('#' + _this.getTimelineClipId( $node ) )
117 - if( $timelineClip.length == 0 ){
118 -
 115+ if( $timelineClip.length == 0 ){
119116 $timelineClip = _this.getTimelineClip( $clipTrackSet, $node );
120117 if( $previusClip ){
121118 $previusClip.after(
@@ -125,17 +122,19 @@
126123 $clipTrackSet.prepend(
127124 $timelineClip
128125 );
129 - }
 126+ }
130127 reRenderThumbFlag = true;
131128 } else {
132 - // confirm order
133 - mw.log( $timelineClip.attr('id') + ' found ');
134 - if( $timelineClip.data('prevIndex') != seqOrder ){
 129+ // Confirm clip is in the correct indexOrder
 130+ //mw.log( 'indexOrder::' + $timelineClip.attr('id') + ' '+ $timelineClip.data('indexOrder') + ' == ' + $node.data('indexOrder'));
 131+ if( $timelineClip.data('indexOrder') != $node.data('indexOrder') ){
135132 reOrderTimelineFlag = true;
136 - }
 133+ }
137134 }
138 - // xxx Check if the start time was changed
139135
 136+ // xxx Check if the start time was changed to set reRenderThumbFlag
 137+
 138+
140139 if ( reRenderThumbFlag ){
141140 // issue a draw Thumb request ( since we reinserted into the dom )
142141 // Check Buffer for when the first frame of the smilNode can be grabbed:
@@ -152,12 +151,15 @@
153152
154153 // Check if we need to re-sort the list
155154 if( reOrderTimelineFlag ){
156 - alert(" reorder clips!");
157155 // move every node in-order to the end.
158156 smil.getBody().getRefElementsRecurse( sequenceNode, startOffset, function( $node ){
159157 var $timelineClip = $clipTrackSet.find('#' + _this.getTimelineClipId( $node ) )
160158 $timelineClip.appendTo( $clipTrackSet );
161159 });
 160+ // Update the order for all clips
 161+ $clipTrackSet.children().each(function (inx, clip){
 162+ $j( clip ).data('indexOrder', inx);
 163+ });
162164 }
163165
164166
@@ -218,7 +220,7 @@
219221 .attr('id', _this.getTimelineClipId( $node ) )
220222 .data( {
221223 'smilId': $node.attr('id'),
222 - 'prevIndex' : $clipTrackSet.children().length
 224+ 'indexOrder' : $clipTrackSet.children().length
223225 })
224226 .addClass('timelineClip ui-corner-all')
225227 .loadingSpinner()
@@ -269,7 +271,7 @@
270272 $seqParent.append( $movedSmileNode.get(0) );
271273 } else {
272274 // see if the index was affected by our move position
273 - if( clipIndex >= $movedSmileNode.data('prevIndex') ){
 275+ if( clipIndex >= $movedSmileNode.data('indexOrder') ){
274276 $seqParent.children().eq( clipIndex ).after( $movedSmileNode.get(0) );
275277 }else{
276278 $seqParent.children().eq( clipIndex ).before( $movedSmileNode.get(0) );
@@ -291,9 +293,9 @@
292294 });
293295 }
294296
295 - // Update the prevIndex for all clips
 297+ // Update the order for all clips
296298 $seqParent.children().each(function (inx, clip){
297 - $j( clip ).data('prevIndex', inx);
 299+ $j( clip ).data('indexOrder', inx);
298300 });
299301
300302 // Invalidate / update embedPlayer duration / clip offsets
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerActionsEdit.js
@@ -47,7 +47,7 @@
4848 * Apply a smil xml transform state ( to support undo / redo )
4949 */
5050 registerEdit: function(){
51 - mw.log( 'ActionsEdit::registerEdit: ' + this.sequencer.getSmil().getXMLString() );
 51+ mw.log( 'ActionsEdit::registerEdit: stacksize' + this.editStack.length + ' editIndex: ' + this.editIndex );
5252 // Throw away any edit history after the current editIndex:
5353 if( this.editStack.length && this.editIndex > this.editStack.length ) {
5454 this.editStack = this.editStack.splice(0, this.editIndex);
@@ -71,13 +71,15 @@
7272 this.editIndex--;
7373 if( this.editStack[ this.editIndex ] ) {
7474 this.sequencer.updateSmilXML( this.editStack[ this.editIndex ] );
 75+ // Enable redo action
 76+ this.sequencer.getMenu().enableMenuItem( 'edit', 'redo' );
7577 } else {
7678 // index out of range set to 0
7779 this.editIndex = 0;
7880 mw.log("Error: SequenceActionsEdit:: undo Already at oldest index:" + this.editIndex);
79 - }
 81+ }
8082 // if at oldest undo disable undo option
81 - if( this.editIndex - 1 == 0 ){
 83+ if( ( this.editIndex - 1 ) < 0 ){
8284 this.sequencer.getMenu().disableMenuItem( 'edit', 'undo' );
8385 }
8486 },
@@ -87,15 +89,19 @@
8890 redo: function(){
8991 this.editIndex ++;
9092 if( this.editStack[ this.editIndex ] ) {
 93+ mw.log("DO redo for editIndex::" + this.editIndex + ' xml lenght' + this.editStack[ this.editIndex ].length );
9194 this.sequencer.updateSmilXML( this.editStack[ this.editIndex ] );
 95+ // Enable undo action
 96+ this.sequencer.getMenu().enableMenuItem( 'edit', 'undo' );
9297 } else {
93 - // index out of redo range set to last edit
 98+ // Index out of redo range set to last edit
9499 this.editIndex == this.editStack.length - 1
95100 mw.log( 'Error: SequencerActionsEdit::Redo: Already at most recent edit avaliable');
96101 }
97102
98103 // if at newest redo disable redo option
99 - if( this.editIndex == this.editStack.length - 1 ){
 104+ mw.log( this.editIndex + ' >= ' + ( this.editStack.length -1 ) );
 105+ if( this.editIndex >= this.editStack.length -1 ){
100106 this.sequencer.getMenu().disableMenuItem( 'edit', 'redo' );
101107 }
102108 }
Index: branches/MwEmbedStandAlone/libraries/jquery/plugins/jquery.menu/jquery.menu.js
@@ -126,6 +126,7 @@
127127 linkToFront: false
128128 },
129129 showSpeed: 200, // show/hide speed in milliseconds
 130+ createMenuCallback: null,
130131 callerOnState: 'ui-state-active', // class to change the appearance of the link/button when the menu is showing
131132 loadingState: 'ui-state-loading', // class added to the link/button while the menu is created
132133 linkHover: 'ui-state-hover', // class for menu option hover state
@@ -277,7 +278,7 @@
278279 };
279280 break;
280281 };
281 - });
 282+ });
282283 };
283284
284285 this.create = function() {
@@ -323,12 +324,12 @@
324325 var menuli = menuitem.parent();
325326 if( !menuli.hasClass('divider') && !menuli.hasClass('disabled') ){
326327 $('.'+options.linkHover).removeClass(options.linkHover).blur().parent().removeAttr('id');
327 - $(this).addClass(options.linkHover).focus().parent().attr('id','active-menuitem');
 328+ $(this).addClass(options.linkHover).focus().parent().addClass('active-menuitem');
328329 }
329330 },
330331 function() {
331332 if( !menuitem.hasClass('divider') && !menuitem.hasClass('disabled') ){
332 - $(this).removeClass(options.linkHover).blur().parent().removeAttr('id');
 333+ $(this).removeClass(options.linkHover).blur().parent().removeClass('active-menuitem');
333334 }
334335 }
335336 );
@@ -347,6 +348,10 @@
348349
349350 menu.setPosition(container, caller, options);
350351 menu.menuExists = true;
 352+
 353+ if( typeof options.createMenuCallback == 'function' ){
 354+ options.createMenuCallback();
 355+ }
351356 };
352357
353358 this.chooseItem = function(item) {

Status & tagging log