PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.11
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.11
1.1.11 1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 All 35 releases
desktop-mode / assets / js / admin-bar.js

admin-bar.js in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.11, at assets/js/admin-bar.js

58 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function() {
2 // The "Switch to OpenStation" node only renders in classic admin —
3 // PHP skips it once the user is viewing the shell, where the
4 // "Exit OpenStation" dock tile is the way back out. So this handler
5 // only ever enables.
6 var toggle = document.getElementById( 'wp-admin-bar-os-toggle' );
7 if ( ! toggle ) {
8 return;
9 }
10 var cfg = window.openStationAdminBar || {};
11 toggle.addEventListener( 'click', function( e ) {
12 e.preventDefault();
13 // Fallback target if the server response is missing a `redirect`
14 // field (shouldn't happen, but keep the click functional either
15 // way): the portal URL, so the shell takes over.
16 var fallback = cfg.portalUrl;
17 // The toggle lives in an admin bar that may be rendered either in
18 // the top window (classic) or — today it's suppressed in iframes,
19 // but a plugin could surface it — inside a chromeless iframe. In
20 // either case we want the ENTIRE browser tab to navigate, so we
21 // hit `window.top` and fall back to `window` if cross-origin
22 // security blocks access.
23 function navigate( url ) {
24 try {
25 window.top.location.href = url;
26 } catch ( err ) {
27 window.location.href = url;
28 }
29 }
30 var body = new URLSearchParams();
31 body.set( 'action', 'save-openstation' );
32 body.set( 'nonce', cfg.nonce );
33 body.set( 'enabled', '1' );
34 // Tells the handler which admin this click came from; see the
35 // note in `includes/ajax.php`.
36 if ( cfg.network ) {
37 body.set( 'network', '1' );
38 }
39 var xhr = new XMLHttpRequest();
40 xhr.open( 'POST', cfg.ajaxUrl, true );
41 xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
42 xhr.onload = function() {
43 if ( xhr.status !== 200 ) {
44 return;
45 }
46 var target = fallback;
47 try {
48 var resp = JSON.parse( xhr.responseText );
49 if ( resp && resp.success && resp.data && resp.data.redirect ) {
50 target = resp.data.redirect;
51 }
52 } catch ( parseErr ) {}
53 navigate( target );
54 };
55 xhr.send( body.toString() );
56 } );
57 } )();
58