-
Notifications
You must be signed in to change notification settings - Fork 7
[WIP] Add checkbox field to use the attachment's alt or caption values #78
base: master
Are you sure you want to change the base?
[WIP] Add checkbox field to use the attachment's alt or caption values #78
Conversation
The `alt` and `caption` attributes of the shortcode will be used by default.
I wasn't able to effectively disable the text input fields associated with the alt and caption checkboxes. I got that working for changed values, but not for the initial load of the modal. Here's what I have so far in attachmentAlt: function( changed, collection, shortcode ) {
var $altField = sui.views.editAttributeField.getField( collection, 'alt' ).$el.find('input');
if ( changed.value === true ) {
$altField.attr('disabled', 'disabled');
} else {
$altField.removeAttr('disabled');
}
},
attachmentCaption: function( changed, collection, shortcode ) {
var $captionField = sui.views.editAttributeField.getField( collection, 'caption' ).$el.find('input');
if ( changed.value === true ) {
$captionField.attr('disabled', 'disabled');
} else {
$captionField.removeAttr('disabled');
}
}
}
}
/**
* If using a recent enough version of Shortcake (0.4.0 and up),
* attach these listeners to the attributes.
*
*/
if ( typeof wp.shortcake !== 'undefined' && typeof wp.shortcake.hooks !== 'undefined' ) {
wp.shortcake.hooks.addAction( 'img.attachment', ImageShortcake.listeners.attachment );
wp.shortcake.hooks.addAction( 'img.linkto', ImageShortcake.listeners.linkto );
wp.shortcake.hooks.addAction( 'img.attachment_alt', ImageShortcake.listeners.attachmentAlt );
wp.shortcake.hooks.addAction( 'img.attachment_caption', ImageShortcake.listeners.attachmentCaption );
} I think the wording of the checkbox label is clear enough to indicate what's going on without disabling the associated text input, but I'd appreciate any pointers on how I'd set the |
Also it looks like the build errors have nothing to do with my changes. |
I'm also unsure how to set a default value on a checkbox with Shortcake – I've tried |
Travis no longer supports testing against pre-installed PHP5.3, and we don't have to either. Updating the build matric so new tests can pass (see #78 (comment))
Looks like the problem is that you're checking
Hmm. I just looked into that, and it doesn't look like it's currently possible. This is a bit of a conundrum with the current architecture, since most of our field templates are based on the assumption that an empty value will be set to the default. I wonder if you could make use of the |
Also, the build issues you have should be fixed once #80 is merged in. |
Thanks, that worked, see 2b6d625 .
I tried using Note that the error that shows in the console is #75. Another alternative solution that would allow for setting a default might be using a select field instead of a checkbox? |
Oh yeah. I was thinking you only needed this behavior to implement the default value, which you would only need to set on inserting a new shortcode. If you want it to fire on editing an existing post element as well, the hook to use there is |
#77
The
alt
andcaption
attributes of the shortcode will be used bydefault.