@microsoft/sp-webpart-base
Version:
SharePoint Framework support for building web parts
58 lines • 2.65 kB
JavaScript
/**
* This file contains code for the ClientSideWebPartManager. The webpart host is expected to
* load and manage webparts through the webpart manager APIs.
*/
import { EnvironmentType, Validate } from '@microsoft/sp-core-library';
/**
* Utility class to help fixup web part DOM in classic pages to make the behaviour consistent.
*
* @internal
*/
var ClassicPageUtils = /** @class */ (function () {
function ClassicPageUtils() {
}
/**
* Disable all automatic postbacks by button clicks or enter in an input tag.
*/
ClassicPageUtils.disableAutomaticPostbacks = function (domElement, env) {
Validate.isNotNullOrUndefined(domElement, 'domElement');
if (env === EnvironmentType.ClassicSharePoint) {
/**
* These are temporary fixes to disable the postbacks in classic pages. This works well with React
* based web parts because the eventing happens through the React synthetic events and not the
* browser native events. This may cause problems with non-React based web parts. We may need to
* revisit this fix and come up with a better fix. . (SPPPLAT VSO#243894) tracks creating a better fix.
*/
domElement.addEventListener('click', function (event) {
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
}, true /* useCapture */);
domElement.addEventListener('keydown', function (event) {
if (event.keyCode === 13) {
event.preventDefault ? event.preventDefault() : (event.returnValue = false);
}
}, true /* useCapture */);
}
};
/**
* Method to remove the unwanted old fabric styles from the page, which are being injected from the
* server side. Permanent fix would be remove the server side injection.
*
* todo: (VSO SPPPLAT#258820) Remove fabric.min.css and related injections from the server side on the classic page.
*/
ClassicPageUtils.removeFabricLinks = function () {
var links = document.getElementsByTagName('link');
if (links && links.length) {
for (var i = 0; i < links.length; i++) {
if (links[i] && links[i].href.indexOf('fabric.min.css') !== -1) {
var parentNode = links[i].parentNode;
if (parentNode) {
parentNode.removeChild(links[i]);
}
}
}
}
};
return ClassicPageUtils;
}());
export default ClassicPageUtils;
//# sourceMappingURL=ClassicPageUtils.js.map