common.js 4.62 KB
Newer Older
Kim Peace committed
1 2
String.prototype.replaceAll = function (org, dest) {
  return this.split(org).join(dest);
Kim Peace committed
3
};
Kim Peace committed
4

Kim Peace committed
5 6 7 8 9 10 11 12 13
function includeJs(jsFilePath) {
  var js = document.createElement("script");

  js.type = "text/javascript";
  js.src = jsFilePath;

  document.body.appendChild(js);
}

Kim Peace committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
function getTemplate(url) {
  var template;
  $.get({ url: url, async: false }, function (text) {
    template = text;
  });
  return template;
}

function getNoResultMessage() {
  const noResultMsg = $("<div/>", {
    width: "auto",
    style: "text-align: center",
  });
  noResultMsg.append(getLocalizedString("noResult"));
  return noResultMsg;
}

Lee Munkyeong committed
31
// アコーディオン
Kim Peace committed
32
$(".category").on("click", function () {
Lee Munkyeong committed
33 34 35
  $(this).toggleClass("open");
  $(this).next().slideToggle();
});
藤川諒 committed
36

Kim Peace committed
37
$(".home_btn").on("click", function () {
38
  NativeBridgeDelegate.goHome();
Lee Munkyeong committed
39
});
Kim Peace committed
40

Kim Peace committed
41
document.addEventListener("DOMContentLoaded", function () {
藤川諒 committed
42
  // ローディング表示
Kim Peace committed
43
  $("footer a").click(function (event) {
藤川諒 committed
44 45
    const a = $(this);
    event.preventDefault();
Kim Peace committed
46
    Common.showLoadingIndicator();
藤川諒 committed
47

Kim Peace committed
48
    setTimeout(function () {
藤川諒 committed
49 50 51 52 53
      window.location.href = a[0].href;
    }, 1000);
  });

  // 共通検索フォーム キャンセルボタン表示
Kim Peace committed
54 55
  $('.search_form input[type="search"]').click(function () {
    $(this).addClass("focus");
藤川諒 committed
56
    // キャンセルボタン表示
Kim Peace committed
57 58 59 60
    $(".cancel").removeClass("none");
    $(".search_form form").addClass("d-flex flex-row h-100 align-items-center");
    $(".content").addClass("none");
    $(".craeteRoomButton").addClass("none");
藤川諒 committed
61
  });
Kim Peace committed
62

藤川諒 committed
63
  // 共通検索フォーム キャンセルボタン押下イベント
Kim Peace committed
64 65 66 67 68 69 70 71
  $(".search_form .cancel").click(function () {
    $(this).addClass("none");
    $(".search_form input").removeClass("focus");
    $(".search_form input").val("");
    $(".search_form form").removeClass();
    $(".content").removeClass("none");
    $(".overlay_src_msg").empty();
    $(".craeteRoomButton").removeClass("none");
藤川諒 committed
72
  });
73
});
藤川諒 committed
74

Kim Peace committed
75 76 77 78 79 80
document.addEventListener("readystatechange", () => {
  
  switch (document.readyState) {
    case "interactive":
      break;
    case "complete":
81 82 83
      if (typeof initialLoading != "undefined" && initialLoading) {
        break;
      }
Kim Peace committed
84 85 86 87 88
      Common.dismissLoadingIndicator();
      break;
  }
});

89
var Common = {};
Kim Peace committed
90

91 92
//loadingIndicatorを表示
Common.showLoadingIndicator = function () {
Kim Peace committed
93
  NativeBridgeDelegate.showLoadingIndicator();
94 95 96 97
};

//loadingIndicatorを表示しない
Common.dismissLoadingIndicator = function () {
Kim Peace committed
98
  NativeBridgeDelegate.hideLoadingIndicator();
99 100 101
};

Common.refreshForOnline = function () {
Kim Peace committed
102
  Common.showLoadingIndicator();
103
  serverInfo.isOnline = true;
104
  $(".footer_item a").removeClass("ui-state-disabled");
105
  if (typeof ChatList != "undefined") {
106 107
    ChatList.refreshForOnline();
  }
108
  if (typeof ChatRoom != "undefined") {
109 110
    ChatRoom.refreshForOnline();
  }
111
  if (typeof Namecard != "undefined") {
112 113
    Namecard.refreshForOnline();
  }
114 115 116
};

Common.refreshForOffline = function () {
117
  serverInfo.isOnline = false;
118
  $(".footer_item a").addClass("ui-state-disabled");
119
  if (typeof ChatList != "undefined") {
120 121
    ChatList.refreshForOffline();
  }
122
  if (typeof ChatRoom != "undefined") {
123 124
    ChatRoom.refreshForOffline();
  }
125
  if (typeof CollaborationUI != "undefined") {
126 127
    CollaborationUI.refreshForOffline();
  }
128
  if (typeof Namecard != "undefined") {
129 130
    Namecard.refreshForOffline();
  }
131 132 133 134 135 136 137
};

// #36170 画像パスが存在しない場合はデフォルトの画像を返す
// 存在する場合はプロフィール画像取得用APIのURLを生成して返す
Common.getProfileImgUrl = function (path) {
  if (path == undefined || path == "") {
    return "./img/noImage.png";
138 139 140 141 142 143 144 145 146 147 148 149
  } else if (path.includes("/mnt")) {
    const userInfo = path.split("/").reverse();
    return (
      serverInfo.cmsURL +
      "/chatapi/user?profileFileName=" +
      userInfo[0] +
      "&profileGetLoginId=" +
      userInfo[1] +
      "&sid=" +
      currentUserInfo.sid +
      "&cmd=12"
    );
150
  } else {
151
    return path;
152
  }
153
};
154 155 156 157 158 159 160 161

Common.startCollaboration = function (collaborationType) {
  if (deviceInfo.isAndroid()) {
    if (
      collaborationType == COLLABORATION_TYPE.DOCUMENT &&
      deviceInfo.androidVersion < ANDROID_SDK_VERSION.O
    ) {
      alert(getLocalizedString("not_support_version"));
162
      Common.dismissLoadingIndicator();
163 164 165 166 167 168 169 170 171 172
      return;
    }
  }

  if ($(".collabo_area.start").length != 0) {
    if (!confirm(getLocalizedString("already_exist_collaboration"))) {
      Common.dismissLoadingIndicator();
      return;
    }
  }
173 174 175

  CHAT_SOCKET.emitCollaborationFinishMessage();
  NativeBridgeDelegate.finishAllCollaboration();
176
  NativeBridgeDelegate.startCollaboration(collaborationType);
177
  Common.dismissLoadingIndicator();
178
};