Ajax post uploading takes place for you with certain javascript-events. To one of these events ( ajax:success
, for example) you need to bind a block initialization script with buttons:
var share = Ya.share2('my-share', { content: { url: 'https://yandex.com' } // здесь вы можете указать и другие параметры });
Learn more: https://tech.yandex.ru/share/doc/dg/api-docpage/
In your case, each loaded post will already have a Yandex div
-block with the necessary parameters in the data
attributes. You will only need to receive data through them in the initialization script:
var share = Ya.share2('my-share', { content: { image: $('#my-share').attr('data-image') url: $('#my-share').attr('data-url') ... } });
Where my-share
is the block ID. In your case, the algorithm is as follows:
- Ayaksovo get html with new posts
- Browse all the Share blocks in them (for example, through the class
ya-share2
) - Each block will recognize the ID (it must be assigned in advance and be unique) and run the initializer Ya.share2 ()