chat-room-search.js 4.11 KB
Newer Older
Kim Peace committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
ChatRoom.bindSearchUI = function () {
  const chatSearchForm = $(".chat_room_src_form");
  const chatSearchInput = $('.chat_room_src_form input[type="search"]');
  const searchMessage = $("#searchMessage");

  // 検索アイコン押下イベント
  $(".nav_item_wrap .search_menu").click(function () {
    $(".nav_item_wrap").addClass("none");
    $(".footer-wrap").addClass("none");
    chatSearchForm.removeClass("none");
    $(".room_container").addClass("none");
    $(".overlay_src_msg").removeClass("none");
    // フィルタ表示
    $("#filter").removeClass("none");
    $("#user_list").addClass("none");

    chatSearchInput.focus();
    searchMessage.addClass("onfocus");
    $(".chat_list").removeClass("none");
20

21 22
    //メッセージ情報をCMS側から最新に更新
    NativeBridgeDelegate.updatePreMessage("");
Kim Peace committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  });

  $(".chat_room_src_form .cancel").click(function () {
    $(".nav_item_wrap").removeClass("none");
    $(".footer-wrap").removeClass("none");
    chatSearchForm.addClass("none");
    $(".chat_room_src_form input").val("");
    $(".room_container").removeClass("none");
    $(".overlay_src_msg").empty();
    // ユーザーリスト表示
    $("#filter").addClass("none");
    $("#user_list").removeClass("none");

    chatSearchInput.blur();
    searchMessage.removeClass("onfocus");
    $(".chat_list").addClass("none");
    ChatRoom.scrollToBottom();
  });

  chatSearchInput.click(function () {
    if (searchMessage.hasClass("onfocus")) {
      searchMessage.removeClass("onfocus");
      searchMessage.blur();
    } else {
      searchMessage.addClass("onfocus");
      searchMessage.focus();
    }
  });

  searchMessage.blur(function () {
    searchMessage.removeClass("onfocus");
  });

  // チャットルーム
  // メッセージ検索イベント
  chatSearchInput.keyup(function (e) {
    let workVal = "";
    const keyword = chatSearchInput.val();
    const enterKeyPressed = e.key == "Enter" || e.KeyCode == 13;
    if (enterKeyPressed) {
      if (keyword != "" && keyword.length != 0) {
        chatSearchInput.blur();
        return;
      }
    } else if (keyword == "" || keyword.length < 2) {
      $(".overlay_src_msg").empty();
      return;
    }
    ChatRoom.searchMessage(keyword, workVal);

    if (enterKeyPressed) {
      searchMessage.removeClass("onfocus");
      chatSearchInput.blur();
      return;
    }
  });

  // iOSキーボード変換検知用
  chatSearchInput.on("compositionend", function () {
onuma committed
82
    if (deviceInfo.isiOS()) {
Kim Peace committed
83 84 85 86 87 88 89 90 91 92 93
      let workVal = "";
      var keyword = chatSearchInput.val();
      ChatRoom.searchMessage(keyword, workVal);
    }
  });

  // フィルタ選択イベント
  $(document).on("click", "#filter .img_wrap", function (event) {
    // チェックアイコン追加
    $(this).toggleClass("filter");
  });
94 95

  ChatRoom.bindUserFilteredMessage();
96 97 98 99

  $("#messageSearchCancel").on("click", function (event) {
    $(".img_wrap.filter").removeClass("filter");
  });
Kim Peace committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
};

ChatRoom.bindUserFilteredMessage = function () {
  $(document).on("click", ".filter_img", function (event) {
    const keyword = $('.chat_room_src_form input[type="search"]').val();
    $(".overlay_src_msg").empty();
    let checkedUserList = ChatRoom.getCheckedUserList();
    if (keyword.length == 1) {
      return;
    }
    const messages = NativeBridgeDataSource.searchMessages(
      keyword,
      checkedUserList.join(",")
    );
    ChatRoom.appendSearchMessages(messages);
  });
};

// メッセージ検索
ChatRoom.searchMessage = function (keyword, workVal) {
  $(".overlay_src_msg").empty();
  let checkedUserList = ChatRoom.getCheckedUserList();
  const messages = NativeBridgeDataSource.searchMessages(
    keyword,
    checkedUserList.join(",")
  );

  ChatRoom.appendSearchMessages(messages, workVal);

  if (messages.length == 0) {
    const noResultMsg = getNoResultMessage();
    $(".overlay_src_msg").append(noResultMsg);
  }
};

ChatRoom.getCheckedUserList = function () {
  let checkedUserList = [];
  $(".img_wrap.filter").each(function (user) {
    const selectedUser = $(".img_wrap.filter")[user];
    checkedUserList.push($(selectedUser).data("user-id"));
  });
  return checkedUserList;
142
};