PluginProbe
RabbitLoader / 4.0.2
RabbitLoader v4.0.2
4.0.2 4.0.1 4.0 3.2.0 3.1.1 3.1.0 3.0.5 3.0.3 3.0.4 2.17.1 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.7 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.18.5 2.18.6 2.18.7 2.18.8 All 129 releases
rabbit-loader / admin / js / connect.js

connect.js in RabbitLoader 4.0.2, at admin/js/connect.js

88 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 function cfg() {
5 return window.RL5Config || {};
6 }
7
8 function setStatus(message, type) {
9 var el = document.getElementById('rl5-connect-status');
10 if (!el) {
11 return;
12 }
13
14 el.textContent = message || '';
15 el.dataset.type = type || '';
16 }
17
18 function openConnectPopup(event) {
19 if (event) {
20 event.preventDefault();
21 }
22
23 var config = cfg();
24 var button = document.getElementById('rl5-connect-button');
25
26 if (!button) {
27 return;
28 }
29
30 var url = new URL(config.connectBaseUrl || 'https://dash.rabbitloader.com/connect');
31 url.searchParams.set('site_url', window.location.origin);
32 url.searchParams.set('redirect_url', window.location.href);
33 url.searchParams.set('source', 'wordpress');
34 url.searchParams.set('action', 'connect');
35
36 var width = 600;
37 var height = 700;
38 var left = Math.max(0, Math.round((window.screen.width - width) / 2));
39 var top = Math.max(0, Math.round((window.screen.height - height) / 2));
40
41 var popup = window.open(
42 url.toString(),
43 'Connect',
44 [
45 'width=' + width,
46 'height=' + height,
47 'left=' + left,
48 'top=' + top,
49 'resizable=yes',
50 'scrollbars=yes'
51 ].join(',')
52 );
53
54 if (!popup) {
55 setStatus('The login popup was blocked by the browser.', 'error');
56 return;
57 }
58
59 button.disabled = true;
60 button.dataset.originalLabel = button.textContent;
61 button.textContent = 'Waiting for RabbitLoader…';
62 setStatus('Complete the RabbitLoader login in the popup.', 'info');
63
64 var timer = window.setInterval(function () {
65 if (!popup || popup.closed) {
66 window.clearInterval(timer);
67
68 if (!window.RL5ConnectionCompleted) {
69 button.disabled = false;
70 button.textContent = button.dataset.originalLabel || 'Connect RabbitLoader';
71 setStatus('Popup closed. You can try connecting again.', 'info');
72 }
73 }
74 }, 500);
75 }
76
77 document.addEventListener('DOMContentLoaded', function () {
78 var button = document.getElementById('rl5-connect-button');
79 if (button) {
80 button.addEventListener('click', openConnectPopup);
81 }
82 });
83
84 window.RL5ConnectUI = {
85 status: setStatus
86 };
87 })();
88