r72274 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72273‎ | r72274 | r72275 >
Date:09:16, 3 September 2010
Author:dale
Status:deferred
Tags:
Comment:
* improved template slide editing
Modified paths:
  • /branches/MwEmbedStandAlone/components/mw.Api.js (modified) (history)
  • /branches/MwEmbedStandAlone/components/mw.Parser.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js (modified) (history)
  • /branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/components/mw.Api.js
@@ -48,7 +48,7 @@
4949 return ;
5050 }
5151 }
52 - callbac( false );
 52+ callback( false );
5353 } );
5454 }
5555
Index: branches/MwEmbedStandAlone/components/mw.Parser.js
@@ -33,7 +33,8 @@
3434 */
3535 mw.Parser = function( wikiText, options) {
3636 // return the parserObj
37 - this.init( wikiText, options ) ;
 37+ this.init( wikiText, options ) ;
 38+ return this;
3839 };
3940
4041 mw.Parser.prototype = {
@@ -42,7 +43,13 @@
4344 pOut: false,
4445
4546 init: function( wikiText, parserOptions ) {
46 - this.wikiText = wikiText;
 47+ this.wikiText = wikiText;
 48+
 49+ var defaultParserOptions = {
 50+ 'templateParCount' : 2
 51+ }
 52+
 53+ this.options = $j.extend( defaultParserOptions, parserOptions);
4754 },
4855
4956 // Update the text value
@@ -52,24 +59,40 @@
5360 // invalidate the output ( will force a re-parse )
5461 this.pOut = false;
5562 },
56 -
 63+ // checks if the required number of parenthesis are found
 64+ // xxx this is just a stop gap solution
 65+ checkParlookAheadOpen: function(text, a){
 66+ if( this.options.templateParCount == 2 ){
 67+ return ( text[a] == '{' && text[a + 1] == '{' );
 68+ } else if( this.options.templateParCount == 3 ) {
 69+ return ( text[a] == '{' && text[a + 1] == '{' && text[a + 2] == '{');
 70+ }
 71+ },
 72+ checkParlookAheadClose: function( text, a){
 73+ if( this.options.templateParCount == 2 ){
 74+ return ( text[a] == '}' && text[a + 1] == '}' );
 75+ } else if( this.options.templateParCount == 3 ) {
 76+ return ( text[a] == '}' && text[a + 1] == '}' && text[a + 2] == '}');
 77+ }
 78+ },
5779 /**
5880 * Quickly recursive / parse out templates:
5981 */
6082 parse: function() {
 83+ var _this = this;
6184 function recurseTokenizeNodes ( text ) {
6285 var node = { };
6386 // Inspect each char
6487 for ( var a = 0; a < text.length; a++ ) {
65 - if ( text[a] == '{' && text[a + 1] == '{' ) {
66 - a = a + 2;
 88+ if ( _this.checkParlookAheadOpen( text, a ) ) {
 89+ a = a + _this.options.templateParCount;
6790 node['parent'] = node;
6891 if ( !node['child'] ) {
6992 node['child'] = new Array();
7093 }
7194
7295 node['child'].push( recurseTokenizeNodes( text.substr( a ) ) );
73 - } else if ( text[a] == '}' && text[a + 1] == '}' ) {
 96+ } else if ( _this.checkParlookAheadClose( text, a ) ) {
7497 a++;
7598 if ( !node['parent'] ) {
7699 return node;
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js
@@ -396,15 +396,10 @@
397397 );
398398 // Links go to a new window and are disable when smaller than player size
399399 $html.find('a').each( function(inx, link ){
400 - if( scalePercent < 1 ){
401 - $j(link).attr('href', '#');
402 - } else {
403 - $j(link).attr('target', '_new');
404 - // Filter the link for any xss
405 - $j(link).attr('href',
406 - mw.escapeQuotesHTML( $j(link).attr('href') )
407 - )
408 - }
 400+ // escape link output as to not include scirpt execution
 401+ $j(link).attr('href',
 402+ mw.escapeQuotesHTML( $j(link).attr('href') )
 403+ )
409404 });
410405
411406 // Make every asset url absolute and restrict domain of assets
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js
@@ -27,7 +27,7 @@
2828 'editWidgets' : [ 'trimTimeline' ],
2929 'editableAttributes' : ['clipBegin','dur' ],
3030 'contentTypes': ['video', 'audio']
31 - },
 31+ },
3232 'duration':{
3333 'editableAttributes' : [ 'dur' ],
3434 'contentTypes': ['img', 'mwtemplate']
@@ -38,9 +38,14 @@
3939 'contentTypes': [ 'img'], // xxx todo add video support
4040 'animate' : 'true'
4141 },
 42+ 'templateedit':{
 43+ 'editWidgets' : ['edittemplate'],
 44+ 'editableAttributes' : [ 'apiTitleKey' ],
 45+ 'contentTypes' : ['mwtemplate']
 46+ },
4247 'transitions' : {
4348 'editableAttributes' : [ 'transIn', 'transOut' ],
44 - 'contentTypes': ['video', 'img' ]
 49+ 'contentTypes': ['video', 'img', 'mwtemplate' ]
4550 }
4651 },
4752 editableAttributes:{
@@ -53,11 +58,16 @@
5459 'title' : gM('mwe-sequencer-clip-duration' )
5560 },
5661 'panZoom' :{
57 - 'type' : 'display',
 62+ 'type' : 'string',
5863 'inputSize' : 15,
5964 'title' : gM('mwe-sequencer-clip-panzoom' ),
6065 'defaultValue' : '0%, 0%, 100%, 100%'
6166 },
 67+ 'apiTitleKey' : {
 68+ 'type' : 'string',
 69+ 'inputSize' : 15,
 70+ 'title' : gM('mwe-sequencer-template-name' )
 71+ },
6272 'transIn' : {
6373 'type' : 'select',
6474 'selectValues' : [ 'fadeFromColor' ]
@@ -65,10 +75,35 @@
6676 'transOut' : {
6777 'type' : 'select',
6878 'selectValues' : [ 'fadeFromColor', 'crossfade' ]
 79+ },
 80+ // Special child node type
 81+ 'param' : {
 82+ 'type' : 'childParam',
 83+ 'inputSize' : 20
6984 }
7085 },
7186 editableTypes: {
72 - 'display': {
 87+ 'childParam': {
 88+ update: function( _this, smilElement, paramName, value){
 89+ // Check if the param already exists
 90+ $paramNode = $j( smilElement ).find( "[name='"+ paramName + '"]' );
 91+ if( $paramNode.length == 0){
 92+ $j( smilElement ).append(
 93+ $j('<param />').attr('name', paramName)
 94+ )
 95+ }
 96+ // Update the param value
 97+ $paramNode.attr( 'value', value);
 98+ },
 99+ getSmilVal: function( _this, smilElement, paramName, value){
 100+ $paramNode = $j( smilElement ).find( "[name='"+ paramName + '"]' );
 101+ if( $paramNode.length == 0){
 102+ return '';
 103+ }
 104+ $paramNode.attr('value');
 105+ }
 106+ },
 107+ 'string': {
73108 update: function( _this, smilElement, attributeName, value){
74109 $j( smilElement ).attr( attributeName, value);
75110 // update the display
@@ -149,6 +184,53 @@
150185 }
151186 },
152187 editWidgets: {
 188+ 'edittemplate':{
 189+ 'onChange' : function( _this, target, smilElement ){
 190+
 191+ },
 192+ 'draw': function( _this, target, smilElement ){
 193+ // Parse the set of templates from the template text cache
 194+ $j( target ).loadingSpinner();
 195+
 196+ if( ! $j( smilElement).attr('apititlekey') ){
 197+ mw.log("Error: can't grab template without title key")
 198+ return ;
 199+ }
 200+ // Get the template wikitext
 201+ _this.sequencer.getServer().getTemplateText($j( smilElement).attr('apititlekey'), function( templateText ){
 202+ if( ! templateText ){
 203+ mw.log("Error: could not get wikitext form titlekey: " + $j( smilElement).attr('apititlekey'))
 204+ return ;
 205+ }
 206+ $j( target ).empty().append(
 207+ $j('<h3 />').text('mwe-sequencer-edittemplate-params')
 208+ )
 209+
 210+ // This is not supposed to be perfect ..
 211+ // just get you 'most' of the input vars 'most' of the time via the greedy regEx:
 212+ var templateVars = templateText.match(/\{\{\{([^\}]*)\}\}\}/gi);
 213+ var cleanTemplateParams = {};
 214+ for( i =0;i<templateVars.length; i++ ){
 215+ var tVar = templateVars[i];
 216+ // Remove all {{{ and }}}
 217+ tVar = tVar.replace(/\{\{\{/, '' ).replace( /\}\}\}/, '');
 218+ // Check for | operator
 219+ if( tVar.indexOf("|") != -1 ){
 220+ // Only the first version of the template var
 221+ tVar = tVar.split( '|')[0];
 222+ }
 223+ cleanTemplateParams[ tVar ] = true;
 224+ }
 225+ // Output input boxes for each template var as a param
 226+ for( var paramName in cleanTemplateParams ){
 227+ $j( target ).append(
 228+ _this.getEditableAttribute(smilElement, 'edittemplate', 'param', paramName ),
 229+ $j('<br />')
 230+ )
 231+ }
 232+ });
 233+ }
 234+ },
153235 'panzoom' : {
154236 'onChange': function( _this, target, smilElement ){
155237 var panZoomVal = $j('#' +_this.getEditToolInputId( 'panzoom', 'panZoom')).val();
@@ -482,7 +564,7 @@
483565 )
484566 },
485567 getEditToolInputId: function( toolId, attributeName){
486 - return 'editTool_' + toolId + '_' + attributeName;
 568+ return 'editTool_' + toolId + '_' + attributeName.replace('/\s/', '');
487569 },
488570 /**
489571 * update the current displayed tool ( when an undo, redo or history jump changes smil state )
@@ -651,7 +733,7 @@
652734 return $actionButton;
653735 },
654736 /* get the editiable attribute input html */
655 - getEditableAttribute: function( smilElement, toolId, attributeName ){
 737+ getEditableAttribute: function( smilElement, toolId, attributeName, paramName ){
656738 if( ! this.editableAttributes[ attributeName ] ){
657739 mw.log("Error: editableAttributes : " + attributeName + ' not found');
658740 return;
@@ -663,15 +745,21 @@
664746 mw.log(" Error: No editableTypes interface for " + editType);
665747 return ;
666748 }
 749+ // Set the update key to the paramName if provided:
 750+ var updateKey = ( paramName ) ? paramName : attributeName;
 751+
667752 var initialValue = _this.editableTypes[ editType ].getSmilVal(
668753 _this,
669754 smilElement,
670 - attributeName
 755+ updateKey
671756 );
672757 // Set the default input size
673758 var inputSize = ( _this.editableAttributes[ attributeName ].inputSize)?
674759 _this.editableAttributes[ attributeName ].inputSize : 6;
675 -
 760+
 761+ // Set paramName based attributes:
 762+ var attributeTitle = ( editAttribute.title ) ? editAttribute.title : paramName;
 763+
676764 return $j( '<div />' )
677765 .css({
678766 'float': 'left',
@@ -685,22 +773,22 @@
686774 .append(
687775 $j('<span />')
688776 .css('margin', '5px')
689 - .text( editAttribute.title ),
 777+ .text( attributeTitle ),
690778
691779 $j('<input />')
692780 .attr( {
693 - 'id' : _this.getEditToolInputId( toolId, attributeName),
 781+ 'id' : _this.getEditToolInputId( toolId, updateKey ),
694782 'size': inputSize
695783 })
696784 .data('initialValue', initialValue )
697785 .sequencerInput( _this.sequencer )
698786 .val( initialValue )
699 - .change(function(){
 787+ .change(function(){
700788 // Run the editableType update function:
701789 _this.editableTypes[ editType ].update(
702790 _this,
703791 smilElement,
704 - attributeName,
 792+ updateKey,
705793 $j( this ).val()
706794 );
707795 // widgets can bind directly to this change action.
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js
@@ -35,6 +35,9 @@
3636 // Flags if the sequence was successfully saved in this session
3737 sequenceSaved: false,
3838
 39+ //Template cache of wikitext for templates loaded in this session
 40+ templateTextCache: [],
 41+
3942 /**
4043 * init the sequencer
4144 */
@@ -111,6 +114,17 @@
112115 callback( smilXml );
113116 })
114117 },
 118+ getTemplateText: function( templateTitle, callback ){
 119+ var _this = this;
 120+ if(this.templateTextCache[templateTitle]){
 121+ callback(templateTitle);
 122+ return ;
 123+ }
 124+ mw.getTitleText( this.getApiUrl(),templateTitle, function( templateText ){
 125+ _this.templateTextCache[templateTitle] = templateText;
 126+ callback(templateText);
 127+ });
 128+ },
115129 // Check if there have been local changes
116130 hasLocalChanges: function(){
117131 return ( this.serverSmilXml != this.sequencer.getSmil().getXMLString() );
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js
@@ -95,6 +95,14 @@
9696
9797 // Close the dialog loading:
9898 mw.closeLoaderDialog();
 99+
 100+ /*
 101+ * Soon sequence transclution fun:
 102+ * else if( titleKey.indexOf('Sequence:') == 0 ) {
 103+ */
 104+
 105+ } else {
 106+ $dialog.html( 'Error loading asset type');
99107 }
100108
101109 });

Status & tagging log