@@ -5,11 +5,6 @@ import { Application } from "@hotwired/stimulus";
55import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers" ;
66import { Autocomplete } from "stimulus-autocomplete" ;
77
8- // We'll use docReady as a modern replacement for $(document).ready() which
9- // does not require all of jQuery to use. This will let us use it without
10- // having to load all of jQuery, which will make things faster.
11- import docReady from "warehouse/utils/doc-ready" ;
12-
138// Import our utility functions
149import HTMLInclude from "warehouse/utils/html-include" ;
1510import * as formUtils from "warehouse/utils/forms" ;
@@ -23,63 +18,51 @@ import {GuardWebAuthn, AuthenticateWebAuthn, ProvisionWebAuthn} from "warehouse/
2318import checkProxyProtection from "warehouse/utils/proxy-protection" ;
2419
2520// Show unsupported browser warning if necessary
26- docReady ( ( ) => {
27- if ( navigator . appVersion . includes ( "MSIE 10" ) ) {
28- if ( document . getElementById ( "unsupported-browser" ) !== null ) return ;
29-
21+ if ( navigator . appVersion . includes ( "MSIE 10" ) ) {
22+ if ( document . getElementById ( "unsupported-browser" ) === null ) {
3023 let warning_div = document . createElement ( "div" ) ;
3124 warning_div . innerHTML = "<div id='unsupported-browser' class='notification-bar notification-bar--warning' role='status'><span class='notification-bar__icon'><i class='fa fa-exclamation-triangle' aria-hidden='true'></i><span class='sr-only'>Warning:</span></span><span class='notification-bar__message'>You are using an unsupported browser, please upgrade to a newer version.</span></div>" ;
3225
3326 document . getElementById ( "sticky-notifications" ) . appendChild ( warning_div ) ;
3427 }
35- } ) ;
28+ }
3629
3730// Human-readable timestamps for project histories
38- docReady ( ( ) => {
39- timeAgo ( ) ;
40- } ) ;
31+ timeAgo ( ) ;
4132
4233// toggle search panel behavior
43- docReady ( ( ) => {
44- if ( document . querySelector ( ".-js-add-filter" ) ) searchFilterToggle ( ) ;
45- } ) ;
34+ if ( document . querySelector ( ".-js-add-filter" ) ) searchFilterToggle ( ) ;
4635
4736// Kick off the client side HTML includes.
48- docReady ( HTMLInclude ) ;
37+ HTMLInclude ( ) ;
4938
5039// Handle the JS based automatic form submission.
51- docReady ( formUtils . submitTriggers ) ;
52- docReady ( formUtils . registerFormValidation ) ;
40+ formUtils . submitTriggers ( ) ;
41+ formUtils . registerFormValidation ( ) ;
5342
54- docReady ( Statuspage ) ;
43+ Statuspage ( ) ;
5544
5645// Close modals when escape button is pressed
57- docReady ( ( ) => {
58- document . addEventListener ( "keydown" , event => {
59- // Only handle the escape key press when a modal is open
60- if ( document . querySelector ( ".modal:target" ) && event . keyCode === 27 ) {
61- for ( let element of document . querySelectorAll ( ".modal" ) ) {
62- application
63- . getControllerForElementAndIdentifier ( element , "confirm" )
64- . cancel ( ) ;
65- }
46+ document . addEventListener ( "keydown" , event => {
47+ // Only handle the escape key press when a modal is open
48+ if ( document . querySelector ( ".modal:target" ) && event . keyCode === 27 ) {
49+ for ( let element of document . querySelectorAll ( ".modal" ) ) {
50+ application
51+ . getControllerForElementAndIdentifier ( element , "confirm" )
52+ . cancel ( ) ;
6653 }
67- } ) ;
54+ }
6855} ) ;
6956
7057// Position sticky bar
71- docReady ( ( ) => {
72- setTimeout ( PositionWarning , 200 ) ;
73- } ) ;
58+ setTimeout ( PositionWarning , 200 ) ;
7459
75- docReady ( ( ) => {
76- let resizeTimer ;
77- const onResize = ( ) => {
78- clearTimeout ( resizeTimer ) ;
79- resizeTimer = setTimeout ( PositionWarning , 200 ) ;
80- } ;
81- window . addEventListener ( "resize" , onResize , false ) ;
82- } ) ;
60+ let resizeTimer ;
61+ const onResize = ( ) => {
62+ clearTimeout ( resizeTimer ) ;
63+ resizeTimer = setTimeout ( PositionWarning , 200 ) ;
64+ } ;
65+ window . addEventListener ( "resize" , onResize , false ) ;
8366
8467let bindDropdowns = function ( ) {
8568 // Bind click handlers to dropdowns for keyboard users
@@ -137,33 +120,29 @@ let bindDropdowns = function () {
137120} ;
138121
139122// Bind the dropdowns when the page is ready
140- docReady ( bindDropdowns ) ;
123+ bindDropdowns ( ) ;
141124
142125// Get modal keypress event listeners ready
143- docReady ( BindModalKeys ) ;
126+ BindModalKeys ( ) ;
144127
145128// Get filter pane keypress event listeners ready
146- docReady ( BindFilterKeys ) ;
129+ BindFilterKeys ( ) ;
147130
148131// Get WebAuthn compatibility checks ready
149- docReady ( GuardWebAuthn ) ;
132+ GuardWebAuthn ( ) ;
150133
151134// Get WebAuthn provisioning ready
152- docReady ( ProvisionWebAuthn ) ;
135+ ProvisionWebAuthn ( ) ;
153136
154137// Get WebAuthn authentication ready
155- docReady ( AuthenticateWebAuthn ) ;
138+ AuthenticateWebAuthn ( ) ;
156139
157140// Initialize proxy protection
158- docReady ( checkProxyProtection ) ;
141+ checkProxyProtection ( ) ;
159142
160- docReady ( ( ) => {
161- const tokenSelect = document . getElementById ( "token_scope" ) ;
162-
163- if ( tokenSelect === null ) {
164- return ;
165- }
143+ const tokenSelect = document . getElementById ( "token_scope" ) ;
166144
145+ if ( tokenSelect !== null ) {
167146 tokenSelect . addEventListener ( "change" , ( ) => {
168147 const tokenScopeWarning = document . getElementById ( "api-token-scope-warning" ) ;
169148 if ( tokenScopeWarning === null ) {
@@ -173,7 +152,7 @@ docReady(() => {
173152 const tokenScope = tokenSelect . options [ tokenSelect . selectedIndex ] . value ;
174153 tokenScopeWarning . hidden = ( tokenScope !== "scope:user" ) ;
175154 } ) ;
176- } ) ;
155+ }
177156
178157// Bind again when client-side includes have been loaded (for the logged-in
179158// user dropdown)
0 commit comments