<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>like UI Component</title><link>https://community.telligent.com/community/13/w/api-documentation/75815/like-ui-component</link><description>&lt;p&gt;&lt;span&gt;Developing on Verint Community? Use the API documentation as a reference for all supported interactions with Verint Community.&lt;/span&gt;&lt;/p&gt;</description><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>like UI Component</title><link>https://community.telligent.com/community/13/w/api-documentation/75815/like-ui-component</link><pubDate>Fri, 08 Mar 2024 17:52:04 GMT</pubDate><guid isPermaLink="false">84a90848-39ec-4ede-8fdc-40f53ac8b666</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/13/w/api-documentation/75815/like-ui-component#comments</comments><description>Current Revision posted to API Documentation by Ben Tiedt on 03/08/2024 17:52:04&lt;br /&gt;
&lt;hr class="generated-documentation-start" style="border-width:0;" /&gt;&lt;h3&gt;jQuery.telligent.evolution.ui.components.like&lt;/h3&gt;
&lt;p&gt;[[ui JavaScript API Module|UI Component]] which handles presentation of like behavior for content. Transforms the output from &lt;code&gt;$core_v2_ui.Like()&lt;/code&gt;, which is a &lt;code&gt;&amp;lt;span class=&amp;quot;ui-like&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;/code&gt; stub. The default implementation uses the [[evolutionLike jQuery Plugin|evolutionLike plugin]]. [[ui JavaScript API Module|Overrides can be provided]] at the theme level to present liking differently.&lt;/p&gt;
&lt;h3&gt;Options&lt;/h3&gt;
&lt;p&gt;Data made available to instances of the component:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;contenttypeid&lt;/code&gt;: (string) Content Type Id Guid&lt;/li&gt;
&lt;li&gt;&lt;code&gt;contentid&lt;/code&gt;: (string) Content Id Guid&lt;/li&gt;
&lt;li&gt;&lt;code&gt;initialcount&lt;/code&gt;: (number) Current Like Count&lt;/li&gt;
&lt;li&gt;&lt;code&gt;initialstate&lt;/code&gt;: (boolean) Whether the accessing user has already liked the content&lt;/li&gt;
&lt;li&gt;&lt;code&gt;readonly&lt;/code&gt;: (boolean) Whether the UI component should render in a read-only state&lt;/li&gt;
&lt;li&gt;&lt;code&gt;initialmessage&lt;/code&gt;: (string) Pre-rendered message regarding the current likes a piece of content has&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;format&lt;/code&gt;: string containing tokens identifying if, and where, the component should render a count, toggle link, and &amp;#39;who likes&amp;#39; message. For example, &lt;code&gt;&amp;quot;{toggle} {count}&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;{count} - {message}&amp;quot;&lt;/code&gt;.
&lt;ul&gt;
&lt;li&gt;
Tokens:
&lt;ul&gt;
&lt;li&gt;{count}&lt;/li&gt;
&lt;li&gt;{toggle}&lt;/li&gt;
&lt;li&gt;{message}&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;configuration&lt;/code&gt;: Object of all other keys and values passed via the options dictionary to &lt;code&gt;$core_v2_ui.Like()&lt;/code&gt;, regardless of whether they have been pre-defined
&lt;ul&gt;
&lt;li&gt;
[[evolutionLike jQuery Plugin|jQuery.evolutionLike]] looks for the following optional configuration:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;LinkClassName&lt;/code&gt;:&lt;/li&gt;
&lt;li&gt;&lt;code&gt;LikeTypeId&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Example&lt;/h3&gt;
&lt;p&gt;A barebones UI component override which would result in rendering a read-only message of &amp;#39;Likes: [count] Liked? [yes|no]&amp;#39;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$.telligent.evolution.ui.components.like = {
    setup: function() {
    },
    add: function(elm, options) {
        var message = &amp;#39;Likes: &amp;#39; + (options.initialcount || 0);
        if(options.initialstate) {
            message = message + &amp;#39; Liked? yes&amp;#39;;
        } else {
            message = message + &amp;#39; Liked? no&amp;#39;;
        }

        $(elm).html(message);
    }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Default Implementation&lt;/h3&gt;
&lt;p&gt;For reference purposes or as the basis for an override:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(function($){

var getCurrentCount = function(contentId, contentTypeId, typeId, complete) {
    $.telligent.evolution.get({
        url: $.telligent.evolution.site.getBaseUrl() + &amp;#39;api.ashx/v2/likes.json&amp;#39;,
        data: {
            ContentId: contentId,
            ContentTypeId: contentTypeId,
            TypeId: typeId,
            SortBy: &amp;#39;Date&amp;#39;,
            SortOrder: &amp;#39;Descending&amp;#39;,
            PageSize: 1,
            PageIndex: 0
        },
        cache: false,
        dataType: &amp;#39;json&amp;#39;,
        success: function(response) {
            complete.call(this, {
                count: response.TotalCount,
                latestLike: response.Likes.length &amp;gt; 0 ? response.Likes[0] : null
            });
        }
    });
};

$.telligent.evolution.messaging.subscribe(&amp;#39;ui.like&amp;#39;, function(data) {
    // update existing like components so that if they regenerate, have the proper value
    var likeLinks = data.typeId
        ? $(&amp;#39;.ui-like[data-contentid=&amp;quot;' + data.contentId + '&amp;quot;][data-contenttypeid=&amp;quot;' + data.contentTypeId + '&amp;quot;][data-typeid=&amp;quot;' + data.typeId + '&amp;quot;]&amp;#39;)
        : $(&amp;#39;.ui-like[data-contentid=&amp;quot;' + data.contentId + '&amp;quot;][data-contenttypeid=&amp;quot;' + data.contentTypeId + '&amp;quot;]&amp;#39;);
    likeLinks
        .attr(&amp;#39;data-initialstate&amp;#39;, data.liked.toString())
        .attr(&amp;#39;data-initialcount&amp;#39;, data.count.toString())
        .attr(&amp;#39;data-initialmessage&amp;#39;, data.message.toString());
});

$.telligent.evolution.ui.components.like = {
    // set up efficient event-delegated handling of showing/hiding who likes popups
    setup: function() {
        $.fn.evolutionLike.delegatePopups({
            containerSelector: &amp;#39;.content-fragment&amp;#39;,
            delegatedSelector: &amp;#39;.ui-like&amp;#39;,
            onList: function(contentId, contentTypeId, typeId, complete, pageSize, pageIndex) {
                $.telligent.evolution.get({
                    url: $.telligent.evolution.site.getBaseUrl() + &amp;#39;api.ashx/v2/likes.json&amp;#39;,
                    data: {
                        ContentId: contentId,
                        ContentTypeId: contentTypeId,
                        TypeId: typeId,
                        SortBy: &amp;#39;Date&amp;#39;,
                        SortOrder: &amp;#39;Descending&amp;#39;,
                        PageSize: pageSize || 20,
                        PageIndex: pageIndex || 0
                    },
                    cache: false,
                    dataType: &amp;#39;json&amp;#39;,
                    success: function(response) {
                        // get the resized image html of all the avatars within a batch
                        $.telligent.evolution.batch(function(){
                            $.each(response.Likes, function(i, like) {
                                $.telligent.evolution.get({
                                    url: $.telligent.evolution.site.getBaseUrl() + &amp;#39;api.ashx/v2/ui/image.json&amp;#39;,
                                    data: {
                                        url: like.User.AvatarUrl,
                                        maxWidth: 32,
                                        maxHeight: 32,
                                        resizeMethod: &amp;#39;ZoomAndCrop&amp;#39;
                                    }
                                }).then(function(response){
                                    like.userAvatarHtml = response.Html;
                                });
                            });
                        }).then(function(){
                            complete({
                                likers: $.map(response.Likes, function(like) {
                                    var liker = {
                                        displayName: like.User.DisplayName,
                                        profileUrl: like.User.ProfileUrl,
                                        avatarHtml: like.userAvatarHtml
                                    };
                                    return liker;
                                }),
                                hasMorePages: (((response.PageIndex + 1) * response.PageSize) &amp;lt; response.TotalCount)
                            });
                        })
                    }
                });
            },
            onOptions: function(elm) {
                var data = $.telligent.evolution.ui.data(elm);
                var parsedData = {
                    contentId: data.contentid,
                    contentTypeId: data.contenttypeid,
                    typeId: data.configuration.LikeTypeId
                };
                return parsedData;
            }
        });
    },
    // set up instances of bus-bound like toggles/counts/messages
    add: function(elm, options) {
        var readOnly = options.readonly === &amp;#39;true&amp;#39;;
        $(elm).evolutionLike({
            contentId: options.contentid,
            contentTypeId: options.contenttypeid,
            initialState: options.initialstate,
            initialMessage: options.initialmessage,
            initialCount: options.initialcount,
            format: (readOnly ? options.format.replace(&amp;#39;{toggle}&amp;#39;,&amp;#39;&amp;#39;) : options.format),
            typeId: options.configuration.LikeTypeId,
            onLike: function(contentId, contentTypeId, typeId, complete) {
                $.fn.evolutionTip.hide();
                var data = {
                    ContentId: contentId,
                    ContentTypeId: contentTypeId
                };
                if(typeId !== null &amp;amp;&amp;amp; typeId.length &amp;gt; 0) {
                    data.TypeId = typeId;
                }
                $.telligent.evolution.post({
                    url: $.telligent.evolution.site.getBaseUrl() + &amp;#39;api.ashx/v2/likes.json&amp;#39;,
                    data: data,
                    cache: false,
                    dataType: &amp;#39;json&amp;#39;,
                    success: function(response) {
                        getCurrentCount(contentId, contentTypeId, typeId, complete);
                    }
                });
            },
            onUnlike: function(contentId, contentTypeId, typeId, complete) {
                $.fn.evolutionTip.hide();
                var data = {
                    ContentId: contentId
                };
                if(typeId !== null &amp;amp;&amp;amp; typeId.length &amp;gt; 0) {
                    data.TypeId = typeId;
                }
                $.telligent.evolution.del({
                    url: $.telligent.evolution.site.getBaseUrl() + &amp;#39;api.ashx/v2/like.json&amp;#39;,
                    data: data,
                    cache: false,
                    dataType: &amp;#39;json&amp;#39;,
                    success: function(response) {
                        getCurrentCount(contentId, contentTypeId, typeId, complete);
                    }
                });
            }
        });
    }
};

}(jQuery));
&lt;/code&gt;&lt;/pre&gt;

&lt;hr class="generated-documentation-end" style="border-width:0;" /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>