S
S
Sergey Zolotarev2018-08-07 11:31:08
JavaScript
Sergey Zolotarev, 2018-08-07 11:31:08

Compatibility of API methods of the "Share" block from Yandex with jQuery objects, is it available?

Hello!
Now I'm learning to make a website on PHP+Yii Framework. In the client side, I use not only HTML5 and CSS3, but also JS + JQuery.
Have you heard of the "Share" button for websites? I have known about this for a long time. For several years, Yandex has been developing its technology for third-party web developers - the "Share" block with its JavaScript API. I wanted to try it for future promotion (I'm currently working on the local host).
I wanted to use the API, but the single script of my site is written in the same JQuery and I used JQuery methods and objects in the API call code, and this is my written example (I haven’t tested it yet):

var siteshare=$('.dobriye-vzroslye-site-ya-share');//Открываю доступ к элементу для социальных иконок с помощью объекта JQuery

var ssh=Ya.share2(siteshare,{
   theme: {
        services: 'facebook,twitter,vkontakte,odnoklassniki,gplus,tumblr,viber,whatsapp',
        counter: true,
        lang: 'ru',
        size: 'm',
        bare: false,
        direction: 'horizontal'
    },
    content: {
        url: $("site-social-all-data > #url").val(),
        title: $("site-social-all-data > #title").val(),
        description: $("site-social-all-data > #description").val(),
        image: $("site-social-all-data > #imagesrc").val()   
    }
    
});

ssh.updateContentByService({
  facebook:{
    url: $("site-social-all-data > #url").val(),
    title: $("site-social-all-data > #title").val(),
    description: $("site-social-all-data > #description").val(),
    image: $("site-social-all-data > #imagesrc").val(),
    accessToken: 'EAADIvyUDV1MBAMEjXhru312PZCMQGXDtmwqxL1GfMa9y4EJvSZAO0ZAUUdIwEs91bypuBAWZAUYHB5s4R1lu8rYZBAxo0lZB18bouSgs6qV4KoegvvVonzorbbsMG3R69rA9bV3vibOsJYRSAMOWEULZBVaxTqe5thhhaU6ZA511H9lKcwZBzmrCA7LZAPFxhWXZAQZD'
  }
});

I read in the documentation that regular JavaScript objects can be used in the call ( Full documentation on this API is here ) and I want to know if in my example the API can be combined with the JQuery $() object and its val() method (where the special data is located for social networks and services in hidden fields on each page) and in general with all JQuery methods for accessing data and texts?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-08-07
@lebonnet

  • firstly, no one uses these buttons anymore, they do not make sense
    not an element, but a collection of elements
    in the third docs clearly says:
    Also, instead of an id, you can pass the element itself
    i.e. if you want to use jQuery, then you need to pass it like this:
  • there is simply no need to pass a collection of jQuery DOM elements to the Yandex constructor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question