mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	We now treat util like a leaf module and use "require" to import it everywhere it's used. An earlier version of this commit moved util into our "shared" library, but we decided to wait on that. Once we're ready to do that, we should only need to do a simple search/replace on various require/zrequire statements plus a small tweak to one of the custom linter checks. It turns out we don't really need util.js for our most immediate code-sharing goal, which is to reuse our markdown code on mobile. There's a little bit of cleanup still remaining to break the dependency, but it's minor. The util module still calls the global blueslip module in one place, but that code is about to be removed in the next few commits. I am pretty confident that once we start sharing things like the typeahead code more aggressively, we'll start having dependencies on util. The module is barely more than 300 lines long, so we'll probably just move the whole thing into shared rather than break it apart. Also, we can continue to nibble away at the cruftier parts of the module.
		
			
				
	
	
		
			89 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const util = require("./util");
 | 
						|
const resize_app = function () {
 | 
						|
    const panels_height = $("#panels").height();
 | 
						|
    $("body > .app").height("calc(100% - " + panels_height + "px)");
 | 
						|
    // the floating recipient bar is usually positioned 10px below the
 | 
						|
    // header, so add that to the panels height to get the new `top` value.
 | 
						|
    $("#floating_recipient_bar").css("top", panels_height + $(".header").height() + 10 + "px");
 | 
						|
};
 | 
						|
 | 
						|
exports.resize_app = resize_app;
 | 
						|
 | 
						|
const show_step = function ($process, step) {
 | 
						|
    $process.find("[data-step]").hide().filter("[data-step=" + step + "]").show();
 | 
						|
};
 | 
						|
 | 
						|
const get_step = function ($process) {
 | 
						|
    return $process.find("[data-step]").filter(":visible").data("step");
 | 
						|
};
 | 
						|
 | 
						|
exports.initialize = function () {
 | 
						|
    // if email has not been set up and the user is the admin, display a warning
 | 
						|
    // to tell them to set up an email server.
 | 
						|
    if (page_params.warn_no_email === true && page_params.is_admin) {
 | 
						|
        exports.open($("[data-process='email-server']"));
 | 
						|
    } else {
 | 
						|
        exports.open($("[data-process='notifications']"));
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
exports.open = function ($process) {
 | 
						|
    const ls = localstorage();
 | 
						|
 | 
						|
    $("[data-process]").hide();
 | 
						|
 | 
						|
    let should_show_notifications =
 | 
						|
        // notifications *basically* don't work on any mobile platforms, so don't
 | 
						|
        // event show the banners. This prevents trying to access things that
 | 
						|
        // don't exist like `Notification.permission`.
 | 
						|
        !util.is_mobile() &&
 | 
						|
        // if permission has not been granted yet.
 | 
						|
        !notifications.granted_desktop_notifications_permission() &&
 | 
						|
        // if permission is allowed to be requested (e.g. not in "denied" state).
 | 
						|
        notifications.permission_state() !== "denied"
 | 
						|
    ;
 | 
						|
 | 
						|
    if (localstorage.supported()) {
 | 
						|
        // if the user said to never show banner on this computer again, it will
 | 
						|
        // be stored as `true` so we want to negate that.
 | 
						|
        should_show_notifications = should_show_notifications && !ls.get("dontAskForNotifications");
 | 
						|
    }
 | 
						|
 | 
						|
    if (should_show_notifications) {
 | 
						|
        $process.show();
 | 
						|
        resize_app();
 | 
						|
    }
 | 
						|
 | 
						|
    // if it is not the notifications prompt, show the error if it has been
 | 
						|
    // initialized here.
 | 
						|
    if ($process.is(":not([data-process='notifications'])")) {
 | 
						|
        $process.show();
 | 
						|
        resize_app();
 | 
						|
    }
 | 
						|
 | 
						|
    $(".request-desktop-notifications").on("click", function (e) {
 | 
						|
        e.preventDefault();
 | 
						|
        $(this).closest(".alert").hide();
 | 
						|
        notifications.request_desktop_notifications_permission();
 | 
						|
        resize_app();
 | 
						|
    });
 | 
						|
 | 
						|
    $(".reject-notifications").on("click", function () {
 | 
						|
        $(this).closest(".alert").hide();
 | 
						|
        ls.set("dontAskForNotifications", true);
 | 
						|
        resize_app();
 | 
						|
    });
 | 
						|
 | 
						|
    $("#panels").on("click", ".alert .close, .alert .exit", function (e) {
 | 
						|
        e.stopPropagation();
 | 
						|
        if (get_step($process) === 1 && $process.data("process") === "notifications") {
 | 
						|
            show_step($process, 2);
 | 
						|
        } else {
 | 
						|
            $(this).closest(".alert").hide();
 | 
						|
        }
 | 
						|
        resize_app();
 | 
						|
    });
 | 
						|
};
 | 
						|
 | 
						|
window.panels = exports;
 |