PageSourceSearch

https://straightsale.lk/wp-content/themes/realhomes/common/js/compare-properties.js?ver=3.10.1

js straightsale.lk collected 2026-10-07 15:45:35 UTC 10,800 bytes, 244 lines download raw bytes

1(function ($) {
2    "use strict";
3
4    $(document).ready(function () {
5        /*-----------------------------------------------------------------------------------*/
6        /* Compare Properties
7         /*-----------------------------------------------------------------------------------*/
8
9        // Add class if container has properties
10        function addClassForChildren() {
11            var compare_properties_number = $('.rh_compare .rh_compare__carousel > div').length;
12            if (compare_properties_number !== 0) {
13                $('.rh_wrapper_properties_compare').addClass('rh_has_compare_children');
14            } else {
15                $('.rh_wrapper_properties_compare').removeClass('rh_has_compare_children');
16            }
17            if (!$('.rh_wrapper_properties_compare').hasClass('rh_has_compare_children')) {
18                $('.rh_wrapper_properties_compare').removeClass('rh_compare_open');
19                $('.rh_fixed_side_bar_compare').fadeOut(0);
20            }
21
22        }
23
24        $('html').on('click', '.rh_floating_compare_button', function (e) {
25
26            $('.rh_wrapper_properties_compare').toggleClass('rh_compare_open');
27            if ($('.rh_wrapper_properties_compare').hasClass('rh_compare_open')) {
28                $('.rh_fixed_side_bar_compare').fadeIn(200);
29            } else {
30                $('.rh_fixed_side_bar_compare').fadeOut(200);
31            }
32            e.stopPropagation();
33        });
34
35        addClassForChildren();
36
37        // Inject HTML in floating Compare count
38        function floatCompareCount() {
39            var getDivCount = $('body .rh_compare .rh_compare__carousel > div').length;
40            $('.rh_wrapper_properties_compare .rh_compare_count').html(' ( ' + getDivCount + '/4 ) ');
41        }
42
43        floatCompareCount();
44
45        // Notification for exceeding more than 4 properties
46        function compare_action_notification() {
47            const $rh_compare_action_notification = $('#rh_compare_action_notification');
48            $rh_compare_action_notification.addClass("show");
49
50            setTimeout(function () {
51                $rh_compare_action_notification.removeClass("show");
52            }, 6000);
53        }
54
55        // Inject Property HTML in Compare View
56        var rhCompareInstance = '';
57
58        function injectCompareHtml(img, id, url, width, height, title, titleUrl) {
59
60
61            if (id !== rhCompareInstance) {
62
63                $('.rh_compare__carousel').append(
64                    '<div class="rh_compare__slide">' +
65                    '<div class="rh_compare__slide_img">' +
66                    '<div class="rh_compare_img_inner">' +
67                    '<a target="_blank" href="' + titleUrl + '"><img src="' + img + '" width="' + width + '" height=" ' + height + '" ></a>' +
68                    '<a class="rh_compare__remove" data-property-id=" ' + id + ' " href=" ' + url + ' " ><i class="fa"><svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" style="fill:none;stroke-linejoin:round;stroke-width:2;stroke:currentColor">' +
69                    '<line x1="18" x2="6" y1="6" y2="18"/>' +
70                    '<line x1="6" x2="18" y1="6" y2="18"/>' +
71                    '</svg></i></a>' +
72                    '</div>' +
73                    '<a target="_blank" href="' + titleUrl + '" class="rh_compare_view_title">' + title + '</a>' +
74                    '</div>' +
75                    '</div>'
76                );
77            }
78            rhCompareInstance = id;
79
80        }
81
82        // Match the ids of properties in all section that are added to compare
83        function matchAddedId() {
84            var dataArray = [];
85            $('.rh_compare__carousel > div').each(function () {
86                var thisData = $(this).find('.rh_compare__remove').data('property-id');
87                dataArray.push(parseInt(thisData));
88            });
89
90            $('span.add-to-compare-span').each(function () {
91                var thisSpanData = $(this).data('button-id');
92                if ($.inArray(thisSpanData, dataArray) !== -1) {
93
94                    $(this).find('.compare-placeholder').removeClass('hide');
95                    $(this).find('a.rh_trigger_compare').addClass('hide');
96                } else {
97                    $(this).find('.compare-placeholder').addClass('hide');
98                    $(this).find('a.rh_trigger_compare').removeClass('hide');
99                }
100            });
101        }
102
103
104        /*-----------------------------------------------------------------------------------*/
105        /* Add to compare
106         /*-----------------------------------------------------------------------------------*/
107        $('body').on('click', 'a.rh_trigger_compare', function (e) {
108            e.preventDefault();
109
110            var slides_number = $('.rh_compare__carousel .rh_compare__slide').length;
111
112            if (slides_number > 3) {
113                var remove_last_check = 1;
114                $('.rh_compare__carousel .rh_compare__slide:nth-child(1) a.rh_compare__remove').trigger("click", [$(this), remove_last_check]);
115                compare_action_notification();
116
117            } else {
118                var compare_placeholder = $(this).parent().find('.compare-placeholder');
119                var compare_link = $(this); // Add to compare link.
120                var button_title = $(this).parent().data('button-title');
121                var title_url = $(this).parent().data('button-url');
122
123                var classicIconATC = $(this).find('.rh_classic_icon_atc');
124                classicIconATC.addClass('fa-spin');
125
126                var add_compare_request = $.ajax({
127                    url: $(compare_link).attr('href'),
128                    type: "POST",
129                    data: {
130                        property_id: $(compare_link).data('property-id'),
131                        action: "inspiry_add_to_compare"
132                    },
133                    dataType: "json"
134                });
135
136                add_compare_request.done(function (response) {
137                    if (response.success) {
138                        injectCompareHtml(response.img, response.property_id, response.ajaxURL, response.img_width, response.img_height, button_title, title_url);
139
140                        matchAddedId();
141                        addClassForChildren();
142                        $('.rh_compare_count').fadeOut(200, function () {
143                            floatCompareCount();
144                        });
145                        $('.rh_compare_count').fadeIn(200);
146
147                        classicIconATC.removeClass('fa-spin');
148
149                    } else {
150                        classicIconATC.removeClass('fa-spin');
151                    }
152                });
153
154                add_compare_request.fail(function (jqXHR, textStatus) {});
155            }
156
157        });
158
159        /*-----------------------------------------------------------------------------------*/
160        /* Remove from compare
161         /*-----------------------------------------------------------------------------------*/
162        $('body').on('click', 'a.rh_compare__remove', function (event, add_compare_target, remove_last) {
163            event.preventDefault();
164            var current_link = $(this);
165            var cross = $(this).find('i');
166            var plus = $(add_compare_target).find('.rh_classic_icon_atc');
167
168            cross.addClass('fa-spin');
169            plus.addClass('fa-spin');
170
171            $.when(
172                $.ajax({
173                    url: current_link.attr('href'),
174                    type: "POST",
175                    data: {
176                        property_id: current_link.data('property-id'),
177                        action: "inspiry_remove_from_compare"
178                    },
179                    dataType: "json"
180                })
181                    .done(function (response) {
182                        cross.removeClass('fa-spin');
183                        if (response.success) {
184
185                            current_link.parents('div.rh_compare__slide').remove();
186                            var property_item = $('span.add-to-compare-span *[data-property-id="' + response.property_id + '"]').parent();
187                            property_item.find('span.compare-placeholder').addClass('hide');
188                            $('span.add-to-compare-span *[data-property-id="' + response.property_id + '"]').removeClass('hide').delay(200).show();
189                            var compare_properties_number = $('.rh_compare .rh_compare__carousel > div').length;
190
191                            $('.rh_compare_count').fadeOut(200, function () {
192                                floatCompareCount();
193                            });
194
195                            matchAddedId();
196
197                            addClassForChildren();
198                        }
199                    })
200                    .fail(function (jqXHR, textStatus) {
201
202                    }))
203                .then(function (response) {
204
205                    if (remove_last) {
206                        var compare_link = $(add_compare_target);
207                        var compare_placeholder = $(add_compare_target).parent().find('.compare-placeholder');
208                        var button_title = $(add_compare_target).parent().data('button-title');
209                        var title_url = $(add_compare_target).parent().data('button-url');
210
211                        var classicIconATC = $(this).find('.rh_classic_icon_atc');
212                        classicIconATC.addClass('fa-spin');
213
214                        var add_compare_request = $.ajax({
215                            url: $(compare_link).attr('href'),
216                            type: "POST",
217                            data: {
218                                property_id: $(compare_link).data('property-id'),
219                                action: "inspiry_add_to_compare"
220                            },
221                            dataType: "json"
222                        });
223
224                        add_compare_request.done(function (response) {
225                            plus.removeClass('fa-spin');
226                            if (response.success) {
227                                injectCompareHtml(response.img, response.property_id, response.ajaxURL, response.img_width, response.img_height, button_title, title_url);
228
229                                floatCompareCount();
230
231                                matchAddedId();
232                                classicIconATC.removeClass('fa-spin');
233
234                            } else {
235                                classicIconATC.removeClass('fa-spin');
236                            }
237                        });
238                    }
239                    $('.rh_compare_count').fadeIn(200);
240
241                });
242        });
243    });
244})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.