diff --git a/js/build/shortcode-ui.js b/js/build/shortcode-ui.js index 732890e1..d7f26ead 100644 --- a/js/build/shortcode-ui.js +++ b/js/build/shortcode-ui.js @@ -167,7 +167,15 @@ var Shortcode = Backbone.Model.extend({ 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' ) + '"' ); + } } } ); @@ -356,6 +364,13 @@ var shortcodeViewConstructor = { 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 ); @@ -430,19 +445,37 @@ var shortcodeViewConstructor = { 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++) { + // Keep track of all the unnamed attributes + var unnamedIndex = 0; - 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]); + // 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')); + } } } diff --git a/js/models/shortcode.js b/js/models/shortcode.js index daeb48e7..b0dcac72 100644 --- a/js/models/shortcode.js +++ b/js/models/shortcode.js @@ -65,7 +65,15 @@ var Shortcode = Backbone.Model.extend({ 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' ) + '"' ); + } } } ); diff --git a/js/utils/shortcode-view-constructor.js b/js/utils/shortcode-view-constructor.js index 84c0eb78..280f004f 100644 --- a/js/utils/shortcode-view-constructor.js +++ b/js/utils/shortcode-view-constructor.js @@ -26,6 +26,13 @@ var shortcodeViewConstructor = { 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 ); @@ -100,19 +107,37 @@ var shortcodeViewConstructor = { 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')); + } } }