-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
84 lines (78 loc) · 2.57 KB
/
script.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (C) 2020-present, Concentric Digital Pty Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
//setup variables
var autoOpen = fbcp_variables["autoOpen"],
autoOpenConversationEnabled = fbcp_variables["autoOpenConversationEnabled"],
autoOpenConversationOnceOnly = fbcp_variables["autoOpenConversationOnceOnly"],
autoOpenbyScroll = fbcp_variables["autoOpenbyScroll"],
autoOpenbyDelay = fbcp_variables["autoOpenbyDelay"],
shakeConversationEnabled = fbcp_variables["shakeConversationEnabled"],
openDelay = fbcp_variables["OpenDelay"];
(function ($) {
// add listener to openChat button click event
$(document).ready(function () {
$(".fbcp-open-chat").click(function (event) {
event.preventDefault();
openConversation();
});
});
//add listener
if (autoOpenConversationEnabled) {
if (autoOpenConversationOnceOnly && Cookies.get("chatOpenedOnce")) {
autoOpen = false;
} else {
autoOpen = true;
//set cookies if OpenedOnce during session
window.onload = function () {
FB.Event.subscribe("customerchat.dialogShow", function () {
autoOpen = false;
Cookies.set("chatOpenedOnce", true);
});
};
}
}
if (autoOpenbyDelay) {
setTimeout(function () {
//check autoOpen condition again
if (autoOpen) {
openConversation();
}
}, openDelay);
}
//listen to scroll, and if scroll past element with id #fbcp-scoll-to, open the chat window
if (autoOpenbyScroll && $("#scroll-to").length) {
$(window).scroll(function () {
(hT = $("#fbcp-scroll-to").offset().top),
(hH = $("#fbcp-scroll-to").outerHeight()),
(wH = $(window).height()),
(wS = $(this).scrollTop());
//check autoOpen condition again
if (wS > hT + hH - wH && autoOpen) {
openConversation;
}
});
}
//openConversation
openConversation = () => {
FB.CustomerChat.showDialog();
if (shakeConversationEnabled) {
//shake the conversation if enabled
shakeConversation();
}
};
//shakeConversation
shakeConversation = () => {
setTimeout(function () {
$("#fb-root iframe").effect("shake");
}, 500);
};
})(jQuery);