mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Change global class variables to mw.TemplateData
Nest all classes for the templatedata dialog in mw.TemplateData namespace. Change-Id: Ib514378c9fbc0fb993b3cbc2fa48ced920167226
This commit is contained in:
parent
82986955b2
commit
e6e728b58e
13
.jshintrc
13
.jshintrc
|
@ -20,17 +20,6 @@
|
|||
"globals": {
|
||||
"mw": false,
|
||||
"OO": false,
|
||||
"QUnit": false,
|
||||
"unicodeJS": false,
|
||||
"jQuery": false,
|
||||
"mediaWiki": false,
|
||||
"TemplateDataModel": true,
|
||||
"TemplateDataDialog": true,
|
||||
"TemplateDataOptionWidget": true,
|
||||
"TemplateDataOptionImportWidget": true,
|
||||
"TemplateDataLanguageSearchWidget": true,
|
||||
"TemplateDataLanguageResultWidget": true,
|
||||
"TemplateDataDragDropItemWidget": true,
|
||||
"TemplateDataDragDropWidget": true
|
||||
"QUnit": false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,7 @@ $wgResourceModules['ext.templateDataGenerator.data'] = array(
|
|||
'localBasePath' => $dir,
|
||||
'remoteExtPath' => 'TemplateData',
|
||||
'scripts' => array(
|
||||
'modules/ext.templateDataGenerator.js',
|
||||
'modules/ext.templateDataGenerator.data.js'
|
||||
),
|
||||
'dependencies' => array(
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
( function ( $, mw ) {
|
||||
( function () {
|
||||
/**
|
||||
* TemplateData Generator button fixture
|
||||
* The button will appear on Template namespaces only, above the edit textbox
|
||||
|
@ -27,4 +27,4 @@
|
|||
|
||||
} );
|
||||
|
||||
}( jQuery, mediaWiki ) );
|
||||
}() );
|
||||
|
|
1
modules/ext.templateDataGenerator.js
Normal file
1
modules/ext.templateDataGenerator.js
Normal file
|
@ -0,0 +1 @@
|
|||
mw.TemplateData = {};
|
|
@ -1,4 +1,4 @@
|
|||
( function ( $, mw ) {
|
||||
( function () {
|
||||
/**
|
||||
* TemplateData Generator data model.
|
||||
* This singleton is independent of any UI; it expects
|
||||
|
@ -141,7 +141,7 @@
|
|||
|
||||
// Dialog
|
||||
windowManager = new OO.ui.WindowManager();
|
||||
tdgDialog = new TemplateDataDialog( config );
|
||||
tdgDialog = new mw.TemplateData.Dialog( config );
|
||||
windowManager.addWindows( [ tdgDialog ] );
|
||||
|
||||
// Prepend to container
|
||||
|
@ -167,4 +167,4 @@
|
|||
}
|
||||
};
|
||||
}() );
|
||||
}( jQuery, mediaWiki ) );
|
||||
}() );
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,12 +9,12 @@
|
|||
* @param {Mixed} data Option data
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
TemplateDataDragDropItemWidget = function TemplateDataDragDropItemWidget( config ) {
|
||||
mw.TemplateData.DragDropItemWidget = function mwTemplateDataDragDropItemWidget( config ) {
|
||||
// Configuration initialization
|
||||
config = config || {};
|
||||
|
||||
// Parent constructor
|
||||
TemplateDataDragDropItemWidget.super.call( this, $.extend( {}, { icon: 'parameter' }, config ) );
|
||||
mw.TemplateData.DragDropItemWidget.super.call( this, $.extend( {}, { icon: 'parameter' }, config ) );
|
||||
|
||||
// Mixin constructors
|
||||
OO.ui.DraggableElement.call( this, config );
|
||||
|
@ -26,5 +26,5 @@ TemplateDataDragDropItemWidget = function TemplateDataDragDropItemWidget( config
|
|||
|
||||
/* Setup */
|
||||
|
||||
OO.inheritClass( TemplateDataDragDropItemWidget, OO.ui.DecoratedOptionWidget );
|
||||
OO.mixinClass( TemplateDataDragDropItemWidget, OO.ui.DraggableElement );
|
||||
OO.inheritClass( mw.TemplateData.DragDropItemWidget, OO.ui.DecoratedOptionWidget );
|
||||
OO.mixinClass( mw.TemplateData.DragDropItemWidget, OO.ui.DraggableElement );
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
* @param {Object} [config] Configuration options
|
||||
* @cfg {OO.ui.OptionWidget[]} [items] Options to add
|
||||
*/
|
||||
TemplateDataDragDropWidget = function TemplateDataDragDropWidget( config ) {
|
||||
mw.TemplateData.DragDropWidget = function mwTemplateDataDragDropWidget( config ) {
|
||||
// Configuration initialization
|
||||
config = config || {};
|
||||
|
||||
// Parent constructor
|
||||
TemplateDataDragDropWidget.super.call( this, config );
|
||||
mw.TemplateData.DragDropWidget.super.call( this, config );
|
||||
|
||||
// Mixin constructors
|
||||
OO.ui.DraggableGroupElement.call( this, $.extend( {}, config, { $group: this.$element } ) );
|
||||
|
@ -27,14 +27,14 @@ TemplateDataDragDropWidget = function TemplateDataDragDropWidget( config ) {
|
|||
|
||||
/* Setup */
|
||||
|
||||
OO.inheritClass( TemplateDataDragDropWidget, OO.ui.Widget );
|
||||
OO.mixinClass( TemplateDataDragDropWidget, OO.ui.DraggableGroupElement );
|
||||
OO.inheritClass( mw.TemplateData.DragDropWidget, OO.ui.Widget );
|
||||
OO.mixinClass( mw.TemplateData.DragDropWidget, OO.ui.DraggableGroupElement );
|
||||
|
||||
/**
|
||||
* Get an array of keys based on the current items, in order
|
||||
* @return {string[]} Array of keys
|
||||
*/
|
||||
TemplateDataDragDropWidget.prototype.getKeyArray = function () {
|
||||
mw.TemplateData.DragDropWidget.prototype.getKeyArray = function () {
|
||||
var i, len,
|
||||
arr = [];
|
||||
|
||||
|
@ -51,7 +51,7 @@ TemplateDataDragDropWidget.prototype.getKeyArray = function () {
|
|||
* @param {string} key Unique key
|
||||
* @param {[type]} newIndex New index
|
||||
*/
|
||||
TemplateDataDragDropWidget.prototype.reorderKey = function ( key, newIndex ) {
|
||||
mw.TemplateData.DragDropWidget.prototype.reorderKey = function ( key, newIndex ) {
|
||||
var i, len, item;
|
||||
|
||||
// Get the item that belongs to this key
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
TemplateDataLanguageResultWidget = function TemplateDataLanguageResultWidget( config ) {
|
||||
mw.TemplateData.LanguageResultWidget = function mwTemplateDataLanguageResultWidget( config ) {
|
||||
// Parent constructor
|
||||
OO.ui.OptionWidget.call( this, config );
|
||||
|
||||
|
@ -21,7 +21,7 @@ TemplateDataLanguageResultWidget = function TemplateDataLanguageResultWidget( co
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( TemplateDataLanguageResultWidget, OO.ui.OptionWidget );
|
||||
OO.inheritClass( mw.TemplateData.LanguageResultWidget, OO.ui.OptionWidget );
|
||||
|
||||
/* Methods */
|
||||
|
||||
|
@ -32,7 +32,7 @@ OO.inheritClass( TemplateDataLanguageResultWidget, OO.ui.OptionWidget );
|
|||
* @param {string} [matchedProperty] Data property which matched the query text
|
||||
* @chainable
|
||||
*/
|
||||
TemplateDataLanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty ) {
|
||||
mw.TemplateData.LanguageResultWidget.prototype.updateLabel = function ( query, matchedProperty ) {
|
||||
var $highlighted, data = this.getData();
|
||||
|
||||
// Reset text
|
||||
|
@ -59,7 +59,7 @@ TemplateDataLanguageResultWidget.prototype.updateLabel = function ( query, match
|
|||
* @param {string} query Query to find
|
||||
* @returns {jQuery} Text with query substring wrapped in highlighted span
|
||||
*/
|
||||
TemplateDataLanguageResultWidget.prototype.highlightQuery = function ( text, query ) {
|
||||
mw.TemplateData.LanguageResultWidget.prototype.highlightQuery = function ( text, query ) {
|
||||
var $result = this.$( '<span>' ),
|
||||
offset = text.toLowerCase().indexOf( query.toLowerCase() );
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
TemplateDataLanguageSearchWidget = function TemplateDataLanguageSearchWidget( config ) {
|
||||
mw.TemplateData.LanguageSearchWidget = function mwTemplateDataLanguageSearchWidget( config ) {
|
||||
// Configuration intialization
|
||||
config = $.extend( {
|
||||
placeholder: mw.msg( 'templatedata-modal-search-input-placeholder' )
|
||||
|
@ -26,7 +26,7 @@ TemplateDataLanguageSearchWidget = function TemplateDataLanguageSearchWidget( co
|
|||
for ( i = 0, l = languageCodes.length; i < l; i++ ) {
|
||||
languageCode = languageCodes[i];
|
||||
this.languageResultWidgets.push(
|
||||
new TemplateDataLanguageResultWidget( {
|
||||
new mw.TemplateData.LanguageResultWidget( {
|
||||
data: {
|
||||
code: languageCode,
|
||||
name: $.uls.data.getAutonym( languageCode ),
|
||||
|
@ -43,14 +43,14 @@ TemplateDataLanguageSearchWidget = function TemplateDataLanguageSearchWidget( co
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( TemplateDataLanguageSearchWidget, OO.ui.SearchWidget );
|
||||
OO.inheritClass( mw.TemplateData.LanguageSearchWidget, OO.ui.SearchWidget );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
TemplateDataLanguageSearchWidget.prototype.onQueryChange = function () {
|
||||
mw.TemplateData.LanguageSearchWidget.prototype.onQueryChange = function () {
|
||||
// Parent method
|
||||
OO.ui.SearchWidget.prototype.onQueryChange.call( this );
|
||||
|
||||
|
@ -61,7 +61,7 @@ TemplateDataLanguageSearchWidget.prototype.onQueryChange = function () {
|
|||
/**
|
||||
* Update search results from current query
|
||||
*/
|
||||
TemplateDataLanguageSearchWidget.prototype.addResults = function () {
|
||||
mw.TemplateData.LanguageSearchWidget.prototype.addResults = function () {
|
||||
var i, iLen, j, jLen, languageResult, data, matchedProperty,
|
||||
matchProperties = ['name', 'autonym', 'code'],
|
||||
query = this.query.getValue().trim(),
|
||||
|
@ -107,6 +107,6 @@ TemplateDataLanguageSearchWidget.prototype.addResults = function () {
|
|||
* @param {string} value Text
|
||||
* @returns {string} Text escaped for use in regex
|
||||
*/
|
||||
TemplateDataLanguageSearchWidget.static.escapeRegex = function ( value ) {
|
||||
mw.TemplateData.LanguageSearchWidget.static.escapeRegex = function ( value ) {
|
||||
return value.replace( /[\-\[\]{}()*+?.,\\\^$\|#\s]/g, '\\$&' );
|
||||
};
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
* @extends {OO.ui.DecoratedOptionWidget}
|
||||
* @param {Object} config Dialog configuration object
|
||||
*/
|
||||
TemplateDataOptionImportWidget = function TemplateDataOptionImportWidget( config ) {
|
||||
mw.TemplateData.OptionImportWidget = function mwTemplateDataOptionImportWidget( config ) {
|
||||
config = config || {};
|
||||
|
||||
// Parent constructor
|
||||
TemplateDataOptionImportWidget.super.call( this, $.extend( {}, config, { icon: 'parameter-set' } ) );
|
||||
mw.TemplateData.OptionImportWidget.super.call( this, $.extend( {}, config, { icon: 'parameter-set' } ) );
|
||||
|
||||
this.params = config.params;
|
||||
|
||||
|
@ -16,14 +16,14 @@ TemplateDataOptionImportWidget = function TemplateDataOptionImportWidget( config
|
|||
this.buildParamLabel();
|
||||
};
|
||||
|
||||
OO.inheritClass( TemplateDataOptionImportWidget, OO.ui.DecoratedOptionWidget );
|
||||
OO.inheritClass( mw.TemplateData.OptionImportWidget, OO.ui.DecoratedOptionWidget );
|
||||
|
||||
/**
|
||||
* Build the parameter label in the parameter select widget
|
||||
* @param {Object} paramData Parameter data
|
||||
* @return {jQuery} Label element
|
||||
*/
|
||||
TemplateDataOptionImportWidget.prototype.buildParamLabel = function () {
|
||||
mw.TemplateData.OptionImportWidget.prototype.buildParamLabel = function () {
|
||||
var paramNames = this.params.slice( 0, 9 ).join( mw.msg( 'comma-separator' ) ),
|
||||
$paramName = this.$( '<div>' )
|
||||
.addClass( 'tdg-TemplateDataOptionWidget-param-name' ),
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
* @extends {OO.ui.DecoratedOptionWidget}
|
||||
* @param {Object} config Dialog configuration object
|
||||
*/
|
||||
TemplateDataOptionWidget = function TemplateDataOptionWidget( config ) {
|
||||
mw.TemplateData.OptionWidget = function mwTemplateDataOptionWidget( config ) {
|
||||
var data;
|
||||
|
||||
config = config || {};
|
||||
data = config.data || {};
|
||||
// Parent constructor
|
||||
TemplateDataOptionWidget.super.call( this, $.extend( {}, config, { data: data.key, icon: 'parameter' } ) );
|
||||
mw.TemplateData.OptionWidget.super.call( this, $.extend( {}, config, { data: data.key, icon: 'parameter' } ) );
|
||||
|
||||
this.key = data.key;
|
||||
this.name = data.name;
|
||||
|
@ -21,14 +21,14 @@ TemplateDataOptionWidget = function TemplateDataOptionWidget( config ) {
|
|||
this.buildParamLabel();
|
||||
};
|
||||
|
||||
OO.inheritClass( TemplateDataOptionWidget, OO.ui.DecoratedOptionWidget );
|
||||
OO.inheritClass( mw.TemplateData.OptionWidget, OO.ui.DecoratedOptionWidget );
|
||||
|
||||
/**
|
||||
* Build the parameter label in the parameter select widget
|
||||
* @param {Object} paramData Parameter data
|
||||
* @return {jQuery} Label element
|
||||
*/
|
||||
TemplateDataOptionWidget.prototype.buildParamLabel = function () {
|
||||
mw.TemplateData.OptionWidget.prototype.buildParamLabel = function () {
|
||||
var i, len,
|
||||
$paramName = this.$( '<div>' )
|
||||
.addClass( 'tdg-TemplateDataOptionWidget-param-name' ),
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* TemplateData Generator GUI Unit Tests
|
||||
*/
|
||||
|
||||
( function ( $ ) {
|
||||
( function () {
|
||||
'use strict';
|
||||
|
||||
QUnit.module( 'ext.templateData', QUnit.newMwEnvironment() );
|
||||
|
@ -12,7 +12,7 @@
|
|||
resultDescMockLang = {},
|
||||
resultDescBothLang = {},
|
||||
currLanguage = mw.config.get( 'wgContentLanguage' ) || 'en',
|
||||
model = new TemplateDataModel(),
|
||||
model = new mw.TemplateData.Model(),
|
||||
originalWikitext = 'Some text here that is not templatedata information.' +
|
||||
'<templatedata>' +
|
||||
'{' +
|
||||
|
@ -365,7 +365,7 @@
|
|||
for ( i = 0; i < tests.compare.length; i++ ) {
|
||||
testVars = tests.compare[i];
|
||||
assert.equal(
|
||||
TemplateDataModel.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ),
|
||||
mw.TemplateData.Model.static.compare( testVars.obj1, testVars.obj2, testVars.allowSubset ),
|
||||
testVars.result,
|
||||
testVars.msg
|
||||
);
|
||||
|
@ -375,7 +375,7 @@
|
|||
for ( i = 0; i < tests.splitAndTrimArray.length; i++ ) {
|
||||
testVars = tests.splitAndTrimArray[i];
|
||||
assert.deepEqual(
|
||||
TemplateDataModel.static.splitAndTrimArray( testVars.string, testVars.delim ),
|
||||
mw.TemplateData.Model.static.splitAndTrimArray( testVars.string, testVars.delim ),
|
||||
testVars.result,
|
||||
testVars.msg
|
||||
);
|
||||
|
@ -385,7 +385,7 @@
|
|||
for ( i = 0; i < tests.arrayUnionWithoutEmpty.length; i++ ) {
|
||||
testVars = tests.arrayUnionWithoutEmpty[i];
|
||||
assert.deepEqual(
|
||||
TemplateDataModel.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ),
|
||||
mw.TemplateData.Model.static.arrayUnionWithoutEmpty.apply( testVars, testVars.arrays ),
|
||||
testVars.result,
|
||||
testVars.msg
|
||||
);
|
||||
|
@ -393,12 +393,12 @@
|
|||
|
||||
// Props
|
||||
assert.deepEqual(
|
||||
TemplateDataModel.static.getAllProperties( false ),
|
||||
mw.TemplateData.Model.static.getAllProperties( false ),
|
||||
tests.props.all,
|
||||
'All properties'
|
||||
);
|
||||
assert.deepEqual(
|
||||
TemplateDataModel.static.getPropertiesWithLanguage(),
|
||||
mw.TemplateData.Model.static.getPropertiesWithLanguage(),
|
||||
tests.props.language,
|
||||
'Language properties'
|
||||
);
|
||||
|
@ -571,4 +571,4 @@
|
|||
} );
|
||||
} );
|
||||
|
||||
}( jQuery ) );
|
||||
}() );
|
||||
|
|
Loading…
Reference in a new issue