http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72274
Revision: 72274
Author: dale
Date: 2010-09-03 09:16:10 +0000 (Fri, 03 Sep 2010)
Log Message:
-----------
* improved template slide editing
Modified Paths:
--------------
branches/MwEmbedStandAlone/components/mw.Api.js
branches/MwEmbedStandAlone/components/mw.Parser.js
branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js
branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js
branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js
branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js
Modified: branches/MwEmbedStandAlone/components/mw.Api.js
===================================================================
--- branches/MwEmbedStandAlone/components/mw.Api.js 2010-09-03 08:25:06 UTC
(rev 72273)
+++ branches/MwEmbedStandAlone/components/mw.Api.js 2010-09-03 09:16:10 UTC
(rev 72274)
@@ -48,7 +48,7 @@
return ;
}
}
- callbac( false );
+ callback( false );
} );
}
Modified: branches/MwEmbedStandAlone/components/mw.Parser.js
===================================================================
--- branches/MwEmbedStandAlone/components/mw.Parser.js 2010-09-03 08:25:06 UTC
(rev 72273)
+++ branches/MwEmbedStandAlone/components/mw.Parser.js 2010-09-03 09:16:10 UTC
(rev 72274)
@@ -33,7 +33,8 @@
*/
mw.Parser = function( wikiText, options) {
// return the parserObj
- this.init( wikiText, options ) ;
+ this.init( wikiText, options ) ;
+ return this;
};
mw.Parser.prototype = {
@@ -42,7 +43,13 @@
pOut: false,
init: function( wikiText, parserOptions ) {
- this.wikiText = wikiText;
+ this.wikiText = wikiText;
+
+ var defaultParserOptions = {
+ 'templateParCount' : 2
+ }
+
+ this.options = $j.extend( defaultParserOptions,
parserOptions);
},
// Update the text value
@@ -52,24 +59,40 @@
// invalidate the output ( will force a re-parse )
this.pOut = false;
},
-
+ // checks if the required number of parenthesis are found
+ // xxx this is just a stop gap solution
+ checkParlookAheadOpen: function(text, a){
+ if( this.options.templateParCount == 2 ){
+ return ( text[a] == '{' && text[a + 1] == '{'
);
+ } else if( this.options.templateParCount == 3 ) {
+ return ( text[a] == '{' && text[a + 1] == '{'
&& text[a + 2] == '{');
+ }
+ },
+ checkParlookAheadClose: function( text, a){
+ if( this.options.templateParCount == 2 ){
+ return ( text[a] == '}' && text[a + 1] == '}'
);
+ } else if( this.options.templateParCount == 3 ) {
+ return ( text[a] == '}' && text[a + 1] == '}'
&& text[a + 2] == '}');
+ }
+ },
/**
* Quickly recursive / parse out templates:
*/
parse: function() {
+ var _this = this;
function recurseTokenizeNodes ( text ) {
var node = { };
// Inspect each char
for ( var a = 0; a < text.length; a++ ) {
- if ( text[a] == '{' && text[a + 1] ==
'{' ) {
- a = a + 2;
+ if ( _this.checkParlookAheadOpen( text,
a ) ) {
+ a = a +
_this.options.templateParCount;
node['parent'] = node;
if ( !node['child'] ) {
node['child'] = new
Array();
}
node['child'].push(
recurseTokenizeNodes( text.substr( a ) ) );
- } else if ( text[a] == '}' && text[a +
1] == '}' ) {
+ } else if (
_this.checkParlookAheadClose( text, a ) ) {
a++;
if ( !node['parent'] ) {
return node;
Modified: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js
===================================================================
--- branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js
2010-09-03 08:25:06 UTC (rev 72273)
+++ branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerAddByUrl.js
2010-09-03 09:16:10 UTC (rev 72274)
@@ -95,6 +95,14 @@
// Close the dialog
loading:
mw.closeLoaderDialog();
+
+ /*
+ * Soon sequence transclution
fun:
+ * else if(
titleKey.indexOf('Sequence:') == 0 ) {
+ */
+
+ } else {
+ $dialog.html( 'Error
loading asset type');
}
});
Modified: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js
===================================================================
--- branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js
2010-09-03 08:25:06 UTC (rev 72273)
+++ branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerServer.js
2010-09-03 09:16:10 UTC (rev 72274)
@@ -35,6 +35,9 @@
// Flags if the sequence was successfully saved in this session
sequenceSaved: false,
+ //Template cache of wikitext for templates loaded in this
session
+ templateTextCache: [],
+
/**
* init the sequencer
*/
@@ -111,6 +114,17 @@
callback( smilXml );
})
},
+ getTemplateText: function( templateTitle, callback ){
+ var _this = this;
+ if(this.templateTextCache[templateTitle]){
+ callback(templateTitle);
+ return ;
+ }
+ mw.getTitleText( this.getApiUrl(),templateTitle,
function( templateText ){
+ _this.templateTextCache[templateTitle] =
templateText;
+ callback(templateText);
+ });
+ },
// Check if there have been local changes
hasLocalChanges: function(){
return ( this.serverSmilXml !=
this.sequencer.getSmil().getXMLString() );
Modified: branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js
===================================================================
--- branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js
2010-09-03 08:25:06 UTC (rev 72273)
+++ branches/MwEmbedStandAlone/modules/Sequencer/mw.SequencerTools.js
2010-09-03 09:16:10 UTC (rev 72274)
@@ -27,7 +27,7 @@
'editWidgets' : [ 'trimTimeline' ],
'editableAttributes' : ['clipBegin','dur' ],
'contentTypes': ['video', 'audio']
- },
+ },
'duration':{
'editableAttributes' : [ 'dur' ],
'contentTypes': ['img', 'mwtemplate']
@@ -38,9 +38,14 @@
'contentTypes': [ 'img'], // xxx todo add video support
'animate' : 'true'
},
+ 'templateedit':{
+ 'editWidgets' : ['edittemplate'],
+ 'editableAttributes' : [ 'apiTitleKey' ],
+ 'contentTypes' : ['mwtemplate']
+ },
'transitions' : {
'editableAttributes' : [ 'transIn', 'transOut' ],
- 'contentTypes': ['video', 'img' ]
+ 'contentTypes': ['video', 'img', 'mwtemplate' ]
}
},
editableAttributes:{
@@ -53,11 +58,16 @@
'title' : gM('mwe-sequencer-clip-duration' )
},
'panZoom' :{
- 'type' : 'display',
+ 'type' : 'string',
'inputSize' : 15,
'title' : gM('mwe-sequencer-clip-panzoom' ),
'defaultValue' : '0%, 0%, 100%, 100%'
},
+ 'apiTitleKey' : {
+ 'type' : 'string',
+ 'inputSize' : 15,
+ 'title' : gM('mwe-sequencer-template-name' )
+ },
'transIn' : {
'type' : 'select',
'selectValues' : [ 'fadeFromColor' ]
@@ -65,10 +75,35 @@
'transOut' : {
'type' : 'select',
'selectValues' : [ 'fadeFromColor', 'crossfade' ]
+ },
+ // Special child node type
+ 'param' : {
+ 'type' : 'childParam',
+ 'inputSize' : 20
}
},
editableTypes: {
- 'display': {
+ 'childParam': {
+ update: function( _this, smilElement, paramName, value){
+ // Check if the param already exists
+ $paramNode = $j( smilElement ).find( "[name='"+
paramName + '"]' );
+ if( $paramNode.length == 0){
+ $j( smilElement ).append(
+ $j('<param />').attr('name',
paramName)
+ )
+ }
+ // Update the param value
+ $paramNode.attr( 'value', value);
+ },
+ getSmilVal: function( _this, smilElement, paramName,
value){
+ $paramNode = $j( smilElement ).find(
"[name='"+ paramName + '"]' );
+ if( $paramNode.length == 0){
+ return '';
+ }
+ $paramNode.attr('value');
+ }
+ },
+ 'string': {
update: function( _this, smilElement, attributeName,
value){
$j( smilElement ).attr( attributeName, value);
// update the display
@@ -149,6 +184,53 @@
}
},
editWidgets: {
+ 'edittemplate':{
+ 'onChange' : function( _this, target, smilElement ){
+
+ },
+ 'draw': function( _this, target, smilElement ){
+ // Parse the set of templates from the template
text cache
+ $j( target ).loadingSpinner();
+
+ if( ! $j( smilElement).attr('apititlekey') ){
+ mw.log("Error: can't grab template
without title key")
+ return ;
+ }
+ // Get the template wikitext
+ _this.sequencer.getServer().getTemplateText($j(
smilElement).attr('apititlekey'), function( templateText ){
+ if( ! templateText ){
+ mw.log("Error: could not get
wikitext form titlekey: " + $j( smilElement).attr('apititlekey'))
+ return ;
+ }
+ $j( target ).empty().append(
+ $j('<h3
/>').text('mwe-sequencer-edittemplate-params')
+ )
+
+ // This is not supposed to be perfect
..
+ // just get you 'most' of the input
vars 'most' of the time via the greedy regEx:
+ var templateVars =
templateText.match(/\{\{\{([^\}]*)\}\}\}/gi);
+ var cleanTemplateParams = {};
+ for( i =0;i<templateVars.length; i++ ){
+ var tVar = templateVars[i];
+ // Remove all {{{ and }}}
+ tVar = tVar.replace(/\{\{\{/,
'' ).replace( /\}\}\}/, '');
+ // Check for | operator
+ if( tVar.indexOf("|") != -1 ){
+ // Only the first
version of the template var
+ tVar = tVar.split(
'|')[0];
+ }
+ cleanTemplateParams[ tVar ] =
true;
+ }
+ // Output input boxes for each template
var as a param
+ for( var paramName in
cleanTemplateParams ){
+ $j( target ).append(
+
_this.getEditableAttribute(smilElement, 'edittemplate', 'param', paramName ),
+ $j('<br />')
+ )
+ }
+ });
+ }
+ },
'panzoom' : {
'onChange': function( _this, target, smilElement ){
var panZoomVal = $j('#'
+_this.getEditToolInputId( 'panzoom', 'panZoom')).val();
@@ -482,7 +564,7 @@
)
},
getEditToolInputId: function( toolId, attributeName){
- return 'editTool_' + toolId + '_' + attributeName;
+ return 'editTool_' + toolId + '_' +
attributeName.replace('/\s/', '');
},
/**
* update the current displayed tool ( when an undo, redo or history
jump changes smil state )
@@ -651,7 +733,7 @@
return $actionButton;
},
/* get the editiable attribute input html */
- getEditableAttribute: function( smilElement, toolId, attributeName ){
+ getEditableAttribute: function( smilElement, toolId, attributeName,
paramName ){
if( ! this.editableAttributes[ attributeName ] ){
mw.log("Error: editableAttributes : " + attributeName +
' not found');
return;
@@ -663,15 +745,21 @@
mw.log(" Error: No editableTypes interface for " +
editType);
return ;
}
+ // Set the update key to the paramName if provided:
+ var updateKey = ( paramName ) ? paramName : attributeName;
+
var initialValue = _this.editableTypes[ editType ].getSmilVal(
_this,
smilElement,
- attributeName
+ updateKey
);
// Set the default input size
var inputSize = ( _this.editableAttributes[ attributeName
].inputSize)?
_this.editableAttributes[ attributeName
].inputSize : 6;
-
+
+ // Set paramName based attributes:
+ var attributeTitle = ( editAttribute.title ) ?
editAttribute.title : paramName;
+
return $j( '<div />' )
.css({
'float': 'left',
@@ -685,22 +773,22 @@
.append(
$j('<span />')
.css('margin', '5px')
- .text( editAttribute.title ),
+ .text( attributeTitle ),
$j('<input />')
.attr( {
- 'id' : _this.getEditToolInputId(
toolId, attributeName),
+ 'id' : _this.getEditToolInputId(
toolId, updateKey ),
'size': inputSize
})
.data('initialValue', initialValue )
.sequencerInput( _this.sequencer )
.val( initialValue )
- .change(function(){
+ .change(function(){
// Run the editableType update
function:
_this.editableTypes[ editType ].update(
_this,
smilElement,
- attributeName,
+ updateKey,
$j( this ).val()
);
// widgets can bind directly to this
change action.
Modified: branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js
===================================================================
--- branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js 2010-09-03
08:25:06 UTC (rev 72273)
+++ branches/MwEmbedStandAlone/modules/SmilPlayer/mw.Smil.js 2010-09-03
09:16:10 UTC (rev 72274)
@@ -396,15 +396,10 @@
);
// Links go to a new window and are disable when smaller than
player size
$html.find('a').each( function(inx, link ){
- if( scalePercent < 1 ){
- $j(link).attr('href', '#');
- } else {
- $j(link).attr('target', '_new');
- // Filter the link for any xss
- $j(link).attr('href',
- mw.escapeQuotesHTML(
$j(link).attr('href') )
- )
- }
+ // escape link output as to not include scirpt execution
+ $j(link).attr('href',
+ mw.escapeQuotesHTML(
$j(link).attr('href') )
+ )
});
// Make every asset url absolute and restrict domain of assets
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs