Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric attribute fix #180

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions js/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,15 @@ var Shortcode_UI;
if ( attr.get( 'attr' ) === 'content' ) {
content = attr.get( 'value' );
} else {
attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );

// Numeric attribute names
if ( ! isNaN( attr.get( 'attr' ) ) ) {
attrs.push( '"' + attr.get( 'value' ) + '"' );

// String attribute names
} else {
attrs.push( attr.get( 'attr' ) + '="' + attr.get( 'value' ) + '"' );
}
}

} );
Expand Down Expand Up @@ -836,6 +844,13 @@ var Shortcode_UI;
options.shortcode.attrs.named[ attr.get( 'attr') ]
);
}

if ( attr.get( 'attr') in options.shortcode.attrs.numeric ) {
attr.set(
'value',
options.shortcode.attrs.numeric[ attr.get( 'attr') ]
);
}

if ( attr.get( 'attr' ) === 'content' && ( 'content' in options.shortcode ) ) {
attr.set( 'value', options.shortcode.content );
Expand Down Expand Up @@ -908,17 +923,33 @@ var Shortcode_UI;

if ( matches[2] ) {

attributeMatches = matches[2].match(/(\S+?=".*?")/g ) || [];
// Get all the attributes
attributeMatches = matches[2].match(/([^\s]+)/g ) || [];

// convert attribute strings to object.
for ( var i = 0; i < attributeMatches.length; i++ ) {

var bitsRegEx = /(\S+?)="(.*?)"/g;
var bits = bitsRegEx.exec( attributeMatches[i] );
// Keep track of all the unnamed attributes
var unnamedIndex = 0;

attr = currentShortcode.get( 'attrs' ).findWhere( { attr: bits[1] } );
if ( attr ) {
attr.set( 'value', bits[2] );
// convert attribute strings to object.
for ( var i = 0; i < attributeMatches.length; i++ ) {

// Handler for named attributes
if ( attributeMatches[i].match(/\S+?="(.*?)"/) !== null ) {

var bitsRegEx = /(\S+?)="(.*?)"/g;
var bits = bitsRegEx.exec( attributeMatches[i] );

attr = currentShortcode.get( 'attrs' ).findWhere( { attr: bits[1] } );
if ( attr ) {
attr.set( 'value', bits[2] );
}

// Handler for numeric/unnamed attributes
} else {

attr = currentShortcode.get( 'attrs' ).findWhere( { attr: (unnamedIndex++).toString() } );
if ( attr ) {
attr.set( 'value', attributeMatches[i].replace(/^"(.*)"$/, '$1') );
}
}

}
Expand Down