PageSourceSearch

https://www.lokjun.edu.hk/wp-content/plugins/eclass-integration/pu…ss-integration-latest-news-api.js?ver=2.0.0

js lokjun.edu.hk collected 2026-10-02 22:27:31 UTC 5,720 bytes, 139 lines download raw bytes

1(function ($) {
2    'use strict';
3
4    window.LatestNewsApi = function LatestNewsApi() {
5
6        //// Private var START ////
7        var _self = this;
8        //// Private var END ////
9
10        //// Public var START ////
11        this.isLoading = false;
12        this.allData = [];
13        //// Public var END ////
14
15
16        //// Private func START ////
17        //// Private func END ////
18
19
20        //// Public func START ////
21        this.initLatestNewsAPI = function (displayCount) {
22            return _self.getLatestNews({
23                start_date: (new Date()).toISOString().slice(0, 10)
24            }).done(function () {
25                $('#latestNews .loading').hide();
26                if (_self.allData.length == 0) {
27                    $('#latestNews').html('暫時仍未有任何紀錄');
28                    return false;
29                }
30
31                if (displayCount < _self.allData.length) {
32                    $('#latestNewsArea .btnMoreNews').show();
33                } else {
34                    $('#latestNewsArea .btnMoreNews').hide();
35                }
36
37                var $ul = $('#latestNews #news_event');
38                $ul.empty();
39                var newTemplate = $('#latest-news-template').html();
40                var newAttachmentTemplate = $('#new-attachment-template').html();
41                for (var i = 0; i < displayCount; i++) {
42                    var data = _self.allData[i] || null;
43                    if (!data) {
44                        break;
45                    }
46
47                    var attachmentUrl = '';
48                    _.each(data['Attachments']['Attachment'], function (attachment, index) {
49                        var compiled = _.template(newAttachmentTemplate);
50                        attachmentUrl += compiled({
51                            'attachmentUrl': attachment['FileURL'],
52                            'attachmentIndex': attachment['FileName']
53                        });
54                    });
55
56                    var url = ECLASS_LATEST_NEWS_API.page_url + '?';
57                    url += 'eventId=' + data['AnnouncementID'];
58                    url += '&eventDate=' + data['AnnouncementDate'];
59
60                    var compiled = _.template(newTemplate);
61                    $ul.append(compiled({
62                        'eventId': data['AnnouncementID'],
63                        'eventDate': data['AnnouncementDate'],
64                        'eventTitle': data['Title'],
65                        'eventDescription': ('' + data['Description']).replace(/(<([^>]+)>)/ig, ""),
66                        'eventLink': url,
67                        'attachmentUrl': attachmentUrl
68                    }));
69                }
70            });
71        }; // End initLatestNewsAPI()
72
73        this.getLatestNews = function (data) {
74            var _data = $.extend({}, {
75                'action': 'eclass_latest_news_api',
76                'num_of_record': null,
77                '_ajax_nonce': ECLASS_LATEST_NEWS_API._ajax_nonce
78            }, data);
79
80            var $defer = $.Deferred();
81            $.ajax({
82                url: ECLASS_LATEST_NEWS_API.url,
83                type: 'get',
84                data: _data,
85                beforeSend: function () {
86                    _self.isLoading = true;
87                },
88                complete: function () {
89                    _self.isLoading = false;
90                },
91                success: function (response) {
92                    if (
93                        typeof(response['Announcements']) == 'undefined' ||
94                        typeof(response['Announcements']['Announcement']) == 'undefined'
95                    ) {
96                        _self.allData.length = 0;
97                        $defer.resolve(_self.allData);
98                        return;
99                    }
100
101                    //// Parse data START ////
102                    if (typeof(response['Announcements']['Announcement']['AnnouncementID']) == 'undefined') {
103                        $.each(response['Announcements']['Announcement'], function (index, announcement) {
104                            _self.allData.push(announcement);
105                        });
106                    } else {
107                        _self.allData.push(response['Announcements']['Announcement']);
108                    }
109
110                    $.each(_self.allData, function (index, announcement) {
111                        try {
112                            var SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
113                            while (SCRIPT_REGEX.test(announcement['Description'])) {
114                                announcement['Description'] = announcement['Description'].replace(SCRIPT_REGEX, "");
115                            }
116
117                            if (typeof(announcement['Attachments']['Attachment']['FileURL']) != 'undefined') {
118                                announcement['Attachments']['Attachment'] = [announcement['Attachments']['Attachment']];
119                            }
120                        } catch (e) {
121                            announcement['Attachments']['Attachment'] = [];
122                        }
123                        _self.allData[index] = announcement
124                    });
125                    //// Parse data END ////
126
127                    $defer.resolve(_self.allData);
128                },
129                error: function (err) {
130                    $defer.reject(err);
131                },
132            });
133            return $defer;
134        };
135        //// Public func END ////
136    }; // End class LatestNewsApi
137
138
139})(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.