I just inspect the tools they provide and follow the bread crumbs. The first thing I looked at was editor.min.js which is loaded with many hooks and events that we can use.
Some but not all can be found here https://code.elementor.com/js-hooks/
Here’s how I went about it…
1) I load up my page in the Elementor editor.
2) I open chrome dev tools (right-click inspect)
3) I click on the Sources tab and locate /wp-content/plugins/elementor/assets/js/editor.min.js
and click on the file name to reveal it in the preview and expose the code for that file
4) The code is minified, in chrome dev tools there is a “pretty print” button that looks like {}
in the bottom right corner of the preview window, clicking it will un-minify the code and make it much easier to read
5) I click anywhere in the code in the preview window and press CTRL+F to open the search/find dialog just below the code preview window
6) I search for “save” initially and see there there is two event listeners that look interesting, before:save
and after:save
which are listened via the elementor.saver.on
method.
7) I then include a simple script in my footer by using the wp_footer
action that WordPress provides like so:
//triger javascript events on editor save
add_action( 'wp_footer', function() {
if ( ! defined( 'ELEMENTOR_VERSION' ) ) {
return;
}
?>
<script>
jQuery( function( $ ) {
elementor.saver.on( 'before:save', function() {
alert('Event before changes are saved');
} );
elementor.saver.on( 'after:save', function() {
alert( 'Event after changes are saved' );
} );
} );
</script>
<?php
} );
p.s. You don’t have to wrap it in a jQuery wrapper, I just included it so that it allows the use of jQuery since it’s bundled w/ WordPress anyway and most designers are familiar with it.
p.s.s. I take that back, the “on” method is exclusive to jQuery so it DOES need to be wrapped like I provided.
-
This reply was modified 5 years, 5 months ago by
pingram. Reason: jQuery disclaimer
-
This reply was modified 5 years, 5 months ago by
pingram. Reason: clarify false statement