* made wgMaxUploadSize check work with js2/firefogg uploading interface.
[lhc/web/wiklou.git] / js2 / mwEmbed / libSequencer / mvSequencer.js
1 /*
2 * mvSequencer.js Created on Oct 17, 2007
3 *
4 * All Metavid Wiki code is Released under the GPL2
5 * for more info visit http://metavid.org/wiki/Code
6 *
7 * @author Michael Dale
8 * @email mdale@wikimedia.org
9 *
10 * further developed in open source development partnership with kaltura.
11 * more info at http://kaltura.com & http://kaltura.org
12 *
13 * mv_sequencer.js
14 * is a basic embeddeble sequencer.
15 * extends the playlist with drag/drop/sortable/add/remove functionality
16 * editing of annotative content (mostly for wiki)
17 * enables more dynamic layouts
18 * exports back out to json or inline format
19 */
20
21 loadGM({
22 "menu_clipedit" : "Edit Media",
23 "menu_transition" : "Transitions & Effects",
24 "menu_cliplib" : "Add Media",
25 "menu_resource_overview" : "Resource Overview",
26 "menu_options" : "Options",
27
28 "loading_timeline" : "Loading TimeLine <blink>...</blink>",
29 "loading_user_rights" : "Loading user rights <blink>...</blink>",
30
31 "no_edit_permissions" : "You don't have permissions to save changes to this sequence",
32
33 "edit_clip" : "Edit Clip",
34 "edit_save" : "Save Sequence Changes",
35 "saving_wait": "Save in Progress (please wait)",
36 "save_done" : "Save Done",
37 "edit_cancel" : "Cancel Sequence Edit",
38 "edit_cancel_confirm" : "Are you sure you want to cancel your edit. Changes will be lost",
39
40 "zoom_in" : "Zoom In",
41 "zoom_out" : "Zoom Out",
42 "cut_clip" : "Cut Clips",
43 "expand_track" : "Expand Track",
44 "colapse_track" : "Collapse Track",
45 "play_from_position" : "Play From Playline Position",
46 "pixle2sec" : "pixles to seconds",
47 "rmclip" : "Remove Clip",
48 "clip_in" : "clip in",
49 "clip_out" : "clip out",
50
51 "mv_welcome_to_sequencer" : "<h3>Welcome to the sequencer demo</h3> very <b>limited</b> functionality right now. Not much documentation yet either",
52
53 "no_selected_resource" : "<h3>No Resource Selected</h3> Select a Clip to enable editing",
54 "error_edit_multiple" : "<h3>Multiple Resources Selected</h3> Select a single clip to edit it",
55
56 "mv_editor_options" : "Editor options",
57 "mv_editor_mode" : "Editor mode",
58 "mv_simple_editor_desc" : "simple editor (iMovie style)",
59 "mv_advanced_editor_desc" : "advanced editor (Final Cut style)",
60 "mv_other_options" : "Other Options",
61 "mv_contextmenu_opt" : "Enable Context Menus",
62
63 "mv_sequencer_credit_line":"Developed by <a href=\"http://kaltura.com\">Kaltura, Inc.</a> in partnership with the <a href=\"http://wikimediafoundation.org/wiki/Home\">Wikimedia Foundation</a> ( <a href=\"#\">more info</a> )"
64 });
65 //used to set default values and validate the passed init object
66 var sequencerDefaultValues = {
67
68 instance_name:'mvSeq', //for now only one instance by name mvSeq is allowed
69
70 target_sequence_container:null,//text value (so that its a valid property)
71 target_form_text: null,
72
73 //what is our save mode:
74 // can save to 'api' url or 'form'
75 saveMode : 'api',
76
77 video_container_id:'mv_video_container',
78
79 video_width : 400,
80 video_height: 300,
81
82 sequence_tools_id:'mv_sequence_tools',
83 timeline_id:'mv_timeline',
84 plObj_id:'seq_pl',
85 plObj:'null',
86
87 timeline_scale:.06, //in pixel to second ratio ie 100pixles for every ~30seconds
88 timeline_duration:500, //default timeline length in seconds
89 playline_time:0,
90 track_thumb_height:60,
91 track_text_height:20,
92
93 //default timeline mode: "story" (i-movie like) or "time" (finalCut like)
94 timeline_mode:'storyboard',
95
96 track_clipThumb_height:80, // how large are the i-movie type clips
97
98 base_adj_duration:.5, //default time to subtract or add when adjusting clips.
99
100 //default clipboard is empty:
101 clipboard:new Array(),
102 //stores the clipboard edit token (if user has rights to edit their User page)
103 clipboardEditToken:null,
104 //stores the sequence edit token (if user has rights to edit the current sequence)
105 sequenceEditToken:null,
106 //the time the sequence was last touched (grabbed at time of startup)
107 sequenceTouchedTime:null,
108
109
110
111 //Msg are all the language specific values ...
112 // (@@todo overwrite by msg values preloaded in the page)
113 //tack/clips can be pushed via json or inline playlist format
114 inline_playlist:'null', //text value so its a valid property
115 inline_playlist_id:'null',
116 mv_pl_src:'null',
117 //the edit stack:
118 edit_stack:new Array(),
119 disp_menu_item:null,
120 //trackObj used to payload playlist Track Object (when inline not present)
121 tracks:{}
122 }
123 var mvSequencer = function(iObj) {
124 return this.init(iObj);
125 };
126 //set up the mvSequencer object
127 mvSequencer.prototype = {
128 //the menu_items Object contains: default html, js setup/loader functions
129 menu_items : {
130 'clipedit':{
131 'd':0,
132 'html':'',
133 'js': function(this_seq){
134 this_seq.doEditSelectedClip();
135 },
136 'click_js':function( this_seq ){
137 this_seq.doEditSelectedClip();
138 }
139 },
140 'transition':{
141 'd':0,
142 'html' : '<h3>' + gM('menu_transition') + '</h3>',
143 'js':function(this_seq){
144 this_seq.doEditTransitionSelectedClip();
145 },
146 'click_js':function(this_seq){
147 //highlight the transition of the selected clip:
148 this_seq.doEditTransitionSelectedClip();
149 }
150 },
151 'cliplib':{
152 'd':0,
153 'html': gM('loading_txt'),
154 'js':function( this_seq ){
155 //load the search interface with sequence tool targets
156 mvJsLoader.doLoad( [
157 'remoteSearchDriver',
158 'seqRemoteSearchDriver'
159 ], function(){
160 this_seq.mySearch = new seqRemoteSearchDriver(this_seq);
161 this_seq.mySearch.doInitDisplay();
162 });
163 }
164 },
165 'options':{
166 'd':0,
167 'html' : '<h3>' + gM('menu_options') + '</h3>' +
168 gM('mv_editor_mode') + '<br> ' +
169 '<blockquote><input type="radio" value="simple_editor" name="opt_editor">' +
170 gM('mv_simple_editor_desc') + ' </blockquote>' +
171 '<blockquote><input type="radio" value="advanced_editor" name="opt_editor">' +
172 gM('mv_advanced_editor_desc') + ' </blockquote>'+
173 gM('mv_other_options') + '<br>' +
174 '<blockquote><input type="checkbox" value="contextmenu_opt" name="contextmenu_opt">' +
175 gM('mv_contextmenu_opt') + ' </blockquote>',
176 'js':function(this_seq){
177 $j('#options_ic input[value=\'simple_editor\']').attr({
178 'checked':(this_seq.timeline_mode=='storyboard')?true:false
179 }).click(function(){
180 this_seq.doSimpleTl();
181 });
182 $j('#options_ic input[value=\'advanced_editor\']').attr({
183 'checked':( this_seq.timeline_mode=='time' )?true:false
184 }).click(function(){
185 this_seq.doAdvancedTl();
186 });
187 //set up the options for context menus
188 }
189 }
190 },
191
192 //set up initial key states:
193 key_shift_down:false,
194 key_ctrl_down:false,
195 inputFocus:false,
196
197 init:function( iObj ){
198 //set up pointer to this_seq for current scope:
199 var this_seq = this;
200 //set the default values:
201 for(var i in sequencerDefaultValues){
202 this[ i ] = sequencerDefaultValues[i];
203 }
204 for(var i in iObj){
205 //js_log('on '+ i + ' :' + iObj[i]);
206 if(typeof sequencerDefaultValues[i] != 'undefined'){ //make sure its a valid property
207 this[i] = iObj[i];
208 }
209 }
210
211 //check for sequence_container
212 if($j(this.target_sequence_container).length === 0){
213 js_log("Error: missing target_sequence_container");
214 return false;
215 }
216
217 //$j(this.target_sequence_container).css('position', 'relative');
218 this['base_width'] = $j(this.target_sequence_container).width();
219 this['base_height'] = $j(this.target_sequence_container).height();
220
221 //add the container divs (with basic layout ~universal~
222 $j(this.target_sequence_container).html(''+
223 '<div id="' + this.video_container_id + '" style="position:absolute;right:0px;top:0px;' +
224 'width:' + this.video_width + 'px;height:'+this.video_height+'px;border:solid thin blue;background:#FFF;font-color:black;"/>'+
225 '<div id="' + this.timeline_id + '" class="ui-widget ui-widget-content ui-corner-all" style="position:absolute;' +
226 'left:0px;right:0px;top:'+(this.video_height+34)+'px;bottom:35px;overflow:auto;">'+
227 gM('loading_timeline')+ '</div>'+
228 '<div class="seq_status" style="position:absolute;left:0px;width:300px;"></div>'+
229 '<div class="seq_save_cancel" style="position:absolute;'+
230 'left:5px;bottom:0px;height:25px;">'+
231 gM('loading_user_rights') +
232 '</div>'+
233 '<div class="about_editor" style="position:absolute;right:5px;bottom:7px;">' +
234 gM('mv_sequencer_credit_line') +
235 '</div>'+
236 '<div id="'+this.sequence_tools_id+'" style="position:absolute;' +
237 'left:0px;right:'+(this.video_width+15)+'px;top:0px;height:'+(this.video_height+23)+'px;"/>'
238 ).css({
239 'min-width':'850px'
240 });
241
242 /*js_log('set: '+this.target_sequence_container + ' html to:'+ "\n"+
243 $j(this.target_sequence_container).html()
244 );*/
245 //first check if we got a cloned PL object:
246 //(when the editor is invoked with the plalylist already on the page)
247 //@@NOT WORKING... (need a better "clone" function)
248 /*if( this.plObj != 'null' ){
249 js_log('found plObj clone');
250 //extend with mvSeqPlayList object:
251 this.plObj = new mvSeqPlayList(this.plObj);
252 js_log('mvSeqPlayList added: ' + this.plObj.org_control_height );
253 $j('#'+this.video_container_id).get(0).attachNode( this.plObj );
254 this.plObj.getHTML();
255 this.checkReadyPlObj();
256 return ;
257 }*/
258
259 //else check for source based sequence editor (a clean page load of the editor)
260 if( this.mv_pl_src != 'null' ) {
261 js_log( ' pl src:: ' + this.mv_pl_src );
262 var src_attr=' src="' + this.mv_pl_src+'" ';
263 }else{
264 js_log( ' null playlist src .. (start empty) ');
265 var src_attr='';
266 }
267 $j('#'+this.video_container_id).html('<playlist ' + src_attr +
268 ' style="width:' + this.video_width + 'px;height:' + this.video_height + 'px;" '+
269 ' controls="false" id="' + this.plObj_id + '" />');
270 rewrite_by_id( this.plObj_id );
271 setTimeout(this.instance_name +'.checkReadyPlObj()', 25);
272 },
273 updateSeqSaveButtons:function(){
274 var _this = this;
275 if( this.sequenceEditToken ){
276 $j(this.target_sequence_container+' .seq_save_cancel').html(
277 $j.btnHtml( gM('edit_save'), 'seq_edit_save', 'close') + ' ' +
278 $j.btnHtml( gM('edit_cancel'), 'seq_edit_cancel', 'close')
279 );
280 }else{
281 $j(this.target_sequence_container+' .seq_save_cancel').html( cancel_button + gM('no_edit_permissions') );
282 }
283 //assing bindings
284 $j(this.target_sequence_container +' .seq_edit_cancel').unbind().click(function(){
285 var x = window.confirm( gM('edit_cancel_confirm') );
286 if( x ){
287 _this.closeModEditor();
288 }else{
289 //close request canceled.
290 }
291 });
292 $j(this.target_sequence_container +' .seq_edit_save').unbind().click(function(){
293 //pop up progress dialog ~requesting edit line summary~
294 //remove any other save dialog
295 $j('#seq_save_dialog').remove();
296 $j('body').append('<div id="seq_save_dialog" title="'+ gM('edit_save') +'">' +
297 '<span class="mw-summary">'+
298 '<label for="seq_save_summary">Edit summary: </label>' +
299 '</span>'+
300 '<input id="seq_save_summary" tabindex="1" maxlength="200" value="" size="30" name="seq_save_summary"/>'+
301 '</div>');
302 //dialog:
303 $j('#seq_save_dialog').dialog({
304 bgiframe: true,
305 autoOpen: true,
306 modal: true,
307 buttons:{
308 "Save":function(){
309 var saveReq = {
310 'action' : 'edit',
311 'title' : _this.plObj.mTitle,
312 //the text is the sequence XML + the description
313 'text' : _this.getSeqOutputHLRDXML() + "\n" +
314 _this.plObj.wikiDesc,
315 'token' : _this.sequenceEditToken,
316 'summary' : $j('#seq_save_summary').val()
317 };
318 //change to progress bar and save:
319 $j('#seq_save_dialog').html('<div class="progress" /><br>' +
320 gM('saving_wait')
321 )
322 $j('#seq_save_dialog .progress').progressbar({
323 value: 100
324 });
325 //run the Seq Save Request:
326 do_api_req( {
327 'data': saveReq,
328 'url' : _this.getLocalApiUrl()
329 },function(data){
330 $j('#seq_save_dialog').html( gM('save_done') );
331 $j('#seq_save_dialog').dialog('option',
332 'buttons', {
333 "Done":function(){
334 //refresh the page?
335 window.location.reload();
336 },
337 "Do More Edits": function() {
338 $j(this).dialog("close");
339 }
340 });
341 });
342 },
343 "Cancel":function(){
344 $j(this).dialog('close');
345 }
346 }
347 });
348 })
349 },
350 //display a menu item (hide the rest)
351 disp:function( item, dispCall ){
352 js_log('menu_item disp: ' + item);
353 this.disp_menu_item = item;
354 //update the display and item state:
355 if(this.menu_items[item]){
356 //update the tabs display:
357 if(!dispCall)
358 $j("#seq_menu").tabs('select', this.menu_items[item].inx);
359
360 this.menu_items[item].d = 1;
361 //do any click_js actions:getInsertControl
362 if( this.menu_items[item].click_js )
363 this.menu_items[item].click_js( this );
364 }
365 },
366 //setup the menu items:
367 setupMenuItems:function(){
368 js_log('loadInitMenuItems');
369 var this_seq = this;
370 //do all the menu_items setup: @@we could defer this to once the menu item is requested
371 for( var i in this.menu_items ){
372 if( this.menu_items[i].js )
373 this.menu_items[i].js( this );
374 }
375 },
376 renderTimeLine:function(){
377 //empty out the top level html:
378 $j('#'+this.timeline_id).html('');
379 //add html general for timeline
380 if( this.timeline_mode == 'time'){
381 $j('#'+this.timeline_id).html(''+
382 '<div id="'+this.timeline_id+'_left_cnt" class="mv_tl_left_cnt">'+
383 '<div id="'+this.timeline_id+'_head_control" style="position:absolute;top:0px;left:0px;right:0px;height:30px;">' +
384 '<a title="'+gM('play_from_position')+'" href="javascript:'+this.instance_name+'.play_jt()">'+
385 '<img style="width:16px;height:16px;border:0" src="' + mv_embed_path + 'images/control_play_blue.png">'+
386 '</a>'+
387 '<a title="'+gM('zoom_in')+'" href="javascript:'+this.instance_name+'.zoom_in()">'+
388 '<img style="width:16px;height:16px;border:0" src="' + mv_embed_path + 'images/zoom_in.png">'+
389 '</a>'+
390 '<a title="'+gM('zoom_out')+'" href="javascript:'+this.instance_name+'.zoom_out()">'+
391 '<img style="width:16px;height:16px;border:0" src="' + mv_embed_path + 'images/zoom_out.png">'+
392 '</a>'+
393 '<a title="'+gM('cut_clip')+'" href="javascript:'+this.instance_name+'.cut_mode()">'+
394 '<img style="width:16px;height:16px;border:0" src="' + mv_embed_path + 'images/cut.png">'+
395 '</a>'+
396 '</div>' +
397 '</div>' +
398 '<div id="'+this.timeline_id+'_tracks" class="mv_seq_tracks">' +
399 '<div id="'+this.timeline_id+'_head_jump" class="mv_head_jump" style="position:absolute;top:0px;left:0px;height:20px;"></div>'+
400 '<div id="'+this.timeline_id+'_playline" class="mv_playline"></div>'+
401 '</div>'
402 );
403 //add playlist hook to update timeline
404 this.plObj.update_tl_hook = this.instance_name+'.update_tl_hook';
405 var this_sq = this;
406 var top_pos=25;
407 //add tracks:
408 for(var i in this.plObj.tracks){
409 var track = this.plObj.tracks[i];
410 //js_log("on track: "+ i + ' t:'+ $j('#'+this.timeline_id+'_left_cnt').html() );
411 //set up track based on disp type
412 switch(track.disp_mode){
413 case 'timeline_thumb':
414 var track_height=60;
415 var exc_img = 'opened';
416 var exc_action='close';
417 var exc_msg = gM('colapse_track');
418 break;
419 case 'text':
420 var track_height=20;
421 var exc_img = 'closed';
422 var exc_action='open';
423 var exc_msg = gM('expand_track');
424 break;
425 }
426 //add track name:
427 $j('#'+this.timeline_id+'_left_cnt').append(
428 '<div id="track_cnt_'+i+'" style="top:'+top_pos+'px;height:'+track_height+'px;" class="track_name">'+
429 '<a id="mv_exc_'+i+'" title="'+exc_msg+'" href="javascript:'+this_sq.instance_name+'.exc_track('+i+',\''+exc_action+'\')">'+
430 '<img id="'+this_sq.timeline_id+'_close_expand" style="width:16px;height:16px;border:0" '+
431 ' src="'+mv_embed_path + 'images/'+exc_img+'.png">'+
432 '</a>'+
433 track.title+'</div>'
434 );
435 //also render the clips in the trackset container: (thumb or text view)
436 $j('#'+this.timeline_id+'_tracks').append(
437 '<div id="container_track_'+i+'" style="top:'+top_pos+'px;height:'+(track_height+2)+'px;left:0px;right:0px;" class="container_track" />'
438 );
439 top_pos+=track_height+20;
440 }
441 }
442 if( this.timeline_mode=='storyboard'){
443 var top_pos=this.plObj.org_control_height;
444 //debugger;
445 for(var i in this.plObj.tracks){
446 var track_height=this.track_clipThumb_height;
447 var timeline_id = this.timeline_id
448 //add in play box and container tracks
449 $j('#'+timeline_id).append(''+
450 '<div id="interface_container_track_' + i + '" ' +
451 ' style="position:absolute;top:25px;height:'+(track_height+30)+'px;left:10px;right:0px;"' +
452 '>'+
453 '<div id="container_track_'+i+'" style="position:relative;top:0px;' +
454 'height:'+(track_height+30)+'px;left:0px;right:0px;" class="container_track">' +
455 '</div>'+
456 '<div id="' + timeline_id + '_playline" class="mv_story_playline">' +
457 '<div class="mv_playline_top"/>'+
458 '</div>'+
459 '</div>'
460 );
461 top_pos+=track_height+20;
462 }
463 }
464 },
465 //once playlist is ready continue
466 checkReadyPlObj:function(){
467 //set up pointers from sequencer to pl obj
468 this.plObj = $j('#'+ this.plObj_id ).get(0);
469 //& from seq obj to sequencer
470 this.plObj.pSeq = this;
471
472 if( this.plObj )
473 if( ! this.plObj.loading )
474 this.plReadyInit();
475
476 //else keep checking for the playlist to be ready
477 if( this.plObj.loading ){
478 if(this.plReadyTimeout==200){
479 js_error('error playlist never ready');
480 }else{
481 this.plReadyTimeout++;
482 setTimeout(this.instance_name +'.checkReadyPlObj()', 25);
483 }
484 }
485 },
486 getLocalApiUrl:function(){
487 return this.plObj.interface_url;
488 },
489 plReadyInit:function(){
490 var _this = this;
491 js_log('plReadyInit');
492 js_log( this.plObj );
493 //give the playlist a pointer to its parent seq:
494 this.plObj['seqObj'] = this;
495
496 //update playlist (if its empty right now)
497 if(this.plObj.getClipCount()==0){
498 $j('#'+this.plObj_id).html('empty playlist');
499 }
500
501 //propagate the edit tokens
502 //if on an edit page just grab from the form:
503 this.sequenceEditToken = $j('input[wpEditToken]').val();
504
505 if(typeof this.sequenceEditToken == 'undefined' && this.getLocalApiUrl()!=null){
506 get_mw_token(_this.plObj.mTitle, _this.getLocalApiUrl(),
507 function(token){
508 if(token){
509 _this.sequenceEditToken = token;
510 _this.updateSeqSaveButtons();
511 }
512 }
513 );
514 get_mw_token(_this.plObj.mTalk, _this.getLocalApiUrl(),
515 function(token){
516 _this.clipboardEditToken = token;
517 }
518 );
519 //also grab permissions for sending clipboard commands to the server
520
521 //(calling the sequencer inline) try and get edit token via api call:
522 //(somewhat fragile way to get at the api... should move to config
523 /*var token_url = this.plObj.interface_url.replace(/index\.php/, 'api.php');
524 token_url += '?action=query&format=xml&prop=info&intoken=edit&titles=';
525 $j.ajax({
526 type: "GET",
527 url: token_url + this_seq.plObj.mTitle,
528 success:function(data){
529 var pageElm = data.getElementsByTagName('page')[0];
530 if( $j(pageElm).attr('edittoken') ){
531 this_seq.sequenceEditToken = $j(pageElm).attr('edittoken');
532 }
533
534 }
535 });*/
536 //also grab permissions for sending clipboard commands to the server
537 /*$j.ajax({
538 type:"GET",
539 url: token_url + this_seq.plObj.mTalk,
540 success:function(data){
541 var pageElm = data.getElementsByTagName('page')[0];
542 if( $j(pageElm).attr('edittoken') ){
543 this_seq.clipboardEditToken = $j(pageElm).attr('edittoken');
544 }
545 }
546 });*/
547 }
548
549
550 //render the menu tabs::
551 var item_containers ='';
552 var inx = 0;
553 var selected_tab = 0;
554 var tabc ='';
555 var o='<div id="seq_menu" style="width:100%;height:100%">';
556 o+='<ul>';
557 for(var tab_id in this.menu_items){
558 menu_item = this.menu_items[tab_id];
559 menu_item.inx = inx;
560 if(menu_item.d){
561 selected_tab=inx;
562 _this.disp_menu_item =tab_id;
563 }
564
565 o+='<li>' +
566 '<a id="mv_menu_item_'+tab_id+'" href="#' + tab_id + '_ic">'+gM('menu_' + tab_id ) + '</a>' +
567 '</li>';
568
569 tabc += '<div id="' + tab_id + '_ic" style="overflow:auto;height:268px;" >';
570 tabc += (menu_item.html) ? menu_item.html : '<h3>' + gM('menu_'+tab_id) + '</h3>';
571 tabc +='</div>';
572 inx++;
573 };
574 o+='</ul>';
575 o+=tabc;
576 $j('#'+this.sequence_tools_id).html( o );
577
578
579 $j("#seq_menu").tabs({
580 selected:selected_tab,
581 select: function(event, ui) {
582 _this.disp( $j(ui.tab).attr('id').replace('mv_menu_item_', ''), true );
583 }
584 //add sorting
585 }).find(".ui-tabs-nav").sortable({ axis : 'x' });
586
587
588 //render the timeline
589 this.renderTimeLine();
590 this.do_refresh_timeline();
591
592 //load init content into containers
593 this.setupMenuItems();
594
595 this.doFocusBindings();
596
597 //set up key bidnings
598 $j(window).keydown(function(e){
599 js_log('pushed down on:' + e.which);
600 if( e.which == 16 )
601 _this.key_shift_down = true;
602
603 if( e.which == 17)
604 _this.key_ctrl_down = true;
605
606 if( (e.which == 67 && _this.key_ctrl_down) && !_this.inputFocus)
607 _this.copySelectedClips();
608
609 if( (e.which == 88 && _this.key_ctrl_down) && !_this.inputFocus)
610 _this.cutSelectedClips();
611
612 //paste cips on v + ctrl while not focused on a text area:
613 if( (e.which == 86 && _this.key_ctrl_down) && !_this.inputFocus)
614 _this.pasteClipBoardClips();
615
616 });
617 $j(window).keyup(function(e){
618 js_log('key up on ' + e.which);
619 //user let go of "shift" turn off multi-select
620 if( e.which == 16 )
621 _this.key_shift_down = false;
622
623 if( e.which == 17)
624 _this.key_ctrl_down = false;
625
626 //backspace or delete key while not focused on a text area:
627 if( (e.which == 8 || e.which == 46) && !_this.inputFocus)
628 _this.removeSelectedClips();
629 });
630 },
631 //check all nodes for focus
632 //@@todo it would probably be faster to search a given subnode instead of all text
633 doFocusBindings:function(){
634 var _this = this;
635 //if an input or text area has focus disable delete key binding
636 $j("input,textarea").focus(function () {
637 js_log("inputFocus:true");
638 _this.inputFocus = true;
639 });
640 $j("input,textarea").blur( function () {
641 js_log("inputFocus:blur");
642 _this.inputFocus = false;
643 })
644 },
645 update_tl_hook:function(jh_time_ms){
646 //put into seconds scale:
647 var jh_time_sec_float = jh_time_ms/1000;
648 //render playline at given time
649 //js_log('tl scale: '+this.timeline_scale);
650 $j('#'+this.timeline_id+'_playline').css('left', Math.round(jh_time_sec_float/this.timeline_scale)+'px' );
651 //js_log('at time:'+ jh_time_sec + ' px:'+ Math.round(jh_time_sec_float/this.timeline_scale));
652 },
653 /*returns a xml or json representation of the current sequence */
654 getSeqOutputJSON:function(){
655 js_log('json output:');
656 },
657 getSeqOutputHLRDXML:function(){
658 var o='<sequence_hlrd>' +"\n";
659 o+="\t<head>\n";
660 //get transitions
661 for(var i in this.plObj.transitions){
662 if( this.plObj.transitions[i] ){
663 var tObj = this.plObj.transitions[i].getAttributeObj();
664 o+="\t\t<transition ";
665 for(var j in tObj){
666 o+=' '+j+'="' + tObj[j] + '"\n\t\t';
667 }
668 o+='/>'+"\n"; //transitions don't have children
669 }
670 }
671 o+="\t</head>\n";
672
673 //get clips
674 o+="\t<body>\n";
675 //output each track:
676 for(var i in this.plObj.tracks){
677 var curTrack = this.plObj.tracks[i];
678 o+="\t<seq";
679 var tAttr = curTrack.getAttributeObj();
680 for(var j in tAttr){
681 o+=' '+j+'="' + tAttr[j] + '"\n\t\t\t';
682 }
683 o+=">\n";
684 for( var k in curTrack.clips ){
685 var curClip = curTrack.clips[k];
686 o+="\t\t<ref ";
687 var cAttr = curClip.getAttributeObj();
688 var lt = '';
689 for(var j in cAttr){
690 var val = (j=='transIn' || j=='transOut') ? cAttr[j].id : cAttr[j];
691 o+=lt + j+'="' + val + '"';
692 lt ="\n\t\t";
693 }
694 o+=">\n" //close the clip
695 for(var pName in curClip.params){
696 var pVal = curClip.params[pName];
697 o+="\t\t\t" + '<param name="'+ pName + '">' + pVal + '</param>' + "\n";
698 }
699 o+="\t\t</ref>\n\n";
700 }
701 o+="\n</seq>\n";
702 }
703 o+="\t</body>\n";
704 //close the tag
705 o+='</sequence_hlrd>';
706
707 return o;
708 },
709 editClip:function(track_inx, clip_inx){
710 var cObj = this.plObj.tracks[ track_inx ].clips[ clip_inx ];
711 this.doEditClip( cObj );
712 },
713 doEditTransitionSelectedClip:function(){
714 var _this = this;
715 js_log("f:doEditTransitionSelectedClip:" + $j('.mv_selected_clip').length);
716 if( $j('.mv_selected_clip').length == 1){
717 _this.doEditTransition( _this.getClipFromSeqID( $j('.mv_selected_clip').parent().attr('id') ) );
718 }else if( $j('.mv_selected_clip').length === 0){
719 //no clip selected warning:
720 $j('#transition_ic').html( gM('no_selected_resource') );
721 }else{
722 //multiple clip selected warning:
723 $j('#transition_ic').html( gM('error_edit_multiple') );
724 }
725 },
726 doEditSelectedClip:function(){
727 js_log("f:doEditSelectedClip:");
728 //and only one clip selected
729 if( $j('.mv_selected_clip').length == 1){
730 this.doEditClip( this.getClipFromSeqID( $j('.mv_selected_clip').parent().attr('id') ) );
731 }else if( $j('.mv_selected_clip').length === 0){
732 //no clip selected warning:
733 $j('#clipedit_ic').html( gM('no_selected_resource') );
734 }else{
735 //multiple clip selected warning:
736 $j('#clipedit_ic').html( gM('error_edit_multiple') );
737 }
738 },
739 doEditTransition:function( cObj ){
740 js_log("sequence:doEditTransition");
741 var _this = this;
742 mv_get_loading_img( '#transitions_ic' );
743 mvJsLoader.doLoad([
744 'mvTimedEffectsEdit',
745 '$j.fn.ColorPicker'
746 ],function(){
747 //no idea why this works / is needed.
748 var localSeqRef = _this;
749 _this.myEffectEdit = new mvTimedEffectsEdit({
750 'rObj' : cObj,
751 'control_ct' : 'transition_ic',
752 'pSeq' : localSeqRef
753 });
754 })
755 },
756 //updates the clip details div if edit resource is set
757 doEditClip:function( cObj){
758 var _this = this;
759
760 //set default edit action (maybe edit_action can be sent via by context click)
761 var edit_action = 'fileopts';
762
763 mv_get_loading_img( '#clipedit_ic' );
764 //load the clipEdit library if not already loaded:
765 mvJsLoader.doLoad( [
766 'mvClipEdit'
767 ], function(){
768 _this.myClipEditor = {};
769 //setup the cliploader
770 _this.myClipEditor = new mvClipEdit({
771 'rObj' : cObj,
772 'control_ct' : 'clipedit_ic',
773 'clip_disp_ct' : cObj.id,
774 'edit_action' : edit_action,
775 'p_seqObj' : _this,
776 'profile' : 'sequence'
777 });
778 });
779 },
780 //save new clip segment
781 saveClipEdit:function(){
782 //saves the clip updates
783 },
784 closeModEditor:function(){
785 //unset the sequencer
786 _global['mvSeq'] = null;
787 $j(this.target_sequence_container + ',.ui-widget-overlay').remove();
788 },
789 pasteClipBoardClips:function(){
790 js_log('f:pasteClipBoardClips');
791 //@@todo query the server for updated clipboard
792 //paste before the "current clip"
793 this.addClips( this.clipboard, this.plObj.cur_clip.order );
794 },
795 copySelectedClips:function(){
796 var this_seq = this;
797 //set all the selected clips
798 this.clipboard = new Array();
799 $j('.mv_selected_clip').each(function(){
800 //add each clip to the clip board:
801 var cur_clip = this_seq.getClipFromSeqID( $j(this).parent().attr('id') );
802 this_seq.clipboard.push( cur_clip.getAttributeObj() );
803 });
804 //upload clipboard to the server (if possible)
805 if( parseUri( document.URL ).host != parseUri( this_seq.plObj.interface_url ).host ){
806 js_log('error: presently we can\'t copy clips across domains');
807 }else{
808 //@@we need a api entry point to store a "clipboard"
809 if( this_seq.clipboardEditToken && this_seq.plObj.interface_url ){
810 var req_url = this_seq.plObj.interface_url.replace(/api.php/, 'index.php') + '?action=ajax&rs=mv_seqtool_clipboard&rsargs[]=copy';
811 $j.ajax({
812 type: "POST",
813 url:req_url,
814 data: $j.param( {
815 "clipboard_data": $j.toJSON( this_seq.clipboard ),
816 "clipboardEditToken": this_seq.clipboardEditToken
817 }),
818 success:function(data){
819 //callback( data );
820 js_log('did clipboard push ' + $j.toJSON( this_seq.clipboard ) );
821 }
822 });
823 }else{
824 js_log('error: no clipboardEditToken to uplaod clipboard to server');
825 }
826 }
827 },
828 cutSelectedClips:function(){
829 this.copySelectedClips();
830 this.removeSelectedClips();
831 },
832 removeSelectedClips:function(){
833 var remove_clip_ary=new Array();
834 //remove selected clips from display
835 $j('.container_track .mv_selected_clip').each(function(){
836 //grab the track index from the id (assumes track_#_clip_#
837 remove_clip_ary.push ( $j(this).parent().attr('id').replace('track_','').replace('clip_','').split('_') );
838 });
839 if(remove_clip_ary.length !=0 )
840 this.removeClips(remove_clip_ary);
841
842 //doEdit selected clips (updated selected resource)
843 //@@todo refresh menu of current
844 this.doEditSelectedClip();
845 },
846 addClip:function( clip, before_clip_pos, track_inx){
847 this.addClips([clip], before_clip_pos, track_inx)
848 },
849 //add a single or set of clips
850 //to a given position and track_inx
851 addClips:function( clipSet, before_clip_pos, track_inx){
852 this_seq = this;
853
854 if(!track_inx)
855 track_inx = this.plObj.default_track.inx;
856
857 if(!before_clip_pos)
858 before_clip_pos= this.plObj.default_track.getClipCount();
859
860 js_log("seq: add clip: at: "+ before_clip_pos + ' in track: ' + track_inx);
861 var cur_pos = before_clip_pos;
862
863 $j.each(clipSet, function(inx, clipInitDom){
864 var mediaElement = document.createElement('ref');
865 for(var i in clipInitDom){
866 js_log("set: " + i + ' to ' + clipInitDom[i]);
867 if(i!='id')
868 $j(mediaElement).attr(i, clipInitDom[i]);
869 }
870 if( this_seq.plObj.tryAddMedia( mediaElement, cur_pos, track_inx ) )
871 cur_pos++;
872 });
873 //debugger;
874 this.do_refresh_timeline();
875 },
876 removeClips:function( remove_clip_ary ){
877 var this_seq = this;
878 var jselect = coma ='';
879 js_log('clip count before removal : ' + this_seq.plObj.default_track.clips.length + ' should remove ' + remove_clip_ary.length );
880 var afected_tracks = new Array();
881 //add order to track_clip before we start removing:
882 $j.each( remove_clip_ary, function(inx, track_clip){
883 remove_clip_ary[inx]['order'] = this_seq.plObj.tracks[ track_clip[0] ].clips[ track_clip[1] ].order;
884 });
885 $j.each( remove_clip_ary, function(inx, track_clip){
886 var track_inx = track_clip[0];
887 var clip_inx = track_clip[1];
888 var clip_rm_order = track_clip['order'];
889 js_log('remove t:' + track_inx + ' c:'+ clip_inx + ' id:' +' #track_'+track_inx+'_clip_'+clip_inx + ' order:' + clip_rm_order);
890 //remove the clips from the base tracks
891 for(var i in this_seq.plObj.tracks[ track_inx ].clips){
892 cur_clip = this_seq.plObj.tracks[ track_inx ].clips[i]
893 if(cur_clip.order == clip_rm_order){
894 this_seq.plObj.tracks[ track_clip[0] ].clips.splice( i, 1);
895 }
896 }
897 //add track to affected track list:
898 afected_tracks[ track_inx ]=true;
899 jselect += coma + '#track_' +track_inx + '_clip_' + clip_inx;
900 coma=',';
901 });
902 //update/ reorder:
903 $j.each(afected_tracks, function(track_inx, affected){
904 this_seq.plObj.tracks[track_inx].reOrderClips();
905 });
906
907 js_log('clip count after removal : ' + this_seq.plObj.default_track.clips.length);
908 //animate the removal (@@todo should be able to call the resulting fadeOut only once without a flag)
909 var done_with_refresh=false;
910 $j(jselect).fadeOut("slow", function(){
911 if( !done_with_refresh )
912 this_seq.do_refresh_timeline();
913 done_with_refresh=true;
914 }).empty(); //empty to remove any persistent bindings
915 },
916 doEdit:function( editObj ){
917 //add the current editObj to the edit stack (should allow for "undo")
918 this.edit_stack.push( editObj );
919 //make the adjustments
920 this.makeAdjustment( editObj );
921 },
922 /*
923 * takes adjust ment object with options:
924 * track_inx, clip_inx, start, end delta
925 */
926 makeAdjustment:function(e){
927 switch(e.type){
928 case 'resize_start':
929 this.plObj.tracks[e.track_inx].clips[e.clip_inx].doAdjust('start', e.delta);
930 break;
931 case 'resize_end':
932 this.plObj.tracks[e.track_inx].clips[e.clip_inx].doAdjust('end', e.delta);
933 break;
934 }
935 js_log('re render: '+e.track_inx);
936 //refresh the playlist after adjustment
937 this.do_refresh_timeline();
938 },
939 //@@todo set up key bindings for undo
940 undoEdit:function(){
941 var editObj = this.edit_stack.pop();
942 //invert the delta
943
944 },
945 exc_track:function(inx,req){
946 this_seq = this;
947 if(req=='close'){
948 $j('#mv_exc_'+inx).attr('href', 'javascript:'+this.instance_name+'.exc_track('+inx+',\'open\')');
949 $j('#mv_exc_'+inx + ' > img').attr('src',mv_embed_path + 'images/closed.png');
950 $j('#track_cnt_'+inx+',#container_track_'+inx).animate({height:this.track_text_height}, "slow",'',
951 function(){
952 this_seq.plObj.tracks[inx].disp_mode='text';
953 this_seq.render_tracks( inx );
954 });
955 }else if(req=='open'){
956 $j('#mv_exc_'+inx).attr('href', 'javascript:'+this.instance_name+'.exc_track('+inx+',\'close\')');
957 $j('#mv_exc_'+inx + ' > img').attr('src',mv_embed_path + 'images/opened.png');
958 $j('#track_cnt_'+inx+',#container_track_'+inx).animate({height:this.track_thumb_height}, "slow",'',
959 function(){
960 this_seq.plObj.tracks[inx].disp_mode='timeline_thumb';
961 this_seq.render_tracks(inx);
962 });
963
964 }
965 },
966 //adds tracks
967 add_track:function(inx, track){
968
969 },
970 //toggle cut mode (change icon to cut)
971 cut_mode:function(){
972 js_log('do cut mode');
973 //add cut layer ontop of clips
974 },
975 doAdvancedTl:function(){
976 this.timeline_mode='time';
977 this.renderTimeLine();
978 this.do_refresh_timeline();
979 return false;
980 },
981 doSimpleTl:function(){
982 this.timeline_mode='storyboard';
983 this.renderTimeLine();
984 this.do_refresh_timeline();
985 return false;
986 },
987 //renders updates the timeline based on the current scale
988 render_tracks:function( track_inx ){
989 js_log("f::render track: "+track_inx);
990 var this_seq = this;
991 //inject the tracks into the timeline (if not already there)
992 for(var track_id in this.plObj.tracks){
993 if( track_inx==track_id || typeof track_inx=='undefined' ){
994 //empty out the track container:
995 //$j('#container_track_'+track_id).empty();
996 var track_html=droppable_html='';
997 //set up per track vars:
998 var track = this.plObj.tracks[track_id];
999 var cur_clip_time=0;
1000
1001 //set up some constants for timeline_mode == storyboard:
1002 if(this.timeline_mode == 'storyboard'){
1003 var frame_width = Math.round( this.track_clipThumb_height * 1.3333333 );
1004 var container_width = frame_width+60;
1005 }
1006
1007 //for each clip:
1008 for(var j in track.clips){
1009 clip = track.clips[j];
1010 //var img = clip.getClipImg('icon');
1011 if( this.timeline_mode == 'storyboard' ){
1012 clip.left_px = j*container_width;
1013 clip.width_px = container_width;
1014 var base_id = 'track_'+track_id+'_clip_'+j;
1015 track_html += '<span id="'+base_id+'" '+
1016 'class="mv_storyboard_container mv_clip_drag" '+
1017 'style="'+
1018 'left:'+clip.left_px+'px;'+
1019 'height:' + (this.track_clipThumb_height+30) + 'px;' +
1020 'width:'+(container_width)+'px;" >';
1021 track_html += clip.embed.renderTimelineThumbnail({
1022 'width' : frame_width,
1023 'thumb_class' : 'mv_clip_thumb',
1024 'height':this.track_clipThumb_height,
1025 'time':0
1026 });
1027 //render out edit button
1028 /*track_html+='<div class="clip_edit_button clip_edit_base clip_control"/>';*/
1029
1030 //check if the clip has transitions
1031 var imgHtml = '';
1032 var imsrc = '';
1033 var cat = clip;
1034 if(clip.transIn || clip.transOut){
1035 if( clip.transIn && clip.transIn.getIconSrc )
1036 imsrc = clip.transIn.getIconSrc();
1037 //@@todo put transOut somewhere else
1038 if( clip.transOut && clip.transOut.getIconSrc )
1039 imsrc = clip.transOut.getIconSrc();
1040 if(imsrc != '')
1041 imgHtml = '<img style="width:32px;height:32px" src="' + imsrc + '" />';
1042 }
1043 //render out transition edit box
1044 track_html += '<div id="tb_' + base_id + '" class="clip_trans_box">' +
1045 imgHtml +
1046 '</div>'
1047
1048 //render out adjustment text
1049 /*track_html+='<div id="' + base_id + '_adj' + '" class="mv_adj_text" style="top:'+ (this.track_clipThumb_height+10 )+'px;">'+
1050 '<span class="mv_adjust_click" onClick="'+this.instance_name+'.adjClipDur(' + track_id + ',' + j + ',\'-\')" /> - </span>'+
1051 ( (clip.getDuration() > 60 )? seconds2npt(clip.getDuration()): clip.getDuration() ) +
1052 '<span class="mv_adjust_click" onClick="'+this.instance_name+'.adjClipDur(' + track_id + ',' + j + ',\'+\')" /> + </span>'+
1053 '</div>';
1054 */
1055 track_html+='</span>';
1056
1057 }
1058 //do timeline_mode rendering:
1059 if(this.timeline_mode == 'time'){
1060 clip.left_px = Math.round( cur_clip_time/this.timeline_scale);
1061 clip.width_px = Math.round( Math.round( clip.getDuration() )/this.timeline_scale);
1062 clip.height_px = 60;
1063 js_log('at time:' + cur_clip_time + ' left: ' +clip.left_px + ' clip dur: ' + Math.round( clip.getDuration() ) + ' clip width:' + clip.width_px);
1064
1065 //for every clip_width pixle output image
1066 if(track.disp_mode=='timeline_thumb'){
1067 track_html+='<span id="track_'+track_id+'_clip_'+j+'" '+
1068 'class="mv_tl_clip mv_clip_drag" '+
1069 'style="'+
1070 'left:' + clip.left_px + 'px;'+
1071 'width:'+ clip.width_px + 'px;'+
1072 'height:'+ clip.height_px + 'px" >';
1073 track_html+= this.render_clip_frames( clip );
1074 }else if(track.disp_mode=='text'){
1075 //'+left_px+
1076 track_html+='<span id="track_'+track_id+'_clip_'+j+'" style="left:'+clip.left_px+'px;'+
1077 'width:'+clip.width_px+'px;background:'+clip.getColor()+
1078 '" class="mv_time_clip_text mv_clip_drag">'+clip.title;
1079 }
1080 //add in per clip controls
1081 track_html+='<div title="'+gM('clip_in')+' '+clip.embed.start_ntp+'" class="ui-resizable-w ui-resizable-handle" style="width: 16px; height: 16px; left: 0px; top: 2px;background:url(\''+mv_embed_path+'images/application_side_contract.png\');" ></div>'+"\n";
1082 track_html+='<div title="'+gM('clip_out')+' '+clip.embed.end_ntp+'" class="ui-resizable-e ui-resizable-handle" style="width: 16px; height: 16px; right: 0px; top: 2px;background:url(\''+mv_embed_path+'images/application_side_expand.png\');" ></div>'+"\n";
1083 track_html+='<div title="'+gM('rmclip')+'" onClick="'+this.instance_name + '.removeClips(new Array([' + track_id + ',' + j + ']))" style="position:absolute;cursor:pointer;width: 16px; height: 16px; left: 0px; bottom:2px;background:url(\''+mv_embed_path+'images/delete.png\');"></div>'+"\n";
1084 track_html+='<span style="display:none;" class="mv_clip_stats"></span>';
1085
1086 track_html+='</span>';
1087 //droppable_html+='<div id="dropBefore_'+i+'_c_'+j+'" class="mv_droppable" style="height:'+this.track_thumb_height+'px;left:'+clip.left_px+'px;width:'+Math.round(clip.width_px/2)+'px"></div>';
1088 //droppable_html+='<div id="dropAfter_'+i+'_c_'+j+'" class="mv_droppable" style="height:'+this.track_thumb_height+'px;left:'+(clip.left_px+Math.round(clip.width_px/2))+'px;width:'+(clip.width_px/2)+'px"></div>';
1089 cur_clip_time+=Math.round( clip.getDuration() ); //increment cur_clip_time
1090 }
1091
1092 }
1093
1094 //js_log("new htmL for track i: "+track_id + ' html:'+track_html);
1095 $j('#container_track_'+track_id).html( track_html );
1096
1097 //apply transition click action
1098 $j('.clip_trans_box').click(function(){
1099 if($j(this).hasClass('mv_selected_transition')){
1100 $j(this).removeClass('mv_selected_transition');
1101 this_seq.deselectClip( $j(this).siblings('.mv_clip_thumb').get(0) );
1102 }else{
1103 //deselect others
1104 $j('.clip_trans_box').removeClass('mv_selected_transition');
1105 $j(this).addClass("mv_selected_transition");
1106 $j(this).siblings('.mv_clip_thumb').addClass("mv_selected_clip");
1107 var sClipObj = this_seq.getClipFromSeqID( $j(this).parent().attr('id') );
1108 //jump to the current clip
1109 this_seq.plObj.updateCurrentClip( sClipObj );
1110 //display the transition edit tab:
1111 this_seq.disp( 'transition' );
1112 }
1113 });
1114
1115 //apply edit button mouse over effect:
1116 $j('.clip_edit_button').hover(function(){
1117 $j(this).removeClass("clip_edit_base").addClass("clip_edit_over");
1118 },function(){
1119 $j(this).removeClass("clip_edit_over").addClass("clip_edit_base");
1120 }).click(function(){
1121 //deselect everything else:
1122 $j('.mv_selected_clip').each(function(inx, selected_clip){
1123 this_seq.deselectClip( this );
1124 });
1125
1126 var sClipObj = this_seq.getClipFromSeqID( $j(this).parent().attr('id') );
1127 this_seq.plObj.updateCurrentClip( sClipObj );
1128 //get the clip (siblings with mv_clip_thumb class)
1129 var cur_clip_elm = $j(this).siblings('.mv_clip_thumb');
1130 //select the clip (add mv_selected_clip if not already selected)
1131 if( ! $j( cur_clip_elm ).hasClass("mv_selected_clip") ){
1132 $j( cur_clip_elm ).addClass('mv_selected_clip');
1133 $j('#' + $j( cur_clip_elm ).parent().attr("id") + '_adj').fadeIn("fast");
1134 }
1135 //display the edit tab:
1136 this_seq.disp( 'clipedit' );
1137 //display edit dialog:
1138 this_seq.doEditClip( sClipObj );
1139 });
1140
1141 //apply onClick edit controls:
1142 $j('.mv_clip_thumb').click(function(){
1143 var cur_clip_click = this;
1144 //if not in multi select mode remove all existing selections
1145 //(except for the current click which is handled down below)
1146 js_log(' ks: ' + this_seq.key_shift_down + ' ctrl_down:' +this_seq.key_ctrl_down);
1147 if( ! this_seq.key_shift_down && ! this_seq.key_ctrl_down){
1148 $j('.mv_selected_clip').each(function(inx, selected_clip){
1149 if( $j(this).parent().attr('id') != $j(cur_clip_click).parent().attr('id')
1150 || ( $j('.mv_selected_clip').length > 1 ) ){
1151 this_seq.deselectClip( this );
1152 }
1153 });
1154 }
1155
1156 //jump to clip time
1157 var sClipObj = this_seq.getClipFromSeqID( $j(this).parent().attr('id') );
1158 this_seq.plObj.updateCurrentClip( sClipObj );
1159 if( $j(this).hasClass("mv_selected_clip") ){
1160 $j(this).removeClass("mv_selected_clip");
1161 $j('#' + $j(this).parent().attr("id") + '_adj').fadeOut("fast");
1162 }else{
1163 $j(this).addClass('mv_selected_clip');
1164 $j('#' + $j(this).parent().attr("id") + '_adj').fadeIn("fast");
1165 }
1166 //if shift select is down select the in-between clips
1167 if( this_seq.key_shift_down ){
1168 //get the min max of current selection (within the current track)
1169 var max_order = 0;
1170 var min_order = 999999999;
1171 $j('.mv_selected_clip').each(function(){
1172 var cur_clip = this_seq.getClipFromSeqID( $j(this).parent().attr('id') );
1173 //get min max
1174 if(cur_clip.order < min_order)
1175 min_order = cur_clip.order;
1176 if(cur_clip.order > max_order)
1177 max_order = cur_clip.order;
1178 });
1179 //select all non-selected between max or min
1180 js_log('sOrder: ' + sClipObj.order + ' min:' + min_order + ' max:'+ max_order);
1181 if( sClipObj.order <= min_order ){
1182 for( var i = sClipObj.order; i <= max_order; i++ ){
1183 $j('#track_' + track_id + '_clip_' + i + ' > .mv_clip_thumb' ).addClass('mv_selected_clip');
1184 }
1185 }
1186 if( sClipObj.order >= max_order ){
1187 for( var i =min_order; i <= max_order; i++ ){
1188 $j('#track_' + track_id + '_clip_' + i + ' > .mv_clip_thumb' ).addClass('mv_selected_clip');
1189 }
1190 }
1191 }
1192 this_seq.doEditSelectedClip();
1193 });
1194 //add in control for time based display
1195 //debugger;
1196 if(this.timeline_mode == 'time'){
1197 $j('.ui-resizable-handle').mousedown( function(){
1198 js_log('hid: ' + $j(this).attr('class'));
1199 this_seq.resize_mode = ($j(this).attr('class').indexOf('ui-resizable-e')!=-1)?
1200 'resize_end':'resize_start';
1201 });
1202 }
1203 var insert_key='na';
1204 // drag hooks:
1205 //@@todo support multiple clips
1206 for(var j in track.clips){
1207 $j('#track_'+track_id+'_clip_'+j).draggable({
1208 axis:'x',
1209 containment:'#container_track_'+track_id,
1210 opacity:50,
1211 handle: ":not(.clip_control)",
1212 scroll:true,
1213 drag:function(e, ui){
1214 //debugger;
1215 insert_key = this_seq.clipDragUpdate(ui, this);
1216 },
1217 start:function(e,ui){
1218 js_log('start drag:' + this.id);
1219 //make sure we are ontop
1220 $j(this).css({top:'0px',zindex:10});
1221 },
1222 stop:function(e, ui){
1223 $j(this).css({top:'0px',zindex:0});
1224
1225 var id_parts = this.id.split('_');
1226 var track_inx = id_parts[1];
1227 var clip_inx = id_parts[3];
1228 var clips = this_seq.plObj.tracks[track_inx].clips;
1229 var cur_drag_clip = clips[clip_inx];
1230
1231 if(insert_key!='na' && insert_key!='end' ){
1232 cur_drag_clip.order=insert_key-.5;
1233 }else if (insert_key=='end'){
1234 cur_drag_clip.order=clips.length;
1235 }
1236 //reorder array based on new order
1237 clips.sort(sort_func);
1238 function sort_func(a, b){
1239 return a.order - b.order;
1240 }
1241 //assign keys back to order:
1242 this_seq.plObj.tracks[track_inx].reOrderClips();
1243 //redraw:
1244 this_seq.do_refresh_timeline();
1245 }
1246 });
1247 //add in resize hook if in time mode:
1248 if(this.timeline_mode == 'time'){
1249 $j('#track_'+track_id+'_clip_'+j).resizable({
1250 minWidth:10,
1251 maxWidth:6000,
1252 start: function(e,ui) {
1253 //set border to red
1254 $j(this).css({'border':'solid thin red'});
1255 //fade In Time stats (end or start based on handle)
1256 //dragging east (adjusting end time)
1257 js_log( 'append to: '+ this.id);
1258 $j('#' + this.id + ' > .mv_clip_stats').fadeIn("fast");
1259 },
1260 stop: function(e,ui) {
1261 js_log('stop resize');
1262 //restore border
1263 $j(this).css('border', 'solid thin white');
1264 //remove stats
1265 var clip_drag = this;
1266 $j('#'+this.id+' > .mv_clip_stats').fadeOut("fast",function(){
1267 var id_parts = clip_drag.id.split('_');
1268 var track_inx = id_parts[1];
1269 var clip_inx = id_parts[3];
1270 //update clip
1271 this_seq.doEdit({
1272 type:this_seq.resize_mode,
1273 delta:this_seq.edit_delta,
1274 track_inx:track_inx,
1275 clip_inx:clip_inx})
1276 });
1277 },
1278 resize: function(e,ui) {
1279 //update time stats & render images:
1280 this_seq.update_clip_resize(this);
1281 }
1282 });
1283 }
1284 }
1285 $j('#container_track_'+track_id).width(Math.round( this.timeline_duration / this.timeline_scale));
1286 }
1287 //debugger;
1288 }
1289 },
1290 clipDragUpdate:function( ui, clipElm){
1291 var this_seq = this;
1292
1293 var insert_key='na';
1294 //animate re-arrange by left position:
1295 //js_log('left: '+ui.position.left);
1296 //locate clip (based on clip duration not animate)
1297 var id_parts = clipElm.id.split('_');
1298 var track_inx = id_parts[1];
1299 var clip_inx = id_parts[3];
1300 var clips = this_seq.plObj.tracks[track_inx].clips;
1301 var cur_drag_clip = clips[clip_inx];
1302 var return_org = true;
1303 $j(clipElm).css('zindex',10);
1304 //find out where we are inserting and set left border to solid red thick
1305 for(var k in clips){
1306 if( ui.position.left > clips[k].left_px &&
1307 ui.position.left < (clips[k].left_px + clips[k].width_px)){
1308 if(clip_inx!=k){
1309 //also make sure we are not where we started
1310 if(k-1!=clip_inx){
1311 $j('#track_'+track_inx+'_clip_'+k).css('border-left', 'solid thick red');
1312 insert_key=k;
1313 }else{
1314 insert_key='na';
1315 }
1316 }else{
1317 insert_key='na';
1318 }
1319 }else{
1320 $j('#track_'+track_inx+'_clip_'+k).css('border-left', 'solid thin white');
1321 }
1322 }
1323 //if greater than the last k insert after
1324 if(ui.position.left > (clips[k].left_px + clips[k].width_px) &&
1325 k!=clip_inx ){
1326 $j('#track_'+track_inx+'_clip_'+k).css('border-right', 'solid thick red');
1327 insert_key='end';
1328 }else{
1329 $j('#track_'+track_inx+'_clip_'+k).css('border-right', 'solid thin white');
1330 }
1331 return insert_key;
1332 },
1333 deselectClip:function( clipElm ){
1334 $j(clipElm).removeClass("mv_selected_clip");
1335 //make sure the transition sibling is removed:
1336 $j(clipElm).siblings('.clip_trans_box').removeClass( 'mv_selected_transition' );
1337 $j('#' + $j(clipElm).parent().attr("id") + '_adj').fadeOut("fast");
1338 },
1339 getClipFromSeqID:function( clip_seq_id ){
1340 js_log('get id from: ' + clip_seq_id);
1341 var ct = clip_seq_id.replace('track_','').replace('clip_','').split('_');
1342 return this.plObj.tracks[ ct[0] ].clips[ ct[1] ];
1343 },
1344 //renders clip frames
1345 render_clip_frames:function(clip, frame_offset_count){
1346 js_log('f:render_clip_frames: ' + clip.id + ' foc:' + frame_offset_count);
1347 var clip_frames_html='';
1348 var frame_width = Math.round(this.track_thumb_height*1.3333333);
1349
1350 var pint = (frame_offset_count==null)?0:frame_offset_count*frame_width;
1351
1352 //js_log("pinit: "+ pint+ ' < '+clip.width_px+' ++'+frame_width);
1353 for(var p=pint;p<clip.width_px;p+=frame_width){
1354 var clip_time = (p==0)?0:Math.round(p*this.timeline_scale);
1355 js_log('rendering clip frames: p:' +p+' pts:'+ (p*this.timeline_scale)+' time:' + clip_time + ' height:'+this.track_thumb_height);
1356 clip_frames_html+=clip.embed.renderTimelineThumbnail({
1357 'width': frame_width,
1358 'thumb_class':'mv_tl_thumb',
1359 'height': this.track_thumb_height,
1360 'size' : "icon", //set size to "icon" preset
1361 'time': clip_time
1362 });
1363 }
1364 js_log('render_clip_frames:'+clip_frames_html);
1365 return clip_frames_html;
1366 },
1367 update_clip_resize:function(clip_element){
1368 //js_log('update_clip_resize');
1369 var this_seq = this;
1370 var id_parts = clip_element.id.split('_');
1371 track_inx = id_parts[1];
1372 clip_inx = id_parts[3];
1373 //set clip:
1374 var clip = this.plObj.tracks[ track_inx ].clips[ clip_inx ];
1375 var clip_desc ='';
1376 //would be nice if getting the width did not flicker the border
1377 //@@todo do a work around e in resize function has some screen based offset values
1378 clip.width_px = $j(clip_element).width();
1379 var width_dif = clip.width_px - Math.round( Math.round( clip.getDuration() )/this.timeline_scale);
1380 //var left_px = $j(clip_element).css('left');
1381
1382 var new_clip_dur = Math.round( clip.width_px*this.timeline_scale );
1383 var clip_dif = (new_clip_dur - clip.getDuration() );
1384 var clip_dif_str = (clip_dif >0)?'+'+clip_dif:clip_dif;
1385 //set the edit global delta
1386 this.edit_delta = clip_dif;
1387
1388 //get new length:
1389 clip_desc+='length: ' + seconds2npt(new_clip_dur) +'('+clip_dif_str+')';
1390 if(this_seq.resize_mode=='resize_end'){
1391 //expanding right
1392 var new_end = seconds2npt(npt2seconds(clip.embed.end_ntp)+clip_dif);
1393 clip_desc+='<br>end time: ' + new_end;
1394 //also shift all the other clips (after the current)
1395 //js_log("track_inx: " + track_inx + ' clip inx:'+clip_inx);
1396 //$j('#container_track_'+track_inx+' > .mv_clip_drag :gt('+clip_inx+')').each(function(){
1397 $j('#container_track_'+track_inx+' > :gt('+clip_inx+')').each(function(){
1398 var move_id_parts = this.id.split('_');
1399 var move_clip = this_seq.plObj.tracks[move_id_parts[1]].clips[move_id_parts[3]];
1400 //js_log('should move:'+ this.id);
1401 $j(this).css('left', move_clip.left_px + width_dif);
1402 });
1403 }else{
1404 //expanding left (resize_start)
1405 var new_start = seconds2npt(npt2seconds(clip.embed.start_ntp)+clip_dif);
1406 clip_desc+='<br>start time: ' + new_start;
1407 }
1408
1409 //update clip stats:
1410 $j('#'+clip_element.id+' > .mv_clip_stats').html(clip_desc);
1411 var frame_width = Math.round(this.track_thumb_height*1.3333333);
1412 //check if we need to append some images:
1413 var frame_count = $j('#'+clip_element.id+' > img').length;
1414 if(clip.width_px > (frame_count * frame_width) ){
1415 //if dragging left append
1416 js_log('width_px:'+clip.width_px+' framecount:'+frame_count+' Xcw='+(frame_count * frame_width));
1417 $j('#'+clip_element.id).append(this.render_clip_frames(clip, frame_count));
1418 }
1419 },
1420 //renders cnt_time
1421 render_playheadhead_seeker:function(){
1422 //render out time stamps and time "jump" links
1423 //first get total width
1424
1425 //remove the old one if its still there
1426 $j('#'+this.timeline_id +'_pl_control').remove();
1427 js_log('output controls to: ' + this.target_sequence_container);
1428 //render out a playlist clip wide and all the way to the right (only playhead and play button) (outside of timeline)
1429 $j(this.target_sequence_container).append('<div id="'+ this.timeline_id +'_pl_control"'+
1430 ' style="position:absolute;top:' + (this.plObj.height) +'px;'+
1431 'right:1px;width:'+this.plObj.width+'px;height:'+this.plObj.org_control_height+'" '+
1432 'class="videoPlayer"><div class="ui-widget ui-corner-bottom ui-state-default controls">'+
1433 this.plObj.getControlsHTML() +
1434 '</div>'+
1435 '</div>');
1436 //update time and render out clip dividers .. should be used to show load progress
1437 this.plObj.updateBaseStatus();
1438
1439 //once the controls are in the DOM add hooks:
1440 ctrlBuilder.addControlHooks(this.plObj);
1441
1442 //render out the "jump" div
1443 if(this.timeline_mode=='time'){
1444 /*$j('#'+this.timeline_id+'_head_jump').width(pixle_length);
1445 //output times every 50pixles
1446 var out='';
1447 //output time-desc every 50pixles and jump links every 10 pixles
1448 var n=0;
1449 for(i=0;i<pixle_length;i+=10){
1450 out+='<div onclick="'+this.instance_name+'.jt('+i*this.timeline_scale+');"' +
1451 ' style="z-index:2;position:absolute;left:'+i+'px;width:10px;height:20px;top:0px;"></div>';
1452 if(n==0)
1453 out+='<span style="position:absolute;left:'+i+'px;">|'+seconds2npt(Math.round(i*this.timeline_scale))+'</span>';
1454 n++;
1455 if(n==10)n=0;
1456 }*/
1457
1458 }
1459 },
1460 jt:function( jh_time ){
1461 js_log('jt:' + jh_time);
1462 var this_seq = this;
1463 this.playline_time = jh_time;
1464 js_log('time: ' + seconds2npt(jh_time) + ' ' + Math.round(jh_time/this.timeline_scale));
1465 //render playline at given time
1466 $j('#'+this.timeline_id+'_playline').css('left', Math.round(jh_time/this.timeline_scale)+'px' );
1467 cur_pl_time=0;
1468 //update the thumb with the requested time:
1469 this.plObj.updateThumbTime( jh_time );
1470 },
1471 //adjusts the current scale
1472 zoom_in:function(){
1473 this.timeline_scale = this.timeline_scale*.75;
1474 this.do_refresh_timeline();
1475 js_log('zoomed in:'+this.timeline_scale);
1476 },
1477 zoom_out:function(){
1478 this.timeline_scale = this.timeline_scale*(1+(1/3));
1479 this.do_refresh_timeline();
1480 js_log('zoom out: '+this.timeline_scale);
1481 },
1482 do_refresh_timeline:function( preserve_selection ){
1483 //@@todo should "lock" interface while refreshing timeline
1484 var pSelClips = [];
1485 if(preserve_selection){
1486 $j('.mv_selected_clip').each(function(){
1487 pSelClips.push( $j(this).parent().attr('id') );
1488 });
1489 }
1490 //regen duration
1491 this.plObj.getDuration( true );
1492 //refresh player:
1493 this.plObj.getHTML();
1494
1495 this.render_playheadhead_seeker();
1496 this.render_tracks();
1497 this.jt(this.playline_time);
1498
1499 if(preserve_selection){
1500 for(var i=0;i < pSelClips.length; i++){
1501 $j('#' + pSelClips[i] + ' .mv_clip_thumb').addClass('mv_selected_clip');
1502 }
1503 }
1504 }
1505
1506 }
1507 /* extension to mvPlayList to support sequencer features properties */
1508 var mvSeqPlayList = function( element ){
1509 return this.init( element );
1510 }
1511 mvSeqPlayList.prototype = {
1512 init:function(element){
1513 var myPlObj = new mvPlayList(element);
1514 //inherit mvClip
1515 for(var method in myPlObj){
1516 if(typeof this[method] != 'undefined' ){
1517 this['parent_'+method]=myPlObj[method];
1518 }else{
1519 this[method] = myPlObj[method];
1520 }
1521 }
1522 this.org_control_height = this.pl_layout.control_height;
1523 //do specific mods:(controls and title are managed by the sequencer)
1524 this.pl_layout.title_bar_height=0;
1525 this.pl_layout.control_height=0;
1526 },
1527 setSliderValue:function( perc ){
1528 //get the track_clipThumb_height from parent mvSequencer
1529 var frame_width = Math.round( this.pSeq.track_clipThumb_height * 1.3333333 );
1530 var container_width = frame_width+60;
1531
1532 var perc_clip = this.cur_clip.embed.currentTime / this.cur_clip.getDuration();
1533
1534 var left_px = parseInt( (this.cur_clip.order * container_width) + (frame_width*perc_clip) ) + 'px';
1535 js_log("set " + perc + ' of cur_clip: ' + this.cur_clip.order + ' lp:'+left_px);
1536
1537
1538 //update the timeline playhead and
1539 $j('#'+ this.seqObj.timeline_id + '_playline').css('left', left_px);
1540
1541 //pass update request to parent:
1542 this.parent_setSliderValue( perc );
1543 },
1544 getControlsHTML:function(){
1545 //get controls from current clip add some playlist specific controls:
1546 this.cur_clip.embed.supports['prev_next'] = true;
1547 this.cur_clip.embed.supports['options'] = false;
1548 return ctrlBuilder.getControls( this.cur_clip.embed );
1549 },
1550 //override renderDisplay
1551 renderDisplay:function(){
1552 js_log('mvSequence:renderDisplay');
1553 //setup layout for title and dc_ clip container
1554 $j(this).html('<div id="dc_'+this.id+'" style="width:'+this.width+'px;' +
1555 'height:'+(this.height)+'px;position:relative;" />');
1556
1557 this.setupClipDisplay();
1558 }
1559 };