jenkins-bot has submitted this change and it was merged.
Change subject: Improve smw constructor
......................................................................
Improve smw constructor
Change-Id: I4f862761e3a649fdcb9c44358aa09b37d8585f7b
---
M .jshintrc
M resources/smw/ext.smw.css
M resources/smw/ext.smw.js
3 files changed, 276 insertions(+), 328 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/.jshintrc b/.jshintrc
index 63739b0..c33a3da 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,7 +1,6 @@
{
"predef": [
"mediaWiki",
- "smw",
"semanticMediaWiki",
"jQuery",
"QUnit"
diff --git a/resources/smw/ext.smw.css b/resources/smw/ext.smw.css
index 02d99d8..02a0c2e 100644
--- a/resources/smw/ext.smw.css
+++ b/resources/smw/ext.smw.css
@@ -1,4 +1,4 @@
-/**
+/*!
* This file is part of the Semantic MediaWiki Extension
* @see https://semantic-mediawiki.org/
*
@@ -20,8 +20,6 @@
* @since 1.8
*
* @file
- * @ignore
- *
* @ingroup SMW
*
* @licence GNU GPL v2+
@@ -29,18 +27,12 @@
* @author mwjames
*/
-/**
- * highlighting for builtin elements
- * @ignore
- */
+/* highlighting for builtin elements */
span.smwbuiltin, span.smwttactiveinline span.smwbuiltin {
font-style: italic;
}
-/**
- * make divs look like <pre>
- * @ignore
- */
+/* make divs look like <pre> */
div.smwpre {
white-space: pre;
font-family: monospace;
@@ -53,34 +45,22 @@
margin-top: 0.5em;
}
-/**
- * terminate page contents when inserting stuff below a page, typically used
in <br>
- * @ignore
- */
+/* terminate page contents when inserting stuff below a page, typically used
in <br> */
#smwfootbr {
clear: both;
}
-/**
- * hide keys for sorting table entries
- * @ignore
- */
+/* hide keys for sorting table entries */
span.smwsortkey {
display: none;
}
-/**
- * buttons for sort-arrows
- * @ignore
- */
+/* buttons for sort-arrows */
a.sortheader:hover {
text-decoration: none;
}
-/**
- * "semantic" span classes for Timeline
- * @ignore
- */
+/* "semantic" span classes for Timeline */
div.smwtimeline {
border: 1px solid #AAAAAA;
background-color: #F9F9F9;
@@ -100,10 +80,7 @@
padding: 5px;
}
-/**
- * Factbox
- * @ignore
- */
+/* Factbox */
div.smwfact {
clear: both;
background-color: #F9F9F9;
@@ -145,10 +122,7 @@
color: #DDDDDD;
}
-/**
- * warning messages
- * @ignore
- */
+/* warning messages */
span.smwwarning {
color: #888888;
font-style: italic;
@@ -156,11 +130,7 @@
}
-/**
- * search, browse, RDF icons
- * FIXME: this was only used for Factbox docu, should be removed from code
- * @ignore
- */
+/* Search, browse, RDF icons/ FIXME: this was only used for Factbox docu,
should be removed from code */
span.smwsearchicon {
padding-right: 16px;
margin-right: 2px;
@@ -243,11 +213,7 @@
/* @embed */ background: url(../images/rdf_flyer.18.gif) center right
no-repeat;
}
-/**
- * @TODO Browse and Factbox should be split into seperated CSS file
- * CSS style file for Semantic MediaWiki Special Browse.
- * @ignore
- */
+/* @TODO Browse and Factbox should be split into seperated CSS file, CSS style
file for Semantic MediaWiki Special Browse. */
table.smwb-factbox {
border-left: 8px solid #DDDDDD;
width: 100%
@@ -343,21 +309,14 @@
span.smwb-ivalue {
}
-/**
- * @since 1.9
- * @ignore
- */
+/* @since 1.9; Spinner */
.smw-spinner .text {
padding-left: 2.1em;
font-size: 12px;
vertical-align: middle;
}
-/**
- * Spinner for left side in-text
- * @since 1.9
- * @ignore
- */
+/* @since 1.9; Spinner for left side in-text */
.smw-spinner.left.mw-small-spinner {
background-position:left;
vertical-align: middle;
@@ -365,11 +324,7 @@
padding: 0px !important;
}
-/**
- * Sppiner for image center
- * @since 1.9
- * @ignore
- */
+/* @since 1.9; Sppinner for image center */
.smw-spinner.center.mw-small-spinner {
vertical-align: middle;
display:inline-block;
diff --git a/resources/smw/ext.smw.js b/resources/smw/ext.smw.js
index e4b5708..b26c588 100644
--- a/resources/smw/ext.smw.js
+++ b/resources/smw/ext.smw.js
@@ -28,328 +28,322 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
* @author mwjames
*/
-
-/**
- * Declares methods and properties that are available through the smw namespace
- *
- * @since 1.8
- * @class smw
- * @singleton
- */
-var instance = ( function ( $ ) {
+var smw = ( function ( $, undefined ) {
'use strict';
/*global console:true message:true */
- var instance = {};
-
/**
- * Outputs a debug log
+ *
+ * Declares methods and properties that are available through the smw
namespace
*
* @since 1.8
- *
- * @return {string}
+ * @class smw
+ * @alternateClassName semanticMediaWiki
+ * @singleton
*/
- instance.log = function( message ) {
- if ( typeof mediaWiki === 'undefined' ) {
- if ( typeof console !== 'undefined' ) {
- console.log( 'SMW: ', message );
- }
- } else {
- return mediaWiki.log.call( mediaWiki.log, 'SMW: ',
message );
- }
- };
+ return {
- /**
- * Outputs a message
- *
- * @since 1.8
- *
- * @return {string}
- */
- instance.msg = function() {
- if ( typeof mediaWiki === 'undefined' ) {
- message = window.wgSMWMessages[arguments[0]];
-
- for ( var i = arguments.length - 1; i > 0; i-- ) {
- message = message.replace( '$' + i,
arguments[i] );
- }
- return message;
- } else {
- return mediaWiki.msg.apply( mediaWiki.msg, arguments );
- }
- };
-
- /**
- * Returns current debug status
- *
- * @since 1.9
- *
- * @return {boolean}
- */
- instance.debug = function() {
- return mediaWiki.config.get( 'debug' );
- };
-
- /**
- * Returns Semantic MediaWiki version
- *
- * @since 1.9
- *
- * @return {string}
- */
- instance.version = function() {
- return mediaWiki.config.get( 'smw-config' ).version;
- };
-
- /**
- * Declares methods to access utility functions
- *
- * @since 1.9
- *
- * @static
- * @class smw.util
- * @alias smw.Util
- */
- instance.util = {
+ /* Public Members */
/**
- * Strip some illegal chars: control chars, colon, less than,
greater than,
- * brackets, braces, pipe, whitespace and normal spaces. This
still leaves some insanity
- * intact, like unicode bidi chars, but it's a good start..
+ * Outputs a debug log
*
- * Borrowed from mw.Title
+ * @since 1.8
*
- * @ignore
- * @param {string} s
* @return {string}
*/
- clean: function ( s ) {
- if ( s !== undefined ) {
- return s.trim().replace(
/[\x00-\x1f\x23\x3c\x3e\x5b\x5d\x7b\x7c\x7d\x7f\s]+/g, '_' );
+ log: function( message ) {
+ if ( typeof mediaWiki === 'undefined' ) {
+ if ( typeof console !== 'undefined' ) {
+ console.log( 'SMW: ', message );
+ }
+ } else {
+ return mediaWiki.log.call( mediaWiki.log, 'SMW:
', message );
}
},
/**
- * Capitalizes the first letter of a string
+ * Outputs a message
*
- * @ignore
- * @param {string} s
+ * @since 1.8
+ *
* @return {string}
*/
- ucFirst: function( s ) {
- return s.charAt(0).toUpperCase() + s.slice(1);
+ msg: function() {
+ if ( typeof mediaWiki === 'undefined' ) {
+ message = window.wgSMWMessages[arguments[0]];
+
+ for ( var i = arguments.length - 1; i > 0; i--
) {
+ message = message.replace( '$' + i,
arguments[i] );
+ }
+ return message;
+ } else {
+ return mediaWiki.msg.apply( mediaWiki.msg,
arguments );
+ }
},
/**
- * Declares methods to access information about namespace
settings
+ * Returns current debug status
+ *
+ * @since 1.9
+ *
+ * @return {boolean}
+ */
+ debug: function() {
+ return mediaWiki.config.get( 'debug' );
+ },
- * Example to find localised name:
- * smw.util.namespace.getName( 'property' );
- * smw.util.namespace.getName( 'file' );
+ /**
+ * Returns Semantic MediaWiki version
+ *
+ * @since 1.9
+ *
+ * @return {string}
+ */
+ version: function() {
+ return mediaWiki.config.get( 'smw-config' ).version;
+ },
+
+ /**
+ * Declares methods to access utility functions
*
* @since 1.9
*
* @static
- * @class smw.util.namespace
+ * @class smw.util
+ * @alias smw.Util
*/
- namespace: {
+ util: {
/**
- * Returns list of available namespaces
+ * Strip some illegal chars: control chars, colon, less
than, greater than,
+ * brackets, braces, pipe, whitespace and normal
spaces. This still leaves some insanity
+ * intact, like unicode bidi chars, but it's a good
start..
+ *
+ * Borrowed from mw.Title
+ *
+ * @ignore
+ * @param {string} s
+ * @return {string}
+ */
+ clean: function ( s ) {
+ if ( s !== undefined ) {
+ return s.trim().replace(
/[\x00-\x1f\x23\x3c\x3e\x5b\x5d\x7b\x7c\x7d\x7f\s]+/g, '_' );
+ }
+ },
+
+ /**
+ * Capitalizes the first letter of a string
+ *
+ * @ignore
+ * @param {string} s
+ * @return {string}
+ */
+ ucFirst: function( s ) {
+ return s.charAt(0).toUpperCase() + s.slice(1);
+ },
+
+ /**
+ * Declares methods to access information about
namespace settings
+
+ * Example to find localised name:
+ * smw.util.namespace.getName( 'property' );
+ * smw.util.namespace.getName( 'file' );
+ *
+ * @since 1.9
+ *
+ * @static
+ * @class smw.util.namespace
+ */
+ namespace: {
+
+ /**
+ * Returns list of available namespaces
+ *
+ * @since 1.9
+ *
+ * @return {Object}
+ */
+ getList: function() {
+ return smw.settings.get( 'namespace' );
+ },
+
+ /**
+ * Returns namespace Id
+ *
+ * @since 1.9
+ *
+ * @param {string} key
+ *
+ * @return {number}
+ */
+ getId: function( key ) {
+ if( typeof key === 'string' ) {
+ return this.getList()[
smw.util.ucFirst( smw.util.clean( key ) ) ];
+ }
+ return undefined;
+ },
+
+ /**
+ * Returns formatted localized name for a
selected namespace
+ *
+ * @since 1.9
+ *
+ * @param {string} key
+ *
+ * @return {string}
+ */
+ getName: function( key ) {
+ if( typeof key === 'string' ) {
+ var id = this.getId( key );
+ return id &&
mediaWiki.config.get( 'wgFormattedNamespaces' )[id.toString()];
+ }
+ return undefined;
+ }
+ }
+ },
+
+ /**
+ * Declares methods to improve browser responsiveness by loading
+ * invoked methods asynchronously using the jQuery.eachAsync
plug-in
+ *
+ * Example:
+ * var fn = function( options ) {};
+ * smw.async.load( $( this ), fn, {} );
+ *
+ * @since 1.9
+ *
+ * @singleton
+ * @class smw.async
+ */
+ async: {
+
+ /**
+ * Returns if eachAsync is available for asynchronous
loading
+ *
+ * @return {boolean}
+ */
+ isEnabled: function() {
+ return $.isFunction( $.fn.eachAsync );
+ },
+
+ /**
+ * Negotiates and executes asynchronous loading
+ *
+ * @since 1.9
+ *
+ * @param {object} context
+ * @param {function} method
+ * @param {object|string} args
+ *
+ * @return {boolean}
+ * @throws {Error} Missing callback
+ */
+ load: function( context, method ) {
+ if ( typeof method !== 'function' ) {
+ throw new Error( 'Invoked parameter was
not a function' );
+ }
+
+ // Filter arguments that are attached to the
caller
+ var args = Array.prototype.slice.call(
arguments, 2 );
+
+ if ( this.isEnabled() ) {
+ context.eachAsync( {
+ delay: 100,
+ bulk: 0,
+ loop: function() {
+ method.apply( $( this
), args );
+ }
+ } );
+ } else {
+ context.each( function() {
+ method.apply( $( this ), args );
+ } );
+ }
+ }
+ },
+
+ /**
+ * Declares methods to access information about available
formats
+ *
+ * @since 1.9
+ *
+ * @class smw.formats
+ * @alias smw.Formats
+ */
+ formats: {
+
+ /**
+ * Returns list of available formats
+ *
+ * @since 1.9
+ * @extends smw.formats
+ *
+ * @return {Object}
+ */
+ getList: function() {
+ return mediaWiki.config.get( 'smw-config'
).formats;
+ },
+
+ /**
+ * Returns localized name for a select format
+ *
+ * @since 1.9
+ *
+ * @param {string} format
+ *
+ * @return {string}
+ */
+ getName: function( format ) {
+ if( typeof format === 'string' ){
+ return this.getList()[ smw.util.clean(
format ).toLowerCase() ];
+ }
+ return undefined;
+ }
+ },
+
+ /**
+ * Declares methods to access information about invoked
settings (see also
+ * SMWHooks::onResourceLoaderGetConfigVars)
+ *
+ * @since 1.9
+ *
+ * @class smw.settings
+ * @singleton
+ */
+ settings: {
+
+ /**
+ * Returns list of available settings
*
* @since 1.9
*
* @return {Object}
*/
getList: function() {
- return instance.settings.get( 'namespace' );
+ return mediaWiki.config.get( 'smw-config'
).settings;
},
/**
- * Returns namespace Id
+ * Returns a specific settings value (see
SMW\Settings::get)
*
* @since 1.9
*
- * @param {string} key
+ * @param {string} key to be selected
*
- * @return {number}
+ * @return {mixed}
*/
- getId: function( key ) {
+ get: function( key ) {
if( typeof key === 'string' ) {
- return this.getList()[
instance.util.ucFirst( instance.util.clean( key ) ) ];
- }
- return undefined;
- },
-
- /**
- * Returns formatted localized name for a selected
namespace
- *
- * @since 1.9
- *
- * @param {string} key
- *
- * @return {string}
- */
- getName: function( key ) {
- if( typeof key === 'string' ) {
- var id = this.getId( key );
- return id && mediaWiki.config.get(
'wgFormattedNamespaces' )[id.toString()];
+ return this.getList()[key];
}
return undefined;
}
}
};
-
- /**
- * Declares methods to improve browser responsiveness by loading
- * invoked methods asynchronously using the jQuery.eachAsync plug-in
- *
- * Example:
- * var fn = function( options ) {};
- * smw.async.load( $( this ), fn, {} );
- *
- * @since 1.9
- *
- * @singleton
- * @class smw.async
- */
- instance.async = {
-
- /**
- * Returns if eachAsync is available for asynchronous loading
- *
- * @return {boolean}
- */
- isEnabled: function() {
- return $.isFunction( $.fn.eachAsync );
- },
-
- /**
- * Negotiates and executes asynchronous loading
- *
- * @since 1.9
- *
- * @param {object} context
- * @param {function} method
- * @param {object|string} args
- *
- * @return {boolean}
- * @throws {Error} Missing callback
- */
- load: function( context, method ) {
- if ( typeof method !== 'function' ) {
- throw new Error( 'Invoked parameter was not a
function' );
- }
-
- // Filter arguments that are attached to the caller
- var args = Array.prototype.slice.call( arguments, 2 );
-
- if ( this.isEnabled() ) {
- context.eachAsync( {
- delay: 100,
- bulk: 0,
- loop: function() {
- method.apply( $( this ), args );
- }
- } );
- } else {
- context.each( function() {
- method.apply( $( this ), args );
- } );
- }
- }
- };
-
-
- /**
- * Declares methods to access information about available formats
- *
- * @since 1.9
- *
- * @class smw.formats
- * @alias smw.Formats
- */
- instance.formats = {
-
- /**
- * Returns list of available formats
- *
- * @since 1.9
- * @extends smw.formats
- *
- * @return {Object}
- */
- getList: function() {
- return mediaWiki.config.get( 'smw-config' ).formats;
- },
-
- /**
- * Returns localized name for a select format
- *
- * @since 1.9
- *
- * @param {string} format
- *
- * @return {string}
- */
- getName: function( format ) {
- if( typeof format === 'string' ){
- return this.getList()[ instance.util.clean(
format ).toLowerCase() ];
- }
- return undefined;
- }
- };
-
- /**
- * Declares methods to access information about invoked settings (see
also
- * SMWHooks::onResourceLoaderGetConfigVars)
- *
- * @since 1.9
- *
- * @class smw.settings
- * @singleton
- */
- instance.settings = {
-
- /**
- * Returns list of available settings
- *
- * @since 1.9
- *
- * @return {Object}
- */
- getList: function() {
- return mediaWiki.config.get( 'smw-config' ).settings;
- },
-
- /**
- * Returns a specific settings value (see SMW\Settings::get)
- *
- * @since 1.9
- *
- * @param {string} key to be selected
- *
- * @return {mixed}
- */
- get: function( key ) {
- if( typeof key === 'string' ) {
- return this.getList()[key];
- }
- return undefined;
- }
- };
-
- // Define aliases
- instance.Util = instance.util;
-
- // Expose invoked methods
- return instance;
} )( jQuery );
// Assign namespace
-window.smw = window.semanticMediaWiki = instance;
-
-( function( $ ) { 'use strict'; $( document ).ready( function() {
-} ); } )( jQuery );
\ No newline at end of file
+window.smw = window.semanticMediaWiki = smw;
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/65352
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4f862761e3a649fdcb9c44358aa09b37d8585f7b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits