utils.js
26 lines
| 1 | /** |
| 2 | * Will attach the post model to the window object if it doesn't exist. |
| 3 | * |
| 4 | * @param {number} elementorId Id of the page/post. |
| 5 | * @return {Promise<void>} |
| 6 | */ |
| 7 | export const setPostModel = async ( elementorId ) => { |
| 8 | if ( undefined !== window.tiTpc.postModel ) { |
| 9 | return; |
| 10 | } |
| 11 | |
| 12 | let postModel; |
| 13 | if ( 'page' === window.tiTpc.postType ) { |
| 14 | postModel = await new wp.api.models.Page( { id: elementorId } ); |
| 15 | } else { |
| 16 | postModel = await new wp.api.models.Post( { id: elementorId } ); |
| 17 | } |
| 18 | |
| 19 | if ( undefined === postModel ) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | window.tiTpc.postModel = postModel; |
| 24 | await window.tiTpc.postModel.fetch(); |
| 25 | }; |
| 26 |