-
Notifications
You must be signed in to change notification settings - Fork 142
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
Unnamed/numeric attribute fix (revised) #198
Open
bfintal
wants to merge
11
commits into
wp-shortcake:master
Choose a base branch
from
bfintal:numeric-attribute-fix-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7151827
Merge pull request #2 from fusioneng/master
bfintal 44001d0
Merge pull request #3 from fusioneng/master
bfintal 85919fa
Merge pull request #4 from fusioneng/master
bfintal 2b76387
Numeric attribute fix (revised)
bfintal 75c6192
Removed quotes on unnamed attributes
bfintal 2169cbb
Merge pull request #7 from fusioneng/master
bfintal 5cf76c5
Preserve empty unnamed attributes
bfintal 6933baa
Merge pull request #8 from fusioneng/master
bfintal 020fdef
Merge pull request #9 from fusioneng/master
bfintal c15c6aa
Merge branch 'master' into numeric-attribute-fix-2
bfintal e32b259
Synced to master, but now not working
bfintal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' ) + '"' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to wrap in quotes? |
||
|
||
// 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')); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of double negatives here... We could check
$.isNumeric( attr.get( 'attr' ) )
instead?