mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	The only reason to use typeof foo === "undefined" is when foo is a global identifier that might not have been declared at all, so it might raise a ReferenceError if evaluated. For a variable declared with const or let or import, a function argument, or a complex expression, simply foo === undefined is equivalent. Some of these conditions have become impossible and can be removed entirely, and some can be replaced more idiomatically with default parameters (note that JavaScript does not share the Python misfeature of evaluating the default parameter at function declaration time). Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import $ from "jquery";
 | 
						|
 | 
						|
// Add functions to this that have no non-trivial
 | 
						|
// dependencies other than jQuery.
 | 
						|
 | 
						|
export function change_tab_to(tabname) {
 | 
						|
    $(`#gear-menu a[href="${CSS.escape(tabname)}"]`).tab("show");
 | 
						|
}
 | 
						|
 | 
						|
// https://stackoverflow.com/questions/4233265/contenteditable-set-caret-at-the-end-of-the-text-cross-browser
 | 
						|
export function place_caret_at_end(el) {
 | 
						|
    el.focus();
 | 
						|
 | 
						|
    if (window.getSelection !== undefined && document.createRange !== undefined) {
 | 
						|
        const range = document.createRange();
 | 
						|
        range.selectNodeContents(el);
 | 
						|
        range.collapse(false);
 | 
						|
        const sel = window.getSelection();
 | 
						|
        sel.removeAllRanges();
 | 
						|
        sel.addRange(range);
 | 
						|
    } else if (document.body.createTextRange !== undefined) {
 | 
						|
        const textRange = document.body.createTextRange();
 | 
						|
        textRange.moveToElementText(el);
 | 
						|
        textRange.collapse(false);
 | 
						|
        textRange.select();
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export function blur_active_element() {
 | 
						|
    // this blurs anything that may perhaps be actively focused on.
 | 
						|
    document.activeElement.blur();
 | 
						|
}
 |