You are here

function zopim_footer in Zopim Live Chat 6.2

Same name and namespace in other branches
  1. 6 zopim.module \zopim_footer()

File

./zopim.module, line 106

Code

function zopim_footer($main = 0) {

  // 1. Check if the Zopim account number has a value.
  // 2. Add JS based on visibility value.
  // 3. Check if we should add the JS for the currently active user's role.
  global $user;
  $settings = zopim_get_settings();
  if (!empty($settings['general']['account_key']) && $settings['visibility']['enabled'] && _zopim_visibility_pages() && _zopim_visibility_user($user)) {
    if (!empty($settings['general']['salt']) && $settings['general']['account'] === 1 && $settings['visibility']['enabled'] === 1) {
      $script = "\n  var zopimSettings = Drupal.settings.zopim;\n  // Start of Zopim Live Chat Script\n  window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},\$=\n  z.s=d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o\n  ){z.set._.push(o)};\$.setAttribute('charset','utf-8');\$.async=!0;z.set.\n  _=[];\$.src='//v2.zopim.com/?'+zopimSettings.general.account_key;\$.type='text/java'+s;z.\n  t=+new Date;z._=[];e.parentNode.insertBefore(\$,e)})(document,'script')\n  // End of Zopim Live Chat Script\n\n  // Start Zopim Live Chat customizations\n  \$zopim(function() {\n    if (zopimSettings.widget.language != '--') {\n      \$zopim.livechat.setLanguage(zopimSettings.widget.language);\n    }\n    if (zopimSettings.user.name) {\n      \$zopim.livechat.setName(zopimSettings.user.name);\n    }\n    if (zopimSettings.user.email) {\n      \$zopim.livechat.setEmail(zopimSettings.user.email);\n    }\n    \$zopim.livechat.button.setPosition(zopimSettings.widget.position);\n    if (zopimSettings.customization.widget === 1) {\n      \$zopim.livechat.window.setTheme(zopimSettings.theming.theme);\n    }\n    if (zopimSettings.customization.color === 1) {\n      \$zopim.livechat.window.setColor(zopimSettings.theming.color);\n    }\n    if (zopimSettings.help_bubble.display == 'show') {\n      \$zopim.livechat.bubble.show(true);\n    }\n    if (zopimSettings.help_bubble.display == 'hide') {\n      \$zopim.livechat.bubble.hide(true);\n    }\n    if (zopimSettings.help_bubble.title != '') {\n      \$zopim.livechat.bubble.setTitle(zopimSettings.help_bubble.title);\n    }\n    if (zopimSettings.help_bubble.message != '') {\n      \$zopim.livechat.bubble.setText(zopimSettings.help_bubble.message);\n    }\n    if (zopimSettings.greeting_messages.enabled === 1) {\n      \$zopim.livechat.setGreetings({\n        'online' : [zopimSettings.greeting_messages.chatbar.online, zopimSettings.greeting_messages.panel.online],\n        'offline' : [zopimSettings.greeting_messages.chatbar.offline, zopimSettings.greeting_messages.panel.offline],\n        'away' : [zopimSettings.greeting_messages.chatbar.away, zopimSettings.greeting_messages.panel.away]\n      });\n    }\n    if (zopimSettings.widget.hide_when_offline === 1) {\n      \$zopim.livechat.button.setHideWhenOffline(true);\n    }\n  });\n  // End Zopim Live Chat customizations\n  ";
      drupal_add_js($script, 'inline', 'footer');
    }
  }
}