_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q58100
|
toTitleCase
|
validation
|
function toTitleCase() {
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return input.toString().replace(/\w\S*/g, function (text) {
return text.charAt(0).toUpperCase() + text.substr(1).toLowerCase();
});
}
|
javascript
|
{
"resource": ""
}
|
q58101
|
stripHTML
|
validation
|
function stripHTML(source) {
var fragment = document.createDocumentFragment();
var element = document.createElement('div');
fragment.appendChild(element);
element.innerHTML = source;
return fragment.firstChild.innerText;
}
|
javascript
|
{
"resource": ""
}
|
q58102
|
getHTML
|
validation
|
function getHTML(element) {
var wrapper = document.createElement('div');
wrapper.appendChild(element);
return wrapper.innerHTML;
}
|
javascript
|
{
"resource": ""
}
|
q58103
|
formatTime
|
validation
|
function formatTime() {
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var displayHours = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var inverted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
// Bail if the value isn't a number
if (!is$1.number(time)) {
return formatTime(null, displayHours, inverted);
} // Format time component to add leading zero
var format = function format(value) {
return "0".concat(value).slice(-2);
}; // Breakdown to hours, mins, secs
var hours = getHours(time);
var mins = getMinutes(time);
var secs = getSeconds(time); // Do we need to display hours?
if (displayHours || hours > 0) {
hours = "".concat(hours, ":");
} else {
hours = '';
} // Render
return "".concat(inverted && time > 0 ? '-' : '').concat(hours).concat(format(mins), ":").concat(format(secs));
}
|
javascript
|
{
"resource": ""
}
|
q58104
|
getIconUrl
|
validation
|
function getIconUrl() {
var url = new URL(this.config.iconUrl, window.location);
var cors = url.host !== window.location.host || browser.isIE && !window.svg4everybody;
return {
url: this.config.iconUrl,
cors: cors
};
}
|
javascript
|
{
"resource": ""
}
|
q58105
|
findElements
|
validation
|
function findElements() {
try {
this.elements.controls = getElement.call(this, this.config.selectors.controls.wrapper); // Buttons
this.elements.buttons = {
play: getElements.call(this, this.config.selectors.buttons.play),
pause: getElement.call(this, this.config.selectors.buttons.pause),
restart: getElement.call(this, this.config.selectors.buttons.restart),
rewind: getElement.call(this, this.config.selectors.buttons.rewind),
fastForward: getElement.call(this, this.config.selectors.buttons.fastForward),
mute: getElement.call(this, this.config.selectors.buttons.mute),
pip: getElement.call(this, this.config.selectors.buttons.pip),
airplay: getElement.call(this, this.config.selectors.buttons.airplay),
settings: getElement.call(this, this.config.selectors.buttons.settings),
captions: getElement.call(this, this.config.selectors.buttons.captions),
fullscreen: getElement.call(this, this.config.selectors.buttons.fullscreen)
}; // Progress
this.elements.progress = getElement.call(this, this.config.selectors.progress); // Inputs
this.elements.inputs = {
seek: getElement.call(this, this.config.selectors.inputs.seek),
volume: getElement.call(this, this.config.selectors.inputs.volume)
}; // Display
this.elements.display = {
buffer: getElement.call(this, this.config.selectors.display.buffer),
currentTime: getElement.call(this, this.config.selectors.display.currentTime),
duration: getElement.call(this, this.config.selectors.display.duration)
}; // Seek tooltip
if (is$1.element(this.elements.progress)) {
this.elements.display.seekTooltip = this.elements.progress.querySelector(".".concat(this.config.classNames.tooltip));
}
return true;
} catch (error) {
// Log it
this.debug.warn('It looks like there is a problem with your custom controls HTML', error); // Restore native video controls
this.toggleNativeControls(true);
return false;
}
}
|
javascript
|
{
"resource": ""
}
|
q58106
|
createLabel
|
validation
|
function createLabel(key) {
var attr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var text = i18n.get(key, this.config);
var attributes = Object.assign({}, attr, {
class: [attr.class, this.config.classNames.hidden].filter(Boolean).join(' ')
});
return createElement('span', attributes, text);
}
|
javascript
|
{
"resource": ""
}
|
q58107
|
createBadge
|
validation
|
function createBadge(text) {
if (is$1.empty(text)) {
return null;
}
var badge = createElement('span', {
class: this.config.classNames.menu.value
});
badge.appendChild(createElement('span', {
class: this.config.classNames.menu.badge
}, text));
return badge;
}
|
javascript
|
{
"resource": ""
}
|
q58108
|
createTime
|
validation
|
function createTime(type, attrs) {
var attributes = getAttributesFromSelector(this.config.selectors.display[type], attrs);
var container = createElement('div', extend(attributes, {
class: "".concat(attributes.class ? attributes.class : '', " ").concat(this.config.classNames.display.time, " ").trim(),
'aria-label': i18n.get(type, this.config)
}), '00:00'); // Reference for updates
this.elements.display[type] = container;
return container;
}
|
javascript
|
{
"resource": ""
}
|
q58109
|
createMenuItem
|
validation
|
function createMenuItem(_ref) {
var _this3 = this;
var value = _ref.value,
list = _ref.list,
type = _ref.type,
title = _ref.title,
_ref$badge = _ref.badge,
badge = _ref$badge === void 0 ? null : _ref$badge,
_ref$checked = _ref.checked,
checked = _ref$checked === void 0 ? false : _ref$checked;
var attributes = getAttributesFromSelector(this.config.selectors.inputs[type]);
var menuItem = createElement('button', extend(attributes, {
type: 'button',
role: 'menuitemradio',
class: "".concat(this.config.classNames.control, " ").concat(attributes.class ? attributes.class : '').trim(),
'aria-checked': checked,
value: value
}));
var flex = createElement('span'); // We have to set as HTML incase of special characters
flex.innerHTML = title;
if (is$1.element(badge)) {
flex.appendChild(badge);
}
menuItem.appendChild(flex); // Replicate radio button behaviour
Object.defineProperty(menuItem, 'checked', {
enumerable: true,
get: function get() {
return menuItem.getAttribute('aria-checked') === 'true';
},
set: function set(checked) {
// Ensure exclusivity
if (checked) {
Array.from(menuItem.parentNode.children).filter(function (node) {
return matches$1(node, '[role="menuitemradio"]');
}).forEach(function (node) {
return node.setAttribute('aria-checked', 'false');
});
}
menuItem.setAttribute('aria-checked', checked ? 'true' : 'false');
}
});
this.listeners.bind(menuItem, 'click keyup', function (event) {
if (is$1.keyboardEvent(event) && event.which !== 32) {
return;
}
event.preventDefault();
event.stopPropagation();
menuItem.checked = true;
switch (type) {
case 'language':
_this3.currentTrack = Number(value);
break;
case 'quality':
_this3.quality = value;
break;
case 'speed':
_this3.speed = parseFloat(value);
break;
default:
break;
}
controls.showMenuPanel.call(_this3, 'home', is$1.keyboardEvent(event));
}, type, false);
controls.bindMenuItemShortcuts.call(this, menuItem, type);
list.appendChild(menuItem);
}
|
javascript
|
{
"resource": ""
}
|
q58110
|
formatTime$1
|
validation
|
function formatTime$1() {
var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var inverted = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
// Bail if the value isn't a number
if (!is$1.number(time)) {
return time;
} // Always display hours if duration is over an hour
var forceHours = getHours(this.duration) > 0;
return formatTime(time, forceHours, inverted);
}
|
javascript
|
{
"resource": ""
}
|
q58111
|
updateTimeDisplay
|
validation
|
function updateTimeDisplay() {
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var time = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var inverted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
// Bail if there's no element to display or the value isn't a number
if (!is$1.element(target) || !is$1.number(time)) {
return;
} // eslint-disable-next-line no-param-reassign
target.innerText = controls.formatTime(time, inverted);
}
|
javascript
|
{
"resource": ""
}
|
q58112
|
updateVolume
|
validation
|
function updateVolume() {
if (!this.supported.ui) {
return;
} // Update range
if (is$1.element(this.elements.inputs.volume)) {
controls.setRange.call(this, this.elements.inputs.volume, this.muted ? 0 : this.volume);
} // Update mute state
if (is$1.element(this.elements.buttons.mute)) {
this.elements.buttons.mute.pressed = this.muted || this.volume === 0;
}
}
|
javascript
|
{
"resource": ""
}
|
q58113
|
setRange
|
validation
|
function setRange(target) {
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (!is$1.element(target)) {
return;
} // eslint-disable-next-line
target.value = value; // Webkit range fill
controls.updateRangeFill.call(this, target);
}
|
javascript
|
{
"resource": ""
}
|
q58114
|
updateRangeFill
|
validation
|
function updateRangeFill(target) {
// Get range from event if event passed
var range = is$1.event(target) ? target.target : target; // Needs to be a valid <input type='range'>
if (!is$1.element(range) || range.getAttribute('type') !== 'range') {
return;
} // Set aria values for https://github.com/sampotts/plyr/issues/905
if (matches$1(range, this.config.selectors.inputs.seek)) {
range.setAttribute('aria-valuenow', this.currentTime);
var currentTime = controls.formatTime(this.currentTime);
var duration = controls.formatTime(this.duration);
var format = i18n.get('seekLabel', this.config);
range.setAttribute('aria-valuetext', format.replace('{currentTime}', currentTime).replace('{duration}', duration));
} else if (matches$1(range, this.config.selectors.inputs.volume)) {
var percent = range.value * 100;
range.setAttribute('aria-valuenow', percent);
range.setAttribute('aria-valuetext', "".concat(percent.toFixed(1), "%"));
} else {
range.setAttribute('aria-valuenow', range.value);
} // WebKit only
if (!browser.isWebkit) {
return;
} // Set CSS custom property
range.style.setProperty('--value', "".concat(range.value / range.max * 100, "%"));
}
|
javascript
|
{
"resource": ""
}
|
q58115
|
updateSeekTooltip
|
validation
|
function updateSeekTooltip(event) {
var _this5 = this;
// Bail if setting not true
if (!this.config.tooltips.seek || !is$1.element(this.elements.inputs.seek) || !is$1.element(this.elements.display.seekTooltip) || this.duration === 0) {
return;
} // Calculate percentage
var percent = 0;
var clientRect = this.elements.progress.getBoundingClientRect();
var visible = "".concat(this.config.classNames.tooltip, "--visible");
var toggle = function toggle(_toggle) {
toggleClass(_this5.elements.display.seekTooltip, visible, _toggle);
}; // Hide on touch
if (this.touch) {
toggle(false);
return;
} // Determine percentage, if already visible
if (is$1.event(event)) {
percent = 100 / clientRect.width * (event.pageX - clientRect.left);
} else if (hasClass(this.elements.display.seekTooltip, visible)) {
percent = parseFloat(this.elements.display.seekTooltip.style.left, 10);
} else {
return;
} // Set bounds
if (percent < 0) {
percent = 0;
} else if (percent > 100) {
percent = 100;
} // Display the time a click would seek to
controls.updateTimeDisplay.call(this, this.elements.display.seekTooltip, this.duration / 100 * percent); // Set position
this.elements.display.seekTooltip.style.left = "".concat(percent, "%"); // Show/hide the tooltip
// If the event is a moues in/out and percentage is inside bounds
if (is$1.event(event) && ['mouseenter', 'mouseleave'].includes(event.type)) {
toggle(event.type === 'mouseenter');
}
}
|
javascript
|
{
"resource": ""
}
|
q58116
|
timeUpdate
|
validation
|
function timeUpdate(event) {
// Only invert if only one time element is displayed and used for both duration and currentTime
var invert = !is$1.element(this.elements.display.duration) && this.config.invertTime; // Duration
controls.updateTimeDisplay.call(this, this.elements.display.currentTime, invert ? this.duration - this.currentTime : this.currentTime, invert); // Ignore updates while seeking
if (event && event.type === 'timeupdate' && this.media.seeking) {
return;
} // Playing progress
controls.updateProgress.call(this, event);
}
|
javascript
|
{
"resource": ""
}
|
q58117
|
durationUpdate
|
validation
|
function durationUpdate() {
// Bail if no UI or durationchange event triggered after playing/seek when invertTime is false
if (!this.supported.ui || !this.config.invertTime && this.currentTime) {
return;
} // If duration is the 2**32 (shaka), Infinity (HLS), DASH-IF (Number.MAX_SAFE_INTEGER || Number.MAX_VALUE) indicating live we hide the currentTime and progressbar.
// https://github.com/video-dev/hls.js/blob/5820d29d3c4c8a46e8b75f1e3afa3e68c1a9a2db/src/controller/buffer-controller.js#L415
// https://github.com/google/shaka-player/blob/4d889054631f4e1cf0fbd80ddd2b71887c02e232/lib/media/streaming_engine.js#L1062
// https://github.com/Dash-Industry-Forum/dash.js/blob/69859f51b969645b234666800d4cb596d89c602d/src/dash/models/DashManifestModel.js#L338
if (this.duration >= Math.pow(2, 32)) {
toggleHidden(this.elements.display.currentTime, true);
toggleHidden(this.elements.progress, true);
return;
} // Update ARIA values
if (is$1.element(this.elements.inputs.seek)) {
this.elements.inputs.seek.setAttribute('aria-valuemax', this.duration);
} // If there's a spot to display duration
var hasDuration = is$1.element(this.elements.display.duration); // If there's only one time display, display duration there
if (!hasDuration && this.config.displayDuration && this.paused) {
controls.updateTimeDisplay.call(this, this.elements.display.currentTime, this.duration);
} // If there's a duration element, update content
if (hasDuration) {
controls.updateTimeDisplay.call(this, this.elements.display.duration, this.duration);
} // Update the tooltip (if visible)
controls.updateSeekTooltip.call(this);
}
|
javascript
|
{
"resource": ""
}
|
q58118
|
updateSetting
|
validation
|
function updateSetting(setting, container, input) {
var pane = this.elements.settings.panels[setting];
var value = null;
var list = container;
if (setting === 'captions') {
value = this.currentTrack;
} else {
value = !is$1.empty(input) ? input : this[setting]; // Get default
if (is$1.empty(value)) {
value = this.config[setting].default;
} // Unsupported value
if (!is$1.empty(this.options[setting]) && !this.options[setting].includes(value)) {
this.debug.warn("Unsupported value of '".concat(value, "' for ").concat(setting));
return;
} // Disabled value
if (!this.config[setting].options.includes(value)) {
this.debug.warn("Disabled value of '".concat(value, "' for ").concat(setting));
return;
}
} // Get the list if we need to
if (!is$1.element(list)) {
list = pane && pane.querySelector('[role="menu"]');
} // If there's no list it means it's not been rendered...
if (!is$1.element(list)) {
return;
} // Update the label
var label = this.elements.settings.buttons[setting].querySelector(".".concat(this.config.classNames.menu.value));
label.innerHTML = controls.getLabel.call(this, setting, value); // Find the radio option and check it
var target = list && list.querySelector("[value=\"".concat(value, "\"]"));
if (is$1.element(target)) {
target.checked = true;
}
}
|
javascript
|
{
"resource": ""
}
|
q58119
|
getLabel
|
validation
|
function getLabel(setting, value) {
switch (setting) {
case 'speed':
return value === 1 ? i18n.get('normal', this.config) : "".concat(value, "×");
case 'quality':
if (is$1.number(value)) {
var label = i18n.get("qualityLabel.".concat(value), this.config);
if (!label.length) {
return "".concat(value, "p");
}
return label;
}
return toTitleCase(value);
case 'captions':
return captions.getLabel.call(this);
default:
return null;
}
}
|
javascript
|
{
"resource": ""
}
|
q58120
|
setQualityMenu
|
validation
|
function setQualityMenu(options) {
var _this6 = this;
// Menu required
if (!is$1.element(this.elements.settings.panels.quality)) {
return;
}
var type = 'quality';
var list = this.elements.settings.panels.quality.querySelector('[role="menu"]'); // Set options if passed and filter based on uniqueness and config
if (is$1.array(options)) {
this.options.quality = dedupe(options).filter(function (quality) {
return _this6.config.quality.options.includes(quality);
});
} // Toggle the pane and tab
var toggle = !is$1.empty(this.options.quality) && this.options.quality.length > 1;
controls.toggleMenuButton.call(this, type, toggle); // Empty the menu
emptyElement(list); // Check if we need to toggle the parent
controls.checkMenu.call(this); // If we're hiding, nothing more to do
if (!toggle) {
return;
} // Get the badge HTML for HD, 4K etc
var getBadge = function getBadge(quality) {
var label = i18n.get("qualityBadge.".concat(quality), _this6.config);
if (!label.length) {
return null;
}
return controls.createBadge.call(_this6, label);
}; // Sort options by the config and then render options
this.options.quality.sort(function (a, b) {
var sorting = _this6.config.quality.options;
return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1;
}).forEach(function (quality) {
controls.createMenuItem.call(_this6, {
value: quality,
list: list,
type: type,
title: controls.getLabel.call(_this6, 'quality', quality),
badge: getBadge(quality)
});
});
controls.updateSetting.call(this, type, list);
}
|
javascript
|
{
"resource": ""
}
|
q58121
|
getBadge
|
validation
|
function getBadge(quality) {
var label = i18n.get("qualityBadge.".concat(quality), _this6.config);
if (!label.length) {
return null;
}
return controls.createBadge.call(_this6, label);
}
|
javascript
|
{
"resource": ""
}
|
q58122
|
setSpeedMenu
|
validation
|
function setSpeedMenu(options) {
var _this8 = this;
// Menu required
if (!is$1.element(this.elements.settings.panels.speed)) {
return;
}
var type = 'speed';
var list = this.elements.settings.panels.speed.querySelector('[role="menu"]'); // Set the speed options
if (is$1.array(options)) {
this.options.speed = options;
} else if (this.isHTML5 || this.isVimeo) {
this.options.speed = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
} // Set options if passed and filter based on config
this.options.speed = this.options.speed.filter(function (speed) {
return _this8.config.speed.options.includes(speed);
}); // Toggle the pane and tab
var toggle = !is$1.empty(this.options.speed) && this.options.speed.length > 1;
controls.toggleMenuButton.call(this, type, toggle); // Empty the menu
emptyElement(list); // Check if we need to toggle the parent
controls.checkMenu.call(this); // If we're hiding, nothing more to do
if (!toggle) {
return;
} // Create items
this.options.speed.forEach(function (speed) {
controls.createMenuItem.call(_this8, {
value: speed,
list: list,
type: type,
title: controls.getLabel.call(_this8, 'speed', speed)
});
});
controls.updateSetting.call(this, type, list);
}
|
javascript
|
{
"resource": ""
}
|
q58123
|
getMenuSize
|
validation
|
function getMenuSize(tab) {
var clone = tab.cloneNode(true);
clone.style.position = 'absolute';
clone.style.opacity = 0;
clone.removeAttribute('hidden'); // Append to parent so we get the "real" size
tab.parentNode.appendChild(clone); // Get the sizes before we remove
var width = clone.scrollWidth;
var height = clone.scrollHeight; // Remove from the DOM
removeElement(clone);
return {
width: width,
height: height
};
}
|
javascript
|
{
"resource": ""
}
|
q58124
|
showMenuPanel
|
validation
|
function showMenuPanel() {
var _this9 = this;
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var tabFocus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var target = this.elements.container.querySelector("#plyr-settings-".concat(this.id, "-").concat(type)); // Nothing to show, bail
if (!is$1.element(target)) {
return;
} // Hide all other panels
var container = target.parentNode;
var current = Array.from(container.children).find(function (node) {
return !node.hidden;
}); // If we can do fancy animations, we'll animate the height/width
if (support.transitions && !support.reducedMotion) {
// Set the current width as a base
container.style.width = "".concat(current.scrollWidth, "px");
container.style.height = "".concat(current.scrollHeight, "px"); // Get potential sizes
var size = controls.getMenuSize.call(this, target); // Restore auto height/width
var restore = function restore(event) {
// We're only bothered about height and width on the container
if (event.target !== container || !['width', 'height'].includes(event.propertyName)) {
return;
} // Revert back to auto
container.style.width = '';
container.style.height = ''; // Only listen once
off.call(_this9, container, transitionEndEvent, restore);
}; // Listen for the transition finishing and restore auto height/width
on.call(this, container, transitionEndEvent, restore); // Set dimensions to target
container.style.width = "".concat(size.width, "px");
container.style.height = "".concat(size.height, "px");
} // Set attributes on current tab
toggleHidden(current, true); // Set attributes on target
toggleHidden(target, false); // Focus the first item
controls.focusFirstMenuItem.call(this, target, tabFocus);
}
|
javascript
|
{
"resource": ""
}
|
q58125
|
setDownloadUrl
|
validation
|
function setDownloadUrl() {
var button = this.elements.buttons.download; // Bail if no button
if (!is$1.element(button)) {
return;
} // Set attribute
button.setAttribute('href', this.download);
}
|
javascript
|
{
"resource": ""
}
|
q58126
|
replace
|
validation
|
function replace(input) {
var result = input;
Object.entries(props).forEach(function (_ref2) {
var _ref3 = _slicedToArray(_ref2, 2),
key = _ref3[0],
value = _ref3[1];
result = replaceAll(result, "{".concat(key, "}"), value);
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q58127
|
parseUrl$2
|
validation
|
function parseUrl$2(input) {
var safe = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var url = input;
if (safe) {
var parser = document.createElement('a');
parser.href = url;
url = parser.href;
}
try {
return new URL(url);
} catch (e) {
return null;
}
}
|
javascript
|
{
"resource": ""
}
|
q58128
|
buildUrlParams
|
validation
|
function buildUrlParams(input) {
var params = new URLSearchParams();
if (is$1.object(input)) {
Object.entries(input).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
value = _ref2[1];
params.set(key, value);
});
}
return params;
}
|
javascript
|
{
"resource": ""
}
|
q58129
|
update
|
validation
|
function update() {
var _this = this;
var tracks = captions.getTracks.call(this, true); // Get the wanted language
var _this$captions = this.captions,
active = _this$captions.active,
language = _this$captions.language,
meta = _this$captions.meta,
currentTrackNode = _this$captions.currentTrackNode;
var languageExists = Boolean(tracks.find(function (track) {
return track.language === language;
})); // Handle tracks (add event listener and "pseudo"-default)
if (this.isHTML5 && this.isVideo) {
tracks.filter(function (track) {
return !meta.get(track);
}).forEach(function (track) {
_this.debug.log('Track added', track); // Attempt to store if the original dom element was "default"
meta.set(track, {
default: track.mode === 'showing'
}); // Turn off native caption rendering to avoid double captions
track.mode = 'hidden'; // Add event listener for cue changes
on.call(_this, track, 'cuechange', function () {
return captions.updateCues.call(_this);
});
});
} // Update language first time it matches, or if the previous matching track was removed
if (languageExists && this.language !== language || !tracks.includes(currentTrackNode)) {
captions.setLanguage.call(this, language);
captions.toggle.call(this, active && languageExists);
} // Enable or disable captions based on track length
toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is$1.empty(tracks)); // Update available languages in list
if ((this.config.controls || []).includes('settings') && this.config.settings.includes('captions')) {
controls.setCaptionsMenu.call(this);
}
}
|
javascript
|
{
"resource": ""
}
|
q58130
|
toggle
|
validation
|
function toggle(input) {
var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
// If there's no full support
if (!this.supported.ui) {
return;
}
var toggled = this.captions.toggled; // Current state
var activeClass = this.config.classNames.captions.active; // Get the next state
// If the method is called without parameter, toggle based on current value
var active = is$1.nullOrUndefined(input) ? !toggled : input; // Update state and trigger event
if (active !== toggled) {
// When passive, don't override user preferences
if (!passive) {
this.captions.active = active;
this.storage.set({
captions: active
});
} // Force language if the call isn't passive and there is no matching language to toggle to
if (!this.language && active && !passive) {
var tracks = captions.getTracks.call(this);
var track = captions.findTrack.call(this, [this.captions.language].concat(_toConsumableArray(this.captions.languages)), true); // Override user preferences to avoid switching languages if a matching track is added
this.captions.language = track.language; // Set caption, but don't store in localStorage as user preference
captions.set.call(this, tracks.indexOf(track));
return;
} // Toggle button if it's enabled
if (this.elements.buttons.captions) {
this.elements.buttons.captions.pressed = active;
} // Add class hook
toggleClass(this.elements.container, activeClass, active);
this.captions.toggled = active; // Update settings menu
controls.updateSetting.call(this, 'captions'); // Trigger event (not used internally)
triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
}
}
|
javascript
|
{
"resource": ""
}
|
q58131
|
set
|
validation
|
function set(index) {
var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var tracks = captions.getTracks.call(this); // Disable captions if setting to -1
if (index === -1) {
captions.toggle.call(this, false, passive);
return;
}
if (!is$1.number(index)) {
this.debug.warn('Invalid caption argument', index);
return;
}
if (!(index in tracks)) {
this.debug.warn('Track not found', index);
return;
}
if (this.captions.currentTrack !== index) {
this.captions.currentTrack = index;
var track = tracks[index];
var _ref = track || {},
language = _ref.language; // Store reference to node for invalidation on remove
this.captions.currentTrackNode = track; // Update settings menu
controls.updateSetting.call(this, 'captions'); // When passive, don't override user preferences
if (!passive) {
this.captions.language = language;
this.storage.set({
language: language
});
} // Handle Vimeo captions
if (this.isVimeo) {
this.embed.enableTextTrack(language);
} // Trigger event
triggerEvent.call(this, this.media, 'languagechange');
} // Show captions
captions.toggle.call(this, true, passive);
if (this.isHTML5 && this.isVideo) {
// If we change the active track while a cue is already displayed we need to update it
captions.updateCues.call(this);
}
}
|
javascript
|
{
"resource": ""
}
|
q58132
|
setLanguage
|
validation
|
function setLanguage(input) {
var passive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
if (!is$1.string(input)) {
this.debug.warn('Invalid language argument', input);
return;
} // Normalize
var language = input.toLowerCase();
this.captions.language = language; // Set currentTrack
var tracks = captions.getTracks.call(this);
var track = captions.findTrack.call(this, [language]);
captions.set.call(this, tracks.indexOf(track), passive);
}
|
javascript
|
{
"resource": ""
}
|
q58133
|
getTracks
|
validation
|
function getTracks() {
var _this2 = this;
var update = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
// Handle media or textTracks missing or null
var tracks = Array.from((this.media || {}).textTracks || []); // For HTML5, use cache instead of current tracks when it exists (if captions.update is false)
// Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata)
return tracks.filter(function (track) {
return !_this2.isHTML5 || update || _this2.captions.meta.has(track);
}).filter(function (track) {
return ['captions', 'subtitles'].includes(track.kind);
});
}
|
javascript
|
{
"resource": ""
}
|
q58134
|
findTrack
|
validation
|
function findTrack(languages) {
var _this3 = this;
var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var tracks = captions.getTracks.call(this);
var sortIsDefault = function sortIsDefault(track) {
return Number((_this3.captions.meta.get(track) || {}).default);
};
var sorted = Array.from(tracks).sort(function (a, b) {
return sortIsDefault(b) - sortIsDefault(a);
});
var track;
languages.every(function (language) {
track = sorted.find(function (track) {
return track.language === language;
});
return !track; // Break iteration if there is a match
}); // If no match is found but is required, get first
return track || (force ? sorted[0] : undefined);
}
|
javascript
|
{
"resource": ""
}
|
q58135
|
getLabel
|
validation
|
function getLabel(track) {
var currentTrack = track;
if (!is$1.track(currentTrack) && support.textTracks && this.captions.toggled) {
currentTrack = captions.getCurrentTrack.call(this);
}
if (is$1.track(currentTrack)) {
if (!is$1.empty(currentTrack.label)) {
return currentTrack.label;
}
if (!is$1.empty(currentTrack.language)) {
return track.language.toUpperCase();
}
return i18n.get('enabled', this.config);
}
return i18n.get('disabled', this.config);
}
|
javascript
|
{
"resource": ""
}
|
q58136
|
getProviderByUrl
|
validation
|
function getProviderByUrl(url) {
// YouTube
if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtube-nocookie\.com|youtu\.?be)\/.+$/.test(url)) {
return providers.youtube;
} // Vimeo
if (/^https?:\/\/player.vimeo.com\/video\/\d{0,9}(?=\b|\/)/.test(url)) {
return providers.vimeo;
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q58137
|
get
|
validation
|
function get() {
return (Fullscreen.native || this.player.config.fullscreen.fallback) && this.player.config.fullscreen.enabled && this.player.supported.ui && this.player.isVideo;
}
|
javascript
|
{
"resource": ""
}
|
q58138
|
toggleNativeControls
|
validation
|
function toggleNativeControls() {
var toggle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
if (toggle && this.isHTML5) {
this.media.setAttribute('controls', '');
} else {
this.media.removeAttribute('controls');
}
}
|
javascript
|
{
"resource": ""
}
|
q58139
|
build
|
validation
|
function build() {
var _this = this;
// Re-attach media element listeners
// TODO: Use event bubbling?
this.listeners.media(); // Don't setup interface if no support
if (!this.supported.ui) {
this.debug.warn("Basic support only for ".concat(this.provider, " ").concat(this.type)); // Restore native controls
ui.toggleNativeControls.call(this, true); // Bail
return;
} // Inject custom controls if not present
if (!is$1.element(this.elements.controls)) {
// Inject custom controls
controls.inject.call(this); // Re-attach control listeners
this.listeners.controls();
} // Remove native controls
ui.toggleNativeControls.call(this); // Setup captions for HTML5
if (this.isHTML5) {
captions.setup.call(this);
} // Reset volume
this.volume = null; // Reset mute state
this.muted = null; // Reset loop state
this.loop = null; // Reset quality setting
this.quality = null; // Reset speed
this.speed = null; // Reset volume display
controls.updateVolume.call(this); // Reset time display
controls.timeUpdate.call(this); // Update the UI
ui.checkPlaying.call(this); // Check for picture-in-picture support
toggleClass(this.elements.container, this.config.classNames.pip.supported, support.pip && this.isHTML5 && this.isVideo); // Check for airplay support
toggleClass(this.elements.container, this.config.classNames.airplay.supported, support.airplay && this.isHTML5); // Add iOS class
toggleClass(this.elements.container, this.config.classNames.isIos, browser.isIos); // Add touch class
toggleClass(this.elements.container, this.config.classNames.isTouch, this.touch); // Ready for API calls
this.ready = true; // Ready event at end of execution stack
setTimeout(function () {
triggerEvent.call(_this, _this.media, 'ready');
}, 0); // Set the title
ui.setTitle.call(this); // Assure the poster image is set, if the property was added before the element was created
if (this.poster) {
ui.setPoster.call(this, this.poster, false).catch(function () {});
} // Manually set the duration if user has overridden it.
// The event listeners for it doesn't get called if preload is disabled (#701)
if (this.config.duration) {
controls.durationUpdate.call(this);
}
}
|
javascript
|
{
"resource": ""
}
|
q58140
|
setTitle
|
validation
|
function setTitle() {
// Find the current text
var label = i18n.get('play', this.config); // If there's a media title set, use that for the label
if (is$1.string(this.config.title) && !is$1.empty(this.config.title)) {
label += ", ".concat(this.config.title);
} // If there's a play button, set label
Array.from(this.elements.buttons.play || []).forEach(function (button) {
button.setAttribute('aria-label', label);
}); // Set iframe title
// https://github.com/sampotts/plyr/issues/124
if (this.isEmbed) {
var iframe = getElement.call(this, 'iframe');
if (!is$1.element(iframe)) {
return;
} // Default to media type
var title = !is$1.empty(this.config.title) ? this.config.title : 'video';
var format = i18n.get('frameTitle', this.config);
iframe.setAttribute('title', format.replace('{title}', title));
}
}
|
javascript
|
{
"resource": ""
}
|
q58141
|
checkPlaying
|
validation
|
function checkPlaying(event) {
var _this3 = this;
// Class hooks
toggleClass(this.elements.container, this.config.classNames.playing, this.playing);
toggleClass(this.elements.container, this.config.classNames.paused, this.paused);
toggleClass(this.elements.container, this.config.classNames.stopped, this.stopped); // Set state
Array.from(this.elements.buttons.play || []).forEach(function (target) {
target.pressed = _this3.playing;
}); // Only update controls on non timeupdate events
if (is$1.event(event) && event.type === 'timeupdate') {
return;
} // Toggle controls
ui.toggleControls.call(this);
}
|
javascript
|
{
"resource": ""
}
|
q58142
|
checkLoading
|
validation
|
function checkLoading(event) {
var _this4 = this;
this.loading = ['stalled', 'waiting'].includes(event.type); // Clear timer
clearTimeout(this.timers.loading); // Timer to prevent flicker when seeking
this.timers.loading = setTimeout(function () {
// Update progress bar loading class state
toggleClass(_this4.elements.container, _this4.config.classNames.loading, _this4.loading); // Update controls visibility
ui.toggleControls.call(_this4);
}, this.loading ? 250 : 0);
}
|
javascript
|
{
"resource": ""
}
|
q58143
|
toggleControls
|
validation
|
function toggleControls(force) {
var controls = this.elements.controls;
if (controls && this.config.hideControls) {
// Don't hide controls if a touch-device user recently seeked. (Must be limited to touch devices, or it occasionally prevents desktop controls from hiding.)
var recentTouchSeek = this.touch && this.lastSeekTime + 2000 > Date.now(); // Show controls if force, loading, paused, button interaction, or recent seek, otherwise hide
this.toggleControls(Boolean(force || this.loading || this.paused || controls.pressed || controls.hover || recentTouchSeek));
}
}
|
javascript
|
{
"resource": ""
}
|
q58144
|
removeCurrent
|
validation
|
function removeCurrent() {
var className = player.config.classNames.tabFocus;
var current = getElements.call(player, ".".concat(className));
toggleClass(current, className, false);
}
|
javascript
|
{
"resource": ""
}
|
q58145
|
setPlayerSize
|
validation
|
function setPlayerSize(measure) {
// If we don't need to measure the viewport
if (!measure) {
return setAspectRatio.call(player);
}
var rect = elements.container.getBoundingClientRect();
var width = rect.width,
height = rect.height;
return setAspectRatio.call(player, "".concat(width, ":").concat(height));
}
|
javascript
|
{
"resource": ""
}
|
q58146
|
subscribe
|
validation
|
function subscribe(bundleIds, callbackFn) {
// listify
bundleIds = bundleIds.push ? bundleIds : [bundleIds];
var depsNotFound = [],
i = bundleIds.length,
numWaiting = i,
fn,
bundleId,
r,
q; // define callback function
fn = function fn(bundleId, pathsNotFound) {
if (pathsNotFound.length) depsNotFound.push(bundleId);
numWaiting--;
if (!numWaiting) callbackFn(depsNotFound);
}; // register callback
while (i--) {
bundleId = bundleIds[i]; // execute callback if in result cache
r = bundleResultCache[bundleId];
if (r) {
fn(bundleId, r);
continue;
} // add to callback queue
q = bundleCallbackQueue[bundleId] = bundleCallbackQueue[bundleId] || [];
q.push(fn);
}
}
|
javascript
|
{
"resource": ""
}
|
q58147
|
publish
|
validation
|
function publish(bundleId, pathsNotFound) {
// exit if id isn't defined
if (!bundleId) return;
var q = bundleCallbackQueue[bundleId]; // cache result
bundleResultCache[bundleId] = pathsNotFound; // exit if queue is empty
if (!q) return; // empty callback queue
while (q.length) {
q[0](bundleId, pathsNotFound);
q.splice(0, 1);
}
}
|
javascript
|
{
"resource": ""
}
|
q58148
|
executeCallbacks
|
validation
|
function executeCallbacks(args, depsNotFound) {
// accept function as argument
if (args.call) args = {
success: args
}; // success and error callbacks
if (depsNotFound.length) (args.error || devnull)(depsNotFound);else (args.success || devnull)(args);
}
|
javascript
|
{
"resource": ""
}
|
q58149
|
loadFile
|
validation
|
function loadFile(path, callbackFn, args, numTries) {
var doc = document,
async = args.async,
maxTries = (args.numRetries || 0) + 1,
beforeCallbackFn = args.before || devnull,
pathStripped = path.replace(/^(css|img)!/, ''),
isLegacyIECss,
e;
numTries = numTries || 0;
if (/(^css!|\.css$)/.test(path)) {
// css
e = doc.createElement('link');
e.rel = 'stylesheet';
e.href = pathStripped; // tag IE9+
isLegacyIECss = 'hideFocus' in e; // use preload in IE Edge (to detect load errors)
if (isLegacyIECss && e.relList) {
isLegacyIECss = 0;
e.rel = 'preload';
e.as = 'style';
}
} else if (/(^img!|\.(png|gif|jpg|svg)$)/.test(path)) {
// image
e = doc.createElement('img');
e.src = pathStripped;
} else {
// javascript
e = doc.createElement('script');
e.src = path;
e.async = async === undefined ? true : async;
}
e.onload = e.onerror = e.onbeforeload = function (ev) {
var result = ev.type[0]; // treat empty stylesheets as failures to get around lack of onerror
// support in IE9-11
if (isLegacyIECss) {
try {
if (!e.sheet.cssText.length) result = 'e';
} catch (x) {
// sheets objects created from load errors don't allow access to
// `cssText` (unless error is Code:18 SecurityError)
if (x.code != 18) result = 'e';
}
} // handle retries in case of load failure
if (result == 'e') {
// increment counter
numTries += 1; // exit function and try again
if (numTries < maxTries) {
return loadFile(path, callbackFn, args, numTries);
}
} else if (e.rel == 'preload' && e.as == 'style') {
// activate preloaded stylesheets
return e.rel = 'stylesheet'; // jshint ignore:line
} // execute callback
callbackFn(path, result, ev.defaultPrevented);
}; // add to document (unless callback returns `false`)
if (beforeCallbackFn(path, e) !== false) doc.head.appendChild(e);
}
|
javascript
|
{
"resource": ""
}
|
q58150
|
loadjs
|
validation
|
function loadjs(paths, arg1, arg2) {
var bundleId, args; // bundleId (if string)
if (arg1 && arg1.trim) bundleId = arg1; // args (default is {})
args = (bundleId ? arg2 : arg1) || {}; // throw error if bundle is already defined
if (bundleId) {
if (bundleId in bundleIdCache) {
throw "LoadJS";
} else {
bundleIdCache[bundleId] = true;
}
}
function loadFn(resolve, reject) {
loadFiles(paths, function (pathsNotFound) {
// execute callbacks
executeCallbacks(args, pathsNotFound); // resolve Promise
if (resolve) {
executeCallbacks({
success: resolve,
error: reject
}, pathsNotFound);
} // publish bundle load event
publish(bundleId, pathsNotFound);
}, args);
}
if (args.returnPromise) return new Promise(loadFn);else loadFn();
}
|
javascript
|
{
"resource": ""
}
|
q58151
|
getTitle
|
validation
|
function getTitle(videoId) {
var _this2 = this;
var url = format(this.config.urls.youtube.api, videoId);
fetch(url).then(function (data) {
if (is$1.object(data)) {
var title = data.title,
height = data.height,
width = data.width; // Set title
_this2.config.title = title;
ui.setTitle.call(_this2); // Set aspect ratio
_this2.embed.ratio = [width, height];
}
setAspectRatio.call(_this2);
}).catch(function () {
// Set aspect ratio
setAspectRatio.call(_this2);
});
}
|
javascript
|
{
"resource": ""
}
|
q58152
|
Ads
|
validation
|
function Ads(player) {
var _this = this;
_classCallCheck(this, Ads);
this.player = player;
this.config = player.config.ads;
this.playing = false;
this.initialized = false;
this.elements = {
container: null,
displayContainer: null
};
this.manager = null;
this.loader = null;
this.cuePoints = null;
this.events = {};
this.safetyTimer = null;
this.countdownTimer = null; // Setup a promise to resolve when the IMA manager is ready
this.managerPromise = new Promise(function (resolve, reject) {
// The ad is loaded and ready
_this.on('loaded', resolve); // Ads failed
_this.on('error', reject);
});
this.load();
}
|
javascript
|
{
"resource": ""
}
|
q58153
|
load
|
validation
|
function load() {
var _this2 = this;
if (!this.enabled) {
return;
} // Check if the Google IMA3 SDK is loaded or load it ourselves
if (!is$1.object(window.google) || !is$1.object(window.google.ima)) {
loadScript(this.player.config.urls.googleIMA.sdk).then(function () {
_this2.ready();
}).catch(function () {
// Script failed to load or is blocked
_this2.trigger('error', new Error('Google IMA SDK failed to load'));
});
} else {
this.ready();
}
}
|
javascript
|
{
"resource": ""
}
|
q58154
|
setupIMA
|
validation
|
function setupIMA() {
// Create the container for our advertisements
this.elements.container = createElement('div', {
class: this.player.config.classNames.ads
});
this.player.elements.container.appendChild(this.elements.container); // So we can run VPAID2
google.ima.settings.setVpaidMode(google.ima.ImaSdkSettings.VpaidMode.ENABLED); // Set language
google.ima.settings.setLocale(this.player.config.ads.language); // Set playback for iOS10+
google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.player.config.playsinline); // We assume the adContainer is the video container of the plyr element that will house the ads
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media); // Request video ads to be pre-loaded
this.requestAds();
}
|
javascript
|
{
"resource": ""
}
|
q58155
|
PreviewThumbnails
|
validation
|
function PreviewThumbnails(player) {
_classCallCheck(this, PreviewThumbnails);
this.player = player;
this.thumbnails = [];
this.loaded = false;
this.lastMouseMoveTime = Date.now();
this.mouseDown = false;
this.loadedImages = [];
this.elements = {
thumb: {},
scrubbing: {}
};
this.load();
}
|
javascript
|
{
"resource": ""
}
|
q58156
|
clamp
|
validation
|
function clamp() {
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var min = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 255;
return Math.min(Math.max(input, min), max);
}
|
javascript
|
{
"resource": ""
}
|
q58157
|
togglePlay
|
validation
|
function togglePlay(input) {
// Toggle based on current state if nothing passed
var toggle = is$1.boolean(input) ? input : !this.playing;
if (toggle) {
this.play();
} else {
this.pause();
}
}
|
javascript
|
{
"resource": ""
}
|
q58158
|
newSource
|
validation
|
function newSource(type, init) {
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
if (!(type in types) || !init && type === currentType || !currentType.length && type === types.video) {
return;
}
switch (type) {
case types.video:
player.source = {
type: 'video',
title: 'View From A Blue Moon',
sources: [{
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4',
type: 'video/mp4',
size: 576
}, {
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4',
type: 'video/mp4',
size: 720
}, {
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4',
type: 'video/mp4',
size: 1080
}, {
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1440p.mp4',
type: 'video/mp4',
size: 1440
}],
poster: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg',
tracks: [{
kind: 'captions',
label: 'English',
srclang: 'en',
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
default: true
}, {
kind: 'captions',
label: 'French',
srclang: 'fr',
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt'
}]
};
break;
case types.audio:
player.source = {
type: 'audio',
title: 'Kishi Bashi – “It All Began With A Burst”',
sources: [{
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3',
type: 'audio/mp3'
}, {
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg',
type: 'audio/ogg'
}]
};
break;
case types.youtube:
player.source = {
type: 'video',
sources: [{
src: 'https://youtube.com/watch?v=bTqVqk7FSmY',
provider: 'youtube'
}]
};
break;
case types.vimeo:
player.source = {
type: 'video',
sources: [{
src: 'https://vimeo.com/76979871',
provider: 'vimeo'
}]
};
break;
default:
break;
} // Set the current type for next time
currentType = type; // Remove active classes
Array.from(buttons).forEach(function (button) {
return toggleClass(button.parentElement, 'active', false);
}); // Set active on parent
toggleClass(document.querySelector("[data-source=\"".concat(type, "\"]")), 'active', true); // Show cite
Array.from(document.querySelectorAll('.plyr__cite')).forEach(function (cite) {
cite.setAttribute('hidden', '');
});
document.querySelector(".plyr__cite--".concat(type)).removeAttribute('hidden');
}
|
javascript
|
{
"resource": ""
}
|
q58159
|
validation
|
function (str) {
const args = arguments
let flag = true
let i = 1
str = str.replace(/%s/g, () => {
const arg = args[i++]
if (typeof arg === 'undefined') {
flag = false
return ''
}
return arg
})
return flag ? str : ''
}
|
javascript
|
{
"resource": ""
}
|
|
q58160
|
preprocessCartForServer
|
validation
|
function preprocessCartForServer( {
coupon,
is_coupon_applied,
is_coupon_removed,
currency,
temporary,
extra,
products,
tax,
} ) {
const needsUrlCoupon = ! (
coupon ||
is_coupon_applied ||
is_coupon_removed ||
typeof document === 'undefined'
);
const urlCoupon = needsUrlCoupon ? url.parse( document.URL, true ).query.coupon : '';
return Object.assign(
{
coupon,
is_coupon_applied,
is_coupon_removed,
currency,
tax,
temporary,
extra,
products: products.map(
( { product_id, meta, free_trial, volume, extra: productExtra } ) => ( {
product_id,
meta,
free_trial,
volume,
extra: productExtra,
} )
),
},
needsUrlCoupon &&
urlCoupon && {
coupon: urlCoupon,
is_coupon_applied: false,
}
);
}
|
javascript
|
{
"resource": ""
}
|
q58161
|
getNewMessages
|
validation
|
function getNewMessages( previousCartValue, nextCartValue ) {
previousCartValue = previousCartValue || {};
nextCartValue = nextCartValue || {};
const nextCartMessages = nextCartValue.messages || [];
// If there is no previous cart then just return the messages for the new cart
if (
! previousCartValue ||
! previousCartValue.client_metadata ||
! nextCartValue.client_metadata
) {
return nextCartMessages;
}
const previousDate = previousCartValue.client_metadata.last_server_response_date;
const nextDate = nextCartValue.client_metadata.last_server_response_date;
const hasNewServerData = i18n.moment( nextDate ).isAfter( previousDate );
return hasNewServerData ? nextCartMessages : [];
}
|
javascript
|
{
"resource": ""
}
|
q58162
|
isRedirectToValidForSsr
|
validation
|
function isRedirectToValidForSsr( redirectToQueryValue ) {
if ( 'undefined' === typeof redirectToQueryValue ) {
return true;
}
const redirectToDecoded = decodeURIComponent( redirectToQueryValue );
return (
redirectToDecoded.startsWith( 'https://wordpress.com/theme' ) ||
redirectToDecoded.startsWith( 'https://wordpress.com/go' )
);
}
|
javascript
|
{
"resource": ""
}
|
q58163
|
highlight
|
validation
|
function highlight( term, html, wrapperNode ) {
debug( 'Starting highlight' );
if ( ! wrapperNode ) {
wrapperNode = document.createElement( 'mark' );
}
if ( ! term || ! html ) {
return html;
}
const root = document.createElement( 'div' );
root.innerHTML = html;
walk( root, term, wrapperNode );
return root.innerHTML;
}
|
javascript
|
{
"resource": ""
}
|
q58164
|
MailingList
|
validation
|
function MailingList( category, wpcom ) {
if ( ! ( this instanceof MailingList ) ) {
return new MailingList( category, wpcom );
}
this._category = category;
this.wpcom = wpcom;
}
|
javascript
|
{
"resource": ""
}
|
q58165
|
embed
|
validation
|
function embed( editor ) {
let embedDialogContainer;
/**
* Open or close the EmbedDialog
*
* @param {boolean} visible `true` makes the dialog visible; `false` hides it.
*/
const render = ( visible = true ) => {
const selectedEmbedNode = editor.selection.getNode();
const store = editor.getParam( 'redux_store' );
const embedDialogProps = {
embedUrl: selectedEmbedNode.innerText || selectedEmbedNode.textContent,
isVisible: visible,
onCancel: () => render( false ),
onUpdate: newUrl => {
editor.execCommand( 'mceInsertContent', false, newUrl );
render( false );
},
};
renderWithReduxStore(
React.createElement( EmbedDialog, embedDialogProps ),
embedDialogContainer,
store
);
// Focus on the editor when closing the dialog, so that the user can start typing right away
// instead of having to tab back to the editor.
if ( ! visible ) {
editor.focus();
}
};
editor.addCommand( 'embedDialog', () => render() );
editor.on( 'init', () => {
embedDialogContainer = editor.getContainer().appendChild( document.createElement( 'div' ) );
} );
editor.on( 'remove', () => {
ReactDom.unmountComponentAtNode( embedDialogContainer );
embedDialogContainer.parentNode.removeChild( embedDialogContainer );
embedDialogContainer = null;
} );
}
|
javascript
|
{
"resource": ""
}
|
q58166
|
onexit
|
validation
|
function onexit( code ) {
let changedFiles;
cssMake.stderr.removeListener( 'data', onstderr );
cssMake.stdout.removeListener( 'data', onstdout );
cssMake = null;
if ( scheduleBuild ) {
// Handle new css build request
scheduleBuild = false;
spawnMake();
} else if ( 0 === code ) {
// 'make build-css' success
changedFiles = updateChangedCssFiles();
if ( 0 !== changedFiles.length ) {
debug( chalk.green( 'css reload' ) );
io.of( '/css-hot-reload' ).emit( 'css-hot-reload', {
status: 'reload',
changedFiles: changedFiles,
} );
} else {
debug( chalk.green( 'css up to date' ) );
io.of( '/css-hot-reload' ).emit( 'css-hot-reload', { status: 'up-to-date' } );
}
} else {
// 'make build-css' failed
debug( chalk.red( 'css build failed' ) );
io.of( '/css-hot-reload' ).emit( 'css-hot-reload', {
status: 'build-failed',
error: errors,
} );
}
}
|
javascript
|
{
"resource": ""
}
|
q58167
|
updateChangedCssFiles
|
validation
|
function updateChangedCssFiles() {
let hash, filePath;
const changedFiles = [];
for ( filePath in publicCssFiles ) {
hash = md5File.sync( filePath );
if ( hash !== publicCssFiles[ filePath ] ) {
publicCssFiles[ filePath ] = hash;
changedFiles.push( path.basename( filePath ) );
}
}
return changedFiles;
}
|
javascript
|
{
"resource": ""
}
|
q58168
|
updateSiteState
|
validation
|
function updateSiteState( state, siteId, attributes ) {
return Object.assign( {}, state, {
[ siteId ]: Object.assign( {}, initialSiteState, state[ siteId ], attributes ),
} );
}
|
javascript
|
{
"resource": ""
}
|
q58169
|
isValidCategoriesArray
|
validation
|
function isValidCategoriesArray( categories ) {
for ( let i = 0; i < categories.length; i++ ) {
if ( ! isValidProductCategory( categories[ i ] ) ) {
// Short-circuit the loop and return now.
return false;
}
}
return true;
}
|
javascript
|
{
"resource": ""
}
|
q58170
|
isValidProductCategory
|
validation
|
function isValidProductCategory( category ) {
return (
category &&
category.id &&
'number' === typeof category.id &&
category.name &&
'string' === typeof category.name &&
category.slug &&
'string' === typeof category.slug
);
}
|
javascript
|
{
"resource": ""
}
|
q58171
|
hasLanguageChanged
|
validation
|
function hasLanguageChanged( languageSettingValue, settings = {} ) {
if ( ! languageSettingValue ) {
return false;
}
// if there is a saved variant we know that the user is changing back to the root language === setting hasn't changed
// but if settings.locale_variant is not empty then we assume the user is trying to switch back to the root
return (
( languageSettingValue === settings.language && isEmpty( settings.locale_variant ) ) ||
//if the incoming language code is the variant itself === setting hasn't changed
languageSettingValue === settings.locale_variant
);
}
|
javascript
|
{
"resource": ""
}
|
q58172
|
UserSettings
|
validation
|
function UserSettings() {
if ( ! ( this instanceof UserSettings ) ) {
return new UserSettings();
}
this.settings = false;
this.initialized = false;
this.reAuthRequired = false;
this.fetchingSettings = false;
this.unsavedSettings = {};
}
|
javascript
|
{
"resource": ""
}
|
q58173
|
getDomainNameFromReceiptOrCart
|
validation
|
function getDomainNameFromReceiptOrCart( receipt, cart ) {
let domainRegistration;
if ( receipt && ! isEmpty( receipt.purchases ) ) {
domainRegistration = find( values( receipt.purchases ), isDomainRegistration );
}
if ( cartItems.hasDomainRegistration( cart ) ) {
domainRegistration = cartItems.getDomainRegistrations( cart )[ 0 ];
}
if ( domainRegistration ) {
return domainRegistration.meta;
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q58174
|
bustHashForHrefs
|
validation
|
function bustHashForHrefs( { name, oldValue } ) {
// http://some.site.com/and/a/path?with=a&query -> http://some.site.com/and/a/path?v=13508135781
const value =
'href' === name ? `${ oldValue.split( '?' ).shift() }?v=${ new Date().getTime() }` : oldValue;
return { name, value };
}
|
javascript
|
{
"resource": ""
}
|
q58175
|
updateCachedProduct
|
validation
|
function updateCachedProduct( products, product ) {
let found = false;
const updatedProduct = { ...product, name: decodeEntities( product.name ) };
const newProducts = products.map( p => {
if ( p.id === product.id ) {
found = true;
return updatedProduct;
}
return p;
} );
if ( ! found ) {
newProducts.push( updatedProduct );
}
return newProducts;
}
|
javascript
|
{
"resource": ""
}
|
q58176
|
setLoading
|
validation
|
function setLoading( state, params, newStatus ) {
const queries = ( state.queries && { ...state.queries } ) || {};
const key = getSerializedProductsQuery( params );
queries[ key ] = { ...( queries[ key ] || {} ), isLoading: newStatus };
return queries;
}
|
javascript
|
{
"resource": ""
}
|
q58177
|
generateStaticUrls
|
validation
|
function generateStaticUrls( target ) {
const urls = { ...staticFilesUrls };
const assets = getAssets( target ).assetsByChunkName;
forEach( assets, ( asset, name ) => {
urls[ name ] = asset;
} );
return urls;
}
|
javascript
|
{
"resource": ""
}
|
q58178
|
getAcceptedLanguagesFromHeader
|
validation
|
function getAcceptedLanguagesFromHeader( header ) {
if ( ! header ) {
return [];
}
return header
.split( ',' )
.map( lang => {
const match = lang.match( /^[A-Z]{2,3}(-[A-Z]{2,3})?/i );
if ( ! match ) {
return false;
}
return match[ 0 ].toLowerCase();
} )
.filter( lang => lang );
}
|
javascript
|
{
"resource": ""
}
|
q58179
|
setUpCSP
|
validation
|
function setUpCSP( req, res, next ) {
const originalUrlPathname = req.originalUrl.split( '?' )[ 0 ];
// We only setup CSP for /log-in* for now
if ( ! /^\/log-in/.test( originalUrlPathname ) ) {
next();
return;
}
// This is calculated by taking the contents of the script text from between the tags,
// and calculating SHA256 hash on it, encoded in base64, example:
// `sha256-${ base64( sha256( 'window.AppBoot();' ) ) }` === sha256-3yiQswl88knA3EhjrG5tj5gmV6EUdLYFvn2dygc0xUQ
// you can also just run it in Chrome, chrome will give you the hash of the violating scripts
const inlineScripts = [
'sha256-3yiQswl88knA3EhjrG5tj5gmV6EUdLYFvn2dygc0xUQ=',
'sha256-ZKTuGaoyrLu2lwYpcyzib+xE4/2mCN8PKv31uXS3Eg4=',
];
req.context.inlineScriptNonce = crypto.randomBytes( 48 ).toString( 'hex' );
const policy = {
'default-src': [ "'self'" ],
'script-src': [
"'self'",
"'report-sample'",
"'unsafe-eval'",
'stats.wp.com',
'https://widgets.wp.com',
'*.wordpress.com',
'https://apis.google.com',
`'nonce-${ req.context.inlineScriptNonce }'`,
'www.google-analytics.com',
...inlineScripts.map( hash => `'${ hash }'` ),
],
'base-uri': [ "'none'" ],
'style-src': [ "'self'", '*.wp.com', 'https://fonts.googleapis.com' ],
'form-action': [ "'self'" ],
'object-src': [ "'none'" ],
'img-src': [
"'self'",
'data',
'*.wp.com',
'*.files.wordpress.com',
'*.gravatar.com',
'https://www.google-analytics.com',
'https://amplifypixel.outbrain.com',
'https://img.youtube.com',
],
'frame-src': [ "'self'", 'https://public-api.wordpress.com', 'https://accounts.google.com/' ],
'font-src': [
"'self'",
'*.wp.com',
'https://fonts.gstatic.com',
'data:', // should remove 'data:' ASAP
],
'media-src': [ "'self'" ],
'connect-src': [ "'self'", 'https://*.wordpress.com/', 'https://*.wp.com' ],
'report-uri': [ '/cspreport' ],
};
const policyString = Object.keys( policy )
.map( key => `${ key } ${ policy[ key ].join( ' ' ) }` )
.join( '; ' );
// For now we're just logging policy violations and not blocking them
// so we won't actually break anything, later we'll remove the 'Report-Only'
// part so browsers will block violating content.
res.set( { 'Content-Security-Policy-Report-Only': policyString } );
next();
}
|
javascript
|
{
"resource": ""
}
|
q58180
|
validation
|
function( post ) {
let latitude, longitude;
if ( ! post ) {
return;
}
latitude = parseFloat( getValueByKey( post.metadata, 'geo_latitude' ) );
longitude = parseFloat( getValueByKey( post.metadata, 'geo_longitude' ) );
if ( latitude && longitude ) {
return [ latitude, longitude ];
}
}
|
javascript
|
{
"resource": ""
}
|
|
q58181
|
validation
|
function( post ) {
if ( ! post ) {
return null;
}
const isSharedPublicly = getValueByKey( post.metadata, 'geo_public' );
if ( parseInt( isSharedPublicly, 10 ) ) {
return true;
}
if ( undefined === isSharedPublicly ) {
// If they have no geo_public value but they do have a lat/long, then we assume they saved with Calypso
// before it supported geo_public, in which case we should treat it as private.
if (
getValueByKey( post.metadata, 'geo_latitude' ) ||
getValueByKey( post.metadata, 'geo_longitude' )
) {
return false;
}
return true;
}
return false;
}
|
javascript
|
{
"resource": ""
}
|
|
q58182
|
sanitizeExtra
|
validation
|
function sanitizeExtra( data ) {
const path = data._contactDetailsCache ? [ '_contactDetailsCache', 'extra' ] : 'extra';
return data && isArray( get( data, path ) ) ? omit( data, path ) : data;
}
|
javascript
|
{
"resource": ""
}
|
q58183
|
transmitDraftId
|
validation
|
function transmitDraftId( calypsoPort ) {
// Bail if we are not writing a new post.
if ( ! /wp-admin\/post-new.php/.test( location.href ) ) {
return;
}
const unsubscribe = subscribe( () => {
const currentPost = select( 'core/editor' ).getCurrentPost();
if ( currentPost && currentPost.id && currentPost.status !== 'auto-draft' ) {
calypsoPort.postMessage( {
action: 'draftIdSet',
payload: { postId: currentPost.id },
} );
unsubscribe();
}
} );
}
|
javascript
|
{
"resource": ""
}
|
q58184
|
handlePostLocked
|
validation
|
function handlePostLocked( calypsoPort ) {
const unsubscribe = subscribe( () => {
const isLocked = select( 'core/editor' ).isPostLocked();
const isLockTakeover = select( 'core/editor' ).isPostLockTakeover();
const lockedDialogButtons = document.querySelectorAll(
'div.editor-post-locked-modal__buttons > a'
);
const isPostTakeoverDialog = isLocked && ! isLockTakeover && lockedDialogButtons.length === 3;
if ( isPostTakeoverDialog ) {
//signal the parent frame to navigate to All Posts
lockedDialogButtons[ 0 ].addEventListener(
'click',
event => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
);
//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
lockedDialogButtons[ 0 ].setAttribute( 'target', '_parent' );
lockedDialogButtons[ 0 ].setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}
//changes the Take Over link url to add the frame-nonce
lockedDialogButtons[ 2 ].setAttribute(
'href',
addQueryArgs( lockedDialogButtons[ 2 ].getAttribute( 'href' ), {
calypsoify: 1,
'frame-nonce': getQueryArg( window.location.href, 'frame-nonce' ),
} )
);
unsubscribe();
}
} );
}
|
javascript
|
{
"resource": ""
}
|
q58185
|
handlePostLockTakeover
|
validation
|
function handlePostLockTakeover( calypsoPort ) {
const unsubscribe = subscribe( () => {
const isLocked = select( 'core/editor' ).isPostLocked();
const isLockTakeover = select( 'core/editor' ).isPostLockTakeover();
const allPostsButton = document.querySelector( 'div.editor-post-locked-modal__buttons > a' );
const isPostTakeoverDialog = isLocked && isLockTakeover && allPostsButton;
if ( isPostTakeoverDialog ) {
//handle All Posts button click event
allPostsButton.addEventListener(
'click',
event => {
event.preventDefault();
calypsoPort.postMessage( { action: 'goToAllPosts' } );
},
false
);
//overrides the all posts link just in case the user treats the link... as a link.
if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
allPostsButton.setAttribute( 'target', '_parent' );
allPostsButton.setAttribute( 'href', calypsoifyGutenberg.closeUrl );
}
unsubscribe();
}
} );
}
|
javascript
|
{
"resource": ""
}
|
q58186
|
updateImageBlocks
|
validation
|
function updateImageBlocks( blocks, image ) {
forEach( blocks, block => {
if ( imageBlocks[ block.name ] ) {
imageBlocks[ block.name ]( block, image );
}
if ( block.innerBlocks.length ) {
updateImageBlocks( block.innerBlocks, image );
}
} );
}
|
javascript
|
{
"resource": ""
}
|
q58187
|
updateFeaturedImagePreview
|
validation
|
function updateFeaturedImagePreview( image ) {
const currentImageId = select( 'core/editor' ).getEditedPostAttribute( 'featured_media' );
if ( currentImageId !== image.id ) {
return;
}
preloadImage( image.url ).then( () => {
const currentImage = select( 'core' ).getMedia( currentImageId );
const updatedImage = {
...currentImage,
media_details: {
height: image.height,
width: image.width,
},
source_url: image.url,
};
dispatch( 'core' ).receiveEntityRecords( 'root', 'media', [ updatedImage ], null, true );
} );
}
|
javascript
|
{
"resource": ""
}
|
q58188
|
handlePreview
|
validation
|
function handlePreview( calypsoPort ) {
$( '#editor' ).on( 'click', '.editor-post-preview', e => {
e.preventDefault();
e.stopPropagation();
const postUrl = select( 'core/editor' ).getCurrentPostAttribute( 'link' );
const previewChannel = new MessageChannel();
calypsoPort.postMessage(
{
action: 'previewPost',
payload: {
postUrl: postUrl,
},
},
[ previewChannel.port2 ]
);
const isAutosaveable = select( 'core/editor' ).isEditedPostAutosaveable();
// If we don't need to autosave the post before previewing, then we simply
// generate the preview.
if ( ! isAutosaveable ) {
sendPreviewData();
return;
}
// Request an autosave before generating the preview.
const postStatus = select( 'core/editor' ).getEditedPostAttribute( 'status' );
const isDraft = [ 'draft', 'auto-draft' ].indexOf( postStatus ) !== -1;
if ( isDraft ) {
dispatch( 'core/editor' ).savePost( { isPreview: true } );
} else {
dispatch( 'core/editor' ).autosave( { isPreview: true } );
}
const unsubscribe = subscribe( () => {
const isSavingPost = select( 'core/editor' ).isSavingPost();
if ( ! isSavingPost ) {
unsubscribe();
sendPreviewData();
}
} );
function sendPreviewData() {
const previewUrl = select( 'core/editor' ).getEditedPostPreviewLink();
const featuredImageId = select( 'core/editor' ).getEditedPostAttribute( 'featured_media' );
const featuredImage = featuredImageId
? get( select( 'core' ).getMedia( featuredImageId ), 'source_url' )
: null;
const authorId = select( 'core/editor' ).getCurrentPostAttribute( 'author' );
const author = find( select( 'core' ).getAuthors(), { id: authorId } );
const editedPost = {
title: select( 'core/editor' ).getEditedPostAttribute( 'title' ),
URL: select( 'core/editor' ).getEditedPostAttribute( 'link' ),
excerpt: select( 'core/editor' ).getEditedPostAttribute( 'excerpt' ),
content: select( 'core/editor' ).getEditedPostAttribute( 'content' ),
featured_image: featuredImage,
author: author,
};
previewChannel.port1.postMessage( {
previewUrl: previewUrl,
editedPost: editedPost,
} );
previewChannel.port1.close();
}
} );
}
|
javascript
|
{
"resource": ""
}
|
q58189
|
handleInsertClassicBlockMedia
|
validation
|
function handleInsertClassicBlockMedia( calypsoPort ) {
calypsoPort.addEventListener( 'message', onInsertClassicBlockMedia, false );
calypsoPort.start();
function onInsertClassicBlockMedia( message ) {
const action = get( message, 'data.action' );
if ( action !== 'insertClassicBlockMedia' ) {
return;
}
const editorId = get( message, 'data.payload.editorId' );
const media = get( message, 'data.payload.media' );
tinymce.editors[ editorId ].execCommand( 'mceInsertContent', false, media );
}
}
|
javascript
|
{
"resource": ""
}
|
q58190
|
handleGoToAllPosts
|
validation
|
function handleGoToAllPosts( calypsoPort ) {
$( '#editor' ).on( 'click', '.edit-post-fullscreen-mode-close__toolbar a', e => {
e.preventDefault();
calypsoPort.postMessage( {
action: 'goToAllPosts',
payload: {
unsavedChanges: select( 'core/editor' ).isEditedPostDirty(),
},
} );
} );
}
|
javascript
|
{
"resource": ""
}
|
q58191
|
openLinksInParentFrame
|
validation
|
function openLinksInParentFrame() {
const viewPostLinkSelectors = [
'.components-notice-list .is-success .components-notice__action.is-link', // View Post link in success notice
'.post-publish-panel__postpublish .components-panel__body.is-opened a', // Post title link in publish panel
'.components-panel__body.is-opened .post-publish-panel__postpublish-buttons a.components-button', // View Post button in publish panel
].join( ',' );
$( '#editor' ).on( 'click', viewPostLinkSelectors, e => {
e.preventDefault();
window.open( e.target.href, '_top' );
} );
if ( calypsoifyGutenberg.manageReusableBlocksUrl ) {
const manageReusableBlocksLinkSelectors = [
'.editor-inserter__manage-reusable-blocks', // Link in the Blocks Inserter
'a.components-menu-item__button[href*="post_type=wp_block"]', // Link in the More Menu
].join( ',' );
$( '#editor' ).on( 'click', manageReusableBlocksLinkSelectors, e => {
e.preventDefault();
window.open( calypsoifyGutenberg.manageReusableBlocksUrl, '_top' );
} );
}
}
|
javascript
|
{
"resource": ""
}
|
q58192
|
toolbarPin
|
validation
|
function toolbarPin( editor ) {
let isMonitoringScroll = false,
isPinned = false,
container;
/**
* Assigns the container top-level variable to the current container.
*/
function setContainer() {
container = editor.getContainer();
}
/**
* Updates the pinned state, toggling the container class as appropriate.
*
* @param {Boolean} toBePinned Whether toolbar should be pinned
*/
function togglePinned( toBePinned ) {
isPinned = toBePinned;
editor.dom.toggleClass( container, 'is-pinned', isPinned );
}
/**
* Checks whether the current pinned state of the editor should change,
* toggling the class as determined by the current viewport compared to the
* top edge of the container.
*/
const pinToolbarOnScroll = throttle( () => {
if ( ! container ) {
return;
}
if ( isPinned && window.pageYOffset < container.offsetTop ) {
// Scroll doesn't reach container top and should be unpinned
togglePinned( false );
} else if ( ! isPinned && window.pageYOffset > container.offsetTop ) {
// Scroll exceeds container top and should be pinned
togglePinned( true );
}
}, 50 );
/**
* Binds or unbinds the scroll event from the global window object, since
* pinning behavior is restricted to larger viewports whilst the visual
* editing mode is active.
*/
const maybeBindScroll = throttle( event => {
const isVisual = ! editor.isHidden();
const shouldBind = 'remove' !== event.type && isVisual && isWithinBreakpoint( '>660px' );
if ( shouldBind === isMonitoringScroll ) {
// Window event binding already matches expectation, so skip
return;
}
const eventBindFn = ( shouldBind ? 'add' : 'remove' ) + 'EventListener';
window[ eventBindFn ]( 'scroll', pinToolbarOnScroll );
isMonitoringScroll = shouldBind;
if ( isMonitoringScroll ) {
setContainer();
// May need to pin if resizing from small to large viewport
pinToolbarOnScroll();
} else {
// Reset to default when not monitoring scroll
togglePinned( false );
}
}, 200 );
editor.on( 'init show hide remove', maybeBindScroll );
window.addEventListener( 'resize', maybeBindScroll );
}
|
javascript
|
{
"resource": ""
}
|
q58193
|
_initStorage
|
validation
|
function _initStorage( options ) {
const dbInfo = {};
if ( options ) {
for ( const i in options ) {
dbInfo[ i ] = options[ i ];
}
}
dbInfo.db = {};
dummyStorage[ dbInfo.name ] = dbInfo.db;
this._dbInfo = dbInfo;
return Promise.resolve();
}
|
javascript
|
{
"resource": ""
}
|
q58194
|
finish
|
validation
|
function finish() {
let node,
regex = new RegExp( 'mceItemHidden|hidden(((Grammar|Spell)Error)|Suggestion)' ),
nodes = editor.dom.select( 'span' ),
i = nodes.length;
while ( i-- ) {
// reversed
node = nodes[ i ];
if ( node.className && regex.test( node.className ) ) {
editor.dom.remove( node, true );
}
}
// Rebuild the DOM so AtD core can find the text nodes
editor.setContent( editor.getContent( { format: 'raw' } ), { format: 'raw' } );
started = false;
editor.nodeChanged();
editor.fire( 'SpellcheckEnd' );
}
|
javascript
|
{
"resource": ""
}
|
q58195
|
build_chunks
|
validation
|
function build_chunks( sub_text, sub_ranges, range_data, container, options ) {
let text_start = null,
text_stop = null,
i,
remove_r_id,
r_id,
sr_id,
range_id,
range_info,
new_i,
new_sub_text,
new_sub_range;
// We use sub_ranges and not sub_text because we *can* have an empty string with a range
// acting upon it. For example an a tag with just an alt-text-less image tag inside of it
for ( i = 0; i < sub_ranges.length; i++ ) {
if ( sub_ranges[ i ].index.length == 0 ) {
// This is a simple text element without applicable ranges
if ( text_start == null ) {
// This is the beginning of the text element
text_start = i;
}
} else {
if ( text_start != null ) {
text_stop = i;
// We're in a range now, but, we were just in text,
// so create the DOM elements for the just-finished text range
container.appendChild(
document.createTextNode( sub_text.substring( text_start, text_stop ) )
);
text_start = null;
text_stop = null;
}
// At this point we have one or more ranges we could be entering. We need to decide
// which one. For recursion to work we must pick the longest range. If there are
// ties for longest range from this position then it doesn't matter which one wins.
// This may not be true for all cases forever. If we find a bug where a particular
// range needs to win out over another then this is the place for that logic.
//
// sub_ranges[i].index looks like:
// [ { id: [index of range in range_data], len: [span of range indices] }, { id: x, len: y }, ..., { id: n, len: m } ]
remove_r_id = null;
for ( r_id in sub_ranges[ i ].index ) {
if (
null === remove_r_id ||
sub_ranges[ i ].index[ r_id ].len > sub_ranges[ i ].index[ remove_r_id ].len
) {
remove_r_id = r_id;
}
}
// Since we've picked a range we'll record some information for future reference
range_id = sub_ranges[ i ].index[ remove_r_id ].id; // To be able to reference thr origin range
range_info = range_data[ range_id ]; // the origin range data
new_i = i + sub_ranges[ i ].index[ remove_r_id ].len - 1; // the position we will be jumping to after resursing
new_sub_text = sub_text.substring( i, i + sub_ranges[ i ].index[ remove_r_id ].len ); // the text we will be recursing with
new_sub_range = sub_ranges.slice( i, 1 + i + sub_ranges[ i ].index[ remove_r_id ].len ); // the new ranges we'll be recursing with
// Remove the range we are recursing into from the ranges we're recursing with.
// Otherwise we will end up in an infinite loop and everybody will be mad at us.
for ( sr_id = 0; sr_id < new_sub_range.length; sr_id++ ) {
new_sub_range[ sr_id ].index.splice( remove_r_id, 1 );
}
container.appendChild(
render_range( new_sub_text, new_sub_range, range_info, range_data, options )
);
i = new_i;
}
}
if ( text_start != null ) {
// We're done, at and below this depth but we finished in a text range, so we need to
// handle the last bit of text
container.appendChild(
document.createTextNode( sub_text.substring( text_start, sub_text.length ) )
);
}
// Just in case we have anything like a bunch of small Text() blocks together, etc, lets
// normalize the document
container.normalize();
}
|
javascript
|
{
"resource": ""
}
|
q58196
|
find_largest_range
|
validation
|
function find_largest_range( rs ) {
let r_id = -1,
r_size = 0,
i;
if ( rs.length < 1 ) {
return null;
}
for ( i = 0; i < rs.length; i++ ) {
if ( null === rs[ i ] ) {
continue;
}
// Set on first valid range and subsequently larger ranges
if ( -1 === r_id || rs[ i ].indices[ 1 ] - rs[ i ].indices[ 0 ] > r_size ) {
r_id = i;
r_size = rs[ i ].indices[ 1 ] - rs[ i ].indices[ 0 ];
}
}
return r_id;
}
|
javascript
|
{
"resource": ""
}
|
q58197
|
setUpLocale
|
validation
|
function setUpLocale( context, next ) {
const language = getLanguage( context.params.lang );
if ( language ) {
context.lang = context.params.lang;
if ( language.rtl ) {
context.isRTL = true;
}
}
next();
}
|
javascript
|
{
"resource": ""
}
|
q58198
|
customPostMetadataToProductAttributes
|
validation
|
function customPostMetadataToProductAttributes( metadata ) {
const productAttributes = {};
metadata.forEach( ( { key, value } ) => {
const schemaKey = metaKeyToSchemaKeyMap[ key ];
if ( ! schemaKey ) {
return;
}
// If the property's type is marked as boolean in the schema,
// convert the value from PHP-ish truthy/falsy numbers to a plain boolean.
// Strings "0" and "" are converted to false, "1" is converted to true.
if ( metadataSchema[ schemaKey ].type === 'boolean' ) {
value = !! Number( value );
}
productAttributes[ schemaKey ] = value;
} );
return productAttributes;
}
|
javascript
|
{
"resource": ""
}
|
q58199
|
parseAsShortcode
|
validation
|
function parseAsShortcode( node, _parsed ) {
// Attempt to convert string element into DOM node. If successful, recurse
// to trigger the shortcode strategy
const shortcode = parse( node );
if ( shortcode ) {
return _recurse( shortcode, _parsed );
}
return _parsed;
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.