You are here

public static function LiveChat::getLivechatJavascript in Rocket.Chat 7.2

Parameters

string $url:

string $version:

Return value

string| null

2 calls to LiveChat::getLivechatJavascript()
RocketChat::hookPageAlter in src/RocketChat.class.inc
Implements hook_page_alter().
RocketChatTestUnitTest::javascriptVersionTest in ./rocket_chat.test

File

src/LiveChat.class.inc, line 14

Class

LiveChat

Namespace

RocketChat

Code

public static function getLivechatJavascript($url = "https://default", $version = "1.0.0") {
  switch ($version) {
    default:
      drupal_set_message("Rocket.Chat Livechat Version supplied not supported");
      watchdog("Rocket.Chat", "Livechat Version supplied [%version] is not supported.", [
        "%version" => $version,
      ], WATCHDOG_ERROR);
      return null;
      break;
    case "1.0.0":
      global $language;
      $langcode = $language->language;
      return <<<JAVASCRIPT
(function (\$) {
  'use strict';
  (function(w, d, s, u) {
    w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u;
    var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
    j.async = true; j.src = '{<span class="php-variable">$url</span>}/livechat/1.0.0/rocketchat-livechat.min.js?_=201903270000';
    h.parentNode.insertBefore(j, h);
  })(window, document, 'script', '{<span class="php-variable">$url</span>}/livechat?version=1.0.0');
  (function(w) {
    w.RocketChat(function(){
      this.setLanguage('{<span class="php-variable">$langcode</span>}');
    });
  }(window))
})(jQuery);
JAVASCRIPT;
      break;
    case "legacy":
      return <<<JAVASCRIPT
(function (\$) {
    'use strict';
    (function (w, d, s, u) {
        w.RocketChat = function (c) { w.RocketChat._.push(c); }; w.RocketChat._ = []; w.RocketChat.url = u;
        var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
        j.async = true;
        j.src = '{<span class="php-variable">$url</span>}/packages/rocketchat_livechat/assets/rocket-livechat.min.js?_=201702160944';
        h.parentNode.insertBefore(j, h);
    })(window, document, 'script', '{<span class="php-variable">$url</span>}/livechat');
})(jQuery);
JAVASCRIPT;
      break;
  }
}