contact-support.js
1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* global HS */
( function( $ ) {
$( window ).on( "YoastSEO:ContactSupport", function( e, data ) {
if( data.usedQueries !== undefined ) {
var identity = HS.beacon.get_helpscout_beacon_identity();
identity[ "User searched for" ] = usedQueriesWithHTML( data.usedQueries );
HS.beacon.identify( identity );
}
HS.beacon.open();
} );
/**
* Format the search queries done by the user in HTML
*
* @param {array} usedQueries List of queries entered by the user.
* @returns {string} The generated output.
*/
function usedQueriesWithHTML( usedQueries ) {
var output = "";
if ( $.isEmptyObject( usedQueries ) ) {
output += "<em>Search history is empty.</em>";
} else {
output += "<table><tr><th>Searched for</th><th>Opened article</th></tr>";
$.each( usedQueries, function( searchString, posts ) {
output += "<tr><td>" + searchString + "</td>";
output += getPostsHTML( posts );
output += "</tr>";
} );
output = output + "</table>";
}
return output;
}
/**
* Format the posts looked at by the user in HTML
*
* @param {array} posts List of posts opened by the user.
* @returns {string} The generated output.
*/
function getPostsHTML( posts ) {
var output = "";
var first = true;
if ( $.isEmptyObject( posts ) ) {
output += "<td><em>No articles were opened.</em></td>";
} else {
$.each( posts, function( postId, post ) {
if ( first === false ) {
output += "<td></td>";
}
output += "<td><a href='" + post.link + "'>" + post.title + "</a></td>";
first = false;
} );
}
return output;
}
} )( jQuery );