Unify coding style of jQuery( '<element>' ) calls

According to the jQuery documentation (and code) all kinds of
$( '<element>' )
$( '<element/>' )
$( '<element />' )
$( '<element></element>' )
are identical. So yes, this patch does not change anything. All it
does is removing characters that are ignored anyway. Using the same
style everywhere makes the code easier to read and understand and
may save a few bytes when it is gzipped.

The current WikiEditor code contains 67 usages of that jQuery call.
Only very few of them are not in the most simple <element> style.

Personally I consider the style <div/> confusing since a <div> can
not be a void element.

Change-Id: I816b4cccc9ee329e9bcdd9bd2353e5653fd10c36
This commit is contained in:
Thiemo Mättig 2014-03-17 22:01:52 +01:00
parent df3c0a1acc
commit 772e39caf2
3 changed files with 29 additions and 29 deletions

View file

@ -119,7 +119,7 @@ context.evt = $.extend( context.evt, {
setTimeout( function() {
context.$content.find( 'br' ).each( function() {
if ( $(this).parent().is( 'body' ) ) {
$(this).wrap( $( '<p></p>' ) );
$(this).wrap( $( '<p>' ) );
}
} );
}, 100 );
@ -297,7 +297,7 @@ context.fn = $.extend( context.fn, {
var origHTML = html;
// We use this elaborate trickery for cross-browser compatibility
// IE does overzealous whitespace collapsing for $( '<pre />' ).html( html );
// IE does overzealous whitespace collapsing for $( '<pre>' ).html( html );
// We also do <br> and easy cases for <p> conversion here, complicated cases are handled later
html = html
.replace( /\r?\n/g, '' ) // IE7 inserts newlines before block elements
@ -682,7 +682,7 @@ context.fn = $.extend( context.fn, {
* Sets up the iframe in place of the textarea to allow more advanced operations
*/
setupIframe: function () {
context.$iframe = $( '<iframe></iframe>' )
context.$iframe = $( '<iframe>' )
.attr( {
'frameBorder': 0,
'border': 0,
@ -749,7 +749,7 @@ context.fn = $.extend( context.fn, {
// Use a dummy div to escape all entities
// This'll also escape <br>, <span> and &nbsp; , so we unescape those after
// We also need to unescape the doubly-escaped things mentioned above
html = $( '<div />' ).text( '<p>' + html.replace( /\r?\n/g, '</p><p>' ) + '</p>' ).html()
html = $( '<div>' ).text( '<p>' + html.replace( /\r?\n/g, '</p><p>' ) + '</p>' ).html()
.replace( /&amp;nbsp;/g, '&nbsp;' )
// Allow <p> tags to survive encoding
.replace( /&lt;p&gt;/g, '<p>' )
@ -894,7 +894,7 @@ context.fn = $.extend( context.fn, {
if ( $.browser.opera ) {
// Opera strips newlines in getSelection(), so we need something more sophisticated
if ( retval.rangeCount > 0 ) {
retval = context.fn.htmlToText( $( '<pre />' )
retval = context.fn.htmlToText( $( '<pre>' )
.append( retval.getRangeAt( 0 ).cloneContents() )
.html()
);

View file

@ -395,12 +395,12 @@ fn: {
$rows = $rows.not( $row );
} else {
// Create a new row
var $paramRow = $( '<div />' )
var $paramRow = $( '<div>' )
.addClass( 'wikiEditor-template-dialog-field-wrapper' );
$( '<label />' )
$( '<label>' )
.text( paramText )
.appendTo( $paramRow );
$( '<textarea />' )
$( '<textarea>' )
.data( 'name', param.name )
.val( paramVal )
.each( function() {

View file

@ -227,7 +227,7 @@ fn: {
if ( '$toolbar' in context.modules.toolbar ) {
return;
}
context.modules.toolbar.$toolbar = $( '<div/>' )
context.modules.toolbar.$toolbar = $( '<div>' )
.addClass( 'wikiEditor-ui-toolbar' )
.attr( 'id', 'wikiEditor-ui-toolbar' );
$.wikiEditor.modules.toolbar.fn.build( context, config );
@ -280,7 +280,7 @@ fn: {
}
},
buildGroup : function( context, id, group ) {
var $group = $( '<div/>' ).attr( { 'class' : 'group group-' + id, 'rel' : id } );
var $group = $( '<div>' ).attr( { 'class' : 'group group-' + id, 'rel' : id } );
var label = $.wikiEditor.autoMsg( group, 'label' );
if ( label ) {
$group.append( '<span class="label">' + label + '</div>' );
@ -320,7 +320,7 @@ fn: {
$.wikiEditor.imgPath + 'toolbar/'
);
if ( typeof offsetOrIcon === 'object' ) {
$button = $( '<a/>' )
$button = $( '<a>' )
.attr( {
'href' : '#',
'title' : label,
@ -333,7 +333,7 @@ fn: {
}
}
if ( !$button ) {
$button = $( '<img/>' )
$button = $( '<img>' )
.attr( {
'src' : src,
'width' : 22,
@ -365,14 +365,14 @@ fn: {
}
return $button;
case 'select':
var $select = $( '<div/>' )
var $select = $( '<div>' )
.attr( { 'rel' : id, 'class' : 'tool tool-select' } );
var $options = $( '<div/>' ).addClass( 'options' );
var $options = $( '<div>' ).addClass( 'options' );
if ( 'list' in tool ) {
for ( var option in tool.list ) {
var optionLabel = $.wikiEditor.autoMsg( tool.list[option], 'label' );
$options.append(
$( '<a/>' )
$( '<a>' )
.data( 'action', tool.list[option].action )
.data( 'context', context )
.mousedown( function( e ) {
@ -400,8 +400,8 @@ fn: {
);
}
}
$select.append( $( '<div/>' ).addClass( 'menu' ).append( $options ) );
$select.append( $( '<a/>' )
$select.append( $( '<div>' ).addClass( 'menu' ).append( $options ) );
$select.append( $( '<a>' )
.addClass( 'label' )
.text( label )
.data( 'options', $options )
@ -424,7 +424,7 @@ fn: {
},
buildBookmark : function( context, id, page ) {
var label = $.wikiEditor.autoMsg( page, 'label' );
return $( '<div/>' )
return $( '<div>' )
.text( label )
.attr( 'rel', id )
.data( 'context', context )
@ -453,7 +453,7 @@ fn: {
},
buildPage : function( context, id, page ) {
var html, i;
var $page = $( '<div/>' ).attr( {
var $page = $( '<div>' ).attr( {
'class' : 'page page-' + id,
'rel' : id
} );
@ -474,7 +474,7 @@ fn: {
break;
case 'characters':
$page.addClass( 'page-characters' );
var $characters = $( '<div/>' ).data( 'context', context ).data( 'actions', {} );
var $characters = $( '<div>' ).data( 'context', context ).data( 'actions', {} );
var actions = $characters.data( 'actions' );
if ( 'language' in page ) {
$characters.attr( 'lang', page.language );
@ -580,7 +580,7 @@ fn: {
$.cookie( 'wikiEditor-' + context.instance + '-toolbar-section', selected, { expires: 30, path: '/' } );
}
var $link =
$( '<a/>' )
$( '<a>' )
.addClass( selected === id ? 'current' : null )
.attr( {
href: '#',
@ -660,7 +660,7 @@ fn: {
e.preventDefault();
return false;
});
return $( '<span/>' )
return $( '<span>' )
.attr({
'class' : 'tab tab-' + id,
'rel' : id
@ -668,7 +668,7 @@ fn: {
.append( $link );
},
buildSection: function( context, id, section ) {
var $section = $( '<div/>' ).attr( {
var $section = $( '<div>' ).attr( {
'class': section.type + ' section section-' + id,
'rel': id,
id: 'wikiEditor-section-' + id
@ -678,7 +678,7 @@ fn: {
if ( section.deferLoad !== undefined && section.deferLoad && id !== 'main' && !show ) {
// This class shows the spinner and serves as a marker for the click handler in buildTab()
$section.addClass( 'loading' ).append( $( '<div/>' ).addClass( 'spinner' ) );
$section.addClass( 'loading' ).append( $( '<div>' ).addClass( 'spinner' ) );
$section.bind( 'loadSection', function() {
$.wikiEditor.modules.toolbar.fn.reallyBuildSection( context, id, section, $section );
$section.removeClass( 'loading' );
@ -712,8 +712,8 @@ fn: {
}
break;
case 'booklet':
var $pages = $( '<div/>' ).addClass( 'pages' );
var $index = $( '<div/>' ).addClass( 'index' );
var $pages = $( '<div>' ).addClass( 'pages' );
var $index = $( '<div>' ).addClass( 'index' );
if ( 'pages' in section ) {
for ( var page in section.pages ) {
$pages.append(
@ -749,9 +749,9 @@ fn: {
$selectedIndex.addClass( 'current' );
},
build : function( context, config ) {
var $tabs = $( '<div/>' ).addClass( 'tabs' ).appendTo( context.modules.toolbar.$toolbar );
var $sections = $( '<div/>' ).addClass( 'sections' ).appendTo( context.modules.toolbar.$toolbar );
context.modules.toolbar.$toolbar.append( $( '<div/>' ).css( 'clear', 'both' ) );
var $tabs = $( '<div>' ).addClass( 'tabs' ).appendTo( context.modules.toolbar.$toolbar );
var $sections = $( '<div>' ).addClass( 'sections' ).appendTo( context.modules.toolbar.$toolbar );
context.modules.toolbar.$toolbar.append( $( '<div>' ).css( 'clear', 'both' ) );
var sectionQueue = [];
for ( var section in config ) {
if ( section === 'main' ) {