PageSourceSearch

https://www.kth.se/blogs/rektor/wp-content/plugins/email-subscribe…/js/email-subscribers-public.js?ver=5.9.37

js kth.se collected 2026-09-24 08:26:02 UTC 5,432 bytes, 167 lines download raw bytes

1(function ($) {
2	'use strict';
3
4	/**
5	 * All of the code for your public-facing JavaScript source
6	 * should reside in this file.
7	 *
8	 * Note: It has been assumed you will write jQuery code here, so the
9	 * $ function reference has been prepared for usage within the scope
10	 * of this function.
11	 *
12	 * This enables you to define handlers, for when the DOM is ready:
13	 *
14	 * $(function() {
15	 *
16	 * });
17	 *
18	 * When the window is loaded:
19	 *
20	 * $( window ).load(function() {
21	 *
22	 * });
23	 *
24	 * ...and/or other possibilities.
25	 *
26	 * Ideally, it is not considered best practise to attach more than a
27	 * single DOM-ready or window-load handler for a particular page.
28	 * Although scripts in the WordPress core, Plugins and Themes may be
29	 * practising this, we should strive to set a better example in our own work.
30	 */
31
32    $(document).ready(function () {
33
34        /**
35         * Extend jQuery to convert form into JSON object
36         * @returns {{}}
37         */
38        $.fn.serializeObject = function () {
39            var output = {};
40            var formData = this.serializeArray();
41            $.each(formData, function () {
42                var fieldName = this.name;
43                var fieldValue = this.value || '';
44                var isArrayField = fieldName.slice(-2) === '[]';
45                if (isArrayField) {
46                    if (output[fieldName]) {
47                        output[fieldName].push(fieldValue);
48                    } else {
49                        output[fieldName] = [fieldValue];
50                    }
51                } else {
52                    output[fieldName] = fieldValue;
53                }
54            });
55            return output;
56        };
57
58        /**
59         * Handle subscription form submission
60         */
61        $('.es_ajax_subscription_form').on('submit', function (e) {
62            var form = $(this);
63            e.preventDefault();
64            handleBindFunction(form);
65        });
66
67    });
68
69    function handleResponse(response, form) {
70
71        var redirection_url = response['redirection_url'];
72
73        if ( 'undefined' !== typeof redirection_url ) {
74
75            redirection_url = redirection_url.trim();
76            if (typeof(redirection_url) === 'string' && redirection_url != '') {
77                if (!/^https?:\/\//i.test(redirection_url) ) {
78                    redirection_url = "http://"+redirection_url;
79                }
80                window.location.href = redirection_url;
81            }
82
83        } else {
84            var status = response.status;
85            var message_class = 'success';
86            if (status === 'ERROR') {
87                message_class = 'error';
88            }
89
90            var responseText = response['message_text'];
91            var messageContainer = $(form).next('.es_subscription_message');
92            messageContainer.attr('class', 'es_subscription_message ' + message_class);
93            messageContainer.html(responseText);
94            var esSuccessEvent = {
95                detail: {
96                    es_response: message_class,
97                    msg: responseText
98                },
99                bubbles: true,
100                cancelable: true
101            };
102
103            $(form).trigger('es_response', [esSuccessEvent]);
104        }        
105    }
106
107    function handleBindFunction(form, is_ig = false) {
108        form = $(form);
109        var formData = form.serializeObject();
110        formData['es'] = 'subscribe';
111        formData['action'] = 'es_add_subscriber';
112        $.ajax({
113            type: 'POST',
114            url: es_data.es_ajax_url,
115            data: formData,
116            dataType: 'json',
117            beforeSend: function () {
118                form.find('#spinner-image').show();
119                form.find('.es_submit_button').attr('disabled', true);
120            },
121            success: function (response) {
122                // Handle WordPress AJAX response format
123                var actualResponse = response;
124                if (response.success !== undefined && response.data !== undefined) {
125                    actualResponse = response.data;
126                }
127                
128                if (!is_ig) {
129                    if (actualResponse && typeof actualResponse.status !== 'undefined' && actualResponse.status === "SUCCESS") {
130                        form.slideUp('slow');
131                        form.hide();
132                    } else {
133                        form.find('#spinner-image').hide();
134                    }
135                }
136                form.find('.es_submit_button').attr('disabled', false);
137                jQuery(window).trigger('es.send_response', [form, actualResponse]);
138                handleResponse(actualResponse, form);
139            },
140            error: function (err) {
141                form.find('#spinner-image').hide();
142                form.find('.es_submit_button').attr('disabled', false);
143                console.log(err, 'error');
144            },
145        });
146
147
148		return false;
149	}
150
151	// Compatibility of ES with IG
152	jQuery( window ).on( "init.icegram", function(e, ig) {
153		if(typeof ig !== 'undefined' && typeof ig.messages !== 'undefined' ) {
154			jQuery('.icegram .es_shortcode_form, .icegram form[data-source="ig-es"]').each(function(i, v){
155				jQuery(v).bind('submit', function (e) {
156					e.preventDefault();
157					e.stopImmediatePropagation();
158					var form = $(this);
159					handleBindFunction(form, true);
160				});
161			});
162		}
163	});
164
165})(jQuery);
166
167

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.