Last active
January 26, 2018 16:49
-
-
Save marcusig/8caf1372fc8d929948035185cb2d5aaf to your computer and use it in GitHub Desktop.
wp.media listen to changes / sync when opening a media modal
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
(function($,wp){ | |
var handle_attachment_change = function(attachment){ | |
console.log(attachment); | |
} | |
var media_modal = wp.media({ | |
multiple: 'add', | |
library: {type: 'image'}, | |
button: { | |
text: 'Select image' | |
} | |
}); | |
media_modal.on('attach', function(){ | |
var library = update_slide_frame.state().get('library'); | |
// listen to the change event on the library items | |
media_modal.listenTo(library, 'change', function(attachment)){ | |
// do something with the changed model | |
handle_attachment_change(attachment); | |
}; | |
// listen to the Sync event on the library | |
media_modal.listenTo(library, 'sync', function(attachment)){ | |
// do something with the changed model | |
handle_attachment_change(attachment); | |
}; | |
}); | |
})(jquery, wp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment