PageSourceSearch

https://www.csii.ca/modules/article/article.js

js csii.ca collected 2026-10-02 10:20:13 UTC 6,141 bytes, 174 lines download raw bytes

1var allFormData = typeof (FormData) !== "undefined" ? new FormData() : null;
2
3function castArticleVote(articleID, rating, language) {
4    var url = '/modules/article/vote.jsp?articleID=' + articleID + '&language=' + language + '&rating=' + rating;
5    return $.post(url, function(resp) {
6        if (typeof (resp.error) != "undefined") {
7            alert(resp.error);
8        } else {
9            var container = null;
10            if ($(".subscribeHolder_" + articleID).length === 1) {
11                container = $(".subscribeHolder_" + articleID);
12            } else {
13                container = $(".articleModule");
14            }
15            container.find("#articleVoteLike_" + articleID).attr("data-user-voted", resp.accepted === true);
16            container.find("#articleVotesLike_" + articleID).html(resp.numVotesLike);
17            container.find("#articleVoteDislike_" + articleID).attr("data-user-voted", resp.accepted === false);
18            container.find("#articleVotesDislike_" + articleID).html(resp.numVotesDislike);
19        }
20    }, "json");
21}
22
23function castArticleVoteForComment(articleID, commentID, rating, language) {
24    var url = '/modules/article/vote.jsp?articleID=' + articleID + '&commentID=' + commentID + '&language=' + language + '&rating=' + rating;
25    return $.post(url, function(resp) {
26        if (typeof (resp.error) != "undefined") {
27            alert(resp.error);
28        } else {
29            $("#articleCommentVoteLike_" + commentID).attr("data-user-voted", resp.accepted === true);
30            $("#articleCommentVotesLike_" + commentID).html(resp.numVotesLike);
31            $("#articleCommentVoteDislike_" + commentID).attr("data-user-voted", resp.accepted === false);
32            $("#articleCommentVotesDislike_" + commentID).html(resp.numVotesDislike);
33        }
34    }, "json");
35}
36
37async function publishArticleComment(resourceID, commentId) {
38	document.getElementById('articleCommentStatus' + commentId).innerHTML = 'Status: Publishing...';
39	
40	const response = await fetch('/modules/article/publishComment.jsp?resourceID=' + resourceID + '&id=' + commentId, {
41		method: "GET",
42	});
43	
44	if(!response.ok) {
45		uiAlert("Something went wrong. Couldn't publish article")
46		return;
47	}
48	
49	const responseText = await response.text();
50	
51    var publishedCommentId = parseInt(responseText.replace(/^\s+|\s+$/g, ''));
52    if (!isNaN(publishedCommentId) && publishedCommentId > 0) {
53        document.getElementById('articleCommentStatus' + publishedCommentId).innerHTML =
54            '<span class="articleCommentStatusSuccess">Comment successfully published.</span>';
55    }
56}
57
58function subscribeToArticle(checkbox, articleId, lang) {
59    var sub = "unsubscribe"
60	var subValue = checkbox.find(".activeText").attr("data-value")
61	if(subValue === '1'){
62		var sub = "subscribe"
63	}
64
65	$.ajax({
66		type: "POST",
67		url: "/modules/article/subscribeToArticle.jsp",
68		data: {articleId : articleId, lang : lang, action : sub},
69		success: function() {
70			checkbox.find(".unsub").toggleClass("activeText inactiveText")
71			checkbox.find(".sub").toggleClass("activeText inactiveText")
72		}
73	});   
74}
75
76function loadCommentForm(container, resourceId, articleId, lang, commentId, parentId) {
77	if(commentId != null){
78	   container.html("");
79	}
80	
81	$(".articleCommentPost").hide();
82
83	$.ajax({
84        type: "POST",
85        url: "/modules/article/editComment.jsp",
86        data: {articleID : articleId, lang : lang, resourceID : resourceId, id: commentId, parentID:parentId },
87        success: function(msg) {
88			container.append(msg);
89        },
90        error: function() {
91			uiAlert("Error connecting to server");
92        }
93    });
94}
95
96function loadMoreComments(resourceId, articleId, lang, start, limit, caller) {
97	$.post("/REST/Article/getMoreComments", {
98		resourceID : resourceId,
99		articleId : articleId,
100		lang : lang,
101		start : start,
102		limit : limit
103	}, function(resp) {
104		var id = "more_" + resourceId + "_" + articleId + "_" + start;
105		var hasMore = false;
106		
107		var button = $(caller).replaceWith($("<div id='" + id + "'></div>"));
108		
109		$(resp.comments).each(function(i, obj){
110			if (i < limit - 1) {
111				$("#" + id).append(obj.html);
112			} else {
113				hasMore = true;
114			}
115		});
116		
117		if (hasMore) {
118			button.attr("onclick", "loadMoreComments(" + resourceId + ", " + articleId + ", '" + lang + "', " + (start + limit - 1) + ", " + limit + ", this)");
119			$("#" + id).after(button);
120		}
121		
122	}, "json");
123}
124
125function articleAjaxReload(resourceId, pageResourceId, layoutInstanceId, params) {
126	// Load the params first from the form
127	var container = $("div[data-instanceid=" + layoutInstanceId + "]");
128	var form = container.find("#searchArticleForm");
129	var url = window.location.href.split('?')[0] + "?";
130
131	var postData = form.serializeArray();
132	postData.push({ name : "ajaxLoaded", value : true });  //used to avoid loading list.js again
133	
134	if (params) {
135		for( var key in params ) {
136		  postData.push({ name : key, value : params[key] });
137		}
138	}
139	
140	for (var i = 0; i < postData.length; i++) {
141		if (postData[i].value !== '' && postData[i].name !== 'ajaxLoaded') {
142			url += (i > 0 ? '&' : '') + postData[i].name + "=" + encodeURI(postData[i].value);
143		}
144	}
145
146	callback = function(msg) {
147		container.html(msg);
148	}
149	
150	container.html("<img class='loadingGif' src='/images/loading.gif'/>");
151	
152	
153	// Add a history entry
154	if (history.pushState) {
155		if (!history.state) {
156			history.pushState({'title': document.title }, document.title, document.location);
157		}
158		
159		history.pushState({'title': document.title + ' ' + 'Filter'}, document.title, url);
160	}
161
162	reloadLayoutInstance(resourceId, layoutInstanceId, pageResourceId, postData, callback);
163}
164
165// Attach a new popstate event for news, if there was a state created force a reload
166if (!$("body").attr("data-newsevents")) {
167	$("body").attr("data-newsevents", true);
168	window.addEventListener("popstate", function(e){
169		if(e.state !== null) { // state data available
170			// load the page using state data
171			document.location.reload();
172		}
173	});			
174}

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.