Giter VIP home page Giter VIP logo

Comments (6)

AlexMatusevich avatar AlexMatusevich commented on July 17, 2024
$("#privateMsgModal .modal-title").html("Private chat with " + this.id);
$(".modal-title").attr("id", this.id);
$("#privateMsgModal").modal({ backdrop: "static" });

Во-первых, первую строку стоит переписать с использованием find:

$("#privateMsgModal").find(".modal-title").html("Private chat with " + this.id);

Во-вторых, $("#privateMsgModal") стоит сохранить в локальную переменную, чтобы в третьей строке снова не искать нужный элемент.

from nodachat.

AlexMatusevich avatar AlexMatusevich commented on July 17, 2024

У тебя во многих местах используется подобного рода код:

$("<div/>").addClass("media-body").append($mediaDiv);

Было бы неплохо создать helper-функцию, которая будет принимать аргументы (тег, класс, т.д.) и возвращать элемент. Тем самым получится уменьшить объемы jQuery кода и сделать весь код более читабельным.

from nodachat.

AlexMatusevich avatar AlexMatusevich commented on July 17, 2024
    $("#btnSendMessage").click(function () {
        var message = $("#inputMessage").val();
        $("#inputMessage").val("");
        message = validateInput(message);
        if (message) {
            var data = { from: userEmail, to: "all", message: message };
            sendMessage(data);
        }
    });

$("#inputMessage") стоит сохранить в локальную переменную, чтобы потом снова не искать нужный элемент.

from nodachat.

AlexMatusevich avatar AlexMatusevich commented on July 17, 2024
    $("#btnSendPrivateMessagee").click(function () {
        var message = $("#inputPrivateMessage").val();
        $("#inputPrivateMessage").val("");
        message = validateInput(message);
        if (message) {
            var to = $(".modal-title").attr("id");
            var data = { from: userEmail, to: to, message: message };
            sendMessage(data);
        }
    });

То же самое относится к $("#inputPrivateMessage").

from nodachat.

AlexMatusevich avatar AlexMatusevich commented on July 17, 2024

Можно также сделать одну функцию-обработчик для последних двух случаев, но это не особо важно.

from nodachat.

wxq0910 avatar wxq0910 commented on July 17, 2024

from nodachat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.