rx-player
Version:
Canal+ HTML5 Video Player
139 lines (138 loc) • 5.39 kB
JavaScript
"use strict";
/**
* Copyright 2015 CANAL+ Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = applyPadding;
var add_class_name_1 = require("../../../../compat/add_class_name");
var log_1 = require("../../../../log");
var regexps_1 = require("../regexps");
/**
* @param {HTMLElement} element
* @param {string} padding
*/
function applyPadding(element, padding) {
var trimmedPadding = padding.trim();
var splittedPadding = trimmedPadding.split(" ");
if (splittedPadding.length < 1) {
return;
}
var firstPadding = regexps_1.REGXP_LENGTH.exec(splittedPadding[0]);
if (firstPadding === null) {
return;
}
if (firstPadding[2] === "px" || firstPadding[2] === "%" || firstPadding[2] === "em") {
var firstPaddingValue = firstPadding[1] + firstPadding[2];
if (splittedPadding.length === 1) {
element.style.padding = firstPaddingValue;
}
else if (splittedPadding.length === 2) {
element.style.paddingTop = firstPaddingValue;
element.style.paddingBottom = firstPaddingValue;
}
else {
element.style.paddingTop = firstPaddingValue;
}
}
else if (firstPadding[2] === "c") {
(0, add_class_name_1.default)(element, "proportional-style");
if (splittedPadding.length === 1) {
element.setAttribute("data-proportional-padding-top", firstPadding[1]);
element.setAttribute("data-proportional-padding-bottom", firstPadding[1]);
element.setAttribute("data-proportional-padding-left", firstPadding[1]);
element.setAttribute("data-proportional-padding-right", firstPadding[1]);
}
else if (splittedPadding.length === 2) {
element.setAttribute("data-proportional-padding-top", firstPadding[1]);
element.setAttribute("data-proportional-padding-bottom", firstPadding[1]);
}
else {
element.setAttribute("data-proportional-padding-top", firstPadding[1]);
}
}
else {
log_1.default.warn("ttml", "unhandled padding unit", { unit: firstPadding[2] });
}
if (splittedPadding.length === 1) {
return;
}
var secondPadding = regexps_1.REGXP_LENGTH.exec(splittedPadding[1]);
if (secondPadding === null) {
return;
}
if (secondPadding[2] === "px" ||
secondPadding[2] === "%" ||
secondPadding[2] === "em") {
var secondPaddingValue = secondPadding[1] + secondPadding[2];
if (splittedPadding.length < 4) {
element.style.paddingLeft = secondPaddingValue;
element.style.paddingRight = secondPaddingValue;
}
else {
element.style.paddingRight = secondPaddingValue;
}
}
else if (secondPadding[2] === "c") {
(0, add_class_name_1.default)(element, "proportional-style");
if (splittedPadding.length < 4) {
element.setAttribute("data-proportional-padding-left", secondPadding[1]);
element.setAttribute("data-proportional-padding-right", secondPadding[1]);
}
else {
element.setAttribute("data-proportional-padding-right", secondPadding[1]);
}
}
else {
log_1.default.warn("ttml", "unhandled padding unit", { unit: secondPadding[2] });
}
if (splittedPadding.length === 2) {
return;
}
var thirdPadding = regexps_1.REGXP_LENGTH.exec(splittedPadding[2]);
if (thirdPadding === null) {
return;
}
if (thirdPadding[2] === "px" || thirdPadding[2] === "%" || thirdPadding[2] === "em") {
var thirdPaddingValue = thirdPadding[1] + thirdPadding[2];
element.style.paddingBottom = thirdPaddingValue;
}
else if (thirdPadding[2] === "c") {
(0, add_class_name_1.default)(element, "proportional-style");
element.setAttribute("data-proportional-padding-bottom", thirdPadding[1]);
}
else {
log_1.default.warn("ttml", "unhandled padding unit", { unit: thirdPadding[2] });
}
if (splittedPadding.length === 3) {
return;
}
var fourthPadding = regexps_1.REGXP_LENGTH.exec(splittedPadding[3]);
if (fourthPadding === null) {
return;
}
if (fourthPadding[2] === "px" ||
fourthPadding[2] === "%" ||
fourthPadding[2] === "em") {
var fourthPaddingValue = fourthPadding[1] + fourthPadding[2];
element.style.paddingLeft = fourthPaddingValue;
}
else if (fourthPadding[2] === "c") {
(0, add_class_name_1.default)(element, "proportional-style");
element.setAttribute("data-proportional-padding-left", fourthPadding[1]);
}
else {
log_1.default.warn("ttml", "unhandled padding unit", { unit: fourthPadding[2] });
}
}