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

Example of js hooks #768

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 23 additions & 2 deletions js/build/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1847,12 +1847,33 @@ sui.views.editAttributeSelect2Field = sui.views.editAttributeField.extend( {
dataType: 'json',
delay: 250,
data: function (params) {

var shortcode = self.shortcode.get( 'shortcode_tag' ),
attr = self.model.get( 'attr' ),
filterName = [ shortcode, attr, 'ajax-data' ].join('.'),
collection = _.flatten( _.values( self.views.parent.views._views ) );

/**
* Filter any additional parameters sent along with search request.
*
* Called as `{shortcodeName}.{attributeName}.ajax-data`.
*
* @param ajaxData (object)
* Default fields sent with request
* @param viewModels (array)
* The collections of views (editAttributeFields)
* which make up this shortcode UI form
* @param shortcode (object)
* Reference to the shortcode model which this attribute belongs to.
*/
var ajaxData = wp.shortcake.hooks.applyFilters( filterName, self.ajaxData, collection, self.shortcode );

return $.extend( {
s : params.term, // search term
page : params.page,
shortcode : self.shortcode.get( 'shortcode_tag'),
attr : self.model.get( 'attr' )
}, self.ajaxData );
attr : self.model.get( 'attr' ),
}, ajaxData );
},
processResults: function (response, params) {
if ( ! response.success || 'undefined' === typeof response.data ) {
Expand Down
25 changes: 23 additions & 2 deletions js/src/views/select2-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,33 @@ sui.views.editAttributeSelect2Field = sui.views.editAttributeField.extend( {
dataType: 'json',
delay: 250,
data: function (params) {

var shortcode = self.shortcode.get( 'shortcode_tag' ),
attr = self.model.get( 'attr' ),
filterName = [ shortcode, attr, 'ajax-data' ].join('.'),
collection = _.flatten( _.values( self.views.parent.views._views ) );

/**
* Filter any additional parameters sent along with search request.
*
* Called as `{shortcodeName}.{attributeName}.ajax-data`.
*
* @param ajaxData (object)
* Default fields sent with request
* @param viewModels (array)
* The collections of views (editAttributeFields)
* which make up this shortcode UI form
* @param shortcode (object)
* Reference to the shortcode model which this attribute belongs to.
*/
var ajaxData = wp.shortcake.hooks.applyFilters( filterName, self.ajaxData, collection, self.shortcode );

return $.extend( {
s : params.term, // search term
page : params.page,
shortcode : self.shortcode.get( 'shortcode_tag'),
attr : self.model.get( 'attr' )
}, self.ajaxData );
attr : self.model.get( 'attr' ),
}, ajaxData );
},
processResults: function (response, params) {
if ( ! response.success || 'undefined' === typeof response.data ) {
Expand Down