Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Set the Olark chatbox to appear inline
  2. olark.configure('box.inline', true);
  3.  
  4. // Keep things from polluting the global namespace, except changeClass, which we want accessible
  5. var changeClass;
  6.  
  7. (function (d, olk) {
  8.     // These functions are helpers for the below
  9.     function getOlarkWrapper() {
  10.         return d.getElementById("olark-box-wrapper");
  11.     }
  12.  
  13.     function setOlarkVisible(olark_wrapper) {
  14.         olark_wrapper.className = "chatbox-open";
  15.     }
  16.  
  17.     function setOlarkHidden(olark_wrapper) {
  18.         olark_wrapper.className = "chatbox-closed";
  19.     }
  20.  
  21.     function olarkIsVisible(olark_wrapper) {
  22.         return olark_wrapper.className.match(/(?:^|\s)chatbox-open(?!\S)/);
  23.     }
  24.  
  25.     // This is used by the link to show/hide the inline page element
  26.     changeClass = function() {
  27.         var olark_wrapper = getOlarkWrapper();
  28.         // Get the HTML object containing the Olark chat box
  29.         // If the chat box is already open, close id
  30.         if (olarkIsVisible(olark_wrapper)) {
  31.             setOlarkHidden(olark_wrapper);
  32.         } else {
  33.             setOlarkVisible(olark_wrapper);
  34.         }
  35.     }
  36.  
  37.     // This is used to cause the box to auto-open if a visitor is already in conversation
  38.     olk('api.visitor.getDetails', function (details) {
  39.         if (details.isConversing) {
  40.             setOlarkVisible(getOlarkWrapper());
  41.         }
  42.     });
  43. }(document, olark));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement