PageSourceSearch

https://swz.ai/static/js/edu/code.js?rand=0105bac5046ab230e0478d21b74a982442a0dddb

js swz.ai collected 2026-10-05 13:59:06 UTC 7,349 bytes, 191 lines download raw bytes

1function corePageLoaded() {
2    initElements();
3};
4
5function initElements() {
6    let assignmentCode = getAssignmentCode();
7    $('.code-box').addClass(getRTLClass());
8    getAssignment(assignmentCode, function(assignment) {
9        if (assignment == null) {
10            loadComplete();
11            $('#assignmentCode').focus();
12            return;
13        }
14        if (assignment.status == 'COMPLETED') {
15            $('.flip-card').hide();
16            $('.assignment-complete').show();
17            loadComplete();
18            return;
19        }
20        if (assignment.user_assignments && assignment.user_assignments.length >= 40) {
21            $('.flip-card').hide();
22            $('.assignment-full').show();
23            loadComplete();
24            return;
25        }
26        $('#nameInstructions').text($.t('code:please_fill_in_your_name_to_join', {name: assignment.created_by.first_name}));
27        $('#assignmentCode').val(assignmentCode);
28        secondStep();
29    });
30    $('#nextStep').on('click', secondStep);
31    $('#assignmentCode').on('keyup', function(e) {
32        $('.validation-error').removeClass('d-flex').hide();
33        if (e.keyCode == 13) {
34            secondStep();
35        }
36    });
37    $('.no-code').on('click', function(e) {
38        $('.no-code').addClass('invisible');
39        $('.flip-card').fadeOut(500, function(){
40            $('.no-assignment-code').fadeIn();
41        });
42    });
43    $('.login-back-link').on('click', function(e) {
44        $('.email-login-container').fadeOut(250, function(){
45            let codeBox = $('.login-container').closest('.code-box');
46            codeBox.find('h1').text($.t('code:almost_there'));
47            codeBox.find('#nameInstructions').show();
48            $('.login-container').fadeIn().addClass('d-flex');
49        });
50    });
51    $('.code-input').on('input', function(e){
52        $('.login-error-message').addClass('invisible');
53    });
54    $('#logIn').on('click', function(e){
55        let loginForm = $('form#login')[0];
56        if (!loginForm.checkValidity()) {
57            loginForm.reportValidity();
58            return;
59        }
60        let email = $('#email').val();
61        let password = $('#password').val();
62        $.ajax({
63            url: '/auth/account',
64            type: 'POST',
65            data: JSON.stringify({email: email, password: password}),
66            contentType: 'application/json',
67            success: function(data) {
68                mixpanel.track('Login > Email > Success', {'email': email});
69                let assignmentId = $('#logIn').attr('data-assignment-id');
70                window.location.href = `/auth/token?assignment_id=${assignmentId}&token=${data.access_token}`;
71            },
72            error: function(xhr, status, error) {
73                mixpanel.track('Login > Email > Error', {'email': email});
74                $('.login-error-message').removeClass('invisible');
75            }
76        });
77    });
78
79}
80
81function secondStep() {
82    let assignmentCode = $('#assignmentCode').val();
83    assignmentCode = assignmentCode.split('/').pop();
84    $('.validation-error').removeClass('d-flex').hide();
85    getAssignment(assignmentCode, function(assignment) {
86        if (assignment == null) {
87            loadComplete();
88            $('p.error-text').text($.t('code:no_active_assignment_for_this_code'));
89            $('.validation-error').addClass('d-flex').show();
90            $('#assignmentCode').focus();
91            return;
92        }
93        $('#logIn').attr('data-assignment-id', assignment.id);
94        $('.no-code').addClass('invisible');
95        if (assignment.status == 'COMPLETED') {
96            $('.flip-card').fadeOut(500, function(){
97                $('.assignment-complete').fadeIn();
98            });
99            loadComplete();
100            return;
101        }
102        if (assignment.user_assignments && assignment.user_assignments.length >= 40) {
103            $('.flip-card').fadeOut(500, function(){
104                $('.assignment-full').fadeIn();
105            });
106            loadComplete();
107            return;
108        }
109
110        $('#nameInstructions').text($.t('code:please_fill_in_your_name_to_join', {name: assignment.created_by.first_name}));
111        if (assignment.join_method == 'LOGIN') {
112            $('#nameInstructions').text($.t('code:please_login_to_join', {name: assignment.created_by.first_name}));
113            $('.code-input-container').removeClass('d-flex').hide();
114            if (assignment.preferred_login_method) {
115                $('.external-login-button').hide();
116                $(`.external-login-button[data-provider=${assignment.preferred_login_method.toLowerCase()}]`).show();
117            }
118            $('.login-container').addClass('d-flex').show();
119            $('.external-login-button').on('click', function(e){
120                let provider = $(this).data('provider');
121                if (provider == 'email') {
122                    mixpanel.track('Assignment login using email', {'assignment_id': assignment.id});
123                    let codeBox = $('.login-container').closest('.code-box');
124                    codeBox.find('#nameInstructions').fadeOut(250);
125                    $('.login-container').fadeOut(250, function(){
126                        $('.login-container').removeClass('d-flex').hide();
127                        codeBox.find('h1').text($.t('code:log_in_to_your_account'));
128                        $('.email-login-container').fadeIn();
129                        codeBox.fadeIn();
130                    });
131                } else {
132                    mixpanel.track('Assignment login started', {'provider': provider}, function(){
133                      window.location.href=`${WEB_ENDPOINT}/login/${provider}?assignment_id=${assignment.id}`;
134                    });
135                }
136            });
137        }
138        $('.flip-card').addClass('flip-card-flipped');
139        $('#studentName').focus();
140        $('#studentName').on('keyup', function(e) {
141            $('.validation-error').removeClass('d-flex').hide();
142            if (e.keyCode == 13) {
143                signIn(assignment);
144            }
145        });
146        $('#signIn').on('click', function() {
147            signIn(assignment);
148        });
149        loadComplete();
150    });
151}
152
153function signIn(assignment) {
154    $('.validation-error').removeClass('d-flex').hide();
155    let studentName = $('#studentName').val();
156    if (studentName == '') {
157        $('p.error-text').text($.t('code:please_fill_in_your_name'));
158        $('.validation-error').addClass('d-flex').show();
159        $('#studentName').focus();
160        return;
161    }
162    window.location.href = `/auth/assignment/${assignment.id}?name=${studentName}`;
163}
164
165function getAssignmentCode() {
166    var pathname = window.location.pathname;
167    if (window.location.hostname.startsWith('localhost')) {
168        return pathname.split('/')[2]
169    }
170    return pathname.split('/')[1]
171}
172
173function loadComplete() {
174    corePageRendered();
175}
176
177function getAssignment(assignmentCode, whenDone) {
178    $.ajax({
179        method: "GET",
180        url: `/api/v1/assignments/code/${assignmentCode}`,
181        headers: {
182            'Authorization': `Bearer ${getRegisteredUserToken()}`,
183            'Accept': 'application/json'
184        }
185    })
186    .done(whenDone)
187    .fail(function(jqXHR, textStatus, errorThrown) {
188        console.log(jqXHR.responseJSON);
189        whenDone(null);
190    });
191}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.