mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-04 07:08:34 +02:00
8eac22c628
Multiple entry points can't result in a single bundle.css with a fixed filename, see https://github.com/webpack/extract-text-webpack-plugin/issues/179 Until that's resolved, it's easier to keep the 'css' task separate in Webpack, and have a single entry point for all CSS (bundle.scss). Also partially reverting "Moved frontend assets into admin/ "module"", which moved too many files: debug.css and install.css need to remain as framework (not admin) deps. Split out into a separate `framework-css` Webpack task in preparation for splitting off the module.
93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
import $ from 'jQuery';
|
|
|
|
require('../../../../thirdparty/jquery-ui/jquery-ui.js');
|
|
require('../../../../thirdparty/jquery-cookie/jquery.cookie.js');
|
|
require('../../../../thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
|
|
|
|
// TODO Enable once https://github.com/webpack/extract-text-webpack-plugin/issues/179 is resolved. Included in bundle.scss for now.
|
|
// require('../../../../thirdparty/jquery-ui-themes/smoothness/jquery-ui.css');
|
|
|
|
$.entwine('ss', function($){
|
|
/**
|
|
* Lightweight wrapper around jQuery UI tabs for generic tab set-up
|
|
*/
|
|
$('.ss-tabset').entwine({
|
|
IgnoreTabState: false,
|
|
|
|
onadd: function() {
|
|
var hash = window.location.hash;
|
|
|
|
// Can't name redraw() as it clashes with other CMS entwine classes
|
|
this.redrawTabs();
|
|
|
|
if (hash !== '') {
|
|
this.openTabFromURL(hash);
|
|
}
|
|
|
|
this._super();
|
|
},
|
|
|
|
onremove: function() {
|
|
if(this.data('tabs')) this.tabs('destroy');
|
|
this._super();
|
|
},
|
|
|
|
redrawTabs: function() {
|
|
this.rewriteHashlinks();
|
|
this.tabs();
|
|
},
|
|
|
|
/**
|
|
* @func openTabFromURL
|
|
* @param {string} hash
|
|
* @desc Allows linking to a specific tab.
|
|
*/
|
|
openTabFromURL: function (hash) {
|
|
var $trigger;
|
|
|
|
// Make sure the hash relates to a valid tab.
|
|
$.each(this.find('.cms-panel-link'), function () {
|
|
// The hash in in the button's href and there is exactly one tab with that id.
|
|
if (this.href.indexOf(hash) !== -1 && $(hash).length === 1) {
|
|
$trigger = $(this);
|
|
return false; // break the loop
|
|
}
|
|
});
|
|
|
|
// If there's no tab, it means the hash is invalid, so do nothing.
|
|
if ($trigger === void 0) {
|
|
return;
|
|
}
|
|
|
|
// Switch to the correct tab when AJAX loading completes.
|
|
$(window).one('ajaxComplete', function () {
|
|
$trigger.click();
|
|
});
|
|
},
|
|
|
|
/**
|
|
* @func rewriteHashlinks
|
|
* @desc Ensure hash links are prefixed with the current page URL, otherwise jQuery interprets them as being external.
|
|
*/
|
|
rewriteHashlinks: function() {
|
|
$(this).find('ul a').each(function() {
|
|
if (!$(this).attr('href')) return;
|
|
|
|
var matches = $(this).attr('href').match(/#.*/);
|
|
if(!matches) return;
|
|
$(this).attr('href', document.location.href.replace(/#.*/, '') + matches[0]);
|
|
});
|
|
}
|
|
});
|
|
|
|
// adding bootstrap theme classes to corresponding jQueryUI elements
|
|
$('.ui-tabs-active .ui-tabs-anchor').entwine({
|
|
onmatch: function() {
|
|
this.addClass('nav-link active');
|
|
},
|
|
onunmatch: function() {
|
|
this.removeClass('active');
|
|
}
|
|
});
|
|
});
|