Skip to content

Commit

Permalink
FIX Don't require jquery on the frontend (#2854)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored May 8, 2023
1 parent 241fa3e commit 55eabd6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 27 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/SilverStripeNavigator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 65 additions & 25 deletions client/src/legacy/SilverStripeNavigator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,69 @@
import $ from 'jquery';
(function() {
function windowName(suffix) {
const base = document.getElementsByTagName('base')[0].href.replace('http://','').replace(/\//g,'_').replace(/\./g,'_');
return base + suffix;
}

function windowName(suffix) {
var base = document.getElementsByTagName('base')[0].href.replace('http://','').replace(/\//g,'_').replace(/\./g,'_');
return base + suffix;
}
function displayHide(elem) {
const displayComputed = getComputedStyle(elem).display;
elem.style.display = 'none';
elem.dataset.__toggle_display = displayComputed;
}

function displayShow(elem) {
elem.style.display = elem.dataset.__toggle_display ? elem.dataset.__toggle_display : 'block';
}

$(document).ready(function() {
$('#switchView a.newWindow').on('click', function(e) {
var w = window.open(this.href, windowName(this.target));
w.focus();
return false;
});
function displayToggle(elem) {
const displayComputed = getComputedStyle(elem).display;
if (displayComputed !== 'none') {
displayHide(elem);
} else {
displayShow(elem);
}
}

$('#SilverStripeNavigatorLink').on('click', function(e) {
$('#SilverStripeNavigatorLinkPopup').toggle();
return false;
});

$('#SilverStripeNavigatorLinkPopup a.close').on('click', function(e) {
$('#SilverStripeNavigatorLinkPopup').hide();
return false;
});

$('#SilverStripeNavigatorLinkPopup input').on('focus',function(e) {
this.select();
});
});
const newWindowLinks = document.querySelectorAll('#switchView a.newWindow');
if (newWindowLinks.length > 0) {
for (const link of newWindowLinks.values()) {
link.addEventListener('click', function(e) {
e.preventDefault();
const w = window.open(link.href, windowName(link.target));
w.focus();
return false;
});
}
}

const popup = document.getElementById('SilverStripeNavigatorLinkPopup');
if (popup) {
const navigatorLink = document.getElementById('SilverStripeNavigatorLink');
if (navigatorLink) {
navigatorLink.addEventListener('click', function(e) {
e.preventDefault();
displayToggle(popup);
return false;
});
}

const closeLinks = popup.querySelectorAll('a.close');
if (closeLinks.length > 0) {
for (const link of closeLinks.values()) {
link.addEventListener('click', function(e) {
e.preventDefault();
displayHide(popup);
return false;
});
}
}

const inputs = popup.querySelectorAll('input');
if (inputs.length > 0) {
for (const input of inputs.values()) {
input.addEventListener('focus', function(e) {
input.select();
});
}
}
}
})();
1 change: 0 additions & 1 deletion code/Controllers/ContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public function SilverStripeNavigator()
if (Director::isDev() || Permission::check('CMS_ACCESS_CMSMain') || Permission::check('VIEW_DRAFT_CONTENT')) {
if ($this->dataRecord) {
Requirements::css('silverstripe/cms: client/dist/styles/SilverStripeNavigator.css');
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
Requirements::javascript('silverstripe/cms: client/dist/js/SilverStripeNavigator.js');

$return = $nav = SilverStripeNavigator::get_for_record($this->dataRecord);
Expand Down

0 comments on commit 55eabd6

Please sign in to comment.