[wp-trac] [WordPress Trac] #23954: Checkbox value is not updated correctly inside media-views.js
WordPress Trac
noreply at wordpress.org
Sat Apr 6 01:07:07 UTC 2013
#23954: Checkbox value is not updated correctly inside media-views.js
----------------------------+------------------------------
Reporter: NumberKruncher | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 3.5.1
Severity: major | Resolution:
Keywords: needs-patch |
----------------------------+------------------------------
Comment (by NumberKruncher):
When the checkbox is ticked the shortcode attribute is not outputted as
`show_captions="true"` which I guess is fine. I notice that this can be
explicitly forced by overriding `wp.media.gallery.shortcode` in my plugin,
though this really doesn't bother me.
However, when the "Edit Gallery" interface is first shown, the attribute
"show_captions" is not present because its value is implied. So the
checkbox is not checked (even though it should be).
To fix this I added the following to my plugin:
{{{
var mediaGalleryAttachments = media.gallery.attachments;
media.gallery.attachments = function(shortcode) {
// Needed to ensure that shortcode attribute is added. When "Show
Captions"
// is checked the shortcode is not added to output because the
value `true`
// seems to be implied. But in order for this to work we must
detect when
// attribute is not specified so that checkbox is ticked when the
"Edit Gallery"
// interface is first shown.
if (shortcode && shortcode.tag === 'gallery') {
if (shortcode.attrs.named['show_captions'] === undefined)
shortcode.attrs.named['show_captions'] = true;
}
return mediaGalleryAttachments(shortcode);
};
}}}
This bug fix and the above snippet allow me to add my own checkboxes to
the "Edit Gallery" interface. Once this bug fix has been applied I will
write a tutorial in my blog for others who would like to add a checkbox to
the "Edit Gallery" interface.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23954#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list