SHOW:
|
|
- or go back to the newest paste.
1 | - | // Keep things from polluting the global namespace |
1 | + | // Set the Olark chatbox to appear inline |
2 | - | (function(d) { |
2 | + | olark.configure('box.inline', true); |
3 | ||
4 | - | function getOlarkWrapper(){ |
4 | + | // Keep things from polluting the global namespace, except changeClass, which we want accessible |
5 | var changeClass; | |
6 | ||
7 | (function (d, olk) { | |
8 | - | function setOlarkVisible() { |
8 | + | |
9 | - | getOlarkWrapper().className = "chatbox-open"; |
9 | + | function getOlarkWrapper() { |
10 | return d.getElementById("olark-box-wrapper"); | |
11 | } | |
12 | - | function setOlarkHidden() { |
12 | + | |
13 | - | getOlarkWrapper().className = "chatbox-closed"; |
13 | + | function setOlarkVisible(olark_wrapper) { |
14 | olark_wrapper.className = "chatbox-open"; | |
15 | } | |
16 | - | function olarkIsVisible(){ |
16 | + | |
17 | function setOlarkHidden(olark_wrapper) { | |
18 | olark_wrapper.className = "chatbox-closed"; | |
19 | } | |
20 | ||
21 | - | function changeClass() { |
21 | + | function olarkIsVisible(olark_wrapper) { |
22 | return olark_wrapper.className.match(/(?:^|\s)chatbox-open(?!\S)/); | |
23 | } | |
24 | ||
25 | - | if (olarkIsVisible()) { |
25 | + | |
26 | - | setOlarkHidden(); |
26 | + | changeClass = function() { |
27 | var olark_wrapper = getOlarkWrapper(); | |
28 | - | setOlarkVisible(); |
28 | + | |
29 | // If the chat box is already open, close id | |
30 | if (olarkIsVisible(olark_wrapper)) { | |
31 | setOlarkHidden(olark_wrapper); | |
32 | } else { | |
33 | - | olark('api.visitor.getDetails', function(details){ |
33 | + | setOlarkVisible(olark_wrapper); |
34 | } | |
35 | - | setOlarkVisible(); |
35 | + | |
36 | ||
37 | // This is used to cause the box to auto-open if a visitor is already in conversation | |
38 | - | }(document)); |
38 | + | olk('api.visitor.getDetails', function (details) { |
39 | if (details.isConversing) { | |
40 | setOlarkVisible(getOlarkWrapper()); | |
41 | } | |
42 | }); | |
43 | }(document, olark)); |