Index: branches/MwEmbedStandAlone/components/mw.Api.js |
— | — | @@ -48,7 +48,7 @@ |
49 | 49 | return ; |
50 | 50 | } |
51 | 51 | } |
52 | | - callbac( false ); |
| 52 | + callback( false ); |
53 | 53 | } ); |
54 | 54 | } |
55 | 55 | |
Index: branches/MwEmbedStandAlone/components/mw.Parser.js |
— | — | @@ -33,7 +33,8 @@ |
34 | 34 | */ |
35 | 35 | mw.Parser = function( wikiText, options) { |
36 | 36 | // return the parserObj |
37 | | - this.init( wikiText, options ) ; |
| 37 | + this.init( wikiText, options ) ; |
| 38 | + return this; |
38 | 39 | }; |
39 | 40 | |
40 | 41 | mw.Parser.prototype = { |
— | — | @@ -42,7 +43,13 @@ |
43 | 44 | pOut: false, |
44 | 45 | |
45 | 46 | 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); |
47 | 54 | }, |
48 | 55 | |
49 | 56 | // Update the text value |
— | — | @@ -52,24 +59,40 @@ |
53 | 60 | // invalidate the output ( will force a re-parse ) |
54 | 61 | this.pOut = false; |
55 | 62 | }, |
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 | + }, |
57 | 79 | /** |
58 | 80 | * Quickly recursive / parse out templates: |
59 | 81 | */ |
60 | 82 | parse: function() { |
| 83 | + var _this = this; |
61 | 84 | function recurseTokenizeNodes ( text ) { |
62 | 85 | var node = { }; |
63 | 86 | // Inspect each char |
64 | 87 | 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; |
67 | 90 | node['parent'] = node; |
68 | 91 | if ( !node['child'] ) { |
69 | 92 | node['child'] = new Array(); |
70 | 93 | } |
71 | 94 | |
72 | 95 | node['child'].push( recurseTokenizeNodes( text.substr( a ) ) ); |
73 | | - } else if ( text[a] == '}' && text[a + 1] == '}' ) { |
| 96 | + } else if ( _this.checkParlookAheadClose( text, a ) ) { |
74 | 97 | a++; |
75 | 98 | if ( !node['parent'] ) { |
76 | 99 | return node; |
Index: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js |
— | — | @@ -396,15 +396,10 @@ |
397 | 397 | ); |
398 | 398 | // Links go to a new window and are disable when smaller than player size |
399 | 399 | $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 | + ) |
409 | 404 | }); |
410 | 405 | |
411 | 406 | // Make every asset url absolute and restrict domain of assets |
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | 'editWidgets' : [ 'trimTimeline' ], |
29 | 29 | 'editableAttributes' : ['clipBegin','dur' ], |
30 | 30 | 'contentTypes': ['video', 'audio'] |
31 | | - }, |
| 31 | + }, |
32 | 32 | 'duration':{ |
33 | 33 | 'editableAttributes' : [ 'dur' ], |
34 | 34 | 'contentTypes': ['img', 'mwtemplate'] |
— | — | @@ -38,9 +38,14 @@ |
39 | 39 | 'contentTypes': [ 'img'], // xxx todo add video support |
40 | 40 | 'animate' : 'true' |
41 | 41 | }, |
| 42 | + 'templateedit':{ |
| 43 | + 'editWidgets' : ['edittemplate'], |
| 44 | + 'editableAttributes' : [ 'apiTitleKey' ], |
| 45 | + 'contentTypes' : ['mwtemplate'] |
| 46 | + }, |
42 | 47 | 'transitions' : { |
43 | 48 | 'editableAttributes' : [ 'transIn', 'transOut' ], |
44 | | - 'contentTypes': ['video', 'img' ] |
| 49 | + 'contentTypes': ['video', 'img', 'mwtemplate' ] |
45 | 50 | } |
46 | 51 | }, |
47 | 52 | editableAttributes:{ |
— | — | @@ -53,11 +58,16 @@ |
54 | 59 | 'title' : gM('mwe-sequencer-clip-duration' ) |
55 | 60 | }, |
56 | 61 | 'panZoom' :{ |
57 | | - 'type' : 'display', |
| 62 | + 'type' : 'string', |
58 | 63 | 'inputSize' : 15, |
59 | 64 | 'title' : gM('mwe-sequencer-clip-panzoom' ), |
60 | 65 | 'defaultValue' : '0%, 0%, 100%, 100%' |
61 | 66 | }, |
| 67 | + 'apiTitleKey' : { |
| 68 | + 'type' : 'string', |
| 69 | + 'inputSize' : 15, |
| 70 | + 'title' : gM('mwe-sequencer-template-name' ) |
| 71 | + }, |
62 | 72 | 'transIn' : { |
63 | 73 | 'type' : 'select', |
64 | 74 | 'selectValues' : [ 'fadeFromColor' ] |
— | — | @@ -65,10 +75,35 @@ |
66 | 76 | 'transOut' : { |
67 | 77 | 'type' : 'select', |
68 | 78 | 'selectValues' : [ 'fadeFromColor', 'crossfade' ] |
| 79 | + }, |
| 80 | + // Special child node type |
| 81 | + 'param' : { |
| 82 | + 'type' : 'childParam', |
| 83 | + 'inputSize' : 20 |
69 | 84 | } |
70 | 85 | }, |
71 | 86 | 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': { |
73 | 108 | update: function( _this, smilElement, attributeName, value){ |
74 | 109 | $j( smilElement ).attr( attributeName, value); |
75 | 110 | // update the display |
— | — | @@ -149,6 +184,53 @@ |
150 | 185 | } |
151 | 186 | }, |
152 | 187 | 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 | + }, |
153 | 235 | 'panzoom' : { |
154 | 236 | 'onChange': function( _this, target, smilElement ){ |
155 | 237 | var panZoomVal = $j('#' +_this.getEditToolInputId( 'panzoom', 'panZoom')).val(); |
— | — | @@ -482,7 +564,7 @@ |
483 | 565 | ) |
484 | 566 | }, |
485 | 567 | getEditToolInputId: function( toolId, attributeName){ |
486 | | - return 'editTool_' + toolId + '_' + attributeName; |
| 568 | + return 'editTool_' + toolId + '_' + attributeName.replace('/\s/', ''); |
487 | 569 | }, |
488 | 570 | /** |
489 | 571 | * update the current displayed tool ( when an undo, redo or history jump changes smil state ) |
— | — | @@ -651,7 +733,7 @@ |
652 | 734 | return $actionButton; |
653 | 735 | }, |
654 | 736 | /* get the editiable attribute input html */ |
655 | | - getEditableAttribute: function( smilElement, toolId, attributeName ){ |
| 737 | + getEditableAttribute: function( smilElement, toolId, attributeName, paramName ){ |
656 | 738 | if( ! this.editableAttributes[ attributeName ] ){ |
657 | 739 | mw.log("Error: editableAttributes : " + attributeName + ' not found'); |
658 | 740 | return; |
— | — | @@ -663,15 +745,21 @@ |
664 | 746 | mw.log(" Error: No editableTypes interface for " + editType); |
665 | 747 | return ; |
666 | 748 | } |
| 749 | + // Set the update key to the paramName if provided: |
| 750 | + var updateKey = ( paramName ) ? paramName : attributeName; |
| 751 | + |
667 | 752 | var initialValue = _this.editableTypes[ editType ].getSmilVal( |
668 | 753 | _this, |
669 | 754 | smilElement, |
670 | | - attributeName |
| 755 | + updateKey |
671 | 756 | ); |
672 | 757 | // Set the default input size |
673 | 758 | var inputSize = ( _this.editableAttributes[ attributeName ].inputSize)? |
674 | 759 | _this.editableAttributes[ attributeName ].inputSize : 6; |
675 | | - |
| 760 | + |
| 761 | + // Set paramName based attributes: |
| 762 | + var attributeTitle = ( editAttribute.title ) ? editAttribute.title : paramName; |
| 763 | + |
676 | 764 | return $j( '<div />' ) |
677 | 765 | .css({ |
678 | 766 | 'float': 'left', |
— | — | @@ -685,22 +773,22 @@ |
686 | 774 | .append( |
687 | 775 | $j('<span />') |
688 | 776 | .css('margin', '5px') |
689 | | - .text( editAttribute.title ), |
| 777 | + .text( attributeTitle ), |
690 | 778 | |
691 | 779 | $j('<input />') |
692 | 780 | .attr( { |
693 | | - 'id' : _this.getEditToolInputId( toolId, attributeName), |
| 781 | + 'id' : _this.getEditToolInputId( toolId, updateKey ), |
694 | 782 | 'size': inputSize |
695 | 783 | }) |
696 | 784 | .data('initialValue', initialValue ) |
697 | 785 | .sequencerInput( _this.sequencer ) |
698 | 786 | .val( initialValue ) |
699 | | - .change(function(){ |
| 787 | + .change(function(){ |
700 | 788 | // Run the editableType update function: |
701 | 789 | _this.editableTypes[ editType ].update( |
702 | 790 | _this, |
703 | 791 | smilElement, |
704 | | - attributeName, |
| 792 | + updateKey, |
705 | 793 | $j( this ).val() |
706 | 794 | ); |
707 | 795 | // widgets can bind directly to this change action. |
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js |
— | — | @@ -35,6 +35,9 @@ |
36 | 36 | // Flags if the sequence was successfully saved in this session |
37 | 37 | sequenceSaved: false, |
38 | 38 | |
| 39 | + //Template cache of wikitext for templates loaded in this session |
| 40 | + templateTextCache: [], |
| 41 | + |
39 | 42 | /** |
40 | 43 | * init the sequencer |
41 | 44 | */ |
— | — | @@ -111,6 +114,17 @@ |
112 | 115 | callback( smilXml ); |
113 | 116 | }) |
114 | 117 | }, |
| 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 | + }, |
115 | 129 | // Check if there have been local changes |
116 | 130 | hasLocalChanges: function(){ |
117 | 131 | return ( this.serverSmilXml != this.sequencer.getSmil().getXMLString() ); |
Index: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js |
— | — | @@ -95,6 +95,14 @@ |
96 | 96 | |
97 | 97 | // Close the dialog loading: |
98 | 98 | 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'); |
99 | 107 | } |
100 | 108 | |
101 | 109 | }); |