PageSourceSearch

https://cdn.thestar.com.my/Themes/js/apl-homewidget.js?v20221102

js thestar.com.my collected 2026-09-24 07:20:42 UTC 24,441 bytes, 487 lines download raw bytes

1var thestarURL = "https://www.thestar.com.my";
2
3function getKicker(article, url = '') {
4    var sectionName, sectionId, subSectionName, subSectionId;
5
6    var branded = getArticleCustomField(article, 'branded');
7    if (!isEmpty(branded)) {
8        if (branded[0].hasOwnProperty('is_branded'))
9            if (branded[0].is_branded == 1)
10                return ['BRANDED', '', isPremium(article)];
11    }
12    var columnist = getArticleCustomField(article, 'columnist');
13    var isColumnist = false;
14    if (!isEmpty(columnist)) {
15        if (columnist.length > 0)
16            isColumnist = true;
17    }
18
19    if (!isEmpty(url)) {
20
21        var tagsKicker = getTagsKicker(article);
22        if (!isEmpty(tagsKicker[0]))
23            return tagsKicker;
24
25        if (url.toLowerCase().indexOf('/business/smebiz') != -1) {
26            return ['SMEBiz', '/business/smebiz/', false];
27        } else if (url.toLowerCase().indexOf('/metro/smebiz') != -1) {
28            return ['SMEBiz', '/business/smebiz/', false];
29        } else if (url.toLowerCase().indexOf('/metro/community') != -1) {
30            return ['Metro News', '/metro/metro-news/', false];
31        } else if (url.toLowerCase().indexOf('/news/education') != -1) {
32            return ['Education', '/education/news', false];
33        } else if (url.toLowerCase().indexOf('/metro/scoreboard') != -1) {
34            return ['Community Sports', '/metro/community-sports/', false];
35        } else if (url.toLowerCase().indexOf('/tech/hardware') != -1) {
36            return ['Reviews', '/tech/reviews/', false];
37        } else if (url.toLowerCase().indexOf('/opinion/letters/') != -1) {
38            return ['Letters', '/opinion/letters/', false];
39        } else if (url.toLowerCase().indexOf('aseanplus') != -1) {
40            return getKickerAseanPlus();
41        } else if (url === 'external_link') {
42            return getKickerOtherSite(article);
43        } else {
44            if (url.toLowerCase().indexOf('star2.com/food') == -1 && url.toLowerCase().indexOf('star2.com') != -1) { // Checks for star2.com but not the star2.com/food because Food will not be using Lifestyle kicker
45                sectionName = 'lifestyle';
46            } else {}
47        }
48
49    } else {
50        var tempKicker = ["", "", false];
51
52        if (!isEmpty(getExternalLink(article))) {
53            var origin = getArticleCustomField(article, 'origin')
54            if (origin.length > 0) {
55                if (origin[0] != '' || origin[0] != ' ')
56                    tempKicker = getKickerOtherSite(article);
57            }
58        }
59
60        if (!isEmpty(article.section_name))
61            sectionName = article.section_name.toLowerCase();
62        if (!isEmpty(article.section_id))
63            sectionId = article.section_id.toString().toLowerCase();
64        if (!isEmpty(article.sub_section_name))
65            subSectionName = article.sub_section_name.toLowerCase();
66        if (!isEmpty(article.sub_section_id))
67            subSectionId = article.sub_section_id.toString().toLowerCase();
68    }
69
70    if (tempKicker[0] == "") {
71        if ((strcasecmp(subSectionName, 'viewpoints') == 0 || strcasecmp(subSectionName, 'views') == 0 || strcasecmp(subSectionName, 'say what') == 0 || strcasecmp(subSectionName, 'tech thoughts') == 0 || strcasecmp(subSectionName, 'food for thought') == 0 || strcasecmp(subSectionName, 'insight') == 0) || isColumnist) {
72            var columnKicker = getKickerColumnistsOtherSection(url, sectionName, subSectionName, article);
73            if (!isEmpty(columnKicker[0]))
74                return columnKicker;
75        }
76        var tagsKicker = getTagsKicker(article);
77        if (!isEmpty(tagsKicker[0]))
78            return tagsKicker;
79
80        if ((strcasecmp(sectionName, 'news') == 0)) {
81            return getKickerNews(subSectionName);
82        } else if (strcasecmp(sectionName, 'aseanplus') == 0) {
83            return getKickerAseanPlus();
84        } else if (strcasecmp(sectionName, 'business') == 0 || strcasecmp(sectionName, 'biz news') == 0 || strcasecmp(sectionName, 'biz money') == 0) {
85            return getKickerBusiness(article);
86        } else if (strcasecmp(sectionName, 'tech') == 0) {
87            return getKickerTech();
88        }
88 else if (strcasecmp(sectionName, 'sport') == 0) {
89            return getKickerSport(subSectionName, subSectionId);
90        } else if (strcasecmp(sectionName, 'opinion') == 0 && strcasecmp(subSectionName, 'letters') == 0) {
91            return ['Letters', '/opinion/letters', false];
92        } else if (strcasecmp(sectionName, 'opinion') == 0) {
93            return getKickerOpinion(url);
94        } else if (strcasecmp(sectionName, 'lifestyle') == 0 || (article.hasOwnProperty("is_old_article") && !isNaN(article.is_old_article))) {
95
96            var lifestyleCategory = getLifestyleCategories(article);
97            var keywordTagging = getKeywordTagging(article);
98            return getKickerLifestyle(sectionName, subSectionName, url, lifestyleCategory, keywordTagging);
99        } else if (!isEmpty(sectionName) && !isEmpty(subSectionName)) {
100            return [ucwords(subSectionName), '/' + sectionName + '/' + subSectionName.replace(' ', '-') + '/', false];
101        }
102        return ['', '', false];
103
104    } else {
105        return tempKicker;
106    }
107
108}
109
110function getKeywordTagging(article) {
111    var keyword_tagging = getArticleCustomField(article, 'keyword_tagging');
112    if (!isEmpty(keyword_tagging)) {
113        if (keyword_tagging.length > 0)
114            return keyword_tagging;
115        else
116            return '';
117    } else {
118        return '';
119    }
120}
121
122function getArticleCustomField(article, field) {
123    var customField = null;
124
125    if (article.hasOwnProperty('article_custom_fields')) {
126        if (!isEmpty(article.article_custom_fields)) {
127            var customFieldValue = JSON.parse(article.article_custom_fields)
128            customField = customFieldValue.hasOwnProperty(field) ? customFieldValue[field] : null;
129        }
130    }
131
132    return customField;
133}
134
135function isEmpty(value) {
136    return (value == null || value === '');
137}
138
139function ValidURL(str) {
140    var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
141    if (!regex.test(str)) {
142        return false;
143    } else {
144        return true;
145    }
146}
147
148function isValidVideoSource(str) {
149    if (str.indexOf('vod') >= 0 || str.indexOf('youtube') >= 0 || str.indexOf('youtu.be' >= 0) || str.indexOf('vimeo') >= 0 || str.indexOf('jwplatform') >= 0 || str.indexOf('jwplayer') >= 0 || str.indexOf('dailymotion.com') >= 0 || str.indexOf('dai.ly') >= 0) {
150        return true;
151    } else {
152        return false;
153    }
154}
155
156function GenerateMediaTagW(value, thumb, iframe, vid_source, resolution, lazyload) {
157    if (thumb === undefined) {
158        thumb = false;
159    }
160    if (iframe === undefined) {
161        iframe = false;
162    }
163    if (vid_source === undefined || vid_source == null) {
164        vid_source = '';
165    }
166    if (resolution === undefined) {
167        resolution = '';
168    }
169    if (lazyload === undefined) {
170        lazyload = false;
171    }
172    value = JSON.parse(value);
173
174    value.image_path = value.image_path.replace("http://www.star2.com/wp-content", "https://cdn.star2.com/wp-content").replace("http://cdn.star2.com/wp-content", "https://cdn.star2.com/wp-content").replace("http://www1.star2.com/wp-content", "https://cdn.star2.com/wp-content");
175    var media = '';
176    var type = parseInt(value.media_type);
177    var image_alt_text = "";
178    if (value.image_alt_text) {
179        var regExpr = /[^a-zA-Z0-9-. ]/g;
180        var image_alt_text = value.image_alt_text.replace(regExpr, "");
181    }
182    //If lazyload == true, add lazyload class and src="https://cdn.thestar.com.my/Themes/img/loading.gif, also need to change existing src to data-src"
183    var lazyloadProperty = " class='lazyload' src='https://cdn.thestar.com.my/Themes/img/loading.gif' ";
184    switch (type) {
185        case 0:
186            var mediaStyle = '';
187            try {
188                var img_crop = JSON.parse(value.image_cropping);
189            } catch (e) {
190                var img_crop = "";
191            }
192            if (typeof img_crop.original_image != "undefined") {
193                mediaStyle = '';
194            }
195            if (thumb) {
196
197                var path = value.image_path.split('/');
198
199                if (path[9] != undefined) {
200                    var size = path[9].split('x');
201                    mediaStyle = 'width:' + size[0] + 'px;' + 'height:' + size[1] + 'px;';
202                }
203
204                var n = value.image_path.indexOf("https://");
205                var s = value.image_path.indexOf("http://");
206                if (n >= 0 || s >= 0) {
207                    if (lazyload) {
208                        media = "<img " + lazyloadProperty + " data-source='" + value.image_path + "' style='" + mediaStyle + "' data-src='" + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
209                    } else {
210                        media = "<img data-source=" + value.image_path + " style='" + mediaStyle + "' src='" + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
211                    }
212                } else {
213                    if (lazyload) {
214                        media = "<img " + lazyloadProperty + " data-source='" + value.image_path + "' style='" + mediaStyle + "' data-src='" + IMAGE_
214URL + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
215                    } else {
216                        media = "<img data-source='" + value.image_path + "' style='" + mediaStyle + "' src='" + IMAGE_URL + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
217                    }
218                }
219
220                if (path.indexOf("tsol-default-image2017.png") < 0 && path.indexOf("no-image.png") < 0 && path.length > 4 && resolution != '') {
221                    path.splice(path.length - 1, 0, "thumbs/" + resolution + "");
222                    var imgPath = path.join('/');
223                    if (n >= 0 || s >= 0) {
224                        if (lazyload) {
225                            media = "<img " + lazyloadProperty + " data-source='" + imgPath + "' style='" + mediaStyle + "' data-src='" + imgPath + "' alt='" + image_alt_text + "' onerror=\"this.onerror=null;this.src='" + value.image_path + "'\" />";
226                        } else {
227                            media = "<img data-source='" + imgPath + "' style='" + mediaStyle + "' src='" + imgPath + "' alt='" + image_alt_text + "' onerror=\"this.onerror=null;this.src='" + value.image_path + "'\" />";
228                        }
229                    } else {
230                        if (lazyload) {
231                            media = "<img " + lazyloadProperty + " data-source='" + imgPath + "' style='" + mediaStyle + "' data-src='" + IMAGE_URL + imgPath + "' alt='" + image_alt_text + "' onerror=\"this.onerror=null;this.src='" + IMAGE_URL + value.image_path + "'\" />";
232                        } else {
233                            media = "<img data-source='" + imgPath + "' style='" + mediaStyle + "' src='" + IMAGE_URL + imgPath + "' alt='" + image_alt_text + "' onerror=\"this.onerror=null;this.src='" + IMAGE_URL + value.image_path + "'\" />";
234                        }
235                    }
236                }
237
238            } else {
239                var n = value.image_path.indexOf("https://");
240                var s = value.image_path.indexOf("http://");
241                if (n >= 0 || s >= 0) {
242                    if (lazyload) {
243                        media = "<img " + lazyloadProperty + " data-source='" + value.image_path + "' data-src='" + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\"/>";
244                    } else {
245                        media = "<img data-source='" + value.image_path + "' src='" + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\"/>";
246                    }
247                } else {
248                    if (lazyload) {
249                        media = "<img " + lazyloadProperty + " data-source='" + value.image_path + "' data-src='" + IMAGE_URL + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
250                    } else {
251                        media = "<img data-source='" + value.image_path + "' src='" + IMAGE_URL + value.image_path + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
252                    }
253                }
254            }
255            break;
256        case 1:
257            if (lazyload) {
258                media = "<img " + lazyloadProperty + " data-source='" + value.image_path + "' data-src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png' alt='" + image_alt_text + "' />";
259            } else {
260                media = "<img data-source='" + value.image_path + "' src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png' alt='" + image_alt_text + "' />";
261            }
262            break;
263        case 2:
264            var url = new URL(value.image_path);
265            var parameters = new URLSearchParams(url.search);
266            var parameters = url.searchParams;
267            if (parameters.get('v')) {
268                value.image_path = parameters.get('v');
269            }
270            if (iframe) {
271                media = "<div class='iframe-container'><iframe width='620' height='413' src='https://www.youtube.com/embed/" + value.image_path + "' frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>";
272            } else {
273                if (lazyload) {
274                    media = "<img " + lazyloadProperty + " data-source=" + value.image_path + " data-src='https://img.youtube.com/vi/" + value.image_path + "/hqdefault.jpg' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" /><div class='vid-icon'><img src='https://cdn.thestar.com.my/Themes/img/play-icon.png' alt='icon video'> </div>";
275                } else {
276                    media = "<img data-source=" + value.image_path + " src='https://img.youtube.com/vi/" + value.image_path + "/hqdefault.jpg' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" /><div class='vid-icon'><img src='https://cdn.thestar.com.my/Themes/img/play-icon.png' alt='icon video'> </div>";
277                }
278            }
279            break;
280        case 6:
281            var url = value.image_caption.indexOf("Embed");
282            if (url > -1) {
283                value.image_caption = value.image_caption.substr(value.image_caption.lastIndexOf('/') + 1)
284            }
285            if (iframe) {
286                media = "<iframe width='100%' frameborder='0' allowfullscreen  src='https://vod-platform.net/Embed/" + value.image_caption + "' frameborder='0'></iframe>";
287            } else {
288                if (lazyload) {
289                    media = "<img " + lazyloadProperty + " data-source=" + value.image_path + " data-src='https://vod-platform.net/image/" + value.image_caption + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" /><div class='vid-icon'><img src='https://cdn.thestar.com.my/Themes/img/play-icon.png' alt='icon video'> </div>";
290                } else {
291                    media = "<img data-source=" + value.image_path + " src='https://vod-platform.net/image/" + value.image_caption + "' alt='" + image_alt_text + "' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" /><div class='vid-icon'><img src='https://cdn.thestar.com.my/Themes/img/play-icon.png' alt='icon video'> </div>";
292                }
293            }
294            break;
295        default:
296            var n = value.image_path.indexOf("http");
297            if (n >= 0) {
298                if (lazyload) {
299                    media = "<img " + lazyloadProperty + " data-source=" + value.image_path + " data-src='" + value.image_path + "' alt='' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
300                } else {
301                    media = "<img data-source=" + value.image_path + " src='" + value.image_path + "' alt='' onerror=\"this.src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png'\" />";
302                }
303            } else {
304                if (lazyload) {
305                    media = "<img " + lazyloadProperty + " data-source=" + value.image_path + " data-src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png' alt='" + image_alt_text + "' />";
306                } else {
307                    media = "<img data-source=" + value.image_path + " src='https://cdn.thestar.com.my/Themes/img/tsol-default-image2017.png' alt='" + image_alt_text + "' />";
308                }
309            }
310    }
311    if (type == 0 && vid_source != '' && ValidURL(vid_source) && isValidVideoSource(vid_source)) {
312        media += "<div class='vid-icon'><img src='https://cdn.thestar.com.my/Themes/img/play-icon.png' alt='icon video'> </div>";
313    }
314    return media;
315}
316
317function getTagsKicker(article) {
318    try {
319        //Kicker from keyword
320        var valKicker = ['', '', false];
321
322        var keywords = getTagsKeywords(false, article);
323        if (!isEmpty(keywords) && keywords.length > 0) {
324            var keywordkicker_src = "https://cdn.thestar.com.my/Content/Data/KeywordKicker/keywordkicker.json";
325            $.ajax({
326                url: keywordkicker_src,
327                dataType: 'json',
328                async: false,
329                success: function(data) {
330                    return valKicker = processKickerTag(article, keywords, data);
331                }
332            });
333        }
334
335    } catch (err) {
336        console.log(err.message);
337    }
338    return valKicker;
339}
340
341function processKickerTag(article, keywords, keywordkicker) {
342    var result = ['', '', false];
343    var isExit = false;
344
345    keywords.forEach(function(keyword) {
346        var keyAlph = keyword.charAt(0).toLowerCase();
347        if (isExit)
348            return false;
349        if (keywordkicker.hasOwnProperty(keyAlph)) {
350            keywordkicker[keyAlph].forEach(function(keyw) {
351                if (keyw['k'] == keyword.trim()) {
352                    if (keyw.hasOwnProperty('e')) {
353                        keyw['e'].forEach(function(excl) {
354                            if (excl['s'] == "*") {
355                                result = ['', '', false];
356                                isExit = true;
357                                return false;
358                            } else if (article.section_name.toLowerCase() == excl['s'].toLowerCase()) {
359                                if (excl['ss'] == "*") {
360                                    result = ['', '', false];
361                                    isExit = true;
362                                    return false;
363                                } else if (excl['ss'].toLowerCase() == article.sub_section_name.toLowerCase()) {
364                                    result = ['', '', false];
365                                    isExit = true;
366                                    return false;
367                                }
368                            }
369                        })
370                    }
371                    if (isExit)
372                        return false;
373
374                    if (keyw.hasOwnProperty('i')) {
375                        keyw['i'].forEach(function(incl) {
376                            if (incl['s'] == "*") {
377                                result = [keyword.trim(), keyw['u'], false];
378                                isExit = true;
379                                return false;
380                            } else if (article.section_name.toLowerCase() == incl['s'].toLowerCase()) {
381                                if (incl['ss'] == "*") {
382                                    result = [keyword.trim(), keyw['u'], false];
383                                    isExit = true;
384                                    return false;
385                                } else if (incl['ss'].toLowerCase() == article.sub_section_name.toLowerCase()) {
386                                    result = [keyword.trim(), keyw['u'], false];
387                                    isExit = true;
388                                    return false;
389                                }
390                            }
391                        })
392                    }
393                    if (isExit)
394                        return false;
395                }
396
397            });
398        }
399    });
400    return result;
401}
402
403function getTagsKeywords(strtype = true, article) {
404    var keywordTagging = getArticleCustomField(article, 'keyword_tagging');
405    if (!isEmpty(keywordTagging)) {
406        keywordTagging = keywordTagging.filter(el => {
407            return el != null && el != '';
408        });
409    }
410
411    var otherKeywords = getArticleCustomField(article, 'other_keywords');
412    if (!isEmpty(otherKeywords) && otherKeywords.length > 0) {
413        otherKeywords = otherKeywords[0].split(",").map(function(item) {
414            return item.trim();
415        });
416        otherKeywords = otherKeywords.filter(el => {
417            return el != null && el != '';
418        });
419    }
420
421    var tag = '';
422    if (strtype) {
423        if (!isEmpty(keywordTagging) && !isEmpty(keywordTagging[0])) {
424            tag = keywordTagging.join(",");
425        }
426        if (tag.length > 0 && !isEmpty(otherKeywords) && !isEmpty(otherKeywords[0])) {
427            tag = tag + ',' + otherKeywords.join(",");
428        } else if (!isEmpty(otherKeywords) && !isEmpty(otherKeywords[0])) {
429            tag = otherKeywords.join(",");
430        }
431        return $tag;
432    } else {
433        if (!isEmpty(keywordTagging) && keywordTagging.length > 0 && !isEmpty(otherKeywords) && otherKeywords.length > 0) {
434            let mergeArray = keywordTagging.concat(otherKeywords);
435            mergeArray = mergeArray.filter((item, index) => {
436                return (mergeArray.indexOf(item) == index)
437            })
438            return mergeArray;
439        } else if (!isEmpty(keywordTagging) && keywordTagging.length > 0) {
440            return keywordTagging;
441        } else if (!isEmpty(otherKeywords) && otherKeywords.length > 0) {
442            return otherKeywords;
443        }
444    }
445    return '';
446}
447function getGA360ArticleContentCategory(article) {
448    if (!isEmpty(article.section_name)) {
449        if (!isEmpty(article.sub_section_name)) {
450            return article.section_name + '/' + article.sub_section_name.charAt(0).toUpperCase() + article.sub_section_name.slice(1);
451        } else {
452            return article.section_name;
453        }
454    }
455    else {
456        return 'NA';
457    }
458}
459function getAuthorForGA360(article) {
460    var author = article.article_byline;
461    return (!isEmpty(author) ? author : 'NA');
462}
463
464function getSponsorForGA360(article) {
465    var branded = getArticleCustomField(article, 'branded');
466    if (!isEmpty(branded)) {
467        branded = JSON.parse(branded);
468    }
469    return 'NA';
470}
471function htmlDecode(input) {
472    var entities = {
473        "&amp;": "&",
474        "&lt;": "<",
475        "&gt;": ">"
476    };
477
478    for (var prop in entities) {
479        if (entities.hasOwnProperty(prop)) {
480            input = input.replace(new RegExp(prop, "g"), entities[prop]);
481        }
482    }
483    return input;
484}
485function truncate(str, n) {
486    return str && str.length > n ? str.slice(0, n).split(' ').slice(0, -1).join(' ') + '&hellip;' : str
487};

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.