@mikezimm/npmfunctions
Version:
Functions used in my SPFx webparts
84 lines • 3.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWebpartWidth = exports.setPageFormatting = void 0;
var domSearch_1 = require("./domSearch");
var stringServices_1 = require("../../Services/Strings/stringServices");
//This is from old page styling before newer modern styling.
function setPageFormatting(domElement, fpsPage) {
// fpsPage.Style = 'this.section.maxWidth=100%;next.section.maxWidth=100%';
// fpsPage.Style = 'this.webpart.margin=0px 0px;next.webpart.margin=0px 0px;this.section.maxWidth=100%;next.section.maxWidth=100%';
if (fpsPage.attempted === true) {
return fpsPage;
}
if (fpsPage.Style === '' || fpsPage.Style === null || fpsPage.Style === undefined) {
fpsPage.attempted = true;
return fpsPage;
}
if (fpsPage.Array === null) {
fpsPage.Array = (0, stringServices_1.getStringArrayFromString)(fpsPage.Style, ';or,', true, null, true);
}
if (fpsPage.Array === []) {
fpsPage.Array = fpsPage.Array;
fpsPage.attempted = true;
return fpsPage;
}
else {
try {
var thisCanvasSection_1 = (0, domSearch_1.findParentElementLikeThis)(domElement, "classList", 'CanvasSection', 10, 'contains');
fpsPage.Array.map(function (setting) {
if (setting) {
var thisSetting = setting.split('=');
if (thisSetting.length !== 2) {
console.log('setting incorrect: ', setting);
}
else {
var changeEle = null;
var doThis = thisSetting[0].split('.');
//Get correct section element
if (doThis[1] === 'section') {
if (doThis[0] === 'this') {
changeEle = thisCanvasSection_1.parentElement;
}
else if (doThis[0] === 'next') {
changeEle = thisCanvasSection_1.parentElement.parentElement.nextElementSibling.firstChild;
}
}
else if (['control', 'webpart', 'controlzone'].indexOf(doThis[1]) >= 0) {
if (doThis[0] === 'this') {
changeEle = domElement.parentElement.parentElement.parentElement;
}
else if (doThis[0] === 'next') {
changeEle = domElement.parentElement.nextElementSibling;
if (changeEle === null) { //Get webpart in next section
changeEle = thisCanvasSection_1.parentElement.parentElement.nextElementSibling.firstChild.firstChild.firstChild;
}
}
}
//Sets property of target element
if (changeEle) {
changeEle.style[doThis[2]] = thisSetting[1];
}
console.log('setPageFormatting', doThis, thisSetting[1]);
}
}
});
fpsPage.attempted = true;
return fpsPage;
}
catch (e) {
alert('Opps! Your page formatting is not valid! ');
}
}
}
exports.setPageFormatting = setPageFormatting;
function getWebpartWidth(domElement) {
try {
return domElement.clientWidth;
}
catch (e) {
console.log('could not find clientWidth of: ', domElement);
return -1;
}
}
exports.getWebpartWidth = getWebpartWidth;
//# sourceMappingURL=FPSFormatFunctions.js.map