PageSourceSearch

https://e123.hk/modules/custom/e123_global_js_css/assets/global/js/compare.js?v=3&v=1

js e123.hk collected 2026-10-01 12:23:13 UTC 21,849 bytes, 459 lines download raw bytes

1jQuery(function ($) {
2
3    /* Move All compare-tick-box out of views-row
4    $(document).ajaxComplete(function() {
5        if ($('.view-e123-4a1-listing').length > 0) {
6            $(".view-e123-4a1-listing .views-row").each(function(index) {
7                tick_box = $(this).find('.e123-c4a1-items-compare-tick-box-wrapper');
8                tick_box_html = tick_box.html();
9                if (tick_box_html != "") {
10                    $(this).before(tick_box_html);
11                    tick_box.html("");
12                }
13            });
14        }
15    }); */
16
17    //Click the .e123_c4a1_items_compare_tick_box to save the localStorage: 
18    /*
19        c4a1_node_compare_0_name
20        c4a1_node_compare_0_nid
21        c4a1_node_compare_1_name
22        c4a1_node_compare_1_nid
23        c4a1_node_compare_2_name
24        c4a1_node_compare_2_nid  
25    */
26
27    $(document).ajaxComplete(function () {
28        if ($('.e123_4a1_compare_confirm_box').length > 0) {
29            get_c4a1_node_compare_localStorage_status_to_tickbox();
30            get_c4a1_node_compare_localStorage_to_box();
31        }
32    });
33
34    $('body').on('click', '.e123_c4a1_items_compare_tick_box', function (event) {
35        event.stopPropagation();
36        $('.e123_4a1_compare_confirm_box').removeClass('d-none');
37    });
38
39    $('body').on('click', '.e123_c4a1_items_compare_tick_box.non-active', function (event) {
40        event.stopPropagation();
41        var selected_title = $(this).find(".title").html();
42        var selected_nid = $(this).attr('drupal-nid');
43
44        addValue_to_c4a1_node_compare_localStorage($(this), selected_nid, selected_title);
45        get_c4a1_node_compare_localStorage_status_to_tickbox();
46        get_c4a1_node_compare_localStorage_to_box();
47
48        $('.e123_4a1_compare_confirm_box').removeClass('d-none');
49    });
50    $('body').on('keydown', '.e123_c4a1_items_compare_tick_box.non-active', function (event) {
51        if (event.which === 13) {
52            event.preventDefault();
53            var selected_title = $(this).find(".title").html();
54            var selected_nid = $(this).attr('drupal-nid');
55
56            addValue_to_c4a1_node_compare_localStorage($(this), selected_nid, selected_title);
57            get_c4a1_node_compare_localStorage_status_to_tickbox();
58            get_c4a1_node_compare_localStorage_to_box();
59
60            $('.e123_4a1_compare_confirm_box').removeClass('d-none');
61        }
62    });
63
64
65
66
67    function addValue_to_c4a1_node_compare_localStorage(div, nid, title) {
68        var nid_0 = localStorage.getItem("c4a1_node_compare_0_nid");
69        var nid_1 = localStorage.getItem("c4a1_node_compare_1_nid");
70        var nid_2 = localStorage.getItem("c4a1_node_compare_2_nid");
71
72        var add_succ = true;
73        if (nid_0 == null) {
74            localStorage.setItem("c4a1_node_compare_0_nid", nid);
75            localStorage.setItem("c4a1_node_compare_0_name", title);
76        } else {
77            if (nid_1 == null) {
78                localStorage.setItem("c4a1_node_compare_1_nid", nid);
79                localStorage.setItem("c4a1_node_compare_1_name", title);
80            } else {
81                if (nid_2 == null) {
82                    localStorage.setItem("c4a1_node_compare_2_nid", nid);
83                    localStorage.setItem("c4a1_node_compare_2_name", title);
84                } else {
85                    add_succ = false;
86                }
87            }
88        }
89        if (add_succ) {
90            div.removeClass("non-active");
91            div.addClass("active");
92        }
93        get_c4a1_node_compare_localStorage_to_box();
94    }
95
96    $('body').on('click', '.e123_4a1_compare_confirm_box .e123_4a1_compare_confirm_box_hide', function () {
97        $('.e123_4a1_compare_confirm_box').addClass('d-none');
98    });
99
100
101    $('body').on('click', '.e123_4a1_compare_confirm_box .remove_compare_item', function () {
102        var deleted_index = $(this).attr('index');
103        removeValue_from_c4a1_node_compare_localStorage(deleted_index);
104        get_c4a1_node_compare_localStorage_to_box();
105    });
106
107
108    function removeValue_from_c4a1_node_compare_localStorage(deleted_index) {
109        var nid_0 = localStorage.getItem("c4a1_node_compare_0_nid");
110        var nid_1 = localStorage.getItem("c4a1_node_compare_1_nid");
111        var nid_2 = localStorage.getItem("c4a1_node_compare_2_nid");
112
113        var name_0 = localStorage.getItem("c4a1_node_compare_0_name");
114        var name_1 = localStorage.getItem("c4a1_node_compare_1_name");
115        var name_2 = localStorage.getItem("c4a1_node_compare_2_name");
116
117        localStorage.removeItem("c4a1_node_compare_0_nid");
118        localStorage.removeItem("c4a1_node_compare_0_name");
119
120        localStorage.removeItem("c4a1_node_compare_1_nid");
121        localStorage.removeItem("c4a1_node_compare_1_name");
122
123        localStorage.removeItem("c4a1_node_compare_2_nid");
124        localStorage.removeItem("c4a1_node_compare_2_name");
125
126        //Reassign the var when then item remove from .e123_4a1_compare_confirm_box and reload the .e123_4a1_compare_confirm_box
127        //Remove item 0
128        if (deleted_index == 0) {
129            if (nid_1 != null) {
130                localStorage.setItem("c4a1_node_compare_0_nid", nid_1);
131                localStorage.setItem("c4a1_node_compare_0_name", name_1);
132            }
133
134            if (nid_2 != null) {
135                localStorage.setItem("c4a1_node_compare_1_nid", nid_2);
136                localStorage.setItem("c4a1_node_compare_1_name", name_2);
137            }
138        }
139        //Remove item 1
140        if (deleted_index == 1) {
141            if (nid_0 != null) {
142                localStorage.setItem("c4a1_node_compare_0_nid", nid_0);
143                localStorage.setItem("c4a1_node_compare_0_name", name_0);
144            }
145            if (nid_2 != null) {
146                localStorage.setItem("c4a1_node_compare_1_nid", nid_2);
147                localStorage.setItem("c4a1_node_compare_1_name", name_2);
148            }
149        }
150        //Remove item 2
151        if (deleted_index == 2) {
152            if (nid_0 != null) {
153                localStorage.setItem("c4a1_node_compare_0_nid", nid_0);
154                localStorage.setItem("c4a1_node_compare_0_name", name_0);
155            }
156            if (nid_1 != null) {
157                localStorage.setItem("c4a1_node_compare_1_nid", nid_1);
158                localStorage.setItem("c4a1_node_compare_1_name", name_1);
159            }
160        }
161
162        get_c4a1_node_compare_localStorage_status_to_tickbox();
163        get_c4a1_node_compare_localStorage_to_box();
164    }
165
166
167    //Get the values from localStorage in .e123_4a1_compare_confirm_box
168    function get_c4a1_node_compare_localStorage_status_to_tickbox() {
169        var html = '';
170        var nid_0 = localStorage.getItem("c4a1_node_compare_0_nid");
171        var nid_1 = localStorage.getItem("c4a1_node_compare_1_nid");
172        var nid_2 = localStorage.getItem("c4a1_node_compare_2_nid");
173        var name_0 = localStorage.getItem("c4a1_node_compare_0_name");
174        var name_1 = localStorage.getItem("c4a1_node_compare_1_name");
175        var name_2 = localStorage.getItem("c4a1_node_compare_2_name");
176
177        $(".e123_c4a1_items_compare_tick_box").each(function (index) {
178            var currect_nid = $(this).attr('drupal-nid');
179            $(this).addClass('non-active');
180            $(this).removeClass('active');
181
182            if (nid_0 != null) {
183                if (nid_0 == currect_nid) {
184                    $(this).addClass('active');
185                    $(this).removeClass('non-active');
186                }
187            }
188            if (nid_1 != null) {
189                if (nid_1 == currect_nid) {
190                    $(this).addClass('active');
191                    $(this).removeClass('non-active');
192                }
193            }
194            if (nid_2 != null) {
195                if (nid_2 == currect_nid) {
196                    $(this).addClass('active');
197                    $(this).removeClass('non-active');
198                }
199            }
200        });
201    }
202
203
204    function get_c4a1_node_compare_localStorage_to_box() {
205        var html = '';
206        var nid_0 = localStorage.getItem("c4a1_node_compare_0_nid");
207        var nid_1 = localStorage.getItem("c4a1_node_compare_1_nid");
208        var nid_2 = localStorage.getItem("c4a1_node_compare_2_nid");
209        var name_0 = localStorage.getItem("c4a1_node_compare_0_name");
210        var name_1 = localStorage.getItem("c4a1_node_compare_1_name");
211        var name_2 = localStorage.getItem("c4a1_node_compare_2_name");
212        if (nid_0 != null) {
213            html += '<div class="item_0">' + name_0 + '<span class="remove_compare_item" index="0"> x</span></div>';
214        }
215        if (nid_1 != null) {
216            html += '<div class="item_1">' + name_1 + '<span class="remove_compare_item" index="1"> x</span></div>';
217        }
218        if (nid_2 != null) {
219            html += '<div class="item_2">' + name_2 + '<span class="remove_compare_item" index="2"> x</span></div>';
220        }
221        $('.e123_4a1_compare_confirm_box .content').html(html);
222    }
223
224
225    //Create a compare page and load the /nursing-service/house-info/compare
226    $('body').on('click', '.e123_4a1_compare_confirm_box .e123_4a1_compare_confirm_box_goto', function () {
227        location.href = '/zh-hant/nursing-service/house-compare';
228    });
229
230
231    //For compare page, load the API already created from localStorage
232    if (($(".e123_4a1_compare_main_page").length > 0) || ($(".e123_4a1_compare_cd_table").length > 0)) {
233        var nid_0 = localStorage.getItem("c4a1_node_compare_0_nid");
234        var nid_1 = localStorage.getItem("c4a1_node_compare_1_nid");
235        var nid_2 = localStorage.getItem("c4a1_node_compare_2_nid");
236        var url = '';
237        url += '/custom-api/4a1-compare.php?_format=json';
238        if (nid_0 != null) {
239            url += '&nid_1=' + nid_0;
240        }
241        if (nid_1 != null) {
242            url += '&nid_2=' + nid_1;
243        }
244        if (nid_2 != null) {
245            url += '&nid_3=' + nid_2;
246
247            $(".e123_4a1_compare_main_page").addClass("compare_3_items");
248            $(".e123_4a1_compare_main_page").removeClass("compare_2_items");
249            $(".e123_4a1_compare_cd_table").addClass("compare_3_items");
250            $(".e123_4a1_compare_cd_table").removeClass("compare_2_items");
251        } else {
252            $(".e123_4a1_compare_main_page").addClass("compare_2_items");
253            $(".e123_4a1_compare_main_page").removeClass("compare_3_items");
254            $(".e123_4a1_compare_cd_table").addClass("compare_2_items");
255            $(".e123_4a1_compare_cd_table").removeClass("compare_3_items");
256        }
257
258        if ((nid_1 == null) && (nid_2 == null)) {
259            $(".e123_4a1_compare_main_page .e123_4a1_compare_node_title h2").addClass('d-none');
260            $(".e123_4a1_compare_main_page .e123_4a1_compare_node_title_content").html('請選擇最少兩間院舍! ');
261            $(".e123_4a1_compare_cd_table").html('請選擇最少兩間院舍! ');
262        } else {
263            $.ajax({
264                url: url,
265                cache: false,
266                method: "GET",
267                headers: { "Accept": "application/json", "Content-Type": "application/json" },
268                beforeSend: function (xhr) {
269                    $(".e123_4a1_compare_main_page .e123_4a1_compare_node_title_content").html('正在比較……');
270                },
271                success: function (data, status, xhr) {
272                    var html_for_desktop = "";
273
274                    var html_for_fixed = "";
275                    var html_for_cd_1 = "";
276                    var html_for_cd_2 = "";
277                    var html_for_cd_3 = "";
278
279                    var cd_row_count = 0;
280
281                    //Show the title (院舍名稱)
282                    html_for_desktop += '<div class="record">';
283                    html_for_desktop += '<div class="subject"></div>';
284
285                    html_for_fixed += '<li class="cd_row_' + cd_row_count + '"></li>';
286                    var k = 0;
287                    $.each(data['title'], function (index, val) {
288                        html_for_desktop += '<div class="middle">' + val + '</div>';
289
290                        if (k == 0) html_for_cd_1 += '<li class="cd_row_' + cd_row_count + '">' + val + '</li>';
291                        if (k == 1) html_for_cd_2 += '<li class="cd_row_' + cd_row_count + '">' + val + '</li>';
292                        if (k == 2) html_for_cd_3 += '<li class="cd_row_' + cd_row_count + '">' + val + '</li>';
293                        k++;
294                    });
295                    html_for_desktop += '</div>';
296                    cd_row_count++;
297
298                    $(".e123_4a1_compare_main_page .e123_4a1_compare_node_title_content").html(html_for_desktop);
299
300
301
302                    //Show the content (院舍資料)
303                    html_for_desktop = "";
304                    $.each(data['content'], function (index, val) {
305                        html_for_desktop += '<h2>' + val['title'] + '</h2>';
306
307                        html_for_fixed += '<li class="cd_row_' + cd_row_count + ' title">' + val['title'] + '</li>';
308                        if (nid_0 != null) html_for_cd_1 += '<li class="cd_row_' + cd_row_count + '"></li>';
309                        if (nid_1 != null) html_for_cd_2 += '<li class="cd_row_' + cd_row_count + '"></li>';
310                        if (nid_2 != null) html_for_cd_3 += '<li class="cd_row_' + cd_row_count + '"></li>';
311                        cd_row_count++;
312
313
314                        var item_count = 0;
315                        html_for_desktop += '<div class="content">';
316
317                        $.each(val['value'], function (index2, val2) {
318                            item_count++;
319                            if ((item_count % 2) == 0) {
320                                html_for_desktop += '<div class="record even">';
321                            } else {
322                                html_for_desktop += '<div class="record">';
323                            }
324
325                            html_for_desktop += '<div class="subject">' + val2['subject'] + ': </div>';
326
327                            html_for_fixed += '<li class="cd_row_' + cd_row_count + '">' + val2['subject'] + '</li>';
328
329                            var k = 0;
330                            $.each(val2['value'], function (index3, val3) {
331                                var cd_html = "";
332                                if (val2['type'] == 'bool') {
333                                    if (val3 == true) {
334                                        html_for_desktop += '<div class="bool"><img src="/themes/inv/e123_enar_sub/assets/e123/images/compare_yes.svg"></div>';
335
336                                        cd_html = '<img src="/themes/inv/e123_enar_sub/assets/e123/images/compare_yes.svg">';
337                                    } else {
338                                        html_for_desktop += '<div class="bool"><img src="/themes/inv/e123_enar_sub/assets/e123/images/compare_no.svg"></div>';
339
340                                        cd_html = '<img src="/themes/inv/e123_enar_sub/assets/e123/images/compare_no.svg">';
341                                    }
342                                } else {
343                                    if (val2['type'] == 'action') {
344                                        if (val3 != null) {
345                                            if (val3['url'] != "") {
346                                                html_for_desktop += '<div class="small"><a target="_blank" href="' + val3['url'] + '">' + val3['value'] + '</a></div>';
347                                                cd_html = '<a target="_blank" href="' + val3['url'] + '">' + val3['value'] + '</a>';
348                                            } else {
349                                                html_for_desktop += '<div class="small">' + val3['value'] + '</div>';
350                                                cd_html = val3['value'];
351                                            }
352                                        } else {
353                                            html_for_desktop += '<div class="small"></div>';
354                                        }
355
356                                    } else {
357                                        if (val3 != null) {
358                                            html_for_desktop += '<div class="small">' + val3.replace(/\r\n/g, '<br/>') + '</div>';
359                                            cd_html = val3.replace(/\r\n/g, '<br/>');
360                                        } else {
361                                            html_for_desktop += '<div class="small"></div>';
362                                        }
363                                    }
364                                }
365
366                                if (k == 0) html_for_cd_1 += '<li class="cd_row_' + cd_row_count + '">' + cd_html + '</li>';
367                                if (k == 1) html_for_cd_2 += '<li class="cd_row_' + cd_row_count + '">' + cd_html + '</li>';
368                                if (k == 2) html_for_cd_3 += '<li class="cd_row_' + cd_row_count + '">' + cd_html + '</li>';
369                                k++;
370                            });
371                            html_for_desktop += '</div>';
372                            cd_row_count++;
373                        });
374                        html_for_desktop += '</div>';
375                    });
376                    $(".e123_4a1_compare_main_page .e123_4a1_compare_node_content_content").html(html_for_desktop);
377
378                    if (html_for_fixed != "") {
379                        $(".e123_4a1_compare_cd_table .features").html('<ul class="cd-features-list">' + html_for_fixed + '</ul>');
380                    }
381
382                    if (html_for_cd_1 != "") {
383                        html_for_cd_1 = '<li class="product"><ul class="cd-features-list">' + html_for_cd_1 + '</ul></li>';
384                    }
385                    if (html_for_cd_2 != "") {
386                        html_for_cd_2 = '<li class="product"><ul class="cd-features-list">' + html_for_cd_2 + '</ul></li>';
387                    }
388                    if (html_for_cd_3 != "") {
389                        html_for_cd_3 = '<li class="product"><ul class="cd-features-list">' + html_for_cd_3 + '</ul></li>';
390                    }
391
392                    $(".e123_4a1_compare_cd_table .cd-products-columns").html(html_for_cd_1 + html_for_cd_2 + html_for_cd_3);
393
394                    $(".e123_4a1_compare_cd_table").attr("num_of_row", cd_row_count);
395
396                    /* Start of calc height for cd row */
397                    if ($(window).outerWidth() < 992) {
398                        for (i = 0; i < $(".e123_4a1_compare_cd_table").attr("num_of_row"); i++) {
399                            var all_height = [];
400                            //var j = 0;
401                            $('.cd_row_' + i).each(function (index) {
402                                all_height.push($(this).outerHeight());
403                            });
404                            var max_val = Math.max.apply(null, all_height);
405                            //Set the max height to same row 
406                            $('.cd_row_' + i).css("height", max_val);
407                        }
408                    }
409                    /* End of calc height for cd row */
410                },
411                complete: function (data) {
412                    $('.e123_4a1_compare_node_content_content .content .record').each(function (index) {
413                        var target_height = $(this).outerHeight();
414                        $(this).find('.subject').css('height', target_height + 'px');
415                    });
416
417                    /*  Clear localStorage when visit the compare page  */
418                    localStorage.removeItem("c4a1_node_compare_0_nid");
419                    localStorage.removeItem("c4a1_node_compare_0_name");
420
421                    localStorage.removeItem("c4a1_node_compare_1_nid");
422                    localStorage.removeItem("c4a1_node_compare_1_name");
423
424                    localStorage.removeItem("c4a1_node_compare_2_nid");
425                    localStorage.removeItem("c4a1_node_compare_2_name");
426                },
427                error: function (data) { },
428            })
429        }
430    }
431
432
433    $(window).resize(function () {
434        if ($('.e123_4a1_compare_node_content_content').length > 0) {
435            $('.e123_4a1_compare_node_content_content .content .record').each(function (index) {
436                var target_height = $(this).outerHeight();
437                $(this).find('.subject').css('height', target_height + 'px');
438            });
439        }
440
441        if ($(window).outerWidth() < 992) {
442            if (($(".e123_4a1_compare_cd_table").length > 0)) {
443                var i = 0;
444                /* Start of calc height for cd row */
445                for (i = 0; i < $(".e123_4a1_compare_cd_table").attr("num_of_row"); i++) {
446                    var all_height = [];
447                    //var j = 0;
448                    $('.cd_row_' + i).each(function (index) {
449                        all_height.push($(this).outerHeight());
450                    });
451                    var max_val = Math.max.apply(null, all_height);
452                    //Set the max height to same row 
453                    $('.cd_row_' + i).css("height", max_val);
454                }
455                /* End of calc height for cd row */
456            }
457        }
458    });
vendor: 3 bytes, line 459
459});

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.