PageSourceSearch

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

js e123.hk collected 2026-10-01 12:23:23 UTC 14,930 bytes, 315 lines download raw bytes

1jQuery(function($) {
2    var x_csrf_token = "";
3
4    $(document).ready(function() { 
5        if (($(".e123_comment_like_wrapper").length > 0)) {
6            rest_comment_flagging_api.reading_comment_flagging_status();
7        }
8
9        //Show Edit/delete btn for own comment
10        if (($(".e123_drupal_comments_list").length > 0)) {
11            $('.e123_drupal_comments_list .js-comment').each(function(i) {
12                var this_elm = $(this);
13                var comment_uid = $(this).attr('data-comment-user-id');
14
15                if (drupalSettings.user.uid > 0) {
16                    if ((drupalSettings.user.uid == comment_uid) && (comment_uid > 0)) {
17                        this_elm.find('.e123_comment_edit_wrapper').removeClass('d-none');
18                        this_elm.find('.e123_comment_unpublish_wrapper').removeClass('d-none');
19
20                    } else {
21                        this_elm.find('.e123_comment_edit_wrapper').html("");
22                        this_elm.find('.e123_comment_unpublish_wrapper').html("");
23                    }
24
25                    if ((drupalSettings.user.uid != comment_uid) && (comment_uid > 0)) {
26                        this_elm.find('.e123_comment_report_spam_wrapper').removeClass('d-none');
27                    } else {
28                        this_elm.find('.e123_comment_report_spam_wrapper').addClass('d-none');
29                        this_elm.find('.e123_comment_report_spam_wrapper').html("");
30                    }
31                } else {
32                    this_elm.find('.e123_comment_edit_wrapper').html("");
33                    this_elm.find('.e123_comment_unpublish_wrapper').html("");
34                    this_elm.find('.e123_comment_report_spam_wrapper').html("");
35                }
36            });
37        }
38    })
39
40
41    $(document).ajaxComplete(function() { 
42        if (($(".e123_comment_like_wrapper").length > 0)) {
43            ////$('.e123_comment_like_wrapper .e123_comment_like_status').css("cursor", "pointer");
44        }
45    })
46
47
48    //Start of Read Flagging in Comment (讚好 / 舉報)
49    rest_comment_flagging_api = {
50        reset_ui_status: function(this_elm) {
51            this_elm.find(".e123_comment_like_status").removeClass('active');
52            this_elm.find(".e123_comment_like_status").addClass('non-active');
53            ///this_elm.find(".e123_comment_like_status").html("讚好");
54        },
55
56
57        reading_comment_flagging_status: function() {
58            /* Get the status one by one for each comments in listing */
59            $('.e123_comment_flagging_wrapper').each(function(i) {
60                var this_elm = $(this);
61
62                if (drupalSettings.user.uid > 0) {
63                    var rand = $.now();
64
65                    var system_path = drupalSettings.path.currentPath;
66                    var temp = system_path.split("/");
67                    var nid = temp[1];
68                    var cid = $(this).attr('drupal-cid');
69                    var request_data = {
70                        "_format": "json",
71                        "cid": cid,
72                        "rand": rand
73                    };
74
75                    $.ajax({
76                        url: "/check-my-comment-flagging",
77                        cache: false,
78                        method: "GET",
79                        data: request_data,
80                        headers: {"Accept": "application/json","Content-Type": "application/json"},
81                        success: function(data, status, xhr) {
82                            ///console.log('load status for cid: ' + cid);
83
84                            rest_comment_flagging_api.reset_ui_status(this_elm);
85
86                            this_elm.find(".e123_comment_report_spam_status").removeClass('active');
87                            this_elm.find(".e123_comment_report_spam_status").addClass('non-active');
88                            this_elm.find(".e123_comment_report_spam_status").html("舉報");
89
90                            if (data.length > 0) {
91                                $.each(data , function(index, val) {
92                                    if (val['flag_id'] == 'e123_like_comment') {
93                                        this_elm.find(".e123_comment_like_status").removeClass('non-active');
94                                        this_elm.find(".e123_comment_like_status").addClass('active');
95                                        ///this_elm.find(".e123_comment_like_status").html("已讚好");
96                                    }
97                                    if (val['flag_id'] == 'e123_report_spam_comment') {
98                                        this_elm.find(".e123_comment_report_spam_status").removeClass('non-active');
99                                        this_elm.find(".e123_comment_report_spam_status").addClass('active');
100                                        this_elm.find(".e123_comment_report_spam_status").html("已舉報");
101                                        this_elm.find(".e123_comment_report_spam_status").removeAttr('href');
102                                        this_elm.find(".e123_comment_report_spam_status").removeAttr('data-lity');
103                                    }
104                                });
105                            }
106                        },
107                        error: function(data) {},
108                    })                    
109                } else {
110                    rest_comment_flagging_api.reset_ui_status(this_elm);
111                }
112            });
113        },
114    }
115    //End of Read Flagging in Comment (讚好)
116
117
118    if (($(".e123_comment_like_wrapper").length > 0)) {
119        if (drupalSettings.user.uid > 0) {
120            $.ajax({
121                url: "/session/token?_format=json",
122                cache: false,
123                method: "GET",
124                headers: {"Accept": "application/json","Content-Type": "application/json"},
125                success: function(data, status, xhr) {
126                    x_csrf_token = data;
127                },
128                error: function(data) {},
129            })
130        }
131    }
132
133
134    //Start of Like comment
135    $('body').on('click', '.e123_comment_like_wrapper .e123_comment_like_status.non-active', function() {
136        if (drupalSettings.user.uid > 0) {
137            var this_elm = $(this);
138            var rand = $.now();
139            var flag_type = "e123_like_comment";
140
141            var system_path = drupalSettings.path.currentPath;
142            var temp = system_path.split("/");
143            var nid = temp[1];
144
145            var cid = $(this).attr('drupal-cid');
146
147            var request_data = {
148                "_format": "json",
149                "flag_type": flag_type,
150                "entity_type": "comment",
151                "entity_id": cid,
152                "rand": rand
153            };
154
155            $.ajax({
156                url: "/check-my-flagging",
157                cache: false,
158                method: "GET",
159                data: request_data,
160                headers: {"Accept": "application/json","Content-Type": "application/json"},
161                beforeSend: function( xhr ) {
162                    ///this_elm.html("已讚好");
163                    this_elm.addClass('active');
164                    this_elm.removeClass('non-active');
165                },
166                success: function(data, status, xhr) {
167                    console.log("REST API (GET) run via cookie successfully. ");
168
169                    //If the flagging is not existing in this node for current user, mark the flag
170                    if (data.length == 0) {
171                        var body_data = {}
172                        body_data.uid = [{'target_id':drupalSettings.user.uid}]
173                        body_data.flag_id = [{'target_id':flag_type}]
174                        body_data.entity_type = [{'value':'comment'}]
175                        body_data.entity_id = [{'value':cid}]
176
177                        $.ajax({
178                            url: "/entity/flagging/?_format=json",
179                            cache: false,
180                            method: "POST",
181                            data: JSON.stringify(body_data),
182                            headers: {"Accept": "application/json","Content-Type": "application/json","X-CSRF-Token": x_csrf_token },
183                            success: function(data, status, xhr) {
184                                console.log("REST API (POST) run via cookie successfully. ");
185                                //已讚好
186                            },
187                            error: function(data) {
188                                ///this_elm.html("讚好");
189                                this_elm.addClass('non-active');
190                                this_elm.removeClass('active');
191                            },
192                        })
193                    }
194                },
195                error: function(data) {
196                    ///this_elm.html("讚好");
197                    this_elm.addClass('non-active');
198                    this_elm.removeClass('active');
199                },
200            })
201        } else {
202            ///console.log("Guest not allowed for flagging! ");
203
204            //For guest: redirect to login page with destination
205            var link = '/zh-hant/user/login?destination=' + window.location.pathname;
206            location.href = link;
207        }
208    });
209
210    //End of Like comment
211
212    //Start of 舉報 comment
213    /*
214    $(document).ajaxComplete(function() { 
215        if (($(".e123_comment_report_spam_wrapper").length > 0)) {
216            if (drupalSettings.user.uid == 0) {
217                $('.e123_comment_report_spam_wrapper').addClass('d-none');
218            } else {
219                $('.e123_comment_report_spam_wrapper').removeClass('d-none');
220            }
221        }
222    })      Already set in .html.twig   */
223
224    //Start of Click and show the question box
225    $('body').on('click', '.e123_comment_report_spam_status.non-active', function() {
226        if (drupalSettings.user.uid > 0) {
227            var cid = $(this).attr('drupal-cid');
228            $('#e123_comment_report_spam_popup .e123_comment_report_spam_confirm').attr('drupal-cid', cid);
229
230            //Start of Get the reason List
231            $.ajax({
232                url: "/taxonomy-items/?_format=json&vocab=report_spam_reason",
233                cache: false,
234                method: "GET",
235                headers: {"Accept": "application/json","Content-Type": "application/json"},
236                success: function(data, status, xhr) {
237                    var html = '';
238                    if (data.length > 0) {
239                        $.each(data , function(index, val) { 
240                            html += '<label><input type="radio" name="e123_comment_report_spam_field_reason" value="' + val['tid'] + '">' + val['name'] + '</label>';
241                        });
242
243                        $('#e123_comment_report_spam_field_reason').html(html);
244                        $('#e123_comment_report_spam_field_reason').removeClass('d-none');
245                    }
246
247                    $('.e123_comment_report_spam_confirm_box').removeClass('d-none');
248                    $('.e123_comment_report_spam_confirm_message').html('');
249                    $('.e123_comment_report_spam_confirm_message').addClass('d-none');
250                },
251                error: function(data) {},
252            })
253            //End of Get the reason List
254        }
255    });
256    //End of Click and show the question box
257
258
259    //Start of Click confirm button
260    $('body').on('click', '.e123_comment_report_spam_confirm', function() {
261        if (drupalSettings.user.uid > 0) {
262            var cid = $(this).attr('drupal-cid');
263            var selected_reason_tid = $("#e123_comment_report_spam_popup input[name='e123_comment_report_spam_field_reason']:checked").val();
264
265            if (cid != 0) {
266                if (selected_reason_tid !== undefined) {
267                    $('.e123_comment_report_spam_confirm_message').html('');
268                    $('.e123_comment_report_spam_confirm_message').addClass('d-none');
269
270                    var body_data = {}
271                    body_data.uid = [{'target_id':drupalSettings.user.uid}]
272                    body_data.flag_id = [{'target_id':'e123_report_spam_comment'}]
273                    body_data.entity_type = [{'value':'comment'}]
274                    body_data.entity_id = [{'value':cid}]
275                    body_data.field_report_spam_reason = [{'target_id':selected_reason_tid}]
276
277                    $.ajax({
278                        url: "/entity/flagging/?_format=json",
279                        cache: false,
280                        method: "POST",
281                        data: JSON.stringify(body_data),
282                        headers: {"Accept": "application/json","Content-Type": "application/json","X-CSRF-Token": x_csrf_token },
283                        success: function(data, status, xhr) {
284                            console.log("REST API (POST) run via cookie successfully. ");
285
286                            $('.e123_comment_report_spam_confirm_message').html('<div class="messages messages--status">留言已舉報成功,我們會作進一步的跟進。</div>');
287                            $('.e123_comment_report_spam_confirm_message').removeClass('d-none');
288
289                            $('.e123_comment_report_spam_confirm_box').addClass('d-none');
290
291                            //Show the status on the comment box
292                            var div = $('.e123_drupal_comments_list #comment-' + cid).find('.e123_comment_report_spam_status');
293                            div.removeAttr('href');
294                            div.removeAttr('data-lity');
295                            div.addClass('active');
296                            div.removeClass('non-active');
297                            div.html('已舉報');
298                        },
299                        error: function(data) {
300                            $('.e123_comment_report_spam_confirm_message').html('<div class="messages messages--error">舉報失敗,請再嘗試! </div>');
301                            $('.e123_comment_report_spam_confirm_message').removeClass('d-none');
302                        },
303                    })
304                } else {
305                    $('.e123_comment_report_spam_confirm_message').html('<div class="messages messages--error">請選擇 舉報此留言的原因! </div>');
306                    $('.e123_comment_report_spam_confirm_message').removeClass('d-none');
307                }
308            }
309        }
310    });
311    //End of Click confirm button
312
313
314    //End of 舉報 comment
315});

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.