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

View file

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

View file

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