id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,100 | angular/material | src/components/datepicker/js/dateUtil.js | clampDate | function clampDate(date, minDate, maxDate) {
var boundDate = date;
if (minDate && date < minDate) {
boundDate = new Date(minDate.getTime());
}
if (maxDate && date > maxDate) {
boundDate = new Date(maxDate.getTime());
}
return boundDate;
} | javascript | function clampDate(date, minDate, maxDate) {
var boundDate = date;
if (minDate && date < minDate) {
boundDate = new Date(minDate.getTime());
}
if (maxDate && date > maxDate) {
boundDate = new Date(maxDate.getTime());
}
return boundDate;
} | [
"function",
"clampDate",
"(",
"date",
",",
"minDate",
",",
"maxDate",
")",
"{",
"var",
"boundDate",
"=",
"date",
";",
"if",
"(",
"minDate",
"&&",
"date",
"<",
"minDate",
")",
"{",
"boundDate",
"=",
"new",
"Date",
"(",
"minDate",
".",
"getTime",
"(",
")",
")",
";",
"}",
"if",
"(",
"maxDate",
"&&",
"date",
">",
"maxDate",
")",
"{",
"boundDate",
"=",
"new",
"Date",
"(",
"maxDate",
".",
"getTime",
"(",
")",
")",
";",
"}",
"return",
"boundDate",
";",
"}"
] | Clamps a date between a minimum and a maximum date.
@param {Date} date Date to be clamped
@param {Date=} minDate Minimum date
@param {Date=} maxDate Maximum date
@return {Date} | [
"Clamps",
"a",
"date",
"between",
"a",
"minimum",
"and",
"a",
"maximum",
"date",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/dateUtil.js#L274-L283 |
5,101 | angular/material | src/components/datepicker/js/dateUtil.js | isMonthWithinRange | function isMonthWithinRange(date, minDate, maxDate) {
var month = date.getMonth();
var year = date.getFullYear();
return (!minDate || minDate.getFullYear() < year || minDate.getMonth() <= month) &&
(!maxDate || maxDate.getFullYear() > year || maxDate.getMonth() >= month);
} | javascript | function isMonthWithinRange(date, minDate, maxDate) {
var month = date.getMonth();
var year = date.getFullYear();
return (!minDate || minDate.getFullYear() < year || minDate.getMonth() <= month) &&
(!maxDate || maxDate.getFullYear() > year || maxDate.getMonth() >= month);
} | [
"function",
"isMonthWithinRange",
"(",
"date",
",",
"minDate",
",",
"maxDate",
")",
"{",
"var",
"month",
"=",
"date",
".",
"getMonth",
"(",
")",
";",
"var",
"year",
"=",
"date",
".",
"getFullYear",
"(",
")",
";",
"return",
"(",
"!",
"minDate",
"||",
"minDate",
".",
"getFullYear",
"(",
")",
"<",
"year",
"||",
"minDate",
".",
"getMonth",
"(",
")",
"<=",
"month",
")",
"&&",
"(",
"!",
"maxDate",
"||",
"maxDate",
".",
"getFullYear",
"(",
")",
">",
"year",
"||",
"maxDate",
".",
"getMonth",
"(",
")",
">=",
"month",
")",
";",
"}"
] | Checks if a month is within a min and max range, ignoring the date and time components.
If minDate or maxDate are not dates, they are ignored.
@param {Date} date
@param {Date} minDate
@param {Date} maxDate | [
"Checks",
"if",
"a",
"month",
"is",
"within",
"a",
"min",
"and",
"max",
"range",
"ignoring",
"the",
"date",
"and",
"time",
"components",
".",
"If",
"minDate",
"or",
"maxDate",
"are",
"not",
"dates",
"they",
"are",
"ignored",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/dateUtil.js#L303-L309 |
5,102 | angular/material | src/components/sticky/sticky.js | onScroll | function onScroll() {
var scrollTop = contentEl.prop('scrollTop');
var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);
// Store the previous scroll so we know which direction we are scrolling
onScroll.prevScrollTop = scrollTop;
//
// AT TOP (not scrolling)
//
if (scrollTop === 0) {
// If we're at the top, just clear the current item and return
setCurrentItem(null);
return;
}
//
// SCROLLING DOWN (going towards the next item)
//
if (isScrollingDown) {
// If we've scrolled down past the next item's position, sticky it and return
if (self.next && self.next.top <= scrollTop) {
setCurrentItem(self.next);
return;
}
// If the next item is close to the current one, push the current one up out of the way
if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
return;
}
}
//
// SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
//
if (!isScrollingDown) {
// If we've scrolled up past the previous item's position, sticky it and return
if (self.current && self.prev && scrollTop < self.current.top) {
setCurrentItem(self.prev);
return;
}
// If the next item is close to the current one, pull the current one down into view
if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
return;
}
}
//
// Otherwise, just move the current item to the proper place (scrolling up or down)
//
if (self.current) {
translate(self.current, scrollTop);
}
} | javascript | function onScroll() {
var scrollTop = contentEl.prop('scrollTop');
var isScrollingDown = scrollTop > (onScroll.prevScrollTop || 0);
// Store the previous scroll so we know which direction we are scrolling
onScroll.prevScrollTop = scrollTop;
//
// AT TOP (not scrolling)
//
if (scrollTop === 0) {
// If we're at the top, just clear the current item and return
setCurrentItem(null);
return;
}
//
// SCROLLING DOWN (going towards the next item)
//
if (isScrollingDown) {
// If we've scrolled down past the next item's position, sticky it and return
if (self.next && self.next.top <= scrollTop) {
setCurrentItem(self.next);
return;
}
// If the next item is close to the current one, push the current one up out of the way
if (self.current && self.next && self.next.top - scrollTop <= self.next.height) {
translate(self.current, scrollTop + (self.next.top - self.next.height - scrollTop));
return;
}
}
//
// SCROLLING UP (not at the top & not scrolling down; must be scrolling up)
//
if (!isScrollingDown) {
// If we've scrolled up past the previous item's position, sticky it and return
if (self.current && self.prev && scrollTop < self.current.top) {
setCurrentItem(self.prev);
return;
}
// If the next item is close to the current one, pull the current one down into view
if (self.next && self.current && (scrollTop >= (self.next.top - self.current.height))) {
translate(self.current, scrollTop + (self.next.top - scrollTop - self.current.height));
return;
}
}
//
// Otherwise, just move the current item to the proper place (scrolling up or down)
//
if (self.current) {
translate(self.current, scrollTop);
}
} | [
"function",
"onScroll",
"(",
")",
"{",
"var",
"scrollTop",
"=",
"contentEl",
".",
"prop",
"(",
"'scrollTop'",
")",
";",
"var",
"isScrollingDown",
"=",
"scrollTop",
">",
"(",
"onScroll",
".",
"prevScrollTop",
"||",
"0",
")",
";",
"// Store the previous scroll so we know which direction we are scrolling",
"onScroll",
".",
"prevScrollTop",
"=",
"scrollTop",
";",
"//",
"// AT TOP (not scrolling)",
"//",
"if",
"(",
"scrollTop",
"===",
"0",
")",
"{",
"// If we're at the top, just clear the current item and return",
"setCurrentItem",
"(",
"null",
")",
";",
"return",
";",
"}",
"//",
"// SCROLLING DOWN (going towards the next item)",
"//",
"if",
"(",
"isScrollingDown",
")",
"{",
"// If we've scrolled down past the next item's position, sticky it and return",
"if",
"(",
"self",
".",
"next",
"&&",
"self",
".",
"next",
".",
"top",
"<=",
"scrollTop",
")",
"{",
"setCurrentItem",
"(",
"self",
".",
"next",
")",
";",
"return",
";",
"}",
"// If the next item is close to the current one, push the current one up out of the way",
"if",
"(",
"self",
".",
"current",
"&&",
"self",
".",
"next",
"&&",
"self",
".",
"next",
".",
"top",
"-",
"scrollTop",
"<=",
"self",
".",
"next",
".",
"height",
")",
"{",
"translate",
"(",
"self",
".",
"current",
",",
"scrollTop",
"+",
"(",
"self",
".",
"next",
".",
"top",
"-",
"self",
".",
"next",
".",
"height",
"-",
"scrollTop",
")",
")",
";",
"return",
";",
"}",
"}",
"//",
"// SCROLLING UP (not at the top & not scrolling down; must be scrolling up)",
"//",
"if",
"(",
"!",
"isScrollingDown",
")",
"{",
"// If we've scrolled up past the previous item's position, sticky it and return",
"if",
"(",
"self",
".",
"current",
"&&",
"self",
".",
"prev",
"&&",
"scrollTop",
"<",
"self",
".",
"current",
".",
"top",
")",
"{",
"setCurrentItem",
"(",
"self",
".",
"prev",
")",
";",
"return",
";",
"}",
"// If the next item is close to the current one, pull the current one down into view",
"if",
"(",
"self",
".",
"next",
"&&",
"self",
".",
"current",
"&&",
"(",
"scrollTop",
">=",
"(",
"self",
".",
"next",
".",
"top",
"-",
"self",
".",
"current",
".",
"height",
")",
")",
")",
"{",
"translate",
"(",
"self",
".",
"current",
",",
"scrollTop",
"+",
"(",
"self",
".",
"next",
".",
"top",
"-",
"scrollTop",
"-",
"self",
".",
"current",
".",
"height",
")",
")",
";",
"return",
";",
"}",
"}",
"//",
"// Otherwise, just move the current item to the proper place (scrolling up or down)",
"//",
"if",
"(",
"self",
".",
"current",
")",
"{",
"translate",
"(",
"self",
".",
"current",
",",
"scrollTop",
")",
";",
"}",
"}"
] | As we scroll, push in and select the correct sticky element. | [
"As",
"we",
"scroll",
"push",
"in",
"and",
"select",
"the",
"correct",
"sticky",
"element",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/sticky/sticky.js#L211-L269 |
5,103 | angular/material | src/components/menu/js/menuServiceProvider.js | onRemove | function onRemove(scope, element, opts) {
opts.cleanupInteraction();
opts.cleanupBackdrop();
opts.cleanupResizing();
opts.hideBackdrop();
// Before the menu is closing remove the clickable class.
element.removeClass('md-clickable');
// For navigation $destroy events, do a quick, non-animated removal,
// but for normal closes (from clicks, etc) animate the removal
return (opts.$destroy === true) ? detachAndClean() : animateRemoval().then(detachAndClean);
/**
* For normal closes, animate the removal.
* For forced closes (like $destroy events), skip the animations
*/
function animateRemoval() {
return $animateCss(element, {addClass: 'md-leave'}).start();
}
/**
* Detach the element
*/
function detachAndClean() {
element.removeClass('md-active');
detachElement(element, opts);
opts.alreadyOpen = false;
}
} | javascript | function onRemove(scope, element, opts) {
opts.cleanupInteraction();
opts.cleanupBackdrop();
opts.cleanupResizing();
opts.hideBackdrop();
// Before the menu is closing remove the clickable class.
element.removeClass('md-clickable');
// For navigation $destroy events, do a quick, non-animated removal,
// but for normal closes (from clicks, etc) animate the removal
return (opts.$destroy === true) ? detachAndClean() : animateRemoval().then(detachAndClean);
/**
* For normal closes, animate the removal.
* For forced closes (like $destroy events), skip the animations
*/
function animateRemoval() {
return $animateCss(element, {addClass: 'md-leave'}).start();
}
/**
* Detach the element
*/
function detachAndClean() {
element.removeClass('md-active');
detachElement(element, opts);
opts.alreadyOpen = false;
}
} | [
"function",
"onRemove",
"(",
"scope",
",",
"element",
",",
"opts",
")",
"{",
"opts",
".",
"cleanupInteraction",
"(",
")",
";",
"opts",
".",
"cleanupBackdrop",
"(",
")",
";",
"opts",
".",
"cleanupResizing",
"(",
")",
";",
"opts",
".",
"hideBackdrop",
"(",
")",
";",
"// Before the menu is closing remove the clickable class.",
"element",
".",
"removeClass",
"(",
"'md-clickable'",
")",
";",
"// For navigation $destroy events, do a quick, non-animated removal,",
"// but for normal closes (from clicks, etc) animate the removal",
"return",
"(",
"opts",
".",
"$destroy",
"===",
"true",
")",
"?",
"detachAndClean",
"(",
")",
":",
"animateRemoval",
"(",
")",
".",
"then",
"(",
"detachAndClean",
")",
";",
"/**\n * For normal closes, animate the removal.\n * For forced closes (like $destroy events), skip the animations\n */",
"function",
"animateRemoval",
"(",
")",
"{",
"return",
"$animateCss",
"(",
"element",
",",
"{",
"addClass",
":",
"'md-leave'",
"}",
")",
".",
"start",
"(",
")",
";",
"}",
"/**\n * Detach the element\n */",
"function",
"detachAndClean",
"(",
")",
"{",
"element",
".",
"removeClass",
"(",
"'md-active'",
")",
";",
"detachElement",
"(",
"element",
",",
"opts",
")",
";",
"opts",
".",
"alreadyOpen",
"=",
"false",
";",
"}",
"}"
] | Removing the menu element from the DOM and remove all associated event listeners
and backdrop | [
"Removing",
"the",
"menu",
"element",
"from",
"the",
"DOM",
"and",
"remove",
"all",
"associated",
"event",
"listeners",
"and",
"backdrop"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L78-L109 |
5,104 | angular/material | src/components/menu/js/menuServiceProvider.js | showMenu | function showMenu() {
opts.parent.append(element);
element[0].style.display = '';
return $q(function(resolve) {
var position = calculateMenuPosition(element, opts);
element.removeClass('md-leave');
// Animate the menu scaling, and opacity [from its position origin (default == top-left)]
// to normal scale.
$animateCss(element, {
addClass: 'md-active',
from: animator.toCss(position),
to: animator.toCss({transform: ''})
})
.start()
.then(resolve);
});
} | javascript | function showMenu() {
opts.parent.append(element);
element[0].style.display = '';
return $q(function(resolve) {
var position = calculateMenuPosition(element, opts);
element.removeClass('md-leave');
// Animate the menu scaling, and opacity [from its position origin (default == top-left)]
// to normal scale.
$animateCss(element, {
addClass: 'md-active',
from: animator.toCss(position),
to: animator.toCss({transform: ''})
})
.start()
.then(resolve);
});
} | [
"function",
"showMenu",
"(",
")",
"{",
"opts",
".",
"parent",
".",
"append",
"(",
"element",
")",
";",
"element",
"[",
"0",
"]",
".",
"style",
".",
"display",
"=",
"''",
";",
"return",
"$q",
"(",
"function",
"(",
"resolve",
")",
"{",
"var",
"position",
"=",
"calculateMenuPosition",
"(",
"element",
",",
"opts",
")",
";",
"element",
".",
"removeClass",
"(",
"'md-leave'",
")",
";",
"// Animate the menu scaling, and opacity [from its position origin (default == top-left)]",
"// to normal scale.",
"$animateCss",
"(",
"element",
",",
"{",
"addClass",
":",
"'md-active'",
",",
"from",
":",
"animator",
".",
"toCss",
"(",
"position",
")",
",",
"to",
":",
"animator",
".",
"toCss",
"(",
"{",
"transform",
":",
"''",
"}",
")",
"}",
")",
".",
"start",
"(",
")",
".",
"then",
"(",
"resolve",
")",
";",
"}",
")",
";",
"}"
] | Place the menu into the DOM and call positioning related functions | [
"Place",
"the",
"menu",
"into",
"the",
"DOM",
"and",
"call",
"positioning",
"related",
"functions"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L149-L169 |
5,105 | angular/material | src/components/menu/js/menuServiceProvider.js | sanitizeAndConfigure | function sanitizeAndConfigure() {
if (!opts.target) {
throw Error(
'$mdMenu.show() expected a target to animate from in options.target'
);
}
angular.extend(opts, {
alreadyOpen: false,
isRemoved: false,
target: angular.element(opts.target), // make sure it's not a naked DOM node
parent: angular.element(opts.parent),
menuContentEl: angular.element(element[0].querySelector('md-menu-content'))
});
} | javascript | function sanitizeAndConfigure() {
if (!opts.target) {
throw Error(
'$mdMenu.show() expected a target to animate from in options.target'
);
}
angular.extend(opts, {
alreadyOpen: false,
isRemoved: false,
target: angular.element(opts.target), // make sure it's not a naked DOM node
parent: angular.element(opts.parent),
menuContentEl: angular.element(element[0].querySelector('md-menu-content'))
});
} | [
"function",
"sanitizeAndConfigure",
"(",
")",
"{",
"if",
"(",
"!",
"opts",
".",
"target",
")",
"{",
"throw",
"Error",
"(",
"'$mdMenu.show() expected a target to animate from in options.target'",
")",
";",
"}",
"angular",
".",
"extend",
"(",
"opts",
",",
"{",
"alreadyOpen",
":",
"false",
",",
"isRemoved",
":",
"false",
",",
"target",
":",
"angular",
".",
"element",
"(",
"opts",
".",
"target",
")",
",",
"// make sure it's not a naked DOM node",
"parent",
":",
"angular",
".",
"element",
"(",
"opts",
".",
"parent",
")",
",",
"menuContentEl",
":",
"angular",
".",
"element",
"(",
"element",
"[",
"0",
"]",
".",
"querySelector",
"(",
"'md-menu-content'",
")",
")",
"}",
")",
";",
"}"
] | Check for valid opts and set some sane defaults | [
"Check",
"for",
"valid",
"opts",
"and",
"set",
"some",
"sane",
"defaults"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L174-L187 |
5,106 | angular/material | src/components/menu/js/menuServiceProvider.js | setupBackdrop | function setupBackdrop() {
if (!opts.backdrop) return angular.noop;
opts.backdrop.on('click', onBackdropClick);
return function() {
opts.backdrop.off('click', onBackdropClick);
};
} | javascript | function setupBackdrop() {
if (!opts.backdrop) return angular.noop;
opts.backdrop.on('click', onBackdropClick);
return function() {
opts.backdrop.off('click', onBackdropClick);
};
} | [
"function",
"setupBackdrop",
"(",
")",
"{",
"if",
"(",
"!",
"opts",
".",
"backdrop",
")",
"return",
"angular",
".",
"noop",
";",
"opts",
".",
"backdrop",
".",
"on",
"(",
"'click'",
",",
"onBackdropClick",
")",
";",
"return",
"function",
"(",
")",
"{",
"opts",
".",
"backdrop",
".",
"off",
"(",
"'click'",
",",
"onBackdropClick",
")",
";",
"}",
";",
"}"
] | Sets up the backdrop and listens for click elements.
Once the backdrop will be clicked, the menu will automatically close.
@returns {!Function} Function to remove the backdrop. | [
"Sets",
"up",
"the",
"backdrop",
"and",
"listens",
"for",
"click",
"elements",
".",
"Once",
"the",
"backdrop",
"will",
"be",
"clicked",
"the",
"menu",
"will",
"automatically",
"close",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L220-L228 |
5,107 | angular/material | src/components/menu/js/menuServiceProvider.js | onBackdropClick | function onBackdropClick(event) {
event.preventDefault();
event.stopPropagation();
scope.$apply(function() {
opts.mdMenuCtrl.close(true, { closeAll: true });
});
} | javascript | function onBackdropClick(event) {
event.preventDefault();
event.stopPropagation();
scope.$apply(function() {
opts.mdMenuCtrl.close(true, { closeAll: true });
});
} | [
"function",
"onBackdropClick",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"event",
".",
"stopPropagation",
"(",
")",
";",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"opts",
".",
"mdMenuCtrl",
".",
"close",
"(",
"true",
",",
"{",
"closeAll",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"}"
] | Function to be called whenever the backdrop is clicked.
@param {!MouseEvent} event | [
"Function",
"to",
"be",
"called",
"whenever",
"the",
"backdrop",
"is",
"clicked",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L234-L241 |
5,108 | angular/material | src/components/menu/js/menuServiceProvider.js | captureClickListener | function captureClickListener(e) {
var target = e.target;
// Traverse up the event until we get to the menuContentEl to see if
// there is an ng-click and that the ng-click is not disabled
do {
if (target == opts.menuContentEl[0]) return;
if ((hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') && !hasAnyAttribute(target, ['md-prevent-menu-close'])) {
var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
close();
}
break;
}
} while (target = target.parentNode);
function close() {
scope.$apply(function() {
opts.mdMenuCtrl.close(true, { closeAll: true });
});
}
function hasAnyAttribute(target, attrs) {
if (!target) return false;
for (var i = 0, attr; attr = attrs[i]; ++i) {
if (prefixer.hasAttribute(target, attr)) {
return true;
}
}
return false;
}
} | javascript | function captureClickListener(e) {
var target = e.target;
// Traverse up the event until we get to the menuContentEl to see if
// there is an ng-click and that the ng-click is not disabled
do {
if (target == opts.menuContentEl[0]) return;
if ((hasAnyAttribute(target, ['ng-click', 'ng-href', 'ui-sref']) ||
target.nodeName == 'BUTTON' || target.nodeName == 'MD-BUTTON') && !hasAnyAttribute(target, ['md-prevent-menu-close'])) {
var closestMenu = $mdUtil.getClosest(target, 'MD-MENU');
if (!target.hasAttribute('disabled') && (!closestMenu || closestMenu == opts.parent[0])) {
close();
}
break;
}
} while (target = target.parentNode);
function close() {
scope.$apply(function() {
opts.mdMenuCtrl.close(true, { closeAll: true });
});
}
function hasAnyAttribute(target, attrs) {
if (!target) return false;
for (var i = 0, attr; attr = attrs[i]; ++i) {
if (prefixer.hasAttribute(target, attr)) {
return true;
}
}
return false;
}
} | [
"function",
"captureClickListener",
"(",
"e",
")",
"{",
"var",
"target",
"=",
"e",
".",
"target",
";",
"// Traverse up the event until we get to the menuContentEl to see if",
"// there is an ng-click and that the ng-click is not disabled",
"do",
"{",
"if",
"(",
"target",
"==",
"opts",
".",
"menuContentEl",
"[",
"0",
"]",
")",
"return",
";",
"if",
"(",
"(",
"hasAnyAttribute",
"(",
"target",
",",
"[",
"'ng-click'",
",",
"'ng-href'",
",",
"'ui-sref'",
"]",
")",
"||",
"target",
".",
"nodeName",
"==",
"'BUTTON'",
"||",
"target",
".",
"nodeName",
"==",
"'MD-BUTTON'",
")",
"&&",
"!",
"hasAnyAttribute",
"(",
"target",
",",
"[",
"'md-prevent-menu-close'",
"]",
")",
")",
"{",
"var",
"closestMenu",
"=",
"$mdUtil",
".",
"getClosest",
"(",
"target",
",",
"'MD-MENU'",
")",
";",
"if",
"(",
"!",
"target",
".",
"hasAttribute",
"(",
"'disabled'",
")",
"&&",
"(",
"!",
"closestMenu",
"||",
"closestMenu",
"==",
"opts",
".",
"parent",
"[",
"0",
"]",
")",
")",
"{",
"close",
"(",
")",
";",
"}",
"break",
";",
"}",
"}",
"while",
"(",
"target",
"=",
"target",
".",
"parentNode",
")",
";",
"function",
"close",
"(",
")",
"{",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"opts",
".",
"mdMenuCtrl",
".",
"close",
"(",
"true",
",",
"{",
"closeAll",
":",
"true",
"}",
")",
";",
"}",
")",
";",
"}",
"function",
"hasAnyAttribute",
"(",
"target",
",",
"attrs",
")",
"{",
"if",
"(",
"!",
"target",
")",
"return",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"attr",
";",
"attr",
"=",
"attrs",
"[",
"i",
"]",
";",
"++",
"i",
")",
"{",
"if",
"(",
"prefixer",
".",
"hasAttribute",
"(",
"target",
",",
"attr",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}"
] | Close menu on menu item click, if said menu-item is not disabled | [
"Close",
"menu",
"on",
"menu",
"item",
"click",
"if",
"said",
"menu",
"-",
"item",
"is",
"not",
"disabled"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L346-L379 |
5,109 | angular/material | src/components/menu/js/menuServiceProvider.js | firstVisibleChild | function firstVisibleChild() {
for (var i = 0; i < openMenuNode.children.length; ++i) {
if ($window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
return openMenuNode.children[i];
}
}
} | javascript | function firstVisibleChild() {
for (var i = 0; i < openMenuNode.children.length; ++i) {
if ($window.getComputedStyle(openMenuNode.children[i]).display != 'none') {
return openMenuNode.children[i];
}
}
} | [
"function",
"firstVisibleChild",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"openMenuNode",
".",
"children",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"$window",
".",
"getComputedStyle",
"(",
"openMenuNode",
".",
"children",
"[",
"i",
"]",
")",
".",
"display",
"!=",
"'none'",
")",
"{",
"return",
"openMenuNode",
".",
"children",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] | Gets the first visible child in the openMenuNode
Necessary incase menu nodes are being dynamically hidden | [
"Gets",
"the",
"first",
"visible",
"child",
"in",
"the",
"openMenuNode",
"Necessary",
"incase",
"menu",
"nodes",
"are",
"being",
"dynamically",
"hidden"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/menu/js/menuServiceProvider.js#L569-L575 |
5,110 | angular/material | docs/config/processors/componentsData.js | publicDocData | function publicDocData(doc, extraData) {
const options = _.assign(extraData || {}, { hasDemo: (doc.docType === 'directive') });
// This RegEx always retrieves the last source descriptor.
// For example it retrieves from `/opt/material/src/core/services/ripple/ripple.js` the following
// source descriptor: `src/core/`.
// This is needed because components are not only located in `src/components`.
let descriptor = doc.fileInfo.filePath.toString().match(/src\/.*?\//g).pop();
if (descriptor) {
descriptor = descriptor.substring(descriptor.indexOf('/') + 1, descriptor.lastIndexOf('/'));
}
return buildDocData(doc, options, descriptor || 'components');
} | javascript | function publicDocData(doc, extraData) {
const options = _.assign(extraData || {}, { hasDemo: (doc.docType === 'directive') });
// This RegEx always retrieves the last source descriptor.
// For example it retrieves from `/opt/material/src/core/services/ripple/ripple.js` the following
// source descriptor: `src/core/`.
// This is needed because components are not only located in `src/components`.
let descriptor = doc.fileInfo.filePath.toString().match(/src\/.*?\//g).pop();
if (descriptor) {
descriptor = descriptor.substring(descriptor.indexOf('/') + 1, descriptor.lastIndexOf('/'));
}
return buildDocData(doc, options, descriptor || 'components');
} | [
"function",
"publicDocData",
"(",
"doc",
",",
"extraData",
")",
"{",
"const",
"options",
"=",
"_",
".",
"assign",
"(",
"extraData",
"||",
"{",
"}",
",",
"{",
"hasDemo",
":",
"(",
"doc",
".",
"docType",
"===",
"'directive'",
")",
"}",
")",
";",
"// This RegEx always retrieves the last source descriptor.",
"// For example it retrieves from `/opt/material/src/core/services/ripple/ripple.js` the following",
"// source descriptor: `src/core/`.",
"// This is needed because components are not only located in `src/components`.",
"let",
"descriptor",
"=",
"doc",
".",
"fileInfo",
".",
"filePath",
".",
"toString",
"(",
")",
".",
"match",
"(",
"/",
"src\\/.*?\\/",
"/",
"g",
")",
".",
"pop",
"(",
")",
";",
"if",
"(",
"descriptor",
")",
"{",
"descriptor",
"=",
"descriptor",
".",
"substring",
"(",
"descriptor",
".",
"indexOf",
"(",
"'/'",
")",
"+",
"1",
",",
"descriptor",
".",
"lastIndexOf",
"(",
"'/'",
")",
")",
";",
"}",
"return",
"buildDocData",
"(",
"doc",
",",
"options",
",",
"descriptor",
"||",
"'components'",
")",
";",
"}"
] | We don't need to publish all of a doc's data to the app, that will add many kilobytes of loading overhead. | [
"We",
"don",
"t",
"need",
"to",
"publish",
"all",
"of",
"a",
"doc",
"s",
"data",
"to",
"the",
"app",
"that",
"will",
"add",
"many",
"kilobytes",
"of",
"loading",
"overhead",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/config/processors/componentsData.js#L6-L19 |
5,111 | angular/material | src/components/bottomSheet/bottom-sheet.js | registerGestures | function registerGestures(element, parent) {
var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });
parent.on('$md.dragstart', onDragStart)
.on('$md.drag', onDrag)
.on('$md.dragend', onDragEnd);
return function cleanupGestures() {
deregister();
parent.off('$md.dragstart', onDragStart);
parent.off('$md.drag', onDrag);
parent.off('$md.dragend', onDragEnd);
};
function onDragStart() {
// Disable transitions on transform so that it feels fast
element.css($mdConstant.CSS.TRANSITION_DURATION, '0ms');
}
function onDrag(ev) {
var transform = ev.pointer.distanceY;
if (transform < 5) {
// Slow down drag when trying to drag up, and stop after PADDING
transform = Math.max(-PADDING, transform / 2);
}
element.css($mdConstant.CSS.TRANSFORM, 'translate3d(0,' + (PADDING + transform) + 'px,0)');
}
function onDragEnd(ev) {
if (ev.pointer.distanceY > 0 &&
(ev.pointer.distanceY > 20 || Math.abs(ev.pointer.velocityY) > CLOSING_VELOCITY)) {
var distanceRemaining = element.prop('offsetHeight') - ev.pointer.distanceY;
var transitionDuration = Math.min(distanceRemaining / ev.pointer.velocityY * 0.75, 500);
element.css($mdConstant.CSS.TRANSITION_DURATION, transitionDuration + 'ms');
$mdUtil.nextTick($mdBottomSheet.cancel,true);
} else {
element.css($mdConstant.CSS.TRANSITION_DURATION, '');
element.css($mdConstant.CSS.TRANSFORM, '');
}
}
} | javascript | function registerGestures(element, parent) {
var deregister = $mdGesture.register(parent, 'drag', { horizontal: false });
parent.on('$md.dragstart', onDragStart)
.on('$md.drag', onDrag)
.on('$md.dragend', onDragEnd);
return function cleanupGestures() {
deregister();
parent.off('$md.dragstart', onDragStart);
parent.off('$md.drag', onDrag);
parent.off('$md.dragend', onDragEnd);
};
function onDragStart() {
// Disable transitions on transform so that it feels fast
element.css($mdConstant.CSS.TRANSITION_DURATION, '0ms');
}
function onDrag(ev) {
var transform = ev.pointer.distanceY;
if (transform < 5) {
// Slow down drag when trying to drag up, and stop after PADDING
transform = Math.max(-PADDING, transform / 2);
}
element.css($mdConstant.CSS.TRANSFORM, 'translate3d(0,' + (PADDING + transform) + 'px,0)');
}
function onDragEnd(ev) {
if (ev.pointer.distanceY > 0 &&
(ev.pointer.distanceY > 20 || Math.abs(ev.pointer.velocityY) > CLOSING_VELOCITY)) {
var distanceRemaining = element.prop('offsetHeight') - ev.pointer.distanceY;
var transitionDuration = Math.min(distanceRemaining / ev.pointer.velocityY * 0.75, 500);
element.css($mdConstant.CSS.TRANSITION_DURATION, transitionDuration + 'ms');
$mdUtil.nextTick($mdBottomSheet.cancel,true);
} else {
element.css($mdConstant.CSS.TRANSITION_DURATION, '');
element.css($mdConstant.CSS.TRANSFORM, '');
}
}
} | [
"function",
"registerGestures",
"(",
"element",
",",
"parent",
")",
"{",
"var",
"deregister",
"=",
"$mdGesture",
".",
"register",
"(",
"parent",
",",
"'drag'",
",",
"{",
"horizontal",
":",
"false",
"}",
")",
";",
"parent",
".",
"on",
"(",
"'$md.dragstart'",
",",
"onDragStart",
")",
".",
"on",
"(",
"'$md.drag'",
",",
"onDrag",
")",
".",
"on",
"(",
"'$md.dragend'",
",",
"onDragEnd",
")",
";",
"return",
"function",
"cleanupGestures",
"(",
")",
"{",
"deregister",
"(",
")",
";",
"parent",
".",
"off",
"(",
"'$md.dragstart'",
",",
"onDragStart",
")",
";",
"parent",
".",
"off",
"(",
"'$md.drag'",
",",
"onDrag",
")",
";",
"parent",
".",
"off",
"(",
"'$md.dragend'",
",",
"onDragEnd",
")",
";",
"}",
";",
"function",
"onDragStart",
"(",
")",
"{",
"// Disable transitions on transform so that it feels fast",
"element",
".",
"css",
"(",
"$mdConstant",
".",
"CSS",
".",
"TRANSITION_DURATION",
",",
"'0ms'",
")",
";",
"}",
"function",
"onDrag",
"(",
"ev",
")",
"{",
"var",
"transform",
"=",
"ev",
".",
"pointer",
".",
"distanceY",
";",
"if",
"(",
"transform",
"<",
"5",
")",
"{",
"// Slow down drag when trying to drag up, and stop after PADDING",
"transform",
"=",
"Math",
".",
"max",
"(",
"-",
"PADDING",
",",
"transform",
"/",
"2",
")",
";",
"}",
"element",
".",
"css",
"(",
"$mdConstant",
".",
"CSS",
".",
"TRANSFORM",
",",
"'translate3d(0,'",
"+",
"(",
"PADDING",
"+",
"transform",
")",
"+",
"'px,0)'",
")",
";",
"}",
"function",
"onDragEnd",
"(",
"ev",
")",
"{",
"if",
"(",
"ev",
".",
"pointer",
".",
"distanceY",
">",
"0",
"&&",
"(",
"ev",
".",
"pointer",
".",
"distanceY",
">",
"20",
"||",
"Math",
".",
"abs",
"(",
"ev",
".",
"pointer",
".",
"velocityY",
")",
">",
"CLOSING_VELOCITY",
")",
")",
"{",
"var",
"distanceRemaining",
"=",
"element",
".",
"prop",
"(",
"'offsetHeight'",
")",
"-",
"ev",
".",
"pointer",
".",
"distanceY",
";",
"var",
"transitionDuration",
"=",
"Math",
".",
"min",
"(",
"distanceRemaining",
"/",
"ev",
".",
"pointer",
".",
"velocityY",
"*",
"0.75",
",",
"500",
")",
";",
"element",
".",
"css",
"(",
"$mdConstant",
".",
"CSS",
".",
"TRANSITION_DURATION",
",",
"transitionDuration",
"+",
"'ms'",
")",
";",
"$mdUtil",
".",
"nextTick",
"(",
"$mdBottomSheet",
".",
"cancel",
",",
"true",
")",
";",
"}",
"else",
"{",
"element",
".",
"css",
"(",
"$mdConstant",
".",
"CSS",
".",
"TRANSITION_DURATION",
",",
"''",
")",
";",
"element",
".",
"css",
"(",
"$mdConstant",
".",
"CSS",
".",
"TRANSFORM",
",",
"''",
")",
";",
"}",
"}",
"}"
] | Adds the drag gestures to the bottom sheet. | [
"Adds",
"the",
"drag",
"gestures",
"to",
"the",
"bottom",
"sheet",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/bottomSheet/bottom-sheet.js#L307-L346 |
5,112 | angular/material | src/components/dialog/dialog.js | MdDialogController | function MdDialogController($mdDialog, $mdConstant) {
// For compatibility with AngularJS 1.6+, we should always use the $onInit hook in
// interimElements. The $mdCompiler simulates the $onInit hook for all versions.
this.$onInit = function() {
var isPrompt = this.$type == 'prompt';
if (isPrompt && this.initialValue) {
this.result = this.initialValue;
}
this.hide = function() {
$mdDialog.hide(isPrompt ? this.result : true);
};
this.abort = function() {
$mdDialog.cancel();
};
this.keypress = function($event) {
var invalidPrompt = isPrompt && this.required && !angular.isDefined(this.result);
if ($event.keyCode === $mdConstant.KEY_CODE.ENTER && !invalidPrompt) {
$mdDialog.hide(this.result);
}
};
};
} | javascript | function MdDialogController($mdDialog, $mdConstant) {
// For compatibility with AngularJS 1.6+, we should always use the $onInit hook in
// interimElements. The $mdCompiler simulates the $onInit hook for all versions.
this.$onInit = function() {
var isPrompt = this.$type == 'prompt';
if (isPrompt && this.initialValue) {
this.result = this.initialValue;
}
this.hide = function() {
$mdDialog.hide(isPrompt ? this.result : true);
};
this.abort = function() {
$mdDialog.cancel();
};
this.keypress = function($event) {
var invalidPrompt = isPrompt && this.required && !angular.isDefined(this.result);
if ($event.keyCode === $mdConstant.KEY_CODE.ENTER && !invalidPrompt) {
$mdDialog.hide(this.result);
}
};
};
} | [
"function",
"MdDialogController",
"(",
"$mdDialog",
",",
"$mdConstant",
")",
"{",
"// For compatibility with AngularJS 1.6+, we should always use the $onInit hook in",
"// interimElements. The $mdCompiler simulates the $onInit hook for all versions.",
"this",
".",
"$onInit",
"=",
"function",
"(",
")",
"{",
"var",
"isPrompt",
"=",
"this",
".",
"$type",
"==",
"'prompt'",
";",
"if",
"(",
"isPrompt",
"&&",
"this",
".",
"initialValue",
")",
"{",
"this",
".",
"result",
"=",
"this",
".",
"initialValue",
";",
"}",
"this",
".",
"hide",
"=",
"function",
"(",
")",
"{",
"$mdDialog",
".",
"hide",
"(",
"isPrompt",
"?",
"this",
".",
"result",
":",
"true",
")",
";",
"}",
";",
"this",
".",
"abort",
"=",
"function",
"(",
")",
"{",
"$mdDialog",
".",
"cancel",
"(",
")",
";",
"}",
";",
"this",
".",
"keypress",
"=",
"function",
"(",
"$event",
")",
"{",
"var",
"invalidPrompt",
"=",
"isPrompt",
"&&",
"this",
".",
"required",
"&&",
"!",
"angular",
".",
"isDefined",
"(",
"this",
".",
"result",
")",
";",
"if",
"(",
"$event",
".",
"keyCode",
"===",
"$mdConstant",
".",
"KEY_CODE",
".",
"ENTER",
"&&",
"!",
"invalidPrompt",
")",
"{",
"$mdDialog",
".",
"hide",
"(",
"this",
".",
"result",
")",
";",
"}",
"}",
";",
"}",
";",
"}"
] | Controller for the md-dialog interim elements
@ngInject | [
"Controller",
"for",
"the",
"md",
"-",
"dialog",
"interim",
"elements"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L647-L671 |
5,113 | angular/material | src/components/dialog/dialog.js | onShow | function onShow(scope, element, options, controller) {
angular.element($document[0].body).addClass('md-dialog-is-showing');
var dialogElement = element.find('md-dialog');
// Once a dialog has `ng-cloak` applied on his template the dialog animation will not work properly.
// This is a very common problem, so we have to notify the developer about this.
if (dialogElement.hasClass('ng-cloak')) {
var message = '$mdDialog: using `<md-dialog ng-cloak>` will affect the dialog opening animations.';
$log.warn(message, element[0]);
}
captureParentAndFromToElements(options);
configureAria(dialogElement, options);
showBackdrop(scope, element, options);
activateListeners(element, options);
return dialogPopIn(element, options)
.then(function() {
lockScreenReader(element, options);
warnDeprecatedActions();
focusOnOpen();
});
/**
* Check to see if they used the deprecated .md-actions class and log a warning
*/
function warnDeprecatedActions() {
if (element[0].querySelector('.md-actions')) {
$log.warn('Using a class of md-actions is deprecated, please use <md-dialog-actions>.');
}
}
/**
* For alerts, focus on content... otherwise focus on
* the close button (or equivalent)
*/
function focusOnOpen() {
if (options.focusOnOpen) {
var target = $mdUtil.findFocusTarget(element) || findCloseButton() || dialogElement;
target.focus();
}
/**
* If no element with class dialog-close, try to find the last
* button child in md-actions and assume it is a close button.
*
* If we find no actions at all, log a warning to the console.
*/
function findCloseButton() {
return element[0].querySelector('.dialog-close, md-dialog-actions button:last-child');
}
}
} | javascript | function onShow(scope, element, options, controller) {
angular.element($document[0].body).addClass('md-dialog-is-showing');
var dialogElement = element.find('md-dialog');
// Once a dialog has `ng-cloak` applied on his template the dialog animation will not work properly.
// This is a very common problem, so we have to notify the developer about this.
if (dialogElement.hasClass('ng-cloak')) {
var message = '$mdDialog: using `<md-dialog ng-cloak>` will affect the dialog opening animations.';
$log.warn(message, element[0]);
}
captureParentAndFromToElements(options);
configureAria(dialogElement, options);
showBackdrop(scope, element, options);
activateListeners(element, options);
return dialogPopIn(element, options)
.then(function() {
lockScreenReader(element, options);
warnDeprecatedActions();
focusOnOpen();
});
/**
* Check to see if they used the deprecated .md-actions class and log a warning
*/
function warnDeprecatedActions() {
if (element[0].querySelector('.md-actions')) {
$log.warn('Using a class of md-actions is deprecated, please use <md-dialog-actions>.');
}
}
/**
* For alerts, focus on content... otherwise focus on
* the close button (or equivalent)
*/
function focusOnOpen() {
if (options.focusOnOpen) {
var target = $mdUtil.findFocusTarget(element) || findCloseButton() || dialogElement;
target.focus();
}
/**
* If no element with class dialog-close, try to find the last
* button child in md-actions and assume it is a close button.
*
* If we find no actions at all, log a warning to the console.
*/
function findCloseButton() {
return element[0].querySelector('.dialog-close, md-dialog-actions button:last-child');
}
}
} | [
"function",
"onShow",
"(",
"scope",
",",
"element",
",",
"options",
",",
"controller",
")",
"{",
"angular",
".",
"element",
"(",
"$document",
"[",
"0",
"]",
".",
"body",
")",
".",
"addClass",
"(",
"'md-dialog-is-showing'",
")",
";",
"var",
"dialogElement",
"=",
"element",
".",
"find",
"(",
"'md-dialog'",
")",
";",
"// Once a dialog has `ng-cloak` applied on his template the dialog animation will not work properly.",
"// This is a very common problem, so we have to notify the developer about this.",
"if",
"(",
"dialogElement",
".",
"hasClass",
"(",
"'ng-cloak'",
")",
")",
"{",
"var",
"message",
"=",
"'$mdDialog: using `<md-dialog ng-cloak>` will affect the dialog opening animations.'",
";",
"$log",
".",
"warn",
"(",
"message",
",",
"element",
"[",
"0",
"]",
")",
";",
"}",
"captureParentAndFromToElements",
"(",
"options",
")",
";",
"configureAria",
"(",
"dialogElement",
",",
"options",
")",
";",
"showBackdrop",
"(",
"scope",
",",
"element",
",",
"options",
")",
";",
"activateListeners",
"(",
"element",
",",
"options",
")",
";",
"return",
"dialogPopIn",
"(",
"element",
",",
"options",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"lockScreenReader",
"(",
"element",
",",
"options",
")",
";",
"warnDeprecatedActions",
"(",
")",
";",
"focusOnOpen",
"(",
")",
";",
"}",
")",
";",
"/**\n * Check to see if they used the deprecated .md-actions class and log a warning\n */",
"function",
"warnDeprecatedActions",
"(",
")",
"{",
"if",
"(",
"element",
"[",
"0",
"]",
".",
"querySelector",
"(",
"'.md-actions'",
")",
")",
"{",
"$log",
".",
"warn",
"(",
"'Using a class of md-actions is deprecated, please use <md-dialog-actions>.'",
")",
";",
"}",
"}",
"/**\n * For alerts, focus on content... otherwise focus on\n * the close button (or equivalent)\n */",
"function",
"focusOnOpen",
"(",
")",
"{",
"if",
"(",
"options",
".",
"focusOnOpen",
")",
"{",
"var",
"target",
"=",
"$mdUtil",
".",
"findFocusTarget",
"(",
"element",
")",
"||",
"findCloseButton",
"(",
")",
"||",
"dialogElement",
";",
"target",
".",
"focus",
"(",
")",
";",
"}",
"/**\n * If no element with class dialog-close, try to find the last\n * button child in md-actions and assume it is a close button.\n *\n * If we find no actions at all, log a warning to the console.\n */",
"function",
"findCloseButton",
"(",
")",
"{",
"return",
"element",
"[",
"0",
"]",
".",
"querySelector",
"(",
"'.dialog-close, md-dialog-actions button:last-child'",
")",
";",
"}",
"}",
"}"
] | Show method for dialogs | [
"Show",
"method",
"for",
"dialogs"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L748-L801 |
5,114 | angular/material | src/components/dialog/dialog.js | onRemove | function onRemove(scope, element, options) {
options.deactivateListeners();
options.unlockScreenReader();
options.hideBackdrop(options.$destroy);
// Remove the focus traps that we added earlier for keeping focus within the dialog.
if (topFocusTrap && topFocusTrap.parentNode) {
topFocusTrap.parentNode.removeChild(topFocusTrap);
}
if (bottomFocusTrap && bottomFocusTrap.parentNode) {
bottomFocusTrap.parentNode.removeChild(bottomFocusTrap);
}
// For navigation $destroy events, do a quick, non-animated removal,
// but for normal closes (from clicks, etc) animate the removal
return options.$destroy ? detachAndClean() : animateRemoval().then(detachAndClean);
/**
* For normal closes, animate the removal.
* For forced closes (like $destroy events), skip the animations
*/
function animateRemoval() {
return dialogPopOut(element, options);
}
/**
* Detach the element
*/
function detachAndClean() {
angular.element($document[0].body).removeClass('md-dialog-is-showing');
// Reverse the container stretch if using a content element.
if (options.contentElement) {
options.reverseContainerStretch();
}
// Exposed cleanup function from the $mdCompiler.
options.cleanupElement();
// Restores the focus to the origin element if the last interaction upon opening was a keyboard.
if (!options.$destroy && options.originInteraction === 'keyboard') {
options.origin.focus();
}
}
} | javascript | function onRemove(scope, element, options) {
options.deactivateListeners();
options.unlockScreenReader();
options.hideBackdrop(options.$destroy);
// Remove the focus traps that we added earlier for keeping focus within the dialog.
if (topFocusTrap && topFocusTrap.parentNode) {
topFocusTrap.parentNode.removeChild(topFocusTrap);
}
if (bottomFocusTrap && bottomFocusTrap.parentNode) {
bottomFocusTrap.parentNode.removeChild(bottomFocusTrap);
}
// For navigation $destroy events, do a quick, non-animated removal,
// but for normal closes (from clicks, etc) animate the removal
return options.$destroy ? detachAndClean() : animateRemoval().then(detachAndClean);
/**
* For normal closes, animate the removal.
* For forced closes (like $destroy events), skip the animations
*/
function animateRemoval() {
return dialogPopOut(element, options);
}
/**
* Detach the element
*/
function detachAndClean() {
angular.element($document[0].body).removeClass('md-dialog-is-showing');
// Reverse the container stretch if using a content element.
if (options.contentElement) {
options.reverseContainerStretch();
}
// Exposed cleanup function from the $mdCompiler.
options.cleanupElement();
// Restores the focus to the origin element if the last interaction upon opening was a keyboard.
if (!options.$destroy && options.originInteraction === 'keyboard') {
options.origin.focus();
}
}
} | [
"function",
"onRemove",
"(",
"scope",
",",
"element",
",",
"options",
")",
"{",
"options",
".",
"deactivateListeners",
"(",
")",
";",
"options",
".",
"unlockScreenReader",
"(",
")",
";",
"options",
".",
"hideBackdrop",
"(",
"options",
".",
"$destroy",
")",
";",
"// Remove the focus traps that we added earlier for keeping focus within the dialog.",
"if",
"(",
"topFocusTrap",
"&&",
"topFocusTrap",
".",
"parentNode",
")",
"{",
"topFocusTrap",
".",
"parentNode",
".",
"removeChild",
"(",
"topFocusTrap",
")",
";",
"}",
"if",
"(",
"bottomFocusTrap",
"&&",
"bottomFocusTrap",
".",
"parentNode",
")",
"{",
"bottomFocusTrap",
".",
"parentNode",
".",
"removeChild",
"(",
"bottomFocusTrap",
")",
";",
"}",
"// For navigation $destroy events, do a quick, non-animated removal,",
"// but for normal closes (from clicks, etc) animate the removal",
"return",
"options",
".",
"$destroy",
"?",
"detachAndClean",
"(",
")",
":",
"animateRemoval",
"(",
")",
".",
"then",
"(",
"detachAndClean",
")",
";",
"/**\n * For normal closes, animate the removal.\n * For forced closes (like $destroy events), skip the animations\n */",
"function",
"animateRemoval",
"(",
")",
"{",
"return",
"dialogPopOut",
"(",
"element",
",",
"options",
")",
";",
"}",
"/**\n * Detach the element\n */",
"function",
"detachAndClean",
"(",
")",
"{",
"angular",
".",
"element",
"(",
"$document",
"[",
"0",
"]",
".",
"body",
")",
".",
"removeClass",
"(",
"'md-dialog-is-showing'",
")",
";",
"// Reverse the container stretch if using a content element.",
"if",
"(",
"options",
".",
"contentElement",
")",
"{",
"options",
".",
"reverseContainerStretch",
"(",
")",
";",
"}",
"// Exposed cleanup function from the $mdCompiler.",
"options",
".",
"cleanupElement",
"(",
")",
";",
"// Restores the focus to the origin element if the last interaction upon opening was a keyboard.",
"if",
"(",
"!",
"options",
".",
"$destroy",
"&&",
"options",
".",
"originInteraction",
"===",
"'keyboard'",
")",
"{",
"options",
".",
"origin",
".",
"focus",
"(",
")",
";",
"}",
"}",
"}"
] | Remove function for all dialogs | [
"Remove",
"function",
"for",
"all",
"dialogs"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L806-L851 |
5,115 | angular/material | src/components/dialog/dialog.js | detachAndClean | function detachAndClean() {
angular.element($document[0].body).removeClass('md-dialog-is-showing');
// Reverse the container stretch if using a content element.
if (options.contentElement) {
options.reverseContainerStretch();
}
// Exposed cleanup function from the $mdCompiler.
options.cleanupElement();
// Restores the focus to the origin element if the last interaction upon opening was a keyboard.
if (!options.$destroy && options.originInteraction === 'keyboard') {
options.origin.focus();
}
} | javascript | function detachAndClean() {
angular.element($document[0].body).removeClass('md-dialog-is-showing');
// Reverse the container stretch if using a content element.
if (options.contentElement) {
options.reverseContainerStretch();
}
// Exposed cleanup function from the $mdCompiler.
options.cleanupElement();
// Restores the focus to the origin element if the last interaction upon opening was a keyboard.
if (!options.$destroy && options.originInteraction === 'keyboard') {
options.origin.focus();
}
} | [
"function",
"detachAndClean",
"(",
")",
"{",
"angular",
".",
"element",
"(",
"$document",
"[",
"0",
"]",
".",
"body",
")",
".",
"removeClass",
"(",
"'md-dialog-is-showing'",
")",
";",
"// Reverse the container stretch if using a content element.",
"if",
"(",
"options",
".",
"contentElement",
")",
"{",
"options",
".",
"reverseContainerStretch",
"(",
")",
";",
"}",
"// Exposed cleanup function from the $mdCompiler.",
"options",
".",
"cleanupElement",
"(",
")",
";",
"// Restores the focus to the origin element if the last interaction upon opening was a keyboard.",
"if",
"(",
"!",
"options",
".",
"$destroy",
"&&",
"options",
".",
"originInteraction",
"===",
"'keyboard'",
")",
"{",
"options",
".",
"origin",
".",
"focus",
"(",
")",
";",
"}",
"}"
] | Detach the element | [
"Detach",
"the",
"element"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L835-L850 |
5,116 | angular/material | src/components/dialog/dialog.js | getBoundingClientRect | function getBoundingClientRect (element, orig) {
var source = angular.element((element || {}));
if (source && source.length) {
// Compute and save the target element's bounding rect, so that if the
// element is hidden when the dialog closes, we can shrink the dialog
// back to the same position it expanded from.
//
// Checking if the source is a rect object or a DOM element
var bounds = {top:0,left:0,height:0,width:0};
var hasFn = angular.isFunction(source[0].getBoundingClientRect);
return angular.extend(orig || {}, {
element : hasFn ? source : undefined,
bounds : hasFn ? source[0].getBoundingClientRect() : angular.extend({}, bounds, source[0]),
focus : angular.bind(source, source.focus),
});
}
} | javascript | function getBoundingClientRect (element, orig) {
var source = angular.element((element || {}));
if (source && source.length) {
// Compute and save the target element's bounding rect, so that if the
// element is hidden when the dialog closes, we can shrink the dialog
// back to the same position it expanded from.
//
// Checking if the source is a rect object or a DOM element
var bounds = {top:0,left:0,height:0,width:0};
var hasFn = angular.isFunction(source[0].getBoundingClientRect);
return angular.extend(orig || {}, {
element : hasFn ? source : undefined,
bounds : hasFn ? source[0].getBoundingClientRect() : angular.extend({}, bounds, source[0]),
focus : angular.bind(source, source.focus),
});
}
} | [
"function",
"getBoundingClientRect",
"(",
"element",
",",
"orig",
")",
"{",
"var",
"source",
"=",
"angular",
".",
"element",
"(",
"(",
"element",
"||",
"{",
"}",
")",
")",
";",
"if",
"(",
"source",
"&&",
"source",
".",
"length",
")",
"{",
"// Compute and save the target element's bounding rect, so that if the",
"// element is hidden when the dialog closes, we can shrink the dialog",
"// back to the same position it expanded from.",
"//",
"// Checking if the source is a rect object or a DOM element",
"var",
"bounds",
"=",
"{",
"top",
":",
"0",
",",
"left",
":",
"0",
",",
"height",
":",
"0",
",",
"width",
":",
"0",
"}",
";",
"var",
"hasFn",
"=",
"angular",
".",
"isFunction",
"(",
"source",
"[",
"0",
"]",
".",
"getBoundingClientRect",
")",
";",
"return",
"angular",
".",
"extend",
"(",
"orig",
"||",
"{",
"}",
",",
"{",
"element",
":",
"hasFn",
"?",
"source",
":",
"undefined",
",",
"bounds",
":",
"hasFn",
"?",
"source",
"[",
"0",
"]",
".",
"getBoundingClientRect",
"(",
")",
":",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"bounds",
",",
"source",
"[",
"0",
"]",
")",
",",
"focus",
":",
"angular",
".",
"bind",
"(",
"source",
",",
"source",
".",
"focus",
")",
",",
"}",
")",
";",
"}",
"}"
] | Identify the bounding RECT for the target element | [
"Identify",
"the",
"bounding",
"RECT",
"for",
"the",
"target",
"element"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L912-L929 |
5,117 | angular/material | src/components/dialog/dialog.js | getDomElement | function getDomElement(element, defaultElement) {
if (angular.isString(element)) {
element = $document[0].querySelector(element);
}
// If we have a reference to a raw dom element, always wrap it in jqLite
return angular.element(element || defaultElement);
} | javascript | function getDomElement(element, defaultElement) {
if (angular.isString(element)) {
element = $document[0].querySelector(element);
}
// If we have a reference to a raw dom element, always wrap it in jqLite
return angular.element(element || defaultElement);
} | [
"function",
"getDomElement",
"(",
"element",
",",
"defaultElement",
")",
"{",
"if",
"(",
"angular",
".",
"isString",
"(",
"element",
")",
")",
"{",
"element",
"=",
"$document",
"[",
"0",
"]",
".",
"querySelector",
"(",
"element",
")",
";",
"}",
"// If we have a reference to a raw dom element, always wrap it in jqLite",
"return",
"angular",
".",
"element",
"(",
"element",
"||",
"defaultElement",
")",
";",
"}"
] | If the specifier is a simple string selector, then query for
the DOM element. | [
"If",
"the",
"specifier",
"is",
"a",
"simple",
"string",
"selector",
"then",
"query",
"for",
"the",
"DOM",
"element",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L935-L942 |
5,118 | angular/material | src/components/dialog/dialog.js | activateListeners | function activateListeners(element, options) {
var window = angular.element($window);
var onWindowResize = $mdUtil.debounce(function() {
stretchDialogContainerToViewport(element, options);
}, 60);
var removeListeners = [];
var smartClose = function() {
// Only 'confirm' dialogs have a cancel button... escape/clickOutside will
// cancel or fallback to hide.
var closeFn = (options.$type == 'alert') ? $mdDialog.hide : $mdDialog.cancel;
$mdUtil.nextTick(closeFn, true);
};
if (options.escapeToClose) {
var parentTarget = options.parent;
var keyHandlerFn = function(ev) {
if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
ev.stopImmediatePropagation();
ev.preventDefault();
smartClose();
}
};
// Add keydown listeners
element.on('keydown', keyHandlerFn);
parentTarget.on('keydown', keyHandlerFn);
// Queue remove listeners function
removeListeners.push(function() {
element.off('keydown', keyHandlerFn);
parentTarget.off('keydown', keyHandlerFn);
});
}
// Register listener to update dialog on window resize
window.on('resize', onWindowResize);
removeListeners.push(function() {
window.off('resize', onWindowResize);
});
if (options.clickOutsideToClose) {
var target = element;
var sourceElem;
// Keep track of the element on which the mouse originally went down
// so that we can only close the backdrop when the 'click' started on it.
// A simple 'click' handler does not work,
// it sets the target object as the element the mouse went down on.
var mousedownHandler = function(ev) {
sourceElem = ev.target;
};
// We check if our original element and the target is the backdrop
// because if the original was the backdrop and the target was inside the dialog
// we don't want to dialog to close.
var mouseupHandler = function(ev) {
if (sourceElem === target[0] && ev.target === target[0]) {
ev.stopPropagation();
ev.preventDefault();
smartClose();
}
};
// Add listeners
target.on('mousedown', mousedownHandler);
target.on('mouseup', mouseupHandler);
// Queue remove listeners function
removeListeners.push(function() {
target.off('mousedown', mousedownHandler);
target.off('mouseup', mouseupHandler);
});
}
// Attach specific `remove` listener handler
options.deactivateListeners = function() {
removeListeners.forEach(function(removeFn) {
removeFn();
});
options.deactivateListeners = null;
};
} | javascript | function activateListeners(element, options) {
var window = angular.element($window);
var onWindowResize = $mdUtil.debounce(function() {
stretchDialogContainerToViewport(element, options);
}, 60);
var removeListeners = [];
var smartClose = function() {
// Only 'confirm' dialogs have a cancel button... escape/clickOutside will
// cancel or fallback to hide.
var closeFn = (options.$type == 'alert') ? $mdDialog.hide : $mdDialog.cancel;
$mdUtil.nextTick(closeFn, true);
};
if (options.escapeToClose) {
var parentTarget = options.parent;
var keyHandlerFn = function(ev) {
if (ev.keyCode === $mdConstant.KEY_CODE.ESCAPE) {
ev.stopImmediatePropagation();
ev.preventDefault();
smartClose();
}
};
// Add keydown listeners
element.on('keydown', keyHandlerFn);
parentTarget.on('keydown', keyHandlerFn);
// Queue remove listeners function
removeListeners.push(function() {
element.off('keydown', keyHandlerFn);
parentTarget.off('keydown', keyHandlerFn);
});
}
// Register listener to update dialog on window resize
window.on('resize', onWindowResize);
removeListeners.push(function() {
window.off('resize', onWindowResize);
});
if (options.clickOutsideToClose) {
var target = element;
var sourceElem;
// Keep track of the element on which the mouse originally went down
// so that we can only close the backdrop when the 'click' started on it.
// A simple 'click' handler does not work,
// it sets the target object as the element the mouse went down on.
var mousedownHandler = function(ev) {
sourceElem = ev.target;
};
// We check if our original element and the target is the backdrop
// because if the original was the backdrop and the target was inside the dialog
// we don't want to dialog to close.
var mouseupHandler = function(ev) {
if (sourceElem === target[0] && ev.target === target[0]) {
ev.stopPropagation();
ev.preventDefault();
smartClose();
}
};
// Add listeners
target.on('mousedown', mousedownHandler);
target.on('mouseup', mouseupHandler);
// Queue remove listeners function
removeListeners.push(function() {
target.off('mousedown', mousedownHandler);
target.off('mouseup', mouseupHandler);
});
}
// Attach specific `remove` listener handler
options.deactivateListeners = function() {
removeListeners.forEach(function(removeFn) {
removeFn();
});
options.deactivateListeners = null;
};
} | [
"function",
"activateListeners",
"(",
"element",
",",
"options",
")",
"{",
"var",
"window",
"=",
"angular",
".",
"element",
"(",
"$window",
")",
";",
"var",
"onWindowResize",
"=",
"$mdUtil",
".",
"debounce",
"(",
"function",
"(",
")",
"{",
"stretchDialogContainerToViewport",
"(",
"element",
",",
"options",
")",
";",
"}",
",",
"60",
")",
";",
"var",
"removeListeners",
"=",
"[",
"]",
";",
"var",
"smartClose",
"=",
"function",
"(",
")",
"{",
"// Only 'confirm' dialogs have a cancel button... escape/clickOutside will",
"// cancel or fallback to hide.",
"var",
"closeFn",
"=",
"(",
"options",
".",
"$type",
"==",
"'alert'",
")",
"?",
"$mdDialog",
".",
"hide",
":",
"$mdDialog",
".",
"cancel",
";",
"$mdUtil",
".",
"nextTick",
"(",
"closeFn",
",",
"true",
")",
";",
"}",
";",
"if",
"(",
"options",
".",
"escapeToClose",
")",
"{",
"var",
"parentTarget",
"=",
"options",
".",
"parent",
";",
"var",
"keyHandlerFn",
"=",
"function",
"(",
"ev",
")",
"{",
"if",
"(",
"ev",
".",
"keyCode",
"===",
"$mdConstant",
".",
"KEY_CODE",
".",
"ESCAPE",
")",
"{",
"ev",
".",
"stopImmediatePropagation",
"(",
")",
";",
"ev",
".",
"preventDefault",
"(",
")",
";",
"smartClose",
"(",
")",
";",
"}",
"}",
";",
"// Add keydown listeners",
"element",
".",
"on",
"(",
"'keydown'",
",",
"keyHandlerFn",
")",
";",
"parentTarget",
".",
"on",
"(",
"'keydown'",
",",
"keyHandlerFn",
")",
";",
"// Queue remove listeners function",
"removeListeners",
".",
"push",
"(",
"function",
"(",
")",
"{",
"element",
".",
"off",
"(",
"'keydown'",
",",
"keyHandlerFn",
")",
";",
"parentTarget",
".",
"off",
"(",
"'keydown'",
",",
"keyHandlerFn",
")",
";",
"}",
")",
";",
"}",
"// Register listener to update dialog on window resize",
"window",
".",
"on",
"(",
"'resize'",
",",
"onWindowResize",
")",
";",
"removeListeners",
".",
"push",
"(",
"function",
"(",
")",
"{",
"window",
".",
"off",
"(",
"'resize'",
",",
"onWindowResize",
")",
";",
"}",
")",
";",
"if",
"(",
"options",
".",
"clickOutsideToClose",
")",
"{",
"var",
"target",
"=",
"element",
";",
"var",
"sourceElem",
";",
"// Keep track of the element on which the mouse originally went down",
"// so that we can only close the backdrop when the 'click' started on it.",
"// A simple 'click' handler does not work,",
"// it sets the target object as the element the mouse went down on.",
"var",
"mousedownHandler",
"=",
"function",
"(",
"ev",
")",
"{",
"sourceElem",
"=",
"ev",
".",
"target",
";",
"}",
";",
"// We check if our original element and the target is the backdrop",
"// because if the original was the backdrop and the target was inside the dialog",
"// we don't want to dialog to close.",
"var",
"mouseupHandler",
"=",
"function",
"(",
"ev",
")",
"{",
"if",
"(",
"sourceElem",
"===",
"target",
"[",
"0",
"]",
"&&",
"ev",
".",
"target",
"===",
"target",
"[",
"0",
"]",
")",
"{",
"ev",
".",
"stopPropagation",
"(",
")",
";",
"ev",
".",
"preventDefault",
"(",
")",
";",
"smartClose",
"(",
")",
";",
"}",
"}",
";",
"// Add listeners",
"target",
".",
"on",
"(",
"'mousedown'",
",",
"mousedownHandler",
")",
";",
"target",
".",
"on",
"(",
"'mouseup'",
",",
"mouseupHandler",
")",
";",
"// Queue remove listeners function",
"removeListeners",
".",
"push",
"(",
"function",
"(",
")",
"{",
"target",
".",
"off",
"(",
"'mousedown'",
",",
"mousedownHandler",
")",
";",
"target",
".",
"off",
"(",
"'mouseup'",
",",
"mouseupHandler",
")",
";",
"}",
")",
";",
"}",
"// Attach specific `remove` listener handler",
"options",
".",
"deactivateListeners",
"=",
"function",
"(",
")",
"{",
"removeListeners",
".",
"forEach",
"(",
"function",
"(",
"removeFn",
")",
"{",
"removeFn",
"(",
")",
";",
"}",
")",
";",
"options",
".",
"deactivateListeners",
"=",
"null",
";",
"}",
";",
"}"
] | Listen for escape keys and outside clicks to auto close | [
"Listen",
"for",
"escape",
"keys",
"and",
"outside",
"clicks",
"to",
"auto",
"close"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L949-L1036 |
5,119 | angular/material | src/components/dialog/dialog.js | function(ev) {
if (sourceElem === target[0] && ev.target === target[0]) {
ev.stopPropagation();
ev.preventDefault();
smartClose();
}
} | javascript | function(ev) {
if (sourceElem === target[0] && ev.target === target[0]) {
ev.stopPropagation();
ev.preventDefault();
smartClose();
}
} | [
"function",
"(",
"ev",
")",
"{",
"if",
"(",
"sourceElem",
"===",
"target",
"[",
"0",
"]",
"&&",
"ev",
".",
"target",
"===",
"target",
"[",
"0",
"]",
")",
"{",
"ev",
".",
"stopPropagation",
"(",
")",
";",
"ev",
".",
"preventDefault",
"(",
")",
";",
"smartClose",
"(",
")",
";",
"}",
"}"
] | We check if our original element and the target is the backdrop because if the original was the backdrop and the target was inside the dialog we don't want to dialog to close. | [
"We",
"check",
"if",
"our",
"original",
"element",
"and",
"the",
"target",
"is",
"the",
"backdrop",
"because",
"if",
"the",
"original",
"was",
"the",
"backdrop",
"and",
"the",
"target",
"was",
"inside",
"the",
"dialog",
"we",
"don",
"t",
"want",
"to",
"dialog",
"to",
"close",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1009-L1016 |
|
5,120 | angular/material | src/components/dialog/dialog.js | configureAria | function configureAria(element, options) {
var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
var dialogContent = element.find('md-dialog-content');
var existingDialogId = element.attr('id');
var dialogContentId = 'dialogContent_' + (existingDialogId || $mdUtil.nextUid());
element.attr({
'role': role,
'tabIndex': '-1'
});
if (dialogContent.length === 0) {
dialogContent = element;
// If the dialog element already had an ID, don't clobber it.
if (existingDialogId) {
dialogContentId = existingDialogId;
}
}
dialogContent.attr('id', dialogContentId);
element.attr('aria-describedby', dialogContentId);
if (options.ariaLabel) {
$mdAria.expect(element, 'aria-label', options.ariaLabel);
}
else {
$mdAria.expectAsync(element, 'aria-label', function() {
// If dialog title is specified, set aria-label with it
// See https://github.com/angular/material/issues/10582
if (options.title) {
return options.title;
} else {
var words = dialogContent.text().split(/\s+/);
if (words.length > 3) words = words.slice(0, 3).concat('...');
return words.join(' ');
}
});
}
// Set up elements before and after the dialog content to capture focus and
// redirect back into the dialog.
topFocusTrap = document.createElement('div');
topFocusTrap.classList.add('md-dialog-focus-trap');
topFocusTrap.tabIndex = 0;
bottomFocusTrap = topFocusTrap.cloneNode(false);
// When focus is about to move out of the dialog, we want to intercept it and redirect it
// back to the dialog element.
var focusHandler = function() {
element.focus();
};
topFocusTrap.addEventListener('focus', focusHandler);
bottomFocusTrap.addEventListener('focus', focusHandler);
// The top focus trap inserted immeidately before the md-dialog element (as a sibling).
// The bottom focus trap is inserted at the very end of the md-dialog element (as a child).
element[0].parentNode.insertBefore(topFocusTrap, element[0]);
element.after(bottomFocusTrap);
} | javascript | function configureAria(element, options) {
var role = (options.$type === 'alert') ? 'alertdialog' : 'dialog';
var dialogContent = element.find('md-dialog-content');
var existingDialogId = element.attr('id');
var dialogContentId = 'dialogContent_' + (existingDialogId || $mdUtil.nextUid());
element.attr({
'role': role,
'tabIndex': '-1'
});
if (dialogContent.length === 0) {
dialogContent = element;
// If the dialog element already had an ID, don't clobber it.
if (existingDialogId) {
dialogContentId = existingDialogId;
}
}
dialogContent.attr('id', dialogContentId);
element.attr('aria-describedby', dialogContentId);
if (options.ariaLabel) {
$mdAria.expect(element, 'aria-label', options.ariaLabel);
}
else {
$mdAria.expectAsync(element, 'aria-label', function() {
// If dialog title is specified, set aria-label with it
// See https://github.com/angular/material/issues/10582
if (options.title) {
return options.title;
} else {
var words = dialogContent.text().split(/\s+/);
if (words.length > 3) words = words.slice(0, 3).concat('...');
return words.join(' ');
}
});
}
// Set up elements before and after the dialog content to capture focus and
// redirect back into the dialog.
topFocusTrap = document.createElement('div');
topFocusTrap.classList.add('md-dialog-focus-trap');
topFocusTrap.tabIndex = 0;
bottomFocusTrap = topFocusTrap.cloneNode(false);
// When focus is about to move out of the dialog, we want to intercept it and redirect it
// back to the dialog element.
var focusHandler = function() {
element.focus();
};
topFocusTrap.addEventListener('focus', focusHandler);
bottomFocusTrap.addEventListener('focus', focusHandler);
// The top focus trap inserted immeidately before the md-dialog element (as a sibling).
// The bottom focus trap is inserted at the very end of the md-dialog element (as a child).
element[0].parentNode.insertBefore(topFocusTrap, element[0]);
element.after(bottomFocusTrap);
} | [
"function",
"configureAria",
"(",
"element",
",",
"options",
")",
"{",
"var",
"role",
"=",
"(",
"options",
".",
"$type",
"===",
"'alert'",
")",
"?",
"'alertdialog'",
":",
"'dialog'",
";",
"var",
"dialogContent",
"=",
"element",
".",
"find",
"(",
"'md-dialog-content'",
")",
";",
"var",
"existingDialogId",
"=",
"element",
".",
"attr",
"(",
"'id'",
")",
";",
"var",
"dialogContentId",
"=",
"'dialogContent_'",
"+",
"(",
"existingDialogId",
"||",
"$mdUtil",
".",
"nextUid",
"(",
")",
")",
";",
"element",
".",
"attr",
"(",
"{",
"'role'",
":",
"role",
",",
"'tabIndex'",
":",
"'-1'",
"}",
")",
";",
"if",
"(",
"dialogContent",
".",
"length",
"===",
"0",
")",
"{",
"dialogContent",
"=",
"element",
";",
"// If the dialog element already had an ID, don't clobber it.",
"if",
"(",
"existingDialogId",
")",
"{",
"dialogContentId",
"=",
"existingDialogId",
";",
"}",
"}",
"dialogContent",
".",
"attr",
"(",
"'id'",
",",
"dialogContentId",
")",
";",
"element",
".",
"attr",
"(",
"'aria-describedby'",
",",
"dialogContentId",
")",
";",
"if",
"(",
"options",
".",
"ariaLabel",
")",
"{",
"$mdAria",
".",
"expect",
"(",
"element",
",",
"'aria-label'",
",",
"options",
".",
"ariaLabel",
")",
";",
"}",
"else",
"{",
"$mdAria",
".",
"expectAsync",
"(",
"element",
",",
"'aria-label'",
",",
"function",
"(",
")",
"{",
"// If dialog title is specified, set aria-label with it",
"// See https://github.com/angular/material/issues/10582",
"if",
"(",
"options",
".",
"title",
")",
"{",
"return",
"options",
".",
"title",
";",
"}",
"else",
"{",
"var",
"words",
"=",
"dialogContent",
".",
"text",
"(",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"if",
"(",
"words",
".",
"length",
">",
"3",
")",
"words",
"=",
"words",
".",
"slice",
"(",
"0",
",",
"3",
")",
".",
"concat",
"(",
"'...'",
")",
";",
"return",
"words",
".",
"join",
"(",
"' '",
")",
";",
"}",
"}",
")",
";",
"}",
"// Set up elements before and after the dialog content to capture focus and",
"// redirect back into the dialog.",
"topFocusTrap",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"topFocusTrap",
".",
"classList",
".",
"add",
"(",
"'md-dialog-focus-trap'",
")",
";",
"topFocusTrap",
".",
"tabIndex",
"=",
"0",
";",
"bottomFocusTrap",
"=",
"topFocusTrap",
".",
"cloneNode",
"(",
"false",
")",
";",
"// When focus is about to move out of the dialog, we want to intercept it and redirect it",
"// back to the dialog element.",
"var",
"focusHandler",
"=",
"function",
"(",
")",
"{",
"element",
".",
"focus",
"(",
")",
";",
"}",
";",
"topFocusTrap",
".",
"addEventListener",
"(",
"'focus'",
",",
"focusHandler",
")",
";",
"bottomFocusTrap",
".",
"addEventListener",
"(",
"'focus'",
",",
"focusHandler",
")",
";",
"// The top focus trap inserted immeidately before the md-dialog element (as a sibling).",
"// The bottom focus trap is inserted at the very end of the md-dialog element (as a child).",
"element",
"[",
"0",
"]",
".",
"parentNode",
".",
"insertBefore",
"(",
"topFocusTrap",
",",
"element",
"[",
"0",
"]",
")",
";",
"element",
".",
"after",
"(",
"bottomFocusTrap",
")",
";",
"}"
] | Inject ARIA-specific attributes appropriate for Dialogs | [
"Inject",
"ARIA",
"-",
"specific",
"attributes",
"appropriate",
"for",
"Dialogs"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1076-L1136 |
5,121 | angular/material | src/components/dialog/dialog.js | lockScreenReader | function lockScreenReader(element, options) {
var isHidden = true;
// get raw DOM node
walkDOM(element[0]);
options.unlockScreenReader = function () {
isHidden = false;
walkDOM(element[0]);
options.unlockScreenReader = null;
};
/**
* Get all of an element's parent elements up the DOM tree
* @return {Array} The parent elements
*/
function getParents(element) {
var parents = [];
while (element.parentNode) {
if (element === document.body) {
return parents;
}
var children = element.parentNode.children;
for (var i = 0; i < children.length; i++) {
// skip over child if it is an ascendant of the dialog
// a script or style tag, or a live region.
if (element !== children[i] &&
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
!children[i].hasAttribute('aria-live')) {
parents.push(children[i]);
}
}
element = element.parentNode;
}
return parents;
}
/**
* Walk DOM to apply or remove aria-hidden on sibling nodes
* and parent sibling nodes
*/
function walkDOM(element) {
var elements = getParents(element);
for (var i = 0; i < elements.length; i++) {
elements[i].setAttribute('aria-hidden', isHidden);
}
}
} | javascript | function lockScreenReader(element, options) {
var isHidden = true;
// get raw DOM node
walkDOM(element[0]);
options.unlockScreenReader = function () {
isHidden = false;
walkDOM(element[0]);
options.unlockScreenReader = null;
};
/**
* Get all of an element's parent elements up the DOM tree
* @return {Array} The parent elements
*/
function getParents(element) {
var parents = [];
while (element.parentNode) {
if (element === document.body) {
return parents;
}
var children = element.parentNode.children;
for (var i = 0; i < children.length; i++) {
// skip over child if it is an ascendant of the dialog
// a script or style tag, or a live region.
if (element !== children[i] &&
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
!children[i].hasAttribute('aria-live')) {
parents.push(children[i]);
}
}
element = element.parentNode;
}
return parents;
}
/**
* Walk DOM to apply or remove aria-hidden on sibling nodes
* and parent sibling nodes
*/
function walkDOM(element) {
var elements = getParents(element);
for (var i = 0; i < elements.length; i++) {
elements[i].setAttribute('aria-hidden', isHidden);
}
}
} | [
"function",
"lockScreenReader",
"(",
"element",
",",
"options",
")",
"{",
"var",
"isHidden",
"=",
"true",
";",
"// get raw DOM node",
"walkDOM",
"(",
"element",
"[",
"0",
"]",
")",
";",
"options",
".",
"unlockScreenReader",
"=",
"function",
"(",
")",
"{",
"isHidden",
"=",
"false",
";",
"walkDOM",
"(",
"element",
"[",
"0",
"]",
")",
";",
"options",
".",
"unlockScreenReader",
"=",
"null",
";",
"}",
";",
"/**\n * Get all of an element's parent elements up the DOM tree\n * @return {Array} The parent elements\n */",
"function",
"getParents",
"(",
"element",
")",
"{",
"var",
"parents",
"=",
"[",
"]",
";",
"while",
"(",
"element",
".",
"parentNode",
")",
"{",
"if",
"(",
"element",
"===",
"document",
".",
"body",
")",
"{",
"return",
"parents",
";",
"}",
"var",
"children",
"=",
"element",
".",
"parentNode",
".",
"children",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"// skip over child if it is an ascendant of the dialog",
"// a script or style tag, or a live region.",
"if",
"(",
"element",
"!==",
"children",
"[",
"i",
"]",
"&&",
"!",
"isNodeOneOf",
"(",
"children",
"[",
"i",
"]",
",",
"[",
"'SCRIPT'",
",",
"'STYLE'",
"]",
")",
"&&",
"!",
"children",
"[",
"i",
"]",
".",
"hasAttribute",
"(",
"'aria-live'",
")",
")",
"{",
"parents",
".",
"push",
"(",
"children",
"[",
"i",
"]",
")",
";",
"}",
"}",
"element",
"=",
"element",
".",
"parentNode",
";",
"}",
"return",
"parents",
";",
"}",
"/**\n * Walk DOM to apply or remove aria-hidden on sibling nodes\n * and parent sibling nodes\n */",
"function",
"walkDOM",
"(",
"element",
")",
"{",
"var",
"elements",
"=",
"getParents",
"(",
"element",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"elements",
".",
"length",
";",
"i",
"++",
")",
"{",
"elements",
"[",
"i",
"]",
".",
"setAttribute",
"(",
"'aria-hidden'",
",",
"isHidden",
")",
";",
"}",
"}",
"}"
] | Prevents screen reader interaction behind modal window
on swipe interfaces | [
"Prevents",
"screen",
"reader",
"interaction",
"behind",
"modal",
"window",
"on",
"swipe",
"interfaces"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1142-L1190 |
5,122 | angular/material | src/components/dialog/dialog.js | getParents | function getParents(element) {
var parents = [];
while (element.parentNode) {
if (element === document.body) {
return parents;
}
var children = element.parentNode.children;
for (var i = 0; i < children.length; i++) {
// skip over child if it is an ascendant of the dialog
// a script or style tag, or a live region.
if (element !== children[i] &&
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
!children[i].hasAttribute('aria-live')) {
parents.push(children[i]);
}
}
element = element.parentNode;
}
return parents;
} | javascript | function getParents(element) {
var parents = [];
while (element.parentNode) {
if (element === document.body) {
return parents;
}
var children = element.parentNode.children;
for (var i = 0; i < children.length; i++) {
// skip over child if it is an ascendant of the dialog
// a script or style tag, or a live region.
if (element !== children[i] &&
!isNodeOneOf(children[i], ['SCRIPT', 'STYLE']) &&
!children[i].hasAttribute('aria-live')) {
parents.push(children[i]);
}
}
element = element.parentNode;
}
return parents;
} | [
"function",
"getParents",
"(",
"element",
")",
"{",
"var",
"parents",
"=",
"[",
"]",
";",
"while",
"(",
"element",
".",
"parentNode",
")",
"{",
"if",
"(",
"element",
"===",
"document",
".",
"body",
")",
"{",
"return",
"parents",
";",
"}",
"var",
"children",
"=",
"element",
".",
"parentNode",
".",
"children",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"// skip over child if it is an ascendant of the dialog",
"// a script or style tag, or a live region.",
"if",
"(",
"element",
"!==",
"children",
"[",
"i",
"]",
"&&",
"!",
"isNodeOneOf",
"(",
"children",
"[",
"i",
"]",
",",
"[",
"'SCRIPT'",
",",
"'STYLE'",
"]",
")",
"&&",
"!",
"children",
"[",
"i",
"]",
".",
"hasAttribute",
"(",
"'aria-live'",
")",
")",
"{",
"parents",
".",
"push",
"(",
"children",
"[",
"i",
"]",
")",
";",
"}",
"}",
"element",
"=",
"element",
".",
"parentNode",
";",
"}",
"return",
"parents",
";",
"}"
] | Get all of an element's parent elements up the DOM tree
@return {Array} The parent elements | [
"Get",
"all",
"of",
"an",
"element",
"s",
"parent",
"elements",
"up",
"the",
"DOM",
"tree"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1159-L1178 |
5,123 | angular/material | src/components/dialog/dialog.js | walkDOM | function walkDOM(element) {
var elements = getParents(element);
for (var i = 0; i < elements.length; i++) {
elements[i].setAttribute('aria-hidden', isHidden);
}
} | javascript | function walkDOM(element) {
var elements = getParents(element);
for (var i = 0; i < elements.length; i++) {
elements[i].setAttribute('aria-hidden', isHidden);
}
} | [
"function",
"walkDOM",
"(",
"element",
")",
"{",
"var",
"elements",
"=",
"getParents",
"(",
"element",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"elements",
".",
"length",
";",
"i",
"++",
")",
"{",
"elements",
"[",
"i",
"]",
".",
"setAttribute",
"(",
"'aria-hidden'",
",",
"isHidden",
")",
";",
"}",
"}"
] | Walk DOM to apply or remove aria-hidden on sibling nodes
and parent sibling nodes | [
"Walk",
"DOM",
"to",
"apply",
"or",
"remove",
"aria",
"-",
"hidden",
"on",
"sibling",
"nodes",
"and",
"parent",
"sibling",
"nodes"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1184-L1189 |
5,124 | angular/material | src/components/dialog/dialog.js | stretchDialogContainerToViewport | function stretchDialogContainerToViewport(container, options) {
var isFixed = $window.getComputedStyle($document[0].body).position == 'fixed';
var backdrop = options.backdrop ? $window.getComputedStyle(options.backdrop[0]) : null;
var height = backdrop ? Math.min($document[0].body.clientHeight, Math.ceil(Math.abs(parseInt(backdrop.height, 10)))) : 0;
var previousStyles = {
top: container.css('top'),
height: container.css('height')
};
// If the body is fixed, determine the distance to the viewport in relative from the parent.
var parentTop = Math.abs(options.parent[0].getBoundingClientRect().top);
container.css({
top: (isFixed ? parentTop : 0) + 'px',
height: height ? height + 'px' : '100%'
});
return function() {
// Reverts the modified styles back to the previous values.
// This is needed for contentElements, which should have the same styles after close
// as before.
container.css(previousStyles);
};
} | javascript | function stretchDialogContainerToViewport(container, options) {
var isFixed = $window.getComputedStyle($document[0].body).position == 'fixed';
var backdrop = options.backdrop ? $window.getComputedStyle(options.backdrop[0]) : null;
var height = backdrop ? Math.min($document[0].body.clientHeight, Math.ceil(Math.abs(parseInt(backdrop.height, 10)))) : 0;
var previousStyles = {
top: container.css('top'),
height: container.css('height')
};
// If the body is fixed, determine the distance to the viewport in relative from the parent.
var parentTop = Math.abs(options.parent[0].getBoundingClientRect().top);
container.css({
top: (isFixed ? parentTop : 0) + 'px',
height: height ? height + 'px' : '100%'
});
return function() {
// Reverts the modified styles back to the previous values.
// This is needed for contentElements, which should have the same styles after close
// as before.
container.css(previousStyles);
};
} | [
"function",
"stretchDialogContainerToViewport",
"(",
"container",
",",
"options",
")",
"{",
"var",
"isFixed",
"=",
"$window",
".",
"getComputedStyle",
"(",
"$document",
"[",
"0",
"]",
".",
"body",
")",
".",
"position",
"==",
"'fixed'",
";",
"var",
"backdrop",
"=",
"options",
".",
"backdrop",
"?",
"$window",
".",
"getComputedStyle",
"(",
"options",
".",
"backdrop",
"[",
"0",
"]",
")",
":",
"null",
";",
"var",
"height",
"=",
"backdrop",
"?",
"Math",
".",
"min",
"(",
"$document",
"[",
"0",
"]",
".",
"body",
".",
"clientHeight",
",",
"Math",
".",
"ceil",
"(",
"Math",
".",
"abs",
"(",
"parseInt",
"(",
"backdrop",
".",
"height",
",",
"10",
")",
")",
")",
")",
":",
"0",
";",
"var",
"previousStyles",
"=",
"{",
"top",
":",
"container",
".",
"css",
"(",
"'top'",
")",
",",
"height",
":",
"container",
".",
"css",
"(",
"'height'",
")",
"}",
";",
"// If the body is fixed, determine the distance to the viewport in relative from the parent.",
"var",
"parentTop",
"=",
"Math",
".",
"abs",
"(",
"options",
".",
"parent",
"[",
"0",
"]",
".",
"getBoundingClientRect",
"(",
")",
".",
"top",
")",
";",
"container",
".",
"css",
"(",
"{",
"top",
":",
"(",
"isFixed",
"?",
"parentTop",
":",
"0",
")",
"+",
"'px'",
",",
"height",
":",
"height",
"?",
"height",
"+",
"'px'",
":",
"'100%'",
"}",
")",
";",
"return",
"function",
"(",
")",
"{",
"// Reverts the modified styles back to the previous values.",
"// This is needed for contentElements, which should have the same styles after close",
"// as before.",
"container",
".",
"css",
"(",
"previousStyles",
")",
";",
"}",
";",
"}"
] | Ensure the dialog container fill-stretches to the viewport | [
"Ensure",
"the",
"dialog",
"container",
"fill",
"-",
"stretches",
"to",
"the",
"viewport"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1195-L1219 |
5,125 | angular/material | src/components/dialog/dialog.js | dialogPopIn | function dialogPopIn(container, options) {
// Add the `md-dialog-container` to the DOM
options.parent.append(container);
options.reverseContainerStretch = stretchDialogContainerToViewport(container, options);
var dialogEl = container.find('md-dialog');
var animator = $mdUtil.dom.animator;
var buildTranslateToOrigin = animator.calculateZoomToOrigin;
var translateOptions = {transitionInClass: 'md-transition-in', transitionOutClass: 'md-transition-out'};
var from = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.openFrom || options.origin));
var to = animator.toTransformCss(""); // defaults to center display (or parent or $rootElement)
dialogEl.toggleClass('md-dialog-fullscreen', !!options.fullscreen);
return animator
.translate3d(dialogEl, from, to, translateOptions)
.then(function(animateReversal) {
// Build a reversal translate function synced to this translation...
options.reverseAnimate = function() {
delete options.reverseAnimate;
if (options.closeTo) {
// Using the opposite classes to create a close animation to the closeTo element
translateOptions = {transitionInClass: 'md-transition-out', transitionOutClass: 'md-transition-in'};
from = to;
to = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.closeTo));
return animator
.translate3d(dialogEl, from, to,translateOptions);
}
return animateReversal(
to = animator.toTransformCss(
// in case the origin element has moved or is hidden,
// let's recalculate the translateCSS
buildTranslateToOrigin(dialogEl, options.origin)
)
);
};
// Function to revert the generated animation styles on the dialog element.
// Useful when using a contentElement instead of a template.
options.clearAnimate = function() {
delete options.clearAnimate;
// Remove the transition classes, added from $animateCSS, since those can't be removed
// by reversely running the animator.
dialogEl.removeClass([
translateOptions.transitionOutClass,
translateOptions.transitionInClass
].join(' '));
// Run the animation reversely to remove the previous added animation styles.
return animator.translate3d(dialogEl, to, animator.toTransformCss(''), {});
};
return true;
});
} | javascript | function dialogPopIn(container, options) {
// Add the `md-dialog-container` to the DOM
options.parent.append(container);
options.reverseContainerStretch = stretchDialogContainerToViewport(container, options);
var dialogEl = container.find('md-dialog');
var animator = $mdUtil.dom.animator;
var buildTranslateToOrigin = animator.calculateZoomToOrigin;
var translateOptions = {transitionInClass: 'md-transition-in', transitionOutClass: 'md-transition-out'};
var from = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.openFrom || options.origin));
var to = animator.toTransformCss(""); // defaults to center display (or parent or $rootElement)
dialogEl.toggleClass('md-dialog-fullscreen', !!options.fullscreen);
return animator
.translate3d(dialogEl, from, to, translateOptions)
.then(function(animateReversal) {
// Build a reversal translate function synced to this translation...
options.reverseAnimate = function() {
delete options.reverseAnimate;
if (options.closeTo) {
// Using the opposite classes to create a close animation to the closeTo element
translateOptions = {transitionInClass: 'md-transition-out', transitionOutClass: 'md-transition-in'};
from = to;
to = animator.toTransformCss(buildTranslateToOrigin(dialogEl, options.closeTo));
return animator
.translate3d(dialogEl, from, to,translateOptions);
}
return animateReversal(
to = animator.toTransformCss(
// in case the origin element has moved or is hidden,
// let's recalculate the translateCSS
buildTranslateToOrigin(dialogEl, options.origin)
)
);
};
// Function to revert the generated animation styles on the dialog element.
// Useful when using a contentElement instead of a template.
options.clearAnimate = function() {
delete options.clearAnimate;
// Remove the transition classes, added from $animateCSS, since those can't be removed
// by reversely running the animator.
dialogEl.removeClass([
translateOptions.transitionOutClass,
translateOptions.transitionInClass
].join(' '));
// Run the animation reversely to remove the previous added animation styles.
return animator.translate3d(dialogEl, to, animator.toTransformCss(''), {});
};
return true;
});
} | [
"function",
"dialogPopIn",
"(",
"container",
",",
"options",
")",
"{",
"// Add the `md-dialog-container` to the DOM",
"options",
".",
"parent",
".",
"append",
"(",
"container",
")",
";",
"options",
".",
"reverseContainerStretch",
"=",
"stretchDialogContainerToViewport",
"(",
"container",
",",
"options",
")",
";",
"var",
"dialogEl",
"=",
"container",
".",
"find",
"(",
"'md-dialog'",
")",
";",
"var",
"animator",
"=",
"$mdUtil",
".",
"dom",
".",
"animator",
";",
"var",
"buildTranslateToOrigin",
"=",
"animator",
".",
"calculateZoomToOrigin",
";",
"var",
"translateOptions",
"=",
"{",
"transitionInClass",
":",
"'md-transition-in'",
",",
"transitionOutClass",
":",
"'md-transition-out'",
"}",
";",
"var",
"from",
"=",
"animator",
".",
"toTransformCss",
"(",
"buildTranslateToOrigin",
"(",
"dialogEl",
",",
"options",
".",
"openFrom",
"||",
"options",
".",
"origin",
")",
")",
";",
"var",
"to",
"=",
"animator",
".",
"toTransformCss",
"(",
"\"\"",
")",
";",
"// defaults to center display (or parent or $rootElement)",
"dialogEl",
".",
"toggleClass",
"(",
"'md-dialog-fullscreen'",
",",
"!",
"!",
"options",
".",
"fullscreen",
")",
";",
"return",
"animator",
".",
"translate3d",
"(",
"dialogEl",
",",
"from",
",",
"to",
",",
"translateOptions",
")",
".",
"then",
"(",
"function",
"(",
"animateReversal",
")",
"{",
"// Build a reversal translate function synced to this translation...",
"options",
".",
"reverseAnimate",
"=",
"function",
"(",
")",
"{",
"delete",
"options",
".",
"reverseAnimate",
";",
"if",
"(",
"options",
".",
"closeTo",
")",
"{",
"// Using the opposite classes to create a close animation to the closeTo element",
"translateOptions",
"=",
"{",
"transitionInClass",
":",
"'md-transition-out'",
",",
"transitionOutClass",
":",
"'md-transition-in'",
"}",
";",
"from",
"=",
"to",
";",
"to",
"=",
"animator",
".",
"toTransformCss",
"(",
"buildTranslateToOrigin",
"(",
"dialogEl",
",",
"options",
".",
"closeTo",
")",
")",
";",
"return",
"animator",
".",
"translate3d",
"(",
"dialogEl",
",",
"from",
",",
"to",
",",
"translateOptions",
")",
";",
"}",
"return",
"animateReversal",
"(",
"to",
"=",
"animator",
".",
"toTransformCss",
"(",
"// in case the origin element has moved or is hidden,",
"// let's recalculate the translateCSS",
"buildTranslateToOrigin",
"(",
"dialogEl",
",",
"options",
".",
"origin",
")",
")",
")",
";",
"}",
";",
"// Function to revert the generated animation styles on the dialog element.",
"// Useful when using a contentElement instead of a template.",
"options",
".",
"clearAnimate",
"=",
"function",
"(",
")",
"{",
"delete",
"options",
".",
"clearAnimate",
";",
"// Remove the transition classes, added from $animateCSS, since those can't be removed",
"// by reversely running the animator.",
"dialogEl",
".",
"removeClass",
"(",
"[",
"translateOptions",
".",
"transitionOutClass",
",",
"translateOptions",
".",
"transitionInClass",
"]",
".",
"join",
"(",
"' '",
")",
")",
";",
"// Run the animation reversely to remove the previous added animation styles.",
"return",
"animator",
".",
"translate3d",
"(",
"dialogEl",
",",
"to",
",",
"animator",
".",
"toTransformCss",
"(",
"''",
")",
",",
"{",
"}",
")",
";",
"}",
";",
"return",
"true",
";",
"}",
")",
";",
"}"
] | Dialog open and pop-in animation | [
"Dialog",
"open",
"and",
"pop",
"-",
"in",
"animation"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1224-L1284 |
5,126 | angular/material | src/components/dialog/dialog.js | dialogPopOut | function dialogPopOut(container, options) {
return options.reverseAnimate().then(function() {
if (options.contentElement) {
// When we use a contentElement, we want the element to be the same as before.
// That means, that we have to clear all the animation properties, like transform.
options.clearAnimate();
}
});
} | javascript | function dialogPopOut(container, options) {
return options.reverseAnimate().then(function() {
if (options.contentElement) {
// When we use a contentElement, we want the element to be the same as before.
// That means, that we have to clear all the animation properties, like transform.
options.clearAnimate();
}
});
} | [
"function",
"dialogPopOut",
"(",
"container",
",",
"options",
")",
"{",
"return",
"options",
".",
"reverseAnimate",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"options",
".",
"contentElement",
")",
"{",
"// When we use a contentElement, we want the element to be the same as before.",
"// That means, that we have to clear all the animation properties, like transform.",
"options",
".",
"clearAnimate",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Dialog close and pop-out animation | [
"Dialog",
"close",
"and",
"pop",
"-",
"out",
"animation"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/dialog/dialog.js#L1289-L1297 |
5,127 | angular/material | src/components/progressLinear/progress-linear.js | watchAttributes | function watchAttributes() {
attr.$observe('value', function(value) {
var percentValue = clamp(value);
element.attr('aria-valuenow', percentValue);
if (mode() != MODE_QUERY) animateIndicator(bar2, percentValue);
});
attr.$observe('mdBufferValue', function(value) {
animateIndicator(bar1, clamp(value));
});
attr.$observe('disabled', function(value) {
if (value === true || value === false) {
isDisabled = !!value;
} else {
isDisabled = angular.isDefined(value);
}
element.toggleClass(DISABLED_CLASS, isDisabled);
container.toggleClass(lastMode, !isDisabled);
});
attr.$observe('mdMode', function(mode) {
if (lastMode) container.removeClass(lastMode);
switch (mode) {
case MODE_QUERY:
case MODE_BUFFER:
case MODE_DETERMINATE:
case MODE_INDETERMINATE:
container.addClass(lastMode = "md-mode-" + mode);
break;
default:
container.addClass(lastMode = "md-mode-" + MODE_INDETERMINATE);
break;
}
});
} | javascript | function watchAttributes() {
attr.$observe('value', function(value) {
var percentValue = clamp(value);
element.attr('aria-valuenow', percentValue);
if (mode() != MODE_QUERY) animateIndicator(bar2, percentValue);
});
attr.$observe('mdBufferValue', function(value) {
animateIndicator(bar1, clamp(value));
});
attr.$observe('disabled', function(value) {
if (value === true || value === false) {
isDisabled = !!value;
} else {
isDisabled = angular.isDefined(value);
}
element.toggleClass(DISABLED_CLASS, isDisabled);
container.toggleClass(lastMode, !isDisabled);
});
attr.$observe('mdMode', function(mode) {
if (lastMode) container.removeClass(lastMode);
switch (mode) {
case MODE_QUERY:
case MODE_BUFFER:
case MODE_DETERMINATE:
case MODE_INDETERMINATE:
container.addClass(lastMode = "md-mode-" + mode);
break;
default:
container.addClass(lastMode = "md-mode-" + MODE_INDETERMINATE);
break;
}
});
} | [
"function",
"watchAttributes",
"(",
")",
"{",
"attr",
".",
"$observe",
"(",
"'value'",
",",
"function",
"(",
"value",
")",
"{",
"var",
"percentValue",
"=",
"clamp",
"(",
"value",
")",
";",
"element",
".",
"attr",
"(",
"'aria-valuenow'",
",",
"percentValue",
")",
";",
"if",
"(",
"mode",
"(",
")",
"!=",
"MODE_QUERY",
")",
"animateIndicator",
"(",
"bar2",
",",
"percentValue",
")",
";",
"}",
")",
";",
"attr",
".",
"$observe",
"(",
"'mdBufferValue'",
",",
"function",
"(",
"value",
")",
"{",
"animateIndicator",
"(",
"bar1",
",",
"clamp",
"(",
"value",
")",
")",
";",
"}",
")",
";",
"attr",
".",
"$observe",
"(",
"'disabled'",
",",
"function",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"===",
"true",
"||",
"value",
"===",
"false",
")",
"{",
"isDisabled",
"=",
"!",
"!",
"value",
";",
"}",
"else",
"{",
"isDisabled",
"=",
"angular",
".",
"isDefined",
"(",
"value",
")",
";",
"}",
"element",
".",
"toggleClass",
"(",
"DISABLED_CLASS",
",",
"isDisabled",
")",
";",
"container",
".",
"toggleClass",
"(",
"lastMode",
",",
"!",
"isDisabled",
")",
";",
"}",
")",
";",
"attr",
".",
"$observe",
"(",
"'mdMode'",
",",
"function",
"(",
"mode",
")",
"{",
"if",
"(",
"lastMode",
")",
"container",
".",
"removeClass",
"(",
"lastMode",
")",
";",
"switch",
"(",
"mode",
")",
"{",
"case",
"MODE_QUERY",
":",
"case",
"MODE_BUFFER",
":",
"case",
"MODE_DETERMINATE",
":",
"case",
"MODE_INDETERMINATE",
":",
"container",
".",
"addClass",
"(",
"lastMode",
"=",
"\"md-mode-\"",
"+",
"mode",
")",
";",
"break",
";",
"default",
":",
"container",
".",
"addClass",
"(",
"lastMode",
"=",
"\"md-mode-\"",
"+",
"MODE_INDETERMINATE",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"}"
] | Watch the value, md-buffer-value, and md-mode attributes | [
"Watch",
"the",
"value",
"md",
"-",
"buffer",
"-",
"value",
"and",
"md",
"-",
"mode",
"attributes"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/progressLinear/progress-linear.js#L104-L142 |
5,128 | angular/material | src/components/progressLinear/progress-linear.js | validateMode | function validateMode() {
if (angular.isUndefined(attr.mdMode)) {
var hasValue = angular.isDefined(attr.value);
var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
var info = "Auto-adding the missing md-mode='{0}' to the ProgressLinear element";
element.attr("md-mode", mode);
attr.mdMode = mode;
}
} | javascript | function validateMode() {
if (angular.isUndefined(attr.mdMode)) {
var hasValue = angular.isDefined(attr.value);
var mode = hasValue ? MODE_DETERMINATE : MODE_INDETERMINATE;
var info = "Auto-adding the missing md-mode='{0}' to the ProgressLinear element";
element.attr("md-mode", mode);
attr.mdMode = mode;
}
} | [
"function",
"validateMode",
"(",
")",
"{",
"if",
"(",
"angular",
".",
"isUndefined",
"(",
"attr",
".",
"mdMode",
")",
")",
"{",
"var",
"hasValue",
"=",
"angular",
".",
"isDefined",
"(",
"attr",
".",
"value",
")",
";",
"var",
"mode",
"=",
"hasValue",
"?",
"MODE_DETERMINATE",
":",
"MODE_INDETERMINATE",
";",
"var",
"info",
"=",
"\"Auto-adding the missing md-mode='{0}' to the ProgressLinear element\"",
";",
"element",
".",
"attr",
"(",
"\"md-mode\"",
",",
"mode",
")",
";",
"attr",
".",
"mdMode",
"=",
"mode",
";",
"}",
"}"
] | Auto-defaults the mode to either `determinate` or `indeterminate` mode; if not specified | [
"Auto",
"-",
"defaults",
"the",
"mode",
"to",
"either",
"determinate",
"or",
"indeterminate",
"mode",
";",
"if",
"not",
"specified"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/progressLinear/progress-linear.js#L147-L155 |
5,129 | angular/material | src/components/progressLinear/progress-linear.js | mode | function mode() {
var value = (attr.mdMode || "").trim();
if (value) {
switch (value) {
case MODE_DETERMINATE:
case MODE_INDETERMINATE:
case MODE_BUFFER:
case MODE_QUERY:
break;
default:
value = MODE_INDETERMINATE;
break;
}
}
return value;
} | javascript | function mode() {
var value = (attr.mdMode || "").trim();
if (value) {
switch (value) {
case MODE_DETERMINATE:
case MODE_INDETERMINATE:
case MODE_BUFFER:
case MODE_QUERY:
break;
default:
value = MODE_INDETERMINATE;
break;
}
}
return value;
} | [
"function",
"mode",
"(",
")",
"{",
"var",
"value",
"=",
"(",
"attr",
".",
"mdMode",
"||",
"\"\"",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"value",
")",
"{",
"switch",
"(",
"value",
")",
"{",
"case",
"MODE_DETERMINATE",
":",
"case",
"MODE_INDETERMINATE",
":",
"case",
"MODE_BUFFER",
":",
"case",
"MODE_QUERY",
":",
"break",
";",
"default",
":",
"value",
"=",
"MODE_INDETERMINATE",
";",
"break",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Is the md-mode a valid option? | [
"Is",
"the",
"md",
"-",
"mode",
"a",
"valid",
"option?"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/progressLinear/progress-linear.js#L160-L175 |
5,130 | angular/material | src/components/chips/chips.spec.js | updateInputCursor | function updateInputCursor() {
if (isValidInput) {
var inputLength = input[0].value.length;
try {
input[0].selectionStart = input[0].selectionEnd = inputLength;
} catch (e) {
// Chrome does not allow setting a selection for number inputs and just throws
// a DOMException as soon as something tries to set a selection programmatically.
// Faking the selection properties for the ChipsController works for our tests.
var selectionDescriptor = { writable: true, value: inputLength };
Object.defineProperty(input[0], 'selectionStart', selectionDescriptor);
Object.defineProperty(input[0], 'selectionEnd', selectionDescriptor);
}
}
} | javascript | function updateInputCursor() {
if (isValidInput) {
var inputLength = input[0].value.length;
try {
input[0].selectionStart = input[0].selectionEnd = inputLength;
} catch (e) {
// Chrome does not allow setting a selection for number inputs and just throws
// a DOMException as soon as something tries to set a selection programmatically.
// Faking the selection properties for the ChipsController works for our tests.
var selectionDescriptor = { writable: true, value: inputLength };
Object.defineProperty(input[0], 'selectionStart', selectionDescriptor);
Object.defineProperty(input[0], 'selectionEnd', selectionDescriptor);
}
}
} | [
"function",
"updateInputCursor",
"(",
")",
"{",
"if",
"(",
"isValidInput",
")",
"{",
"var",
"inputLength",
"=",
"input",
"[",
"0",
"]",
".",
"value",
".",
"length",
";",
"try",
"{",
"input",
"[",
"0",
"]",
".",
"selectionStart",
"=",
"input",
"[",
"0",
"]",
".",
"selectionEnd",
"=",
"inputLength",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Chrome does not allow setting a selection for number inputs and just throws",
"// a DOMException as soon as something tries to set a selection programmatically.",
"// Faking the selection properties for the ChipsController works for our tests.",
"var",
"selectionDescriptor",
"=",
"{",
"writable",
":",
"true",
",",
"value",
":",
"inputLength",
"}",
";",
"Object",
".",
"defineProperty",
"(",
"input",
"[",
"0",
"]",
",",
"'selectionStart'",
",",
"selectionDescriptor",
")",
";",
"Object",
".",
"defineProperty",
"(",
"input",
"[",
"0",
"]",
",",
"'selectionEnd'",
",",
"selectionDescriptor",
")",
";",
"}",
"}",
"}"
] | Updates the cursor position of the input.
This is necessary to test the cursor position. | [
"Updates",
"the",
"cursor",
"position",
"of",
"the",
"input",
".",
"This",
"is",
"necessary",
"to",
"test",
"the",
"cursor",
"position",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/chips/chips.spec.js#L814-L829 |
5,131 | catapult-project/catapult | telemetry/telemetry/internal/actions/gesture_common.js | getBoundingRect | function getBoundingRect(el) {
const clientRect = el.getBoundingClientRect();
const bound = {
left: clientRect.left,
top: clientRect.top,
width: clientRect.width,
height: clientRect.height
};
let frame = el.ownerDocument.defaultView.frameElement;
while (frame) {
const frameBound = frame.getBoundingClientRect();
// This computation doesn't account for more complex CSS transforms on the
// frame (e.g. scaling or rotations).
bound.left += frameBound.left;
bound.top += frameBound.top;
frame = frame.ownerDocument.frameElement;
}
return bound;
} | javascript | function getBoundingRect(el) {
const clientRect = el.getBoundingClientRect();
const bound = {
left: clientRect.left,
top: clientRect.top,
width: clientRect.width,
height: clientRect.height
};
let frame = el.ownerDocument.defaultView.frameElement;
while (frame) {
const frameBound = frame.getBoundingClientRect();
// This computation doesn't account for more complex CSS transforms on the
// frame (e.g. scaling or rotations).
bound.left += frameBound.left;
bound.top += frameBound.top;
frame = frame.ownerDocument.frameElement;
}
return bound;
} | [
"function",
"getBoundingRect",
"(",
"el",
")",
"{",
"const",
"clientRect",
"=",
"el",
".",
"getBoundingClientRect",
"(",
")",
";",
"const",
"bound",
"=",
"{",
"left",
":",
"clientRect",
".",
"left",
",",
"top",
":",
"clientRect",
".",
"top",
",",
"width",
":",
"clientRect",
".",
"width",
",",
"height",
":",
"clientRect",
".",
"height",
"}",
";",
"let",
"frame",
"=",
"el",
".",
"ownerDocument",
".",
"defaultView",
".",
"frameElement",
";",
"while",
"(",
"frame",
")",
"{",
"const",
"frameBound",
"=",
"frame",
".",
"getBoundingClientRect",
"(",
")",
";",
"// This computation doesn't account for more complex CSS transforms on the",
"// frame (e.g. scaling or rotations).",
"bound",
".",
"left",
"+=",
"frameBound",
".",
"left",
";",
"bound",
".",
"top",
"+=",
"frameBound",
".",
"top",
";",
"frame",
"=",
"frame",
".",
"ownerDocument",
".",
"frameElement",
";",
"}",
"return",
"bound",
";",
"}"
] | Returns the bounding rectangle wrt to the layout viewport. | [
"Returns",
"the",
"bounding",
"rectangle",
"wrt",
"to",
"the",
"layout",
"viewport",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/telemetry/telemetry/internal/actions/gesture_common.js#L15-L35 |
5,132 | catapult-project/catapult | telemetry/telemetry/internal/actions/gesture_common.js | getPageScaleFactor | function getPageScaleFactor() {
const pageScaleFactor = chrome.gpuBenchmarking.pageScaleFactor;
return pageScaleFactor ? pageScaleFactor.apply(chrome.gpuBenchmarking) : 1;
} | javascript | function getPageScaleFactor() {
const pageScaleFactor = chrome.gpuBenchmarking.pageScaleFactor;
return pageScaleFactor ? pageScaleFactor.apply(chrome.gpuBenchmarking) : 1;
} | [
"function",
"getPageScaleFactor",
"(",
")",
"{",
"const",
"pageScaleFactor",
"=",
"chrome",
".",
"gpuBenchmarking",
".",
"pageScaleFactor",
";",
"return",
"pageScaleFactor",
"?",
"pageScaleFactor",
".",
"apply",
"(",
"chrome",
".",
"gpuBenchmarking",
")",
":",
"1",
";",
"}"
] | Chrome version before M50 doesn't have `pageScaleFactor` function, to run benchmark on them we will need this function to fail back gracefully | [
"Chrome",
"version",
"before",
"M50",
"doesn",
"t",
"have",
"pageScaleFactor",
"function",
"to",
"run",
"benchmark",
"on",
"them",
"we",
"will",
"need",
"this",
"function",
"to",
"fail",
"back",
"gracefully"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/telemetry/telemetry/internal/actions/gesture_common.js#L39-L42 |
5,133 | catapult-project/catapult | telemetry/telemetry/internal/actions/gesture_common.js | getBoundingVisibleRect | function getBoundingVisibleRect(el) {
// Get the element bounding rect in the layout viewport.
const rect = getBoundingRect(el);
// Apply the visual viewport transform (i.e. pinch-zoom) to the bounding
// rect. The viewportX|Y values are in CSS pixels so they don't change
// with page scale. We first translate so that the viewport offset is
// at the origin and then we apply the scaling factor.
const scale = getPageScaleFactor();
const visualViewportX = chrome.gpuBenchmarking.visualViewportX();
const visualViewportY = chrome.gpuBenchmarking.visualViewportY();
rect.top = (rect.top - visualViewportY) * scale;
rect.left = (rect.left - visualViewportX) * scale;
rect.width *= scale;
rect.height *= scale;
// Get the window dimensions.
const windowHeight = getWindowHeight();
const windowWidth = getWindowWidth();
// Then clip the rect to the screen size.
rect.top = clamp(0, rect.top, windowHeight);
rect.left = clamp(0, rect.left, windowWidth);
rect.height = clamp(0, rect.height, windowHeight - rect.top);
rect.width = clamp(0, rect.width, windowWidth - rect.left);
return rect;
} | javascript | function getBoundingVisibleRect(el) {
// Get the element bounding rect in the layout viewport.
const rect = getBoundingRect(el);
// Apply the visual viewport transform (i.e. pinch-zoom) to the bounding
// rect. The viewportX|Y values are in CSS pixels so they don't change
// with page scale. We first translate so that the viewport offset is
// at the origin and then we apply the scaling factor.
const scale = getPageScaleFactor();
const visualViewportX = chrome.gpuBenchmarking.visualViewportX();
const visualViewportY = chrome.gpuBenchmarking.visualViewportY();
rect.top = (rect.top - visualViewportY) * scale;
rect.left = (rect.left - visualViewportX) * scale;
rect.width *= scale;
rect.height *= scale;
// Get the window dimensions.
const windowHeight = getWindowHeight();
const windowWidth = getWindowWidth();
// Then clip the rect to the screen size.
rect.top = clamp(0, rect.top, windowHeight);
rect.left = clamp(0, rect.left, windowWidth);
rect.height = clamp(0, rect.height, windowHeight - rect.top);
rect.width = clamp(0, rect.width, windowWidth - rect.left);
return rect;
} | [
"function",
"getBoundingVisibleRect",
"(",
"el",
")",
"{",
"// Get the element bounding rect in the layout viewport.",
"const",
"rect",
"=",
"getBoundingRect",
"(",
"el",
")",
";",
"// Apply the visual viewport transform (i.e. pinch-zoom) to the bounding",
"// rect. The viewportX|Y values are in CSS pixels so they don't change",
"// with page scale. We first translate so that the viewport offset is",
"// at the origin and then we apply the scaling factor.",
"const",
"scale",
"=",
"getPageScaleFactor",
"(",
")",
";",
"const",
"visualViewportX",
"=",
"chrome",
".",
"gpuBenchmarking",
".",
"visualViewportX",
"(",
")",
";",
"const",
"visualViewportY",
"=",
"chrome",
".",
"gpuBenchmarking",
".",
"visualViewportY",
"(",
")",
";",
"rect",
".",
"top",
"=",
"(",
"rect",
".",
"top",
"-",
"visualViewportY",
")",
"*",
"scale",
";",
"rect",
".",
"left",
"=",
"(",
"rect",
".",
"left",
"-",
"visualViewportX",
")",
"*",
"scale",
";",
"rect",
".",
"width",
"*=",
"scale",
";",
"rect",
".",
"height",
"*=",
"scale",
";",
"// Get the window dimensions.",
"const",
"windowHeight",
"=",
"getWindowHeight",
"(",
")",
";",
"const",
"windowWidth",
"=",
"getWindowWidth",
"(",
")",
";",
"// Then clip the rect to the screen size.",
"rect",
".",
"top",
"=",
"clamp",
"(",
"0",
",",
"rect",
".",
"top",
",",
"windowHeight",
")",
";",
"rect",
".",
"left",
"=",
"clamp",
"(",
"0",
",",
"rect",
".",
"left",
",",
"windowWidth",
")",
";",
"rect",
".",
"height",
"=",
"clamp",
"(",
"0",
",",
"rect",
".",
"height",
",",
"windowHeight",
"-",
"rect",
".",
"top",
")",
";",
"rect",
".",
"width",
"=",
"clamp",
"(",
"0",
",",
"rect",
".",
"width",
",",
"windowWidth",
"-",
"rect",
".",
"left",
")",
";",
"return",
"rect",
";",
"}"
] | Returns the bounding rect in the visual viewport's coordinates. | [
"Returns",
"the",
"bounding",
"rect",
"in",
"the",
"visual",
"viewport",
"s",
"coordinates",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/telemetry/telemetry/internal/actions/gesture_common.js#L59-L86 |
5,134 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/mutable-data.js | mutablePropertyChange | function mutablePropertyChange(inst, property, value, old, mutableData) {
let isObject;
if (mutableData) {
isObject = (typeof value === 'object' && value !== null);
// Pull `old` for Objects from temp cache, but treat `null` as a primitive
if (isObject) {
old = inst.__dataTemp[property];
}
}
// Strict equality check, but return false for NaN===NaN
let shouldChange = (old !== value && (old === old || value === value));
// Objects are stored in temporary cache (cleared at end of
// turn), which is used for dirty-checking
if (isObject && shouldChange) {
inst.__dataTemp[property] = value;
}
return shouldChange;
} | javascript | function mutablePropertyChange(inst, property, value, old, mutableData) {
let isObject;
if (mutableData) {
isObject = (typeof value === 'object' && value !== null);
// Pull `old` for Objects from temp cache, but treat `null` as a primitive
if (isObject) {
old = inst.__dataTemp[property];
}
}
// Strict equality check, but return false for NaN===NaN
let shouldChange = (old !== value && (old === old || value === value));
// Objects are stored in temporary cache (cleared at end of
// turn), which is used for dirty-checking
if (isObject && shouldChange) {
inst.__dataTemp[property] = value;
}
return shouldChange;
} | [
"function",
"mutablePropertyChange",
"(",
"inst",
",",
"property",
",",
"value",
",",
"old",
",",
"mutableData",
")",
"{",
"let",
"isObject",
";",
"if",
"(",
"mutableData",
")",
"{",
"isObject",
"=",
"(",
"typeof",
"value",
"===",
"'object'",
"&&",
"value",
"!==",
"null",
")",
";",
"// Pull `old` for Objects from temp cache, but treat `null` as a primitive",
"if",
"(",
"isObject",
")",
"{",
"old",
"=",
"inst",
".",
"__dataTemp",
"[",
"property",
"]",
";",
"}",
"}",
"// Strict equality check, but return false for NaN===NaN",
"let",
"shouldChange",
"=",
"(",
"old",
"!==",
"value",
"&&",
"(",
"old",
"===",
"old",
"||",
"value",
"===",
"value",
")",
")",
";",
"// Objects are stored in temporary cache (cleared at end of",
"// turn), which is used for dirty-checking",
"if",
"(",
"isObject",
"&&",
"shouldChange",
")",
"{",
"inst",
".",
"__dataTemp",
"[",
"property",
"]",
"=",
"value",
";",
"}",
"return",
"shouldChange",
";",
"}"
] | Common implementation for mixin & behavior | [
"Common",
"implementation",
"for",
"mixin",
"&",
"behavior"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/mutable-data.js#L13-L30 |
5,135 | catapult-project/catapult | tracing/third_party/oboe/src/wire.js | wire | function wire (httpMethodName, contentSource, body, headers, withCredentials){
var oboeBus = pubSub();
// Wire the input stream in if we are given a content source.
// This will usually be the case. If not, the instance created
// will have to be passed content from an external source.
if( contentSource ) {
streamingHttp( oboeBus,
httpTransport(),
httpMethodName,
contentSource,
body,
headers,
withCredentials
);
}
clarinet(oboeBus);
ascentManager(oboeBus, incrementalContentBuilder(oboeBus));
patternAdapter(oboeBus, jsonPathCompiler);
return instanceApi(oboeBus, contentSource);
} | javascript | function wire (httpMethodName, contentSource, body, headers, withCredentials){
var oboeBus = pubSub();
// Wire the input stream in if we are given a content source.
// This will usually be the case. If not, the instance created
// will have to be passed content from an external source.
if( contentSource ) {
streamingHttp( oboeBus,
httpTransport(),
httpMethodName,
contentSource,
body,
headers,
withCredentials
);
}
clarinet(oboeBus);
ascentManager(oboeBus, incrementalContentBuilder(oboeBus));
patternAdapter(oboeBus, jsonPathCompiler);
return instanceApi(oboeBus, contentSource);
} | [
"function",
"wire",
"(",
"httpMethodName",
",",
"contentSource",
",",
"body",
",",
"headers",
",",
"withCredentials",
")",
"{",
"var",
"oboeBus",
"=",
"pubSub",
"(",
")",
";",
"// Wire the input stream in if we are given a content source.",
"// This will usually be the case. If not, the instance created",
"// will have to be passed content from an external source.",
"if",
"(",
"contentSource",
")",
"{",
"streamingHttp",
"(",
"oboeBus",
",",
"httpTransport",
"(",
")",
",",
"httpMethodName",
",",
"contentSource",
",",
"body",
",",
"headers",
",",
"withCredentials",
")",
";",
"}",
"clarinet",
"(",
"oboeBus",
")",
";",
"ascentManager",
"(",
"oboeBus",
",",
"incrementalContentBuilder",
"(",
"oboeBus",
")",
")",
";",
"patternAdapter",
"(",
"oboeBus",
",",
"jsonPathCompiler",
")",
";",
"return",
"instanceApi",
"(",
"oboeBus",
",",
"contentSource",
")",
";",
"}"
] | This file sits just behind the API which is used to attain a new
Oboe instance. It creates the new components that are required
and introduces them to each other. | [
"This",
"file",
"sits",
"just",
"behind",
"the",
"API",
"which",
"is",
"used",
"to",
"attain",
"a",
"new",
"Oboe",
"instance",
".",
"It",
"creates",
"the",
"new",
"components",
"that",
"are",
"required",
"and",
"introduces",
"them",
"to",
"each",
"other",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/wire.js#L7-L34 |
5,136 | catapult-project/catapult | tracing/third_party/oboe/src/publicApi.js | oboe | function oboe(arg1) {
// We use duck-typing to detect if the parameter given is a stream, with the
// below list of parameters.
// Unpipe and unshift would normally be present on a stream but this breaks
// compatibility with Request streams.
// See https://github.com/jimhigson/oboe.js/issues/65
var nodeStreamMethodNames = list('resume', 'pause', 'pipe'),
isStream = partialComplete(
hasAllProperties
, nodeStreamMethodNames
);
if( arg1 ) {
if (isStream(arg1) || isString(arg1)) {
// simple version for GETs. Signature is:
// oboe( url )
// or, under node:
// oboe( readableStream )
return applyDefaults(
wire,
arg1 // url
);
} else {
// method signature is:
// oboe({method:m, url:u, body:b, headers:{...}})
return applyDefaults(
wire,
arg1.url,
arg1.method,
arg1.body,
arg1.headers,
arg1.withCredentials,
arg1.cached
);
}
} else {
// wire up a no-AJAX, no-stream Oboe. Will have to have content
// fed in externally and using .emit.
return wire();
}
} | javascript | function oboe(arg1) {
// We use duck-typing to detect if the parameter given is a stream, with the
// below list of parameters.
// Unpipe and unshift would normally be present on a stream but this breaks
// compatibility with Request streams.
// See https://github.com/jimhigson/oboe.js/issues/65
var nodeStreamMethodNames = list('resume', 'pause', 'pipe'),
isStream = partialComplete(
hasAllProperties
, nodeStreamMethodNames
);
if( arg1 ) {
if (isStream(arg1) || isString(arg1)) {
// simple version for GETs. Signature is:
// oboe( url )
// or, under node:
// oboe( readableStream )
return applyDefaults(
wire,
arg1 // url
);
} else {
// method signature is:
// oboe({method:m, url:u, body:b, headers:{...}})
return applyDefaults(
wire,
arg1.url,
arg1.method,
arg1.body,
arg1.headers,
arg1.withCredentials,
arg1.cached
);
}
} else {
// wire up a no-AJAX, no-stream Oboe. Will have to have content
// fed in externally and using .emit.
return wire();
}
} | [
"function",
"oboe",
"(",
"arg1",
")",
"{",
"// We use duck-typing to detect if the parameter given is a stream, with the",
"// below list of parameters.",
"// Unpipe and unshift would normally be present on a stream but this breaks",
"// compatibility with Request streams.",
"// See https://github.com/jimhigson/oboe.js/issues/65",
"var",
"nodeStreamMethodNames",
"=",
"list",
"(",
"'resume'",
",",
"'pause'",
",",
"'pipe'",
")",
",",
"isStream",
"=",
"partialComplete",
"(",
"hasAllProperties",
",",
"nodeStreamMethodNames",
")",
";",
"if",
"(",
"arg1",
")",
"{",
"if",
"(",
"isStream",
"(",
"arg1",
")",
"||",
"isString",
"(",
"arg1",
")",
")",
"{",
"// simple version for GETs. Signature is:",
"// oboe( url )",
"// or, under node:",
"// oboe( readableStream )",
"return",
"applyDefaults",
"(",
"wire",
",",
"arg1",
"// url",
")",
";",
"}",
"else",
"{",
"// method signature is:",
"// oboe({method:m, url:u, body:b, headers:{...}})",
"return",
"applyDefaults",
"(",
"wire",
",",
"arg1",
".",
"url",
",",
"arg1",
".",
"method",
",",
"arg1",
".",
"body",
",",
"arg1",
".",
"headers",
",",
"arg1",
".",
"withCredentials",
",",
"arg1",
".",
"cached",
")",
";",
"}",
"}",
"else",
"{",
"// wire up a no-AJAX, no-stream Oboe. Will have to have content ",
"// fed in externally and using .emit.",
"return",
"wire",
"(",
")",
";",
"}",
"}"
] | export public API | [
"export",
"public",
"API"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/publicApi.js#L2-L49 |
5,137 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | announceAccessibleMessage | function announceAccessibleMessage(msg) {
var element = document.createElement('div');
element.setAttribute('aria-live', 'polite');
element.style.position = 'relative';
element.style.left = '-9999px';
element.style.height = '0px';
element.innerText = msg;
document.body.appendChild(element);
window.setTimeout(function() {
document.body.removeChild(element);
}, 0);
} | javascript | function announceAccessibleMessage(msg) {
var element = document.createElement('div');
element.setAttribute('aria-live', 'polite');
element.style.position = 'relative';
element.style.left = '-9999px';
element.style.height = '0px';
element.innerText = msg;
document.body.appendChild(element);
window.setTimeout(function() {
document.body.removeChild(element);
}, 0);
} | [
"function",
"announceAccessibleMessage",
"(",
"msg",
")",
"{",
"var",
"element",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"element",
".",
"setAttribute",
"(",
"'aria-live'",
",",
"'polite'",
")",
";",
"element",
".",
"style",
".",
"position",
"=",
"'relative'",
";",
"element",
".",
"style",
".",
"left",
"=",
"'-9999px'",
";",
"element",
".",
"style",
".",
"height",
"=",
"'0px'",
";",
"element",
".",
"innerText",
"=",
"msg",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"element",
")",
";",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"document",
".",
"body",
".",
"removeChild",
"(",
"element",
")",
";",
"}",
",",
"0",
")",
";",
"}"
] | Add an accessible message to the page that will be announced to
users who have spoken feedback on, but will be invisible to all
other users. It's removed right away so it doesn't clutter the DOM.
@param {string} msg The text to be pronounced. | [
"Add",
"an",
"accessible",
"message",
"to",
"the",
"page",
"that",
"will",
"be",
"announced",
"to",
"users",
"who",
"have",
"spoken",
"feedback",
"on",
"but",
"will",
"be",
"invisible",
"to",
"all",
"other",
"users",
".",
"It",
"s",
"removed",
"right",
"away",
"so",
"it",
"doesn",
"t",
"clutter",
"the",
"DOM",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L35-L46 |
5,138 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | url | function url(s) {
// http://www.w3.org/TR/css3-values/#uris
// Parentheses, commas, whitespace characters, single quotes (') and double
// quotes (") appearing in a URI must be escaped with a backslash
var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1');
// WebKit has a bug when it comes to URLs that end with \
// https://bugs.webkit.org/show_bug.cgi?id=28885
if (/\\\\$/.test(s2)) {
// Add a space to work around the WebKit bug.
s2 += ' ';
}
return 'url("' + s2 + '")';
} | javascript | function url(s) {
// http://www.w3.org/TR/css3-values/#uris
// Parentheses, commas, whitespace characters, single quotes (') and double
// quotes (") appearing in a URI must be escaped with a backslash
var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1');
// WebKit has a bug when it comes to URLs that end with \
// https://bugs.webkit.org/show_bug.cgi?id=28885
if (/\\\\$/.test(s2)) {
// Add a space to work around the WebKit bug.
s2 += ' ';
}
return 'url("' + s2 + '")';
} | [
"function",
"url",
"(",
"s",
")",
"{",
"// http://www.w3.org/TR/css3-values/#uris",
"// Parentheses, commas, whitespace characters, single quotes (') and double",
"// quotes (\") appearing in a URI must be escaped with a backslash",
"var",
"s2",
"=",
"s",
".",
"replace",
"(",
"/",
"(\\(|\\)|\\,|\\s|\\'|\\\"|\\\\)",
"/",
"g",
",",
"'\\\\$1'",
")",
";",
"// WebKit has a bug when it comes to URLs that end with \\",
"// https://bugs.webkit.org/show_bug.cgi?id=28885",
"if",
"(",
"/",
"\\\\\\\\$",
"/",
".",
"test",
"(",
"s2",
")",
")",
"{",
"// Add a space to work around the WebKit bug.",
"s2",
"+=",
"' '",
";",
"}",
"return",
"'url(\"'",
"+",
"s2",
"+",
"'\")'",
";",
"}"
] | Generates a CSS url string.
@param {string} s The URL to generate the CSS url for.
@return {string} The CSS url string. | [
"Generates",
"a",
"CSS",
"url",
"string",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L53-L65 |
5,139 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | parseQueryParams | function parseQueryParams(location) {
var params = {};
var query = unescape(location.search.substring(1));
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = pair[1];
}
return params;
} | javascript | function parseQueryParams(location) {
var params = {};
var query = unescape(location.search.substring(1));
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
params[pair[0]] = pair[1];
}
return params;
} | [
"function",
"parseQueryParams",
"(",
"location",
")",
"{",
"var",
"params",
"=",
"{",
"}",
";",
"var",
"query",
"=",
"unescape",
"(",
"location",
".",
"search",
".",
"substring",
"(",
"1",
")",
")",
";",
"var",
"vars",
"=",
"query",
".",
"split",
"(",
"'&'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"vars",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"pair",
"=",
"vars",
"[",
"i",
"]",
".",
"split",
"(",
"'='",
")",
";",
"params",
"[",
"pair",
"[",
"0",
"]",
"]",
"=",
"pair",
"[",
"1",
"]",
";",
"}",
"return",
"params",
";",
"}"
] | Parses query parameters from Location.
@param {Location} location The URL to generate the CSS url for.
@return {Object} Dictionary containing name value pairs for URL | [
"Parses",
"query",
"parameters",
"from",
"Location",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L72-L81 |
5,140 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | setQueryParam | function setQueryParam(location, key, value) {
var query = parseQueryParams(location);
query[encodeURIComponent(key)] = encodeURIComponent(value);
var newQuery = '';
for (var q in query) {
newQuery += (newQuery ? '&' : '?') + q + '=' + query[q];
}
return location.origin + location.pathname + newQuery + location.hash;
} | javascript | function setQueryParam(location, key, value) {
var query = parseQueryParams(location);
query[encodeURIComponent(key)] = encodeURIComponent(value);
var newQuery = '';
for (var q in query) {
newQuery += (newQuery ? '&' : '?') + q + '=' + query[q];
}
return location.origin + location.pathname + newQuery + location.hash;
} | [
"function",
"setQueryParam",
"(",
"location",
",",
"key",
",",
"value",
")",
"{",
"var",
"query",
"=",
"parseQueryParams",
"(",
"location",
")",
";",
"query",
"[",
"encodeURIComponent",
"(",
"key",
")",
"]",
"=",
"encodeURIComponent",
"(",
"value",
")",
";",
"var",
"newQuery",
"=",
"''",
";",
"for",
"(",
"var",
"q",
"in",
"query",
")",
"{",
"newQuery",
"+=",
"(",
"newQuery",
"?",
"'&'",
":",
"'?'",
")",
"+",
"q",
"+",
"'='",
"+",
"query",
"[",
"q",
"]",
";",
"}",
"return",
"location",
".",
"origin",
"+",
"location",
".",
"pathname",
"+",
"newQuery",
"+",
"location",
".",
"hash",
";",
"}"
] | Creates a new URL by appending or replacing the given query key and value.
Not supporting URL with username and password.
@param {Location} location The original URL.
@param {string} key The query parameter name.
@param {string} value The query parameter value.
@return {string} The constructed new URL. | [
"Creates",
"a",
"new",
"URL",
"by",
"appending",
"or",
"replacing",
"the",
"given",
"query",
"key",
"and",
"value",
".",
"Not",
"supporting",
"URL",
"with",
"username",
"and",
"password",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L91-L101 |
5,141 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | disableTextSelectAndDrag | function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) {
// Disable text selection.
document.onselectstart = function(e) {
if (!(opt_allowSelectStart && opt_allowSelectStart.call(this, e)))
e.preventDefault();
};
// Disable dragging.
document.ondragstart = function(e) {
if (!(opt_allowDragStart && opt_allowDragStart.call(this, e)))
e.preventDefault();
};
} | javascript | function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) {
// Disable text selection.
document.onselectstart = function(e) {
if (!(opt_allowSelectStart && opt_allowSelectStart.call(this, e)))
e.preventDefault();
};
// Disable dragging.
document.ondragstart = function(e) {
if (!(opt_allowDragStart && opt_allowDragStart.call(this, e)))
e.preventDefault();
};
} | [
"function",
"disableTextSelectAndDrag",
"(",
"opt_allowSelectStart",
",",
"opt_allowDragStart",
")",
"{",
"// Disable text selection.",
"document",
".",
"onselectstart",
"=",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"(",
"opt_allowSelectStart",
"&&",
"opt_allowSelectStart",
".",
"call",
"(",
"this",
",",
"e",
")",
")",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
";",
"// Disable dragging.",
"document",
".",
"ondragstart",
"=",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"(",
"opt_allowDragStart",
"&&",
"opt_allowDragStart",
".",
"call",
"(",
"this",
",",
"e",
")",
")",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
";",
"}"
] | Disables text selection and dragging, with optional whitelist callbacks.
@param {function(Event):boolean=} opt_allowSelectStart Unless this function
is defined and returns true, the onselectionstart event will be
surpressed.
@param {function(Event):boolean=} opt_allowDragStart Unless this function
is defined and returns true, the ondragstart event will be surpressed. | [
"Disables",
"text",
"selection",
"and",
"dragging",
"with",
"optional",
"whitelist",
"callbacks",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L148-L160 |
5,142 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | queryRequiredElement | function queryRequiredElement(selectors, opt_context) {
var element = (opt_context || document).querySelector(selectors);
return assertInstanceof(element, HTMLElement,
'Missing required element: ' + selectors);
} | javascript | function queryRequiredElement(selectors, opt_context) {
var element = (opt_context || document).querySelector(selectors);
return assertInstanceof(element, HTMLElement,
'Missing required element: ' + selectors);
} | [
"function",
"queryRequiredElement",
"(",
"selectors",
",",
"opt_context",
")",
"{",
"var",
"element",
"=",
"(",
"opt_context",
"||",
"document",
")",
".",
"querySelector",
"(",
"selectors",
")",
";",
"return",
"assertInstanceof",
"(",
"element",
",",
"HTMLElement",
",",
"'Missing required element: '",
"+",
"selectors",
")",
";",
"}"
] | Query an element that's known to exist by a selector. We use this instead of
just calling querySelector and not checking the result because this lets us
satisfy the JSCompiler type system.
@param {string} selectors CSS selectors to query the element.
@param {(!Document|!DocumentFragment|!Element)=} opt_context An optional
context object for querySelector.
@return {!HTMLElement} the Element. | [
"Query",
"an",
"element",
"that",
"s",
"known",
"to",
"exist",
"by",
"a",
"selector",
".",
"We",
"use",
"this",
"instead",
"of",
"just",
"calling",
"querySelector",
"and",
"not",
"checking",
"the",
"result",
"because",
"this",
"lets",
"us",
"satisfy",
"the",
"JSCompiler",
"type",
"system",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L207-L211 |
5,143 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | appendParam | function appendParam(url, key, value) {
var param = encodeURIComponent(key) + '=' + encodeURIComponent(value);
if (url.indexOf('?') == -1)
return url + '?' + param;
return url + '&' + param;
} | javascript | function appendParam(url, key, value) {
var param = encodeURIComponent(key) + '=' + encodeURIComponent(value);
if (url.indexOf('?') == -1)
return url + '?' + param;
return url + '&' + param;
} | [
"function",
"appendParam",
"(",
"url",
",",
"key",
",",
"value",
")",
"{",
"var",
"param",
"=",
"encodeURIComponent",
"(",
"key",
")",
"+",
"'='",
"+",
"encodeURIComponent",
"(",
"value",
")",
";",
"if",
"(",
"url",
".",
"indexOf",
"(",
"'?'",
")",
"==",
"-",
"1",
")",
"return",
"url",
"+",
"'?'",
"+",
"param",
";",
"return",
"url",
"+",
"'&'",
"+",
"param",
";",
"}"
] | Creates a new URL which is the old URL with a GET param of key=value.
@param {string} url The base URL. There is not sanity checking on the URL so
it must be passed in a proper format.
@param {string} key The key of the param.
@param {string} value The value of the param.
@return {string} The new URL. | [
"Creates",
"a",
"new",
"URL",
"which",
"is",
"the",
"old",
"URL",
"with",
"a",
"GET",
"param",
"of",
"key",
"=",
"value",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L250-L256 |
5,144 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | createElementWithClassName | function createElementWithClassName(type, className) {
var elm = document.createElement(type);
elm.className = className;
return elm;
} | javascript | function createElementWithClassName(type, className) {
var elm = document.createElement(type);
elm.className = className;
return elm;
} | [
"function",
"createElementWithClassName",
"(",
"type",
",",
"className",
")",
"{",
"var",
"elm",
"=",
"document",
".",
"createElement",
"(",
"type",
")",
";",
"elm",
".",
"className",
"=",
"className",
";",
"return",
"elm",
";",
"}"
] | Creates an element of a specified type with a specified class name.
@param {string} type The node type.
@param {string} className The class name to use.
@return {Element} The created element. | [
"Creates",
"an",
"element",
"of",
"a",
"specified",
"type",
"with",
"a",
"specified",
"class",
"name",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L264-L268 |
5,145 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | setScrollTopForDocument | function setScrollTopForDocument(doc, value) {
doc.documentElement.scrollTop = doc.body.scrollTop = value;
} | javascript | function setScrollTopForDocument(doc, value) {
doc.documentElement.scrollTop = doc.body.scrollTop = value;
} | [
"function",
"setScrollTopForDocument",
"(",
"doc",
",",
"value",
")",
"{",
"doc",
".",
"documentElement",
".",
"scrollTop",
"=",
"doc",
".",
"body",
".",
"scrollTop",
"=",
"value",
";",
"}"
] | Alias for document.scrollTop setter.
@param {!HTMLDocument} doc The document node where information will be
queried from.
@param {number} value The target Y scroll offset. | [
"Alias",
"for",
"document",
".",
"scrollTop",
"setter",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L315-L317 |
5,146 | catapult-project/catapult | netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js | setScrollLeftForDocument | function setScrollLeftForDocument(doc, value) {
doc.documentElement.scrollLeft = doc.body.scrollLeft = value;
} | javascript | function setScrollLeftForDocument(doc, value) {
doc.documentElement.scrollLeft = doc.body.scrollLeft = value;
} | [
"function",
"setScrollLeftForDocument",
"(",
"doc",
",",
"value",
")",
"{",
"doc",
".",
"documentElement",
".",
"scrollLeft",
"=",
"doc",
".",
"body",
".",
"scrollLeft",
"=",
"value",
";",
"}"
] | Alias for document.scrollLeft setter.
@param {!HTMLDocument} doc The document node where information will be
queried from.
@param {number} value The target X scroll offset. | [
"Alias",
"for",
"document",
".",
"scrollLeft",
"setter",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/netlog_viewer/netlog_viewer/ui_webui_resources_js_util.js#L335-L337 |
5,147 | catapult-project/catapult | tracing/third_party/oboe/src/functional.js | varArgs | function varArgs(fn){
var numberOfFixedArguments = fn.length -1,
slice = Array.prototype.slice;
if( numberOfFixedArguments == 0 ) {
// an optimised case for when there are no fixed args:
return function(){
return fn.call(this, slice.call(arguments));
}
} else if( numberOfFixedArguments == 1 ) {
// an optimised case for when there are is one fixed args:
return function(){
return fn.call(this, arguments[0], slice.call(arguments, 1));
}
}
// general case
// we know how many arguments fn will always take. Create a
// fixed-size array to hold that many, to be re-used on
// every call to the returned function
var argsHolder = Array(fn.length);
return function(){
for (var i = 0; i < numberOfFixedArguments; i++) {
argsHolder[i] = arguments[i];
}
argsHolder[numberOfFixedArguments] =
slice.call(arguments, numberOfFixedArguments);
return fn.apply( this, argsHolder);
}
} | javascript | function varArgs(fn){
var numberOfFixedArguments = fn.length -1,
slice = Array.prototype.slice;
if( numberOfFixedArguments == 0 ) {
// an optimised case for when there are no fixed args:
return function(){
return fn.call(this, slice.call(arguments));
}
} else if( numberOfFixedArguments == 1 ) {
// an optimised case for when there are is one fixed args:
return function(){
return fn.call(this, arguments[0], slice.call(arguments, 1));
}
}
// general case
// we know how many arguments fn will always take. Create a
// fixed-size array to hold that many, to be re-used on
// every call to the returned function
var argsHolder = Array(fn.length);
return function(){
for (var i = 0; i < numberOfFixedArguments; i++) {
argsHolder[i] = arguments[i];
}
argsHolder[numberOfFixedArguments] =
slice.call(arguments, numberOfFixedArguments);
return fn.apply( this, argsHolder);
}
} | [
"function",
"varArgs",
"(",
"fn",
")",
"{",
"var",
"numberOfFixedArguments",
"=",
"fn",
".",
"length",
"-",
"1",
",",
"slice",
"=",
"Array",
".",
"prototype",
".",
"slice",
";",
"if",
"(",
"numberOfFixedArguments",
"==",
"0",
")",
"{",
"// an optimised case for when there are no fixed args: ",
"return",
"function",
"(",
")",
"{",
"return",
"fn",
".",
"call",
"(",
"this",
",",
"slice",
".",
"call",
"(",
"arguments",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"numberOfFixedArguments",
"==",
"1",
")",
"{",
"// an optimised case for when there are is one fixed args:",
"return",
"function",
"(",
")",
"{",
"return",
"fn",
".",
"call",
"(",
"this",
",",
"arguments",
"[",
"0",
"]",
",",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"}",
"}",
"// general case ",
"// we know how many arguments fn will always take. Create a",
"// fixed-size array to hold that many, to be re-used on",
"// every call to the returned function",
"var",
"argsHolder",
"=",
"Array",
"(",
"fn",
".",
"length",
")",
";",
"return",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"numberOfFixedArguments",
";",
"i",
"++",
")",
"{",
"argsHolder",
"[",
"i",
"]",
"=",
"arguments",
"[",
"i",
"]",
";",
"}",
"argsHolder",
"[",
"numberOfFixedArguments",
"]",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"numberOfFixedArguments",
")",
";",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"argsHolder",
")",
";",
"}",
"}"
] | Define variable argument functions but cut out all that tedious messing about
with the arguments object. Delivers the variable-length part of the arguments
list as an array.
Eg:
var myFunction = varArgs(
function( fixedArgument, otherFixedArgument, variableNumberOfArguments ){
console.log( variableNumberOfArguments );
}
)
myFunction('a', 'b', 1, 2, 3); // logs [1,2,3]
var myOtherFunction = varArgs(function( variableNumberOfArguments ){
console.log( variableNumberOfArguments );
})
myFunction(1, 2, 3); // logs [1,2,3] | [
"Define",
"variable",
"argument",
"functions",
"but",
"cut",
"out",
"all",
"that",
"tedious",
"messing",
"about",
"with",
"the",
"arguments",
"object",
".",
"Delivers",
"the",
"variable",
"-",
"length",
"part",
"of",
"the",
"arguments",
"list",
"as",
"an",
"array",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/functional.js#L158-L197 |
5,148 | catapult-project/catapult | tracing/third_party/oboe/src/ascentManager.js | ascentManager | function ascentManager(oboeBus, handlers){
"use strict";
var listenerId = {},
ascent;
function stateAfter(handler) {
return function(param){
ascent = handler( ascent, param);
}
}
for( var eventName in handlers ) {
oboeBus(eventName).on(stateAfter(handlers[eventName]), listenerId);
}
oboeBus(NODE_SWAP).on(function(newNode) {
var oldHead = head(ascent),
key = keyOf(oldHead),
ancestors = tail(ascent),
parentNode;
if( ancestors ) {
parentNode = nodeOf(head(ancestors));
parentNode[key] = newNode;
}
});
oboeBus(NODE_DROP).on(function() {
var oldHead = head(ascent),
key = keyOf(oldHead),
ancestors = tail(ascent),
parentNode;
if( ancestors ) {
parentNode = nodeOf(head(ancestors));
delete parentNode[key];
}
});
oboeBus(ABORTING).on(function(){
for( var eventName in handlers ) {
oboeBus(eventName).un(listenerId);
}
});
} | javascript | function ascentManager(oboeBus, handlers){
"use strict";
var listenerId = {},
ascent;
function stateAfter(handler) {
return function(param){
ascent = handler( ascent, param);
}
}
for( var eventName in handlers ) {
oboeBus(eventName).on(stateAfter(handlers[eventName]), listenerId);
}
oboeBus(NODE_SWAP).on(function(newNode) {
var oldHead = head(ascent),
key = keyOf(oldHead),
ancestors = tail(ascent),
parentNode;
if( ancestors ) {
parentNode = nodeOf(head(ancestors));
parentNode[key] = newNode;
}
});
oboeBus(NODE_DROP).on(function() {
var oldHead = head(ascent),
key = keyOf(oldHead),
ancestors = tail(ascent),
parentNode;
if( ancestors ) {
parentNode = nodeOf(head(ancestors));
delete parentNode[key];
}
});
oboeBus(ABORTING).on(function(){
for( var eventName in handlers ) {
oboeBus(eventName).un(listenerId);
}
});
} | [
"function",
"ascentManager",
"(",
"oboeBus",
",",
"handlers",
")",
"{",
"\"use strict\"",
";",
"var",
"listenerId",
"=",
"{",
"}",
",",
"ascent",
";",
"function",
"stateAfter",
"(",
"handler",
")",
"{",
"return",
"function",
"(",
"param",
")",
"{",
"ascent",
"=",
"handler",
"(",
"ascent",
",",
"param",
")",
";",
"}",
"}",
"for",
"(",
"var",
"eventName",
"in",
"handlers",
")",
"{",
"oboeBus",
"(",
"eventName",
")",
".",
"on",
"(",
"stateAfter",
"(",
"handlers",
"[",
"eventName",
"]",
")",
",",
"listenerId",
")",
";",
"}",
"oboeBus",
"(",
"NODE_SWAP",
")",
".",
"on",
"(",
"function",
"(",
"newNode",
")",
"{",
"var",
"oldHead",
"=",
"head",
"(",
"ascent",
")",
",",
"key",
"=",
"keyOf",
"(",
"oldHead",
")",
",",
"ancestors",
"=",
"tail",
"(",
"ascent",
")",
",",
"parentNode",
";",
"if",
"(",
"ancestors",
")",
"{",
"parentNode",
"=",
"nodeOf",
"(",
"head",
"(",
"ancestors",
")",
")",
";",
"parentNode",
"[",
"key",
"]",
"=",
"newNode",
";",
"}",
"}",
")",
";",
"oboeBus",
"(",
"NODE_DROP",
")",
".",
"on",
"(",
"function",
"(",
")",
"{",
"var",
"oldHead",
"=",
"head",
"(",
"ascent",
")",
",",
"key",
"=",
"keyOf",
"(",
"oldHead",
")",
",",
"ancestors",
"=",
"tail",
"(",
"ascent",
")",
",",
"parentNode",
";",
"if",
"(",
"ancestors",
")",
"{",
"parentNode",
"=",
"nodeOf",
"(",
"head",
"(",
"ancestors",
")",
")",
";",
"delete",
"parentNode",
"[",
"key",
"]",
";",
"}",
"}",
")",
";",
"oboeBus",
"(",
"ABORTING",
")",
".",
"on",
"(",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"eventName",
"in",
"handlers",
")",
"{",
"oboeBus",
"(",
"eventName",
")",
".",
"un",
"(",
"listenerId",
")",
";",
"}",
"}",
")",
";",
"}"
] | A bridge used to assign stateless functions to listen to clarinet.
As well as the parameter from clarinet, each callback will also be passed
the result of the last callback.
This may also be used to clear all listeners by assigning zero handlers:
ascentManager( clarinet, {} ) | [
"A",
"bridge",
"used",
"to",
"assign",
"stateless",
"functions",
"to",
"listen",
"to",
"clarinet",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/ascentManager.js#L12-L62 |
5,149 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/utils/gestures.js | PASSIVE_TOUCH | function PASSIVE_TOUCH(eventName) {
if (isMouseEvent(eventName) || eventName === 'touchend') {
return;
}
if (HAS_NATIVE_TA && SUPPORTS_PASSIVE && passiveTouchGestures) {
return {passive: true};
} else {
return;
}
} | javascript | function PASSIVE_TOUCH(eventName) {
if (isMouseEvent(eventName) || eventName === 'touchend') {
return;
}
if (HAS_NATIVE_TA && SUPPORTS_PASSIVE && passiveTouchGestures) {
return {passive: true};
} else {
return;
}
} | [
"function",
"PASSIVE_TOUCH",
"(",
"eventName",
")",
"{",
"if",
"(",
"isMouseEvent",
"(",
"eventName",
")",
"||",
"eventName",
"===",
"'touchend'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"HAS_NATIVE_TA",
"&&",
"SUPPORTS_PASSIVE",
"&&",
"passiveTouchGestures",
")",
"{",
"return",
"{",
"passive",
":",
"true",
"}",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}"
] | Generate settings for event listeners, dependant on `passiveTouchGestures`
@param {string} eventName Event name to determine if `{passive}` option is
needed
@return {{passive: boolean} | undefined} Options to use for addEventListener
and removeEventListener | [
"Generate",
"settings",
"for",
"event",
"listeners",
"dependant",
"on",
"passiveTouchGestures"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/utils/gestures.js#L67-L76 |
5,150 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/utils/gestures.js | _add | function _add(node, evType, handler) {
let recognizer = gestures[evType];
let deps = recognizer.deps;
let name = recognizer.name;
let gobj = node[GESTURE_KEY];
if (!gobj) {
node[GESTURE_KEY] = gobj = {};
}
for (let i = 0, dep, gd; i < deps.length; i++) {
dep = deps[i];
// don't add mouse handlers on iOS because they cause gray selection overlays
if (IS_TOUCH_ONLY && isMouseEvent(dep) && dep !== 'click') {
continue;
}
gd = gobj[dep];
if (!gd) {
gobj[dep] = gd = {_count: 0};
}
if (gd._count === 0) {
node.addEventListener(dep, _handleNative, PASSIVE_TOUCH(dep));
}
gd[name] = (gd[name] || 0) + 1;
gd._count = (gd._count || 0) + 1;
}
node.addEventListener(evType, handler);
if (recognizer.touchAction) {
setTouchAction(node, recognizer.touchAction);
}
} | javascript | function _add(node, evType, handler) {
let recognizer = gestures[evType];
let deps = recognizer.deps;
let name = recognizer.name;
let gobj = node[GESTURE_KEY];
if (!gobj) {
node[GESTURE_KEY] = gobj = {};
}
for (let i = 0, dep, gd; i < deps.length; i++) {
dep = deps[i];
// don't add mouse handlers on iOS because they cause gray selection overlays
if (IS_TOUCH_ONLY && isMouseEvent(dep) && dep !== 'click') {
continue;
}
gd = gobj[dep];
if (!gd) {
gobj[dep] = gd = {_count: 0};
}
if (gd._count === 0) {
node.addEventListener(dep, _handleNative, PASSIVE_TOUCH(dep));
}
gd[name] = (gd[name] || 0) + 1;
gd._count = (gd._count || 0) + 1;
}
node.addEventListener(evType, handler);
if (recognizer.touchAction) {
setTouchAction(node, recognizer.touchAction);
}
} | [
"function",
"_add",
"(",
"node",
",",
"evType",
",",
"handler",
")",
"{",
"let",
"recognizer",
"=",
"gestures",
"[",
"evType",
"]",
";",
"let",
"deps",
"=",
"recognizer",
".",
"deps",
";",
"let",
"name",
"=",
"recognizer",
".",
"name",
";",
"let",
"gobj",
"=",
"node",
"[",
"GESTURE_KEY",
"]",
";",
"if",
"(",
"!",
"gobj",
")",
"{",
"node",
"[",
"GESTURE_KEY",
"]",
"=",
"gobj",
"=",
"{",
"}",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"dep",
",",
"gd",
";",
"i",
"<",
"deps",
".",
"length",
";",
"i",
"++",
")",
"{",
"dep",
"=",
"deps",
"[",
"i",
"]",
";",
"// don't add mouse handlers on iOS because they cause gray selection overlays",
"if",
"(",
"IS_TOUCH_ONLY",
"&&",
"isMouseEvent",
"(",
"dep",
")",
"&&",
"dep",
"!==",
"'click'",
")",
"{",
"continue",
";",
"}",
"gd",
"=",
"gobj",
"[",
"dep",
"]",
";",
"if",
"(",
"!",
"gd",
")",
"{",
"gobj",
"[",
"dep",
"]",
"=",
"gd",
"=",
"{",
"_count",
":",
"0",
"}",
";",
"}",
"if",
"(",
"gd",
".",
"_count",
"===",
"0",
")",
"{",
"node",
".",
"addEventListener",
"(",
"dep",
",",
"_handleNative",
",",
"PASSIVE_TOUCH",
"(",
"dep",
")",
")",
";",
"}",
"gd",
"[",
"name",
"]",
"=",
"(",
"gd",
"[",
"name",
"]",
"||",
"0",
")",
"+",
"1",
";",
"gd",
".",
"_count",
"=",
"(",
"gd",
".",
"_count",
"||",
"0",
")",
"+",
"1",
";",
"}",
"node",
".",
"addEventListener",
"(",
"evType",
",",
"handler",
")",
";",
"if",
"(",
"recognizer",
".",
"touchAction",
")",
"{",
"setTouchAction",
"(",
"node",
",",
"recognizer",
".",
"touchAction",
")",
";",
"}",
"}"
] | automate the event listeners for the native events
@private
@param {!HTMLElement} node Node on which to add the event.
@param {string} evType Event type to add.
@param {function(!Event)} handler Event handler function.
@return {void}
@this {Gestures} | [
"automate",
"the",
"event",
"listeners",
"for",
"the",
"native",
"events"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/utils/gestures.js#L539-L567 |
5,151 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/utils/gestures.js | _remove | function _remove(node, evType, handler) {
let recognizer = gestures[evType];
let deps = recognizer.deps;
let name = recognizer.name;
let gobj = node[GESTURE_KEY];
if (gobj) {
for (let i = 0, dep, gd; i < deps.length; i++) {
dep = deps[i];
gd = gobj[dep];
if (gd && gd[name]) {
gd[name] = (gd[name] || 1) - 1;
gd._count = (gd._count || 1) - 1;
if (gd._count === 0) {
node.removeEventListener(dep, _handleNative, PASSIVE_TOUCH(dep));
}
}
}
}
node.removeEventListener(evType, handler);
} | javascript | function _remove(node, evType, handler) {
let recognizer = gestures[evType];
let deps = recognizer.deps;
let name = recognizer.name;
let gobj = node[GESTURE_KEY];
if (gobj) {
for (let i = 0, dep, gd; i < deps.length; i++) {
dep = deps[i];
gd = gobj[dep];
if (gd && gd[name]) {
gd[name] = (gd[name] || 1) - 1;
gd._count = (gd._count || 1) - 1;
if (gd._count === 0) {
node.removeEventListener(dep, _handleNative, PASSIVE_TOUCH(dep));
}
}
}
}
node.removeEventListener(evType, handler);
} | [
"function",
"_remove",
"(",
"node",
",",
"evType",
",",
"handler",
")",
"{",
"let",
"recognizer",
"=",
"gestures",
"[",
"evType",
"]",
";",
"let",
"deps",
"=",
"recognizer",
".",
"deps",
";",
"let",
"name",
"=",
"recognizer",
".",
"name",
";",
"let",
"gobj",
"=",
"node",
"[",
"GESTURE_KEY",
"]",
";",
"if",
"(",
"gobj",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"dep",
",",
"gd",
";",
"i",
"<",
"deps",
".",
"length",
";",
"i",
"++",
")",
"{",
"dep",
"=",
"deps",
"[",
"i",
"]",
";",
"gd",
"=",
"gobj",
"[",
"dep",
"]",
";",
"if",
"(",
"gd",
"&&",
"gd",
"[",
"name",
"]",
")",
"{",
"gd",
"[",
"name",
"]",
"=",
"(",
"gd",
"[",
"name",
"]",
"||",
"1",
")",
"-",
"1",
";",
"gd",
".",
"_count",
"=",
"(",
"gd",
".",
"_count",
"||",
"1",
")",
"-",
"1",
";",
"if",
"(",
"gd",
".",
"_count",
"===",
"0",
")",
"{",
"node",
".",
"removeEventListener",
"(",
"dep",
",",
"_handleNative",
",",
"PASSIVE_TOUCH",
"(",
"dep",
")",
")",
";",
"}",
"}",
"}",
"}",
"node",
".",
"removeEventListener",
"(",
"evType",
",",
"handler",
")",
";",
"}"
] | automate event listener removal for native events
@private
@param {!HTMLElement} node Node on which to remove the event.
@param {string} evType Event type to remove.
@param {function(Event?)} handler Event handler function.
@return {void}
@this {Gestures} | [
"automate",
"event",
"listener",
"removal",
"for",
"native",
"events"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/utils/gestures.js#L579-L598 |
5,152 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/utils/gestures.js | _fire | function _fire(target, type, detail) {
let ev = new Event(type, { bubbles: true, cancelable: true, composed: true });
ev.detail = detail;
target.dispatchEvent(ev);
// forward `preventDefault` in a clean way
if (ev.defaultPrevented) {
let preventer = detail.preventer || detail.sourceEvent;
if (preventer && preventer.preventDefault) {
preventer.preventDefault();
}
}
} | javascript | function _fire(target, type, detail) {
let ev = new Event(type, { bubbles: true, cancelable: true, composed: true });
ev.detail = detail;
target.dispatchEvent(ev);
// forward `preventDefault` in a clean way
if (ev.defaultPrevented) {
let preventer = detail.preventer || detail.sourceEvent;
if (preventer && preventer.preventDefault) {
preventer.preventDefault();
}
}
} | [
"function",
"_fire",
"(",
"target",
",",
"type",
",",
"detail",
")",
"{",
"let",
"ev",
"=",
"new",
"Event",
"(",
"type",
",",
"{",
"bubbles",
":",
"true",
",",
"cancelable",
":",
"true",
",",
"composed",
":",
"true",
"}",
")",
";",
"ev",
".",
"detail",
"=",
"detail",
";",
"target",
".",
"dispatchEvent",
"(",
"ev",
")",
";",
"// forward `preventDefault` in a clean way",
"if",
"(",
"ev",
".",
"defaultPrevented",
")",
"{",
"let",
"preventer",
"=",
"detail",
".",
"preventer",
"||",
"detail",
".",
"sourceEvent",
";",
"if",
"(",
"preventer",
"&&",
"preventer",
".",
"preventDefault",
")",
"{",
"preventer",
".",
"preventDefault",
"(",
")",
";",
"}",
"}",
"}"
] | Dispatches an event on the `target` element of `type` with the given
`detail`.
@private
@param {!EventTarget} target The element on which to fire an event.
@param {string} type The type of event to fire.
@param {!Object=} detail The detail object to populate on the event.
@return {void} | [
"Dispatches",
"an",
"event",
"on",
"the",
"target",
"element",
"of",
"type",
"with",
"the",
"given",
"detail",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/utils/gestures.js#L666-L677 |
5,153 | catapult-project/catapult | tracing/third_party/oboe/src/pubSub.js | pubSub | function pubSub(){
var singles = {},
newListener = newSingle('newListener'),
removeListener = newSingle('removeListener');
function newSingle(eventName) {
return singles[eventName] = singleEventPubSub(
eventName,
newListener,
removeListener
);
}
/** pubSub instances are functions */
function pubSubInstance( eventName ){
return singles[eventName] || newSingle( eventName );
}
// add convenience EventEmitter-style uncurried form of 'emit' and 'on'
['emit', 'on', 'un'].forEach(function(methodName){
pubSubInstance[methodName] = varArgs(function(eventName, parameters){
apply( parameters, pubSubInstance( eventName )[methodName]);
});
});
return pubSubInstance;
} | javascript | function pubSub(){
var singles = {},
newListener = newSingle('newListener'),
removeListener = newSingle('removeListener');
function newSingle(eventName) {
return singles[eventName] = singleEventPubSub(
eventName,
newListener,
removeListener
);
}
/** pubSub instances are functions */
function pubSubInstance( eventName ){
return singles[eventName] || newSingle( eventName );
}
// add convenience EventEmitter-style uncurried form of 'emit' and 'on'
['emit', 'on', 'un'].forEach(function(methodName){
pubSubInstance[methodName] = varArgs(function(eventName, parameters){
apply( parameters, pubSubInstance( eventName )[methodName]);
});
});
return pubSubInstance;
} | [
"function",
"pubSub",
"(",
")",
"{",
"var",
"singles",
"=",
"{",
"}",
",",
"newListener",
"=",
"newSingle",
"(",
"'newListener'",
")",
",",
"removeListener",
"=",
"newSingle",
"(",
"'removeListener'",
")",
";",
"function",
"newSingle",
"(",
"eventName",
")",
"{",
"return",
"singles",
"[",
"eventName",
"]",
"=",
"singleEventPubSub",
"(",
"eventName",
",",
"newListener",
",",
"removeListener",
")",
";",
"}",
"/** pubSub instances are functions */",
"function",
"pubSubInstance",
"(",
"eventName",
")",
"{",
"return",
"singles",
"[",
"eventName",
"]",
"||",
"newSingle",
"(",
"eventName",
")",
";",
"}",
"// add convenience EventEmitter-style uncurried form of 'emit' and 'on'",
"[",
"'emit'",
",",
"'on'",
",",
"'un'",
"]",
".",
"forEach",
"(",
"function",
"(",
"methodName",
")",
"{",
"pubSubInstance",
"[",
"methodName",
"]",
"=",
"varArgs",
"(",
"function",
"(",
"eventName",
",",
"parameters",
")",
"{",
"apply",
"(",
"parameters",
",",
"pubSubInstance",
"(",
"eventName",
")",
"[",
"methodName",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"return",
"pubSubInstance",
";",
"}"
] | pubSub is a curried interface for listening to and emitting
events.
If we get a bus:
var bus = pubSub();
We can listen to event 'foo' like:
bus('foo').on(myCallback)
And emit event foo like:
bus('foo').emit()
or, with a parameter:
bus('foo').emit('bar')
All functions can be cached and don't need to be
bound. Ie:
var fooEmitter = bus('foo').emit
fooEmitter('bar'); // emit an event
fooEmitter('baz'); // emit another
There's also an uncurried[1] shortcut for .emit and .on:
bus.on('foo', callback)
bus.emit('foo', 'bar')
[1]: http://zvon.org/other/haskell/Outputprelude/uncurry_f.html | [
"pubSub",
"is",
"a",
"curried",
"interface",
"for",
"listening",
"to",
"and",
"emitting",
"events",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/pubSub.js#L35-L64 |
5,154 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | listAsArray | function listAsArray(list){
return foldR( function(arraySoFar, listItem){
arraySoFar.unshift(listItem);
return arraySoFar;
}, [], list );
} | javascript | function listAsArray(list){
return foldR( function(arraySoFar, listItem){
arraySoFar.unshift(listItem);
return arraySoFar;
}, [], list );
} | [
"function",
"listAsArray",
"(",
"list",
")",
"{",
"return",
"foldR",
"(",
"function",
"(",
"arraySoFar",
",",
"listItem",
")",
"{",
"arraySoFar",
".",
"unshift",
"(",
"listItem",
")",
";",
"return",
"arraySoFar",
";",
"}",
",",
"[",
"]",
",",
"list",
")",
";",
"}"
] | Convert a list back to a js native array | [
"Convert",
"a",
"list",
"back",
"to",
"a",
"js",
"native",
"array"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L75-L84 |
5,155 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | map | function map(fn, list) {
return list
? cons(fn(head(list)), map(fn,tail(list)))
: emptyList
;
} | javascript | function map(fn, list) {
return list
? cons(fn(head(list)), map(fn,tail(list)))
: emptyList
;
} | [
"function",
"map",
"(",
"fn",
",",
"list",
")",
"{",
"return",
"list",
"?",
"cons",
"(",
"fn",
"(",
"head",
"(",
"list",
")",
")",
",",
"map",
"(",
"fn",
",",
"tail",
"(",
"list",
")",
")",
")",
":",
"emptyList",
";",
"}"
] | Map a function over a list | [
"Map",
"a",
"function",
"over",
"a",
"list"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L89-L95 |
5,156 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | without | function without(list, test, removedFn) {
return withoutInner(list, removedFn || noop);
function withoutInner(subList, removedFn) {
return subList
? ( test(head(subList))
? (removedFn(head(subList)), tail(subList))
: cons(head(subList), withoutInner(tail(subList), removedFn))
)
: emptyList
;
}
} | javascript | function without(list, test, removedFn) {
return withoutInner(list, removedFn || noop);
function withoutInner(subList, removedFn) {
return subList
? ( test(head(subList))
? (removedFn(head(subList)), tail(subList))
: cons(head(subList), withoutInner(tail(subList), removedFn))
)
: emptyList
;
}
} | [
"function",
"without",
"(",
"list",
",",
"test",
",",
"removedFn",
")",
"{",
"return",
"withoutInner",
"(",
"list",
",",
"removedFn",
"||",
"noop",
")",
";",
"function",
"withoutInner",
"(",
"subList",
",",
"removedFn",
")",
"{",
"return",
"subList",
"?",
"(",
"test",
"(",
"head",
"(",
"subList",
")",
")",
"?",
"(",
"removedFn",
"(",
"head",
"(",
"subList",
")",
")",
",",
"tail",
"(",
"subList",
")",
")",
":",
"cons",
"(",
"head",
"(",
"subList",
")",
",",
"withoutInner",
"(",
"tail",
"(",
"subList",
")",
",",
"removedFn",
")",
")",
")",
":",
"emptyList",
";",
"}",
"}"
] | Return a list like the one given but with the first instance equal
to item removed | [
"Return",
"a",
"list",
"like",
"the",
"one",
"given",
"but",
"with",
"the",
"first",
"instance",
"equal",
"to",
"item",
"removed"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L128-L141 |
5,157 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | all | function all(fn, list) {
return !list ||
( fn(head(list)) && all(fn, tail(list)) );
} | javascript | function all(fn, list) {
return !list ||
( fn(head(list)) && all(fn, tail(list)) );
} | [
"function",
"all",
"(",
"fn",
",",
"list",
")",
"{",
"return",
"!",
"list",
"||",
"(",
"fn",
"(",
"head",
"(",
"list",
")",
")",
"&&",
"all",
"(",
"fn",
",",
"tail",
"(",
"list",
")",
")",
")",
";",
"}"
] | Returns true if the given function holds for every item in
the list, false otherwise | [
"Returns",
"true",
"if",
"the",
"given",
"function",
"holds",
"for",
"every",
"item",
"in",
"the",
"list",
"false",
"otherwise"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L147-L151 |
5,158 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | applyEach | function applyEach(fnList, args) {
if( fnList ) {
head(fnList).apply(null, args);
applyEach(tail(fnList), args);
}
} | javascript | function applyEach(fnList, args) {
if( fnList ) {
head(fnList).apply(null, args);
applyEach(tail(fnList), args);
}
} | [
"function",
"applyEach",
"(",
"fnList",
",",
"args",
")",
"{",
"if",
"(",
"fnList",
")",
"{",
"head",
"(",
"fnList",
")",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"applyEach",
"(",
"tail",
"(",
"fnList",
")",
",",
"args",
")",
";",
"}",
"}"
] | Call every function in a list of functions with the same arguments
This doesn't make any sense if we're doing pure functional because
it doesn't return anything. Hence, this is only really useful if the
functions being called have side-effects. | [
"Call",
"every",
"function",
"in",
"a",
"list",
"of",
"functions",
"with",
"the",
"same",
"arguments"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L160-L167 |
5,159 | catapult-project/catapult | tracing/third_party/oboe/src/lists.js | reverseList | function reverseList(list){
// js re-implementation of 3rd solution from:
// http://www.haskell.org/haskellwiki/99_questions/Solutions/5
function reverseInner( list, reversedAlready ) {
if( !list ) {
return reversedAlready;
}
return reverseInner(tail(list), cons(head(list), reversedAlready))
}
return reverseInner(list, emptyList);
} | javascript | function reverseList(list){
// js re-implementation of 3rd solution from:
// http://www.haskell.org/haskellwiki/99_questions/Solutions/5
function reverseInner( list, reversedAlready ) {
if( !list ) {
return reversedAlready;
}
return reverseInner(tail(list), cons(head(list), reversedAlready))
}
return reverseInner(list, emptyList);
} | [
"function",
"reverseList",
"(",
"list",
")",
"{",
"// js re-implementation of 3rd solution from:",
"// http://www.haskell.org/haskellwiki/99_questions/Solutions/5",
"function",
"reverseInner",
"(",
"list",
",",
"reversedAlready",
")",
"{",
"if",
"(",
"!",
"list",
")",
"{",
"return",
"reversedAlready",
";",
"}",
"return",
"reverseInner",
"(",
"tail",
"(",
"list",
")",
",",
"cons",
"(",
"head",
"(",
"list",
")",
",",
"reversedAlready",
")",
")",
"}",
"return",
"reverseInner",
"(",
"list",
",",
"emptyList",
")",
";",
"}"
] | Reverse the order of a list | [
"Reverse",
"the",
"order",
"of",
"a",
"list"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/lists.js#L172-L185 |
5,160 | catapult-project/catapult | dashboard/dashboard/spa/alerts-section.js | handleBatch | function handleBatch(results, showingTriaged) {
const alerts = [];
const nextRequests = [];
const triagedRequests = [];
let totalCount = 0;
for (const {body, response} of results) {
alerts.push.apply(alerts, response.anomalies);
if (body.count_limit) totalCount += response.count;
const cursor = response.next_cursor;
if (cursor) {
const request = {...body, cursor};
delete request.count_limit;
nextRequests.push(request);
}
if (!showingTriaged && body.bug_id === '') {
// Prepare to fetch triaged alerts for the untriaged alerts that
// were just received.
const request = {...body, bug_id: '*'};
delete request.recovered;
delete request.count_limit;
delete request.cursor;
delete request.is_improvement;
triagedRequests.push(request);
}
}
return {alerts, nextRequests, triagedRequests, totalCount};
} | javascript | function handleBatch(results, showingTriaged) {
const alerts = [];
const nextRequests = [];
const triagedRequests = [];
let totalCount = 0;
for (const {body, response} of results) {
alerts.push.apply(alerts, response.anomalies);
if (body.count_limit) totalCount += response.count;
const cursor = response.next_cursor;
if (cursor) {
const request = {...body, cursor};
delete request.count_limit;
nextRequests.push(request);
}
if (!showingTriaged && body.bug_id === '') {
// Prepare to fetch triaged alerts for the untriaged alerts that
// were just received.
const request = {...body, bug_id: '*'};
delete request.recovered;
delete request.count_limit;
delete request.cursor;
delete request.is_improvement;
triagedRequests.push(request);
}
}
return {alerts, nextRequests, triagedRequests, totalCount};
} | [
"function",
"handleBatch",
"(",
"results",
",",
"showingTriaged",
")",
"{",
"const",
"alerts",
"=",
"[",
"]",
";",
"const",
"nextRequests",
"=",
"[",
"]",
";",
"const",
"triagedRequests",
"=",
"[",
"]",
";",
"let",
"totalCount",
"=",
"0",
";",
"for",
"(",
"const",
"{",
"body",
",",
"response",
"}",
"of",
"results",
")",
"{",
"alerts",
".",
"push",
".",
"apply",
"(",
"alerts",
",",
"response",
".",
"anomalies",
")",
";",
"if",
"(",
"body",
".",
"count_limit",
")",
"totalCount",
"+=",
"response",
".",
"count",
";",
"const",
"cursor",
"=",
"response",
".",
"next_cursor",
";",
"if",
"(",
"cursor",
")",
"{",
"const",
"request",
"=",
"{",
"...",
"body",
",",
"cursor",
"}",
";",
"delete",
"request",
".",
"count_limit",
";",
"nextRequests",
".",
"push",
"(",
"request",
")",
";",
"}",
"if",
"(",
"!",
"showingTriaged",
"&&",
"body",
".",
"bug_id",
"===",
"''",
")",
"{",
"// Prepare to fetch triaged alerts for the untriaged alerts that",
"// were just received.",
"const",
"request",
"=",
"{",
"...",
"body",
",",
"bug_id",
":",
"'*'",
"}",
";",
"delete",
"request",
".",
"recovered",
";",
"delete",
"request",
".",
"count_limit",
";",
"delete",
"request",
".",
"cursor",
";",
"delete",
"request",
".",
"is_improvement",
";",
"triagedRequests",
".",
"push",
"(",
"request",
")",
";",
"}",
"}",
"return",
"{",
"alerts",
",",
"nextRequests",
",",
"triagedRequests",
",",
"totalCount",
"}",
";",
"}"
] | The BatchIterator in actions.loadAlerts yielded a batch of results. Collect all alerts from all batches into `alerts`. Chase cursors in `nextRequests`. Fetch triaged alerts when a request for untriaged alerts returns. | [
"The",
"BatchIterator",
"in",
"actions",
".",
"loadAlerts",
"yielded",
"a",
"batch",
"of",
"results",
".",
"Collect",
"all",
"alerts",
"from",
"all",
"batches",
"into",
"alerts",
".",
"Chase",
"cursors",
"in",
"nextRequests",
".",
"Fetch",
"triaged",
"alerts",
"when",
"a",
"request",
"for",
"untriaged",
"alerts",
"returns",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/dashboard/dashboard/spa/alerts-section.js#L291-L321 |
5,161 | catapult-project/catapult | dashboard/dashboard/spa/alerts-section.js | loadMore | function loadMore(batches, alertGroups, nextRequests, triagedRequests,
triagedMaxStartRevision, started) {
const minStartRevision = tr.b.math.Statistics.min(
alertGroups, group => tr.b.math.Statistics.min(
group.alerts, a => a.startRevision));
if (!triagedMaxStartRevision ||
(minStartRevision < triagedMaxStartRevision)) {
for (const request of triagedRequests) {
request.min_start_revision = minStartRevision;
if (triagedMaxStartRevision) {
request.max_start_revision = triagedMaxStartRevision;
}
batches.add(wrapRequest(request));
}
}
for (const next of nextRequests) {
// Always chase down cursors for triaged alerts.
// Limit the number of alertGroups displayed to prevent OOM.
if (next.bug_id === '*' ||
(alertGroups.length < ENOUGH_GROUPS &&
((performance.now() - started) < ENOUGH_LOADING_MS))) {
batches.add(wrapRequest(next));
}
}
return minStartRevision;
} | javascript | function loadMore(batches, alertGroups, nextRequests, triagedRequests,
triagedMaxStartRevision, started) {
const minStartRevision = tr.b.math.Statistics.min(
alertGroups, group => tr.b.math.Statistics.min(
group.alerts, a => a.startRevision));
if (!triagedMaxStartRevision ||
(minStartRevision < triagedMaxStartRevision)) {
for (const request of triagedRequests) {
request.min_start_revision = minStartRevision;
if (triagedMaxStartRevision) {
request.max_start_revision = triagedMaxStartRevision;
}
batches.add(wrapRequest(request));
}
}
for (const next of nextRequests) {
// Always chase down cursors for triaged alerts.
// Limit the number of alertGroups displayed to prevent OOM.
if (next.bug_id === '*' ||
(alertGroups.length < ENOUGH_GROUPS &&
((performance.now() - started) < ENOUGH_LOADING_MS))) {
batches.add(wrapRequest(next));
}
}
return minStartRevision;
} | [
"function",
"loadMore",
"(",
"batches",
",",
"alertGroups",
",",
"nextRequests",
",",
"triagedRequests",
",",
"triagedMaxStartRevision",
",",
"started",
")",
"{",
"const",
"minStartRevision",
"=",
"tr",
".",
"b",
".",
"math",
".",
"Statistics",
".",
"min",
"(",
"alertGroups",
",",
"group",
"=>",
"tr",
".",
"b",
".",
"math",
".",
"Statistics",
".",
"min",
"(",
"group",
".",
"alerts",
",",
"a",
"=>",
"a",
".",
"startRevision",
")",
")",
";",
"if",
"(",
"!",
"triagedMaxStartRevision",
"||",
"(",
"minStartRevision",
"<",
"triagedMaxStartRevision",
")",
")",
"{",
"for",
"(",
"const",
"request",
"of",
"triagedRequests",
")",
"{",
"request",
".",
"min_start_revision",
"=",
"minStartRevision",
";",
"if",
"(",
"triagedMaxStartRevision",
")",
"{",
"request",
".",
"max_start_revision",
"=",
"triagedMaxStartRevision",
";",
"}",
"batches",
".",
"add",
"(",
"wrapRequest",
"(",
"request",
")",
")",
";",
"}",
"}",
"for",
"(",
"const",
"next",
"of",
"nextRequests",
")",
"{",
"// Always chase down cursors for triaged alerts.",
"// Limit the number of alertGroups displayed to prevent OOM.",
"if",
"(",
"next",
".",
"bug_id",
"===",
"'*'",
"||",
"(",
"alertGroups",
".",
"length",
"<",
"ENOUGH_GROUPS",
"&&",
"(",
"(",
"performance",
".",
"now",
"(",
")",
"-",
"started",
")",
"<",
"ENOUGH_LOADING_MS",
")",
")",
")",
"{",
"batches",
".",
"add",
"(",
"wrapRequest",
"(",
"next",
")",
")",
";",
"}",
"}",
"return",
"minStartRevision",
";",
"}"
] | This function may add requests to `batches`. See handleBatch for `nextRequests` and `triagedRequests`. | [
"This",
"function",
"may",
"add",
"requests",
"to",
"batches",
".",
"See",
"handleBatch",
"for",
"nextRequests",
"and",
"triagedRequests",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/dashboard/dashboard/spa/alerts-section.js#L325-L353 |
5,162 | catapult-project/catapult | tracing/third_party/oboe/src/patternAdapter.js | patternAdapter | function patternAdapter(oboeBus, jsonPathCompiler) {
var predicateEventMap = {
node:oboeBus(NODE_CLOSED)
, path:oboeBus(NODE_OPENED)
};
function emitMatchingNode(emitMatch, node, ascent) {
/*
We're now calling to the outside world where Lisp-style
lists will not be familiar. Convert to standard arrays.
Also, reverse the order because it is more common to
list paths "root to leaf" than "leaf to root" */
var descent = reverseList(ascent);
emitMatch(
node,
// To make a path, strip off the last item which is the special
// ROOT_PATH token for the 'path' to the root node
listAsArray(tail(map(keyOf,descent))), // path
listAsArray(map(nodeOf, descent)) // ancestors
);
}
/*
* Set up the catching of events such as NODE_CLOSED and NODE_OPENED and, if
* matching the specified pattern, propagate to pattern-match events such as
* oboeBus('node:!')
*
*
*
* @param {Function} predicateEvent
* either oboeBus(NODE_CLOSED) or oboeBus(NODE_OPENED).
* @param {Function} compiledJsonPath
*/
function addUnderlyingListener( fullEventName, predicateEvent, compiledJsonPath ){
var emitMatch = oboeBus(fullEventName).emit;
predicateEvent.on( function (ascent) {
var maybeMatchingMapping = compiledJsonPath(ascent);
/* Possible values for maybeMatchingMapping are now:
false:
we did not match
an object/array/string/number/null:
we matched and have the node that matched.
Because nulls are valid json values this can be null.
undefined:
we matched but don't have the matching node yet.
ie, we know there is an upcoming node that matches but we
can't say anything else about it.
*/
if (maybeMatchingMapping !== false) {
emitMatchingNode(
emitMatch,
nodeOf(maybeMatchingMapping),
ascent
);
}
}, fullEventName);
oboeBus('removeListener').on( function(removedEventName){
// if the fully qualified match event listener is later removed, clean up
// by removing the underlying listener if it was the last using that pattern:
if( removedEventName == fullEventName ) {
if( !oboeBus(removedEventName).listeners( )) {
predicateEvent.un( fullEventName );
}
}
});
}
oboeBus('newListener').on( function(fullEventName){
var match = /(node|path):(.*)/.exec(fullEventName);
if( match ) {
var predicateEvent = predicateEventMap[match[1]];
if( !predicateEvent.hasListener( fullEventName) ) {
addUnderlyingListener(
fullEventName,
predicateEvent,
jsonPathCompiler( match[2] )
);
}
}
})
} | javascript | function patternAdapter(oboeBus, jsonPathCompiler) {
var predicateEventMap = {
node:oboeBus(NODE_CLOSED)
, path:oboeBus(NODE_OPENED)
};
function emitMatchingNode(emitMatch, node, ascent) {
/*
We're now calling to the outside world where Lisp-style
lists will not be familiar. Convert to standard arrays.
Also, reverse the order because it is more common to
list paths "root to leaf" than "leaf to root" */
var descent = reverseList(ascent);
emitMatch(
node,
// To make a path, strip off the last item which is the special
// ROOT_PATH token for the 'path' to the root node
listAsArray(tail(map(keyOf,descent))), // path
listAsArray(map(nodeOf, descent)) // ancestors
);
}
/*
* Set up the catching of events such as NODE_CLOSED and NODE_OPENED and, if
* matching the specified pattern, propagate to pattern-match events such as
* oboeBus('node:!')
*
*
*
* @param {Function} predicateEvent
* either oboeBus(NODE_CLOSED) or oboeBus(NODE_OPENED).
* @param {Function} compiledJsonPath
*/
function addUnderlyingListener( fullEventName, predicateEvent, compiledJsonPath ){
var emitMatch = oboeBus(fullEventName).emit;
predicateEvent.on( function (ascent) {
var maybeMatchingMapping = compiledJsonPath(ascent);
/* Possible values for maybeMatchingMapping are now:
false:
we did not match
an object/array/string/number/null:
we matched and have the node that matched.
Because nulls are valid json values this can be null.
undefined:
we matched but don't have the matching node yet.
ie, we know there is an upcoming node that matches but we
can't say anything else about it.
*/
if (maybeMatchingMapping !== false) {
emitMatchingNode(
emitMatch,
nodeOf(maybeMatchingMapping),
ascent
);
}
}, fullEventName);
oboeBus('removeListener').on( function(removedEventName){
// if the fully qualified match event listener is later removed, clean up
// by removing the underlying listener if it was the last using that pattern:
if( removedEventName == fullEventName ) {
if( !oboeBus(removedEventName).listeners( )) {
predicateEvent.un( fullEventName );
}
}
});
}
oboeBus('newListener').on( function(fullEventName){
var match = /(node|path):(.*)/.exec(fullEventName);
if( match ) {
var predicateEvent = predicateEventMap[match[1]];
if( !predicateEvent.hasListener( fullEventName) ) {
addUnderlyingListener(
fullEventName,
predicateEvent,
jsonPathCompiler( match[2] )
);
}
}
})
} | [
"function",
"patternAdapter",
"(",
"oboeBus",
",",
"jsonPathCompiler",
")",
"{",
"var",
"predicateEventMap",
"=",
"{",
"node",
":",
"oboeBus",
"(",
"NODE_CLOSED",
")",
",",
"path",
":",
"oboeBus",
"(",
"NODE_OPENED",
")",
"}",
";",
"function",
"emitMatchingNode",
"(",
"emitMatch",
",",
"node",
",",
"ascent",
")",
"{",
"/* \n We're now calling to the outside world where Lisp-style \n lists will not be familiar. Convert to standard arrays. \n \n Also, reverse the order because it is more common to \n list paths \"root to leaf\" than \"leaf to root\" */",
"var",
"descent",
"=",
"reverseList",
"(",
"ascent",
")",
";",
"emitMatch",
"(",
"node",
",",
"// To make a path, strip off the last item which is the special",
"// ROOT_PATH token for the 'path' to the root node ",
"listAsArray",
"(",
"tail",
"(",
"map",
"(",
"keyOf",
",",
"descent",
")",
")",
")",
",",
"// path",
"listAsArray",
"(",
"map",
"(",
"nodeOf",
",",
"descent",
")",
")",
"// ancestors ",
")",
";",
"}",
"/* \n * Set up the catching of events such as NODE_CLOSED and NODE_OPENED and, if \n * matching the specified pattern, propagate to pattern-match events such as \n * oboeBus('node:!')\n * \n * \n * \n * @param {Function} predicateEvent \n * either oboeBus(NODE_CLOSED) or oboeBus(NODE_OPENED).\n * @param {Function} compiledJsonPath \n */",
"function",
"addUnderlyingListener",
"(",
"fullEventName",
",",
"predicateEvent",
",",
"compiledJsonPath",
")",
"{",
"var",
"emitMatch",
"=",
"oboeBus",
"(",
"fullEventName",
")",
".",
"emit",
";",
"predicateEvent",
".",
"on",
"(",
"function",
"(",
"ascent",
")",
"{",
"var",
"maybeMatchingMapping",
"=",
"compiledJsonPath",
"(",
"ascent",
")",
";",
"/* Possible values for maybeMatchingMapping are now:\n\n false: \n we did not match \n\n an object/array/string/number/null: \n we matched and have the node that matched.\n Because nulls are valid json values this can be null.\n\n undefined:\n we matched but don't have the matching node yet.\n ie, we know there is an upcoming node that matches but we \n can't say anything else about it. \n */",
"if",
"(",
"maybeMatchingMapping",
"!==",
"false",
")",
"{",
"emitMatchingNode",
"(",
"emitMatch",
",",
"nodeOf",
"(",
"maybeMatchingMapping",
")",
",",
"ascent",
")",
";",
"}",
"}",
",",
"fullEventName",
")",
";",
"oboeBus",
"(",
"'removeListener'",
")",
".",
"on",
"(",
"function",
"(",
"removedEventName",
")",
"{",
"// if the fully qualified match event listener is later removed, clean up ",
"// by removing the underlying listener if it was the last using that pattern:",
"if",
"(",
"removedEventName",
"==",
"fullEventName",
")",
"{",
"if",
"(",
"!",
"oboeBus",
"(",
"removedEventName",
")",
".",
"listeners",
"(",
")",
")",
"{",
"predicateEvent",
".",
"un",
"(",
"fullEventName",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"oboeBus",
"(",
"'newListener'",
")",
".",
"on",
"(",
"function",
"(",
"fullEventName",
")",
"{",
"var",
"match",
"=",
"/",
"(node|path):(.*)",
"/",
".",
"exec",
"(",
"fullEventName",
")",
";",
"if",
"(",
"match",
")",
"{",
"var",
"predicateEvent",
"=",
"predicateEventMap",
"[",
"match",
"[",
"1",
"]",
"]",
";",
"if",
"(",
"!",
"predicateEvent",
".",
"hasListener",
"(",
"fullEventName",
")",
")",
"{",
"addUnderlyingListener",
"(",
"fullEventName",
",",
"predicateEvent",
",",
"jsonPathCompiler",
"(",
"match",
"[",
"2",
"]",
")",
")",
";",
"}",
"}",
"}",
")",
"}"
] | The pattern adaptor listens for newListener and removeListener
events. When patterns are added or removed it compiles the JSONPath
and wires them up.
When nodes and paths are found it emits the fully-qualified match
events with parameters ready to ship to the outside world | [
"The",
"pattern",
"adaptor",
"listens",
"for",
"newListener",
"and",
"removeListener",
"events",
".",
"When",
"patterns",
"are",
"added",
"or",
"removed",
"it",
"compiles",
"the",
"JSONPath",
"and",
"wires",
"them",
"up",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/patternAdapter.js#L10-L112 |
5,163 | catapult-project/catapult | tracing/third_party/oboe/src/instanceApi.js | protectedCallback | function protectedCallback( callback ) {
return function() {
try{
return callback.apply(oboeApi, arguments);
}catch(e) {
setTimeout(function() {
throw new Error(e.message);
});
}
}
} | javascript | function protectedCallback( callback ) {
return function() {
try{
return callback.apply(oboeApi, arguments);
}catch(e) {
setTimeout(function() {
throw new Error(e.message);
});
}
}
} | [
"function",
"protectedCallback",
"(",
"callback",
")",
"{",
"return",
"function",
"(",
")",
"{",
"try",
"{",
"return",
"callback",
".",
"apply",
"(",
"oboeApi",
",",
"arguments",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"throw",
"new",
"Error",
"(",
"e",
".",
"message",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] | wrap a callback so that if it throws, Oboe.js doesn't crash but instead
throw the error in another event loop | [
"wrap",
"a",
"callback",
"so",
"that",
"if",
"it",
"throws",
"Oboe",
".",
"js",
"doesn",
"t",
"crash",
"but",
"instead",
"throw",
"the",
"error",
"in",
"another",
"event",
"loop"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/instanceApi.js#L126-L136 |
5,164 | catapult-project/catapult | tracing/third_party/oboe/src/instanceApi.js | addMultipleNodeOrPathListeners | function addMultipleNodeOrPathListeners(eventId, listenerMap) {
for( var pattern in listenerMap ) {
addSingleNodeOrPathListener(eventId, pattern, listenerMap[pattern]);
}
} | javascript | function addMultipleNodeOrPathListeners(eventId, listenerMap) {
for( var pattern in listenerMap ) {
addSingleNodeOrPathListener(eventId, pattern, listenerMap[pattern]);
}
} | [
"function",
"addMultipleNodeOrPathListeners",
"(",
"eventId",
",",
"listenerMap",
")",
"{",
"for",
"(",
"var",
"pattern",
"in",
"listenerMap",
")",
"{",
"addSingleNodeOrPathListener",
"(",
"eventId",
",",
"pattern",
",",
"listenerMap",
"[",
"pattern",
"]",
")",
";",
"}",
"}"
] | Add several listeners at a time, from a map | [
"Add",
"several",
"listeners",
"at",
"a",
"time",
"from",
"a",
"map"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/instanceApi.js#L183-L188 |
5,165 | catapult-project/catapult | third_party/polymer2/bower_components/web-animations-js/src/handler-utils.js | consumeParenthesised | function consumeParenthesised(parser, string) {
var nesting = 0;
for (var n = 0; n < string.length; n++) {
if (/\s|,/.test(string[n]) && nesting == 0) {
break;
} else if (string[n] == '(') {
nesting++;
} else if (string[n] == ')') {
nesting--;
if (nesting == 0)
n++;
if (nesting <= 0)
break;
}
}
var parsed = parser(string.substr(0, n));
return parsed == undefined ? undefined : [parsed, string.substr(n)];
} | javascript | function consumeParenthesised(parser, string) {
var nesting = 0;
for (var n = 0; n < string.length; n++) {
if (/\s|,/.test(string[n]) && nesting == 0) {
break;
} else if (string[n] == '(') {
nesting++;
} else if (string[n] == ')') {
nesting--;
if (nesting == 0)
n++;
if (nesting <= 0)
break;
}
}
var parsed = parser(string.substr(0, n));
return parsed == undefined ? undefined : [parsed, string.substr(n)];
} | [
"function",
"consumeParenthesised",
"(",
"parser",
",",
"string",
")",
"{",
"var",
"nesting",
"=",
"0",
";",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"string",
".",
"length",
";",
"n",
"++",
")",
"{",
"if",
"(",
"/",
"\\s|,",
"/",
".",
"test",
"(",
"string",
"[",
"n",
"]",
")",
"&&",
"nesting",
"==",
"0",
")",
"{",
"break",
";",
"}",
"else",
"if",
"(",
"string",
"[",
"n",
"]",
"==",
"'('",
")",
"{",
"nesting",
"++",
";",
"}",
"else",
"if",
"(",
"string",
"[",
"n",
"]",
"==",
"')'",
")",
"{",
"nesting",
"--",
";",
"if",
"(",
"nesting",
"==",
"0",
")",
"n",
"++",
";",
"if",
"(",
"nesting",
"<=",
"0",
")",
"break",
";",
"}",
"}",
"var",
"parsed",
"=",
"parser",
"(",
"string",
".",
"substr",
"(",
"0",
",",
"n",
")",
")",
";",
"return",
"parsed",
"==",
"undefined",
"?",
"undefined",
":",
"[",
"parsed",
",",
"string",
".",
"substr",
"(",
"n",
")",
"]",
";",
"}"
] | Consumes a token or expression with balanced parentheses | [
"Consumes",
"a",
"token",
"or",
"expression",
"with",
"balanced",
"parentheses"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer2/bower_components/web-animations-js/src/handler-utils.js#L55-L72 |
5,166 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | doScrollCheck | function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
} | javascript | function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
} | [
"function",
"doScrollCheck",
"(",
")",
"{",
"if",
"(",
"jQuery",
".",
"isReady",
")",
"{",
"return",
";",
"}",
"try",
"{",
"// If IE is used, use the trick by Diego Perini",
"// http://javascript.nwbox.com/IEContentLoaded/",
"document",
".",
"documentElement",
".",
"doScroll",
"(",
"\"left\"",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"setTimeout",
"(",
"doScrollCheck",
",",
"1",
")",
";",
"return",
";",
"}",
"// and execute any waiting functions",
"jQuery",
".",
"ready",
"(",
")",
";",
"}"
] | The DOM ready check for Internet Explorer | [
"The",
"DOM",
"ready",
"check",
"for",
"Internet",
"Explorer"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L937-L953 |
5,167 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | createFlags | function createFlags( flags ) {
var object = flagsCache[ flags ] = {},
i, length;
flags = flags.split( /\s+/ );
for ( i = 0, length = flags.length; i < length; i++ ) {
object[ flags[i] ] = true;
}
return object;
} | javascript | function createFlags( flags ) {
var object = flagsCache[ flags ] = {},
i, length;
flags = flags.split( /\s+/ );
for ( i = 0, length = flags.length; i < length; i++ ) {
object[ flags[i] ] = true;
}
return object;
} | [
"function",
"createFlags",
"(",
"flags",
")",
"{",
"var",
"object",
"=",
"flagsCache",
"[",
"flags",
"]",
"=",
"{",
"}",
",",
"i",
",",
"length",
";",
"flags",
"=",
"flags",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"for",
"(",
"i",
"=",
"0",
",",
"length",
"=",
"flags",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"object",
"[",
"flags",
"[",
"i",
"]",
"]",
"=",
"true",
";",
"}",
"return",
"object",
";",
"}"
] | Convert String-formatted flags into Object-formatted ones and store in cache | [
"Convert",
"String",
"-",
"formatted",
"flags",
"into",
"Object",
"-",
"formatted",
"ones",
"and",
"store",
"in",
"cache"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L964-L972 |
5,168 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | function( obj ) {
if ( obj == null ) {
obj = promise;
} else {
for ( var key in promise ) {
obj[ key ] = promise[ key ];
}
}
return obj;
} | javascript | function( obj ) {
if ( obj == null ) {
obj = promise;
} else {
for ( var key in promise ) {
obj[ key ] = promise[ key ];
}
}
return obj;
} | [
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"{",
"obj",
"=",
"promise",
";",
"}",
"else",
"{",
"for",
"(",
"var",
"key",
"in",
"promise",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"promise",
"[",
"key",
"]",
";",
"}",
"}",
"return",
"obj",
";",
"}"
] | Get a promise for this deferred If obj is provided, the promise aspect is added to the object | [
"Get",
"a",
"promise",
"for",
"this",
"deferred",
"If",
"obj",
"is",
"provided",
"the",
"promise",
"aspect",
"is",
"added",
"to",
"the",
"object"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L1249-L1258 |
|
5,169 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | isEmptyDataObject | function isEmptyDataObject( obj ) {
for ( var name in obj ) {
// if the public data object is empty, the private is still empty
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
continue;
}
if ( name !== "toJSON" ) {
return false;
}
}
return true;
} | javascript | function isEmptyDataObject( obj ) {
for ( var name in obj ) {
// if the public data object is empty, the private is still empty
if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
continue;
}
if ( name !== "toJSON" ) {
return false;
}
}
return true;
} | [
"function",
"isEmptyDataObject",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"obj",
")",
"{",
"// if the public data object is empty, the private is still empty",
"if",
"(",
"name",
"===",
"\"data\"",
"&&",
"jQuery",
".",
"isEmptyObject",
"(",
"obj",
"[",
"name",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"name",
"!==",
"\"toJSON\"",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | checks a cache object for emptiness | [
"checks",
"a",
"cache",
"object",
"for",
"emptiness"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L1962-L1975 |
5,170 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | fixDefaultChecked | function fixDefaultChecked( elem ) {
if ( elem.type === "checkbox" || elem.type === "radio" ) {
elem.defaultChecked = elem.checked;
}
} | javascript | function fixDefaultChecked( elem ) {
if ( elem.type === "checkbox" || elem.type === "radio" ) {
elem.defaultChecked = elem.checked;
}
} | [
"function",
"fixDefaultChecked",
"(",
"elem",
")",
"{",
"if",
"(",
"elem",
".",
"type",
"===",
"\"checkbox\"",
"||",
"elem",
".",
"type",
"===",
"\"radio\"",
")",
"{",
"elem",
".",
"defaultChecked",
"=",
"elem",
".",
"checked",
";",
"}",
"}"
] | Used in clean, fixes the defaultChecked property | [
"Used",
"in",
"clean",
"fixes",
"the",
"defaultChecked",
"property"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L6176-L6180 |
5,171 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | findInputs | function findInputs( elem ) {
var nodeName = ( elem.nodeName || "" ).toLowerCase();
if ( nodeName === "input" ) {
fixDefaultChecked( elem );
// Skip scripts, get other children
} else if ( nodeName !== "script" && typeof elem.getElementsByTagName !== "undefined" ) {
jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
}
} | javascript | function findInputs( elem ) {
var nodeName = ( elem.nodeName || "" ).toLowerCase();
if ( nodeName === "input" ) {
fixDefaultChecked( elem );
// Skip scripts, get other children
} else if ( nodeName !== "script" && typeof elem.getElementsByTagName !== "undefined" ) {
jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
}
} | [
"function",
"findInputs",
"(",
"elem",
")",
"{",
"var",
"nodeName",
"=",
"(",
"elem",
".",
"nodeName",
"||",
"\"\"",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"nodeName",
"===",
"\"input\"",
")",
"{",
"fixDefaultChecked",
"(",
"elem",
")",
";",
"// Skip scripts, get other children",
"}",
"else",
"if",
"(",
"nodeName",
"!==",
"\"script\"",
"&&",
"typeof",
"elem",
".",
"getElementsByTagName",
"!==",
"\"undefined\"",
")",
"{",
"jQuery",
".",
"grep",
"(",
"elem",
".",
"getElementsByTagName",
"(",
"\"input\"",
")",
",",
"fixDefaultChecked",
")",
";",
"}",
"}"
] | Finds all inputs and passes them to fixDefaultChecked | [
"Finds",
"all",
"inputs",
"and",
"passes",
"them",
"to",
"fixDefaultChecked"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L6182-L6190 |
5,172 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js | ajaxConvert | function ajaxConvert( s, response ) {
// Apply the dataFilter if provided
if ( s.dataFilter ) {
response = s.dataFilter( response, s.dataType );
}
var dataTypes = s.dataTypes,
converters = {},
i,
key,
length = dataTypes.length,
tmp,
// Current and previous dataTypes
current = dataTypes[ 0 ],
prev,
// Conversion expression
conversion,
// Conversion function
conv,
// Conversion functions (transitive conversion)
conv1,
conv2;
// For each dataType in the chain
for ( i = 1; i < length; i++ ) {
// Create converters map
// with lowercased keys
if ( i === 1 ) {
for ( key in s.converters ) {
if ( typeof key === "string" ) {
converters[ key.toLowerCase() ] = s.converters[ key ];
}
}
}
// Get the dataTypes
prev = current;
current = dataTypes[ i ];
// If current is auto dataType, update it to prev
if ( current === "*" ) {
current = prev;
// If no auto and dataTypes are actually different
} else if ( prev !== "*" && prev !== current ) {
// Get the converter
conversion = prev + " " + current;
conv = converters[ conversion ] || converters[ "* " + current ];
// If there is no direct converter, search transitively
if ( !conv ) {
conv2 = undefined;
for ( conv1 in converters ) {
tmp = conv1.split( " " );
if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
conv2 = converters[ tmp[1] + " " + current ];
if ( conv2 ) {
conv1 = converters[ conv1 ];
if ( conv1 === true ) {
conv = conv2;
} else if ( conv2 === true ) {
conv = conv1;
}
break;
}
}
}
}
// If we found no converter, dispatch an error
if ( !( conv || conv2 ) ) {
jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
}
// If found converter is not an equivalence
if ( conv !== true ) {
// Convert with 1 or 2 converters accordingly
response = conv ? conv( response ) : conv2( conv1(response) );
}
}
}
return response;
} | javascript | function ajaxConvert( s, response ) {
// Apply the dataFilter if provided
if ( s.dataFilter ) {
response = s.dataFilter( response, s.dataType );
}
var dataTypes = s.dataTypes,
converters = {},
i,
key,
length = dataTypes.length,
tmp,
// Current and previous dataTypes
current = dataTypes[ 0 ],
prev,
// Conversion expression
conversion,
// Conversion function
conv,
// Conversion functions (transitive conversion)
conv1,
conv2;
// For each dataType in the chain
for ( i = 1; i < length; i++ ) {
// Create converters map
// with lowercased keys
if ( i === 1 ) {
for ( key in s.converters ) {
if ( typeof key === "string" ) {
converters[ key.toLowerCase() ] = s.converters[ key ];
}
}
}
// Get the dataTypes
prev = current;
current = dataTypes[ i ];
// If current is auto dataType, update it to prev
if ( current === "*" ) {
current = prev;
// If no auto and dataTypes are actually different
} else if ( prev !== "*" && prev !== current ) {
// Get the converter
conversion = prev + " " + current;
conv = converters[ conversion ] || converters[ "* " + current ];
// If there is no direct converter, search transitively
if ( !conv ) {
conv2 = undefined;
for ( conv1 in converters ) {
tmp = conv1.split( " " );
if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
conv2 = converters[ tmp[1] + " " + current ];
if ( conv2 ) {
conv1 = converters[ conv1 ];
if ( conv1 === true ) {
conv = conv2;
} else if ( conv2 === true ) {
conv = conv1;
}
break;
}
}
}
}
// If we found no converter, dispatch an error
if ( !( conv || conv2 ) ) {
jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
}
// If found converter is not an equivalence
if ( conv !== true ) {
// Convert with 1 or 2 converters accordingly
response = conv ? conv( response ) : conv2( conv1(response) );
}
}
}
return response;
} | [
"function",
"ajaxConvert",
"(",
"s",
",",
"response",
")",
"{",
"// Apply the dataFilter if provided",
"if",
"(",
"s",
".",
"dataFilter",
")",
"{",
"response",
"=",
"s",
".",
"dataFilter",
"(",
"response",
",",
"s",
".",
"dataType",
")",
";",
"}",
"var",
"dataTypes",
"=",
"s",
".",
"dataTypes",
",",
"converters",
"=",
"{",
"}",
",",
"i",
",",
"key",
",",
"length",
"=",
"dataTypes",
".",
"length",
",",
"tmp",
",",
"// Current and previous dataTypes",
"current",
"=",
"dataTypes",
"[",
"0",
"]",
",",
"prev",
",",
"// Conversion expression",
"conversion",
",",
"// Conversion function",
"conv",
",",
"// Conversion functions (transitive conversion)",
"conv1",
",",
"conv2",
";",
"// For each dataType in the chain",
"for",
"(",
"i",
"=",
"1",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"// Create converters map",
"// with lowercased keys",
"if",
"(",
"i",
"===",
"1",
")",
"{",
"for",
"(",
"key",
"in",
"s",
".",
"converters",
")",
"{",
"if",
"(",
"typeof",
"key",
"===",
"\"string\"",
")",
"{",
"converters",
"[",
"key",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"s",
".",
"converters",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"// Get the dataTypes",
"prev",
"=",
"current",
";",
"current",
"=",
"dataTypes",
"[",
"i",
"]",
";",
"// If current is auto dataType, update it to prev",
"if",
"(",
"current",
"===",
"\"*\"",
")",
"{",
"current",
"=",
"prev",
";",
"// If no auto and dataTypes are actually different",
"}",
"else",
"if",
"(",
"prev",
"!==",
"\"*\"",
"&&",
"prev",
"!==",
"current",
")",
"{",
"// Get the converter",
"conversion",
"=",
"prev",
"+",
"\" \"",
"+",
"current",
";",
"conv",
"=",
"converters",
"[",
"conversion",
"]",
"||",
"converters",
"[",
"\"* \"",
"+",
"current",
"]",
";",
"// If there is no direct converter, search transitively",
"if",
"(",
"!",
"conv",
")",
"{",
"conv2",
"=",
"undefined",
";",
"for",
"(",
"conv1",
"in",
"converters",
")",
"{",
"tmp",
"=",
"conv1",
".",
"split",
"(",
"\" \"",
")",
";",
"if",
"(",
"tmp",
"[",
"0",
"]",
"===",
"prev",
"||",
"tmp",
"[",
"0",
"]",
"===",
"\"*\"",
")",
"{",
"conv2",
"=",
"converters",
"[",
"tmp",
"[",
"1",
"]",
"+",
"\" \"",
"+",
"current",
"]",
";",
"if",
"(",
"conv2",
")",
"{",
"conv1",
"=",
"converters",
"[",
"conv1",
"]",
";",
"if",
"(",
"conv1",
"===",
"true",
")",
"{",
"conv",
"=",
"conv2",
";",
"}",
"else",
"if",
"(",
"conv2",
"===",
"true",
")",
"{",
"conv",
"=",
"conv1",
";",
"}",
"break",
";",
"}",
"}",
"}",
"}",
"// If we found no converter, dispatch an error",
"if",
"(",
"!",
"(",
"conv",
"||",
"conv2",
")",
")",
"{",
"jQuery",
".",
"error",
"(",
"\"No conversion from \"",
"+",
"conversion",
".",
"replace",
"(",
"\" \"",
",",
"\" to \"",
")",
")",
";",
"}",
"// If found converter is not an equivalence",
"if",
"(",
"conv",
"!==",
"true",
")",
"{",
"// Convert with 1 or 2 converters accordingly",
"response",
"=",
"conv",
"?",
"conv",
"(",
"response",
")",
":",
"conv2",
"(",
"conv1",
"(",
"response",
")",
")",
";",
"}",
"}",
"}",
"return",
"response",
";",
"}"
] | Chain conversions given the request and the original response | [
"Chain",
"conversions",
"given",
"the",
"request",
"and",
"the",
"original",
"response"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/jquery-1.7.1.js#L7745-L7827 |
5,173 | catapult-project/catapult | telemetry/telemetry/internal/actions/media_action.js | onError | function onError(e) {
window.__error = 'Media error: ' + e.type + ', code:' + e.target.error.code;
throw new Error(window.__error);
} | javascript | function onError(e) {
window.__error = 'Media error: ' + e.type + ', code:' + e.target.error.code;
throw new Error(window.__error);
} | [
"function",
"onError",
"(",
"e",
")",
"{",
"window",
".",
"__error",
"=",
"'Media error: '",
"+",
"e",
".",
"type",
"+",
"', code:'",
"+",
"e",
".",
"target",
".",
"error",
".",
"code",
";",
"throw",
"new",
"Error",
"(",
"window",
".",
"__error",
")",
";",
"}"
] | Listens to HTML5 media errors. | [
"Listens",
"to",
"HTML5",
"media",
"errors",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/telemetry/telemetry/internal/actions/media_action.js#L42-L45 |
5,174 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/markermanager.js | GridBounds | function GridBounds(bounds) {
// [sw, ne]
this.minX = Math.min(bounds[0].x, bounds[1].x);
this.maxX = Math.max(bounds[0].x, bounds[1].x);
this.minY = Math.min(bounds[0].y, bounds[1].y);
this.maxY = Math.max(bounds[0].y, bounds[1].y);
} | javascript | function GridBounds(bounds) {
// [sw, ne]
this.minX = Math.min(bounds[0].x, bounds[1].x);
this.maxX = Math.max(bounds[0].x, bounds[1].x);
this.minY = Math.min(bounds[0].y, bounds[1].y);
this.maxY = Math.max(bounds[0].y, bounds[1].y);
} | [
"function",
"GridBounds",
"(",
"bounds",
")",
"{",
"// [sw, ne]",
"this",
".",
"minX",
"=",
"Math",
".",
"min",
"(",
"bounds",
"[",
"0",
"]",
".",
"x",
",",
"bounds",
"[",
"1",
"]",
".",
"x",
")",
";",
"this",
".",
"maxX",
"=",
"Math",
".",
"max",
"(",
"bounds",
"[",
"0",
"]",
".",
"x",
",",
"bounds",
"[",
"1",
"]",
".",
"x",
")",
";",
"this",
".",
"minY",
"=",
"Math",
".",
"min",
"(",
"bounds",
"[",
"0",
"]",
".",
"y",
",",
"bounds",
"[",
"1",
"]",
".",
"y",
")",
";",
"this",
".",
"maxY",
"=",
"Math",
".",
"max",
"(",
"bounds",
"[",
"0",
"]",
".",
"y",
",",
"bounds",
"[",
"1",
"]",
".",
"y",
")",
";",
"}"
] | Helper class to create a bounds of INT ranges.
@param bounds Array.<Object.<string, number>> Bounds object.
@constructor | [
"Helper",
"class",
"to",
"create",
"a",
"bounds",
"of",
"INT",
"ranges",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/markermanager.js#L485-L493 |
5,175 | catapult-project/catapult | common/py_vulcanize/third_party/rjsmin/bench/markermanager.js | ProjectionHelperOverlay | function ProjectionHelperOverlay(map) {
this.setMap(map);
var TILEFACTOR = 8;
var TILESIDE = 1 << TILEFACTOR;
var RADIUS = 7;
this._map = map;
this._zoom = -1;
this._X0 =
this._Y0 =
this._X1 =
this._Y1 = -1;
} | javascript | function ProjectionHelperOverlay(map) {
this.setMap(map);
var TILEFACTOR = 8;
var TILESIDE = 1 << TILEFACTOR;
var RADIUS = 7;
this._map = map;
this._zoom = -1;
this._X0 =
this._Y0 =
this._X1 =
this._Y1 = -1;
} | [
"function",
"ProjectionHelperOverlay",
"(",
"map",
")",
"{",
"this",
".",
"setMap",
"(",
"map",
")",
";",
"var",
"TILEFACTOR",
"=",
"8",
";",
"var",
"TILESIDE",
"=",
"1",
"<<",
"TILEFACTOR",
";",
"var",
"RADIUS",
"=",
"7",
";",
"this",
".",
"_map",
"=",
"map",
";",
"this",
".",
"_zoom",
"=",
"-",
"1",
";",
"this",
".",
"_X0",
"=",
"this",
".",
"_Y0",
"=",
"this",
".",
"_X1",
"=",
"this",
".",
"_Y1",
"=",
"-",
"1",
";",
"}"
] | Projection overlay helper. Helps in calculating
that markers get into the right grid.
@constructor
@param {Map} map The map to manage. | [
"Projection",
"overlay",
"helper",
".",
"Helps",
"in",
"calculating",
"that",
"markers",
"get",
"into",
"the",
"right",
"grid",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/common/py_vulcanize/third_party/rjsmin/bench/markermanager.js#L912-L928 |
5,176 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | hasAllProperties | function hasAllProperties(fieldList, o) {
return (o instanceof Object)
&&
all(function (field) {
return (field in o);
}, fieldList);
} | javascript | function hasAllProperties(fieldList, o) {
return (o instanceof Object)
&&
all(function (field) {
return (field in o);
}, fieldList);
} | [
"function",
"hasAllProperties",
"(",
"fieldList",
",",
"o",
")",
"{",
"return",
"(",
"o",
"instanceof",
"Object",
")",
"&&",
"all",
"(",
"function",
"(",
"field",
")",
"{",
"return",
"(",
"field",
"in",
"o",
")",
";",
"}",
",",
"fieldList",
")",
";",
"}"
] | Returns true if object o has a key named like every property in
the properties array. Will give false if any are missing, or if o
is not an object. | [
"Returns",
"true",
"if",
"object",
"o",
"has",
"a",
"key",
"named",
"like",
"every",
"property",
"in",
"the",
"properties",
"array",
".",
"Will",
"give",
"false",
"if",
"any",
"are",
"missing",
"or",
"if",
"o",
"is",
"not",
"an",
"object",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L326-L333 |
5,177 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | incrementalContentBuilder | function incrementalContentBuilder( oboeBus ) {
var emitNodeOpened = oboeBus(NODE_OPENED).emit,
emitNodeClosed = oboeBus(NODE_CLOSED).emit,
emitRootOpened = oboeBus(ROOT_PATH_FOUND).emit,
emitRootClosed = oboeBus(ROOT_NODE_FOUND).emit;
function arrayIndicesAreKeys( possiblyInconsistentAscent, newDeepestNode) {
/* for values in arrays we aren't pre-warned of the coming paths
(Clarinet gives no call to onkey like it does for values in objects)
so if we are in an array we need to create this path ourselves. The
key will be len(parentNode) because array keys are always sequential
numbers. */
var parentNode = nodeOf( head( possiblyInconsistentAscent));
return isOfType( Array, parentNode)
?
keyFound( possiblyInconsistentAscent,
len(parentNode),
newDeepestNode
)
:
// nothing needed, return unchanged
possiblyInconsistentAscent
;
}
function nodeOpened( ascent, newDeepestNode ) {
if( !ascent ) {
// we discovered the root node,
emitRootOpened( newDeepestNode);
return keyFound( ascent, ROOT_PATH, newDeepestNode);
}
// we discovered a non-root node
var arrayConsistentAscent = arrayIndicesAreKeys( ascent, newDeepestNode),
ancestorBranches = tail( arrayConsistentAscent),
previouslyUnmappedName = keyOf( head( arrayConsistentAscent));
appendBuiltContent(
ancestorBranches,
previouslyUnmappedName,
newDeepestNode
);
return cons(
namedNode( previouslyUnmappedName, newDeepestNode ),
ancestorBranches
);
}
/**
* Add a new value to the object we are building up to represent the
* parsed JSON
*/
function appendBuiltContent( ancestorBranches, key, node ){
nodeOf( head( ancestorBranches))[key] = node;
}
/**
* For when we find a new key in the json.
*
* @param {String|Number|Object} newDeepestName the key. If we are in an
* array will be a number, otherwise a string. May take the special
* value ROOT_PATH if the root node has just been found
*
* @param {String|Number|Object|Array|Null|undefined} [maybeNewDeepestNode]
* usually this won't be known so can be undefined. Can't use null
* to represent unknown because null is a valid value in JSON
**/
function keyFound(ascent, newDeepestName, maybeNewDeepestNode) {
if( ascent ) { // if not root
// If we have the key but (unless adding to an array) no known value
// yet. Put that key in the output but against no defined value:
appendBuiltContent( ascent, newDeepestName, maybeNewDeepestNode );
}
var ascentWithNewPath = cons(
namedNode( newDeepestName,
maybeNewDeepestNode),
ascent
);
emitNodeOpened( ascentWithNewPath);
return ascentWithNewPath;
}
/**
* For when the current node ends.
*/
function nodeClosed( ascent ) {
emitNodeClosed( ascent);
return tail( ascent) ||
// If there are no nodes left in the ascent the root node
// just closed. Emit a special event for this:
emitRootClosed(nodeOf(head(ascent)));
}
var contentBuilderHandlers = {};
contentBuilderHandlers[SAX_VALUE_OPEN] = nodeOpened;
contentBuilderHandlers[SAX_VALUE_CLOSE] = nodeClosed;
contentBuilderHandlers[SAX_KEY] = keyFound;
return contentBuilderHandlers;
} | javascript | function incrementalContentBuilder( oboeBus ) {
var emitNodeOpened = oboeBus(NODE_OPENED).emit,
emitNodeClosed = oboeBus(NODE_CLOSED).emit,
emitRootOpened = oboeBus(ROOT_PATH_FOUND).emit,
emitRootClosed = oboeBus(ROOT_NODE_FOUND).emit;
function arrayIndicesAreKeys( possiblyInconsistentAscent, newDeepestNode) {
/* for values in arrays we aren't pre-warned of the coming paths
(Clarinet gives no call to onkey like it does for values in objects)
so if we are in an array we need to create this path ourselves. The
key will be len(parentNode) because array keys are always sequential
numbers. */
var parentNode = nodeOf( head( possiblyInconsistentAscent));
return isOfType( Array, parentNode)
?
keyFound( possiblyInconsistentAscent,
len(parentNode),
newDeepestNode
)
:
// nothing needed, return unchanged
possiblyInconsistentAscent
;
}
function nodeOpened( ascent, newDeepestNode ) {
if( !ascent ) {
// we discovered the root node,
emitRootOpened( newDeepestNode);
return keyFound( ascent, ROOT_PATH, newDeepestNode);
}
// we discovered a non-root node
var arrayConsistentAscent = arrayIndicesAreKeys( ascent, newDeepestNode),
ancestorBranches = tail( arrayConsistentAscent),
previouslyUnmappedName = keyOf( head( arrayConsistentAscent));
appendBuiltContent(
ancestorBranches,
previouslyUnmappedName,
newDeepestNode
);
return cons(
namedNode( previouslyUnmappedName, newDeepestNode ),
ancestorBranches
);
}
/**
* Add a new value to the object we are building up to represent the
* parsed JSON
*/
function appendBuiltContent( ancestorBranches, key, node ){
nodeOf( head( ancestorBranches))[key] = node;
}
/**
* For when we find a new key in the json.
*
* @param {String|Number|Object} newDeepestName the key. If we are in an
* array will be a number, otherwise a string. May take the special
* value ROOT_PATH if the root node has just been found
*
* @param {String|Number|Object|Array|Null|undefined} [maybeNewDeepestNode]
* usually this won't be known so can be undefined. Can't use null
* to represent unknown because null is a valid value in JSON
**/
function keyFound(ascent, newDeepestName, maybeNewDeepestNode) {
if( ascent ) { // if not root
// If we have the key but (unless adding to an array) no known value
// yet. Put that key in the output but against no defined value:
appendBuiltContent( ascent, newDeepestName, maybeNewDeepestNode );
}
var ascentWithNewPath = cons(
namedNode( newDeepestName,
maybeNewDeepestNode),
ascent
);
emitNodeOpened( ascentWithNewPath);
return ascentWithNewPath;
}
/**
* For when the current node ends.
*/
function nodeClosed( ascent ) {
emitNodeClosed( ascent);
return tail( ascent) ||
// If there are no nodes left in the ascent the root node
// just closed. Emit a special event for this:
emitRootClosed(nodeOf(head(ascent)));
}
var contentBuilderHandlers = {};
contentBuilderHandlers[SAX_VALUE_OPEN] = nodeOpened;
contentBuilderHandlers[SAX_VALUE_CLOSE] = nodeClosed;
contentBuilderHandlers[SAX_KEY] = keyFound;
return contentBuilderHandlers;
} | [
"function",
"incrementalContentBuilder",
"(",
"oboeBus",
")",
"{",
"var",
"emitNodeOpened",
"=",
"oboeBus",
"(",
"NODE_OPENED",
")",
".",
"emit",
",",
"emitNodeClosed",
"=",
"oboeBus",
"(",
"NODE_CLOSED",
")",
".",
"emit",
",",
"emitRootOpened",
"=",
"oboeBus",
"(",
"ROOT_PATH_FOUND",
")",
".",
"emit",
",",
"emitRootClosed",
"=",
"oboeBus",
"(",
"ROOT_NODE_FOUND",
")",
".",
"emit",
";",
"function",
"arrayIndicesAreKeys",
"(",
"possiblyInconsistentAscent",
",",
"newDeepestNode",
")",
"{",
"/* for values in arrays we aren't pre-warned of the coming paths \n (Clarinet gives no call to onkey like it does for values in objects) \n so if we are in an array we need to create this path ourselves. The \n key will be len(parentNode) because array keys are always sequential \n numbers. */",
"var",
"parentNode",
"=",
"nodeOf",
"(",
"head",
"(",
"possiblyInconsistentAscent",
")",
")",
";",
"return",
"isOfType",
"(",
"Array",
",",
"parentNode",
")",
"?",
"keyFound",
"(",
"possiblyInconsistentAscent",
",",
"len",
"(",
"parentNode",
")",
",",
"newDeepestNode",
")",
":",
"// nothing needed, return unchanged",
"possiblyInconsistentAscent",
";",
"}",
"function",
"nodeOpened",
"(",
"ascent",
",",
"newDeepestNode",
")",
"{",
"if",
"(",
"!",
"ascent",
")",
"{",
"// we discovered the root node, ",
"emitRootOpened",
"(",
"newDeepestNode",
")",
";",
"return",
"keyFound",
"(",
"ascent",
",",
"ROOT_PATH",
",",
"newDeepestNode",
")",
";",
"}",
"// we discovered a non-root node",
"var",
"arrayConsistentAscent",
"=",
"arrayIndicesAreKeys",
"(",
"ascent",
",",
"newDeepestNode",
")",
",",
"ancestorBranches",
"=",
"tail",
"(",
"arrayConsistentAscent",
")",
",",
"previouslyUnmappedName",
"=",
"keyOf",
"(",
"head",
"(",
"arrayConsistentAscent",
")",
")",
";",
"appendBuiltContent",
"(",
"ancestorBranches",
",",
"previouslyUnmappedName",
",",
"newDeepestNode",
")",
";",
"return",
"cons",
"(",
"namedNode",
"(",
"previouslyUnmappedName",
",",
"newDeepestNode",
")",
",",
"ancestorBranches",
")",
";",
"}",
"/**\n * Add a new value to the object we are building up to represent the\n * parsed JSON\n */",
"function",
"appendBuiltContent",
"(",
"ancestorBranches",
",",
"key",
",",
"node",
")",
"{",
"nodeOf",
"(",
"head",
"(",
"ancestorBranches",
")",
")",
"[",
"key",
"]",
"=",
"node",
";",
"}",
"/**\n * For when we find a new key in the json.\n * \n * @param {String|Number|Object} newDeepestName the key. If we are in an \n * array will be a number, otherwise a string. May take the special \n * value ROOT_PATH if the root node has just been found\n * \n * @param {String|Number|Object|Array|Null|undefined} [maybeNewDeepestNode] \n * usually this won't be known so can be undefined. Can't use null \n * to represent unknown because null is a valid value in JSON\n **/",
"function",
"keyFound",
"(",
"ascent",
",",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
"{",
"if",
"(",
"ascent",
")",
"{",
"// if not root",
"// If we have the key but (unless adding to an array) no known value",
"// yet. Put that key in the output but against no defined value: ",
"appendBuiltContent",
"(",
"ascent",
",",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
";",
"}",
"var",
"ascentWithNewPath",
"=",
"cons",
"(",
"namedNode",
"(",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
",",
"ascent",
")",
";",
"emitNodeOpened",
"(",
"ascentWithNewPath",
")",
";",
"return",
"ascentWithNewPath",
";",
"}",
"/**\n * For when the current node ends.\n */",
"function",
"nodeClosed",
"(",
"ascent",
")",
"{",
"emitNodeClosed",
"(",
"ascent",
")",
";",
"return",
"tail",
"(",
"ascent",
")",
"||",
"// If there are no nodes left in the ascent the root node",
"// just closed. Emit a special event for this: ",
"emitRootClosed",
"(",
"nodeOf",
"(",
"head",
"(",
"ascent",
")",
")",
")",
";",
"}",
"var",
"contentBuilderHandlers",
"=",
"{",
"}",
";",
"contentBuilderHandlers",
"[",
"SAX_VALUE_OPEN",
"]",
"=",
"nodeOpened",
";",
"contentBuilderHandlers",
"[",
"SAX_VALUE_CLOSE",
"]",
"=",
"nodeClosed",
";",
"contentBuilderHandlers",
"[",
"SAX_KEY",
"]",
"=",
"keyFound",
";",
"return",
"contentBuilderHandlers",
";",
"}"
] | Create a new set of handlers for clarinet's events, bound to the emit
function given. | [
"Create",
"a",
"new",
"set",
"of",
"handlers",
"for",
"clarinet",
"s",
"events",
"bound",
"to",
"the",
"emit",
"function",
"given",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1390-L1507 |
5,178 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | keyFound | function keyFound(ascent, newDeepestName, maybeNewDeepestNode) {
if( ascent ) { // if not root
// If we have the key but (unless adding to an array) no known value
// yet. Put that key in the output but against no defined value:
appendBuiltContent( ascent, newDeepestName, maybeNewDeepestNode );
}
var ascentWithNewPath = cons(
namedNode( newDeepestName,
maybeNewDeepestNode),
ascent
);
emitNodeOpened( ascentWithNewPath);
return ascentWithNewPath;
} | javascript | function keyFound(ascent, newDeepestName, maybeNewDeepestNode) {
if( ascent ) { // if not root
// If we have the key but (unless adding to an array) no known value
// yet. Put that key in the output but against no defined value:
appendBuiltContent( ascent, newDeepestName, maybeNewDeepestNode );
}
var ascentWithNewPath = cons(
namedNode( newDeepestName,
maybeNewDeepestNode),
ascent
);
emitNodeOpened( ascentWithNewPath);
return ascentWithNewPath;
} | [
"function",
"keyFound",
"(",
"ascent",
",",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
"{",
"if",
"(",
"ascent",
")",
"{",
"// if not root",
"// If we have the key but (unless adding to an array) no known value",
"// yet. Put that key in the output but against no defined value: ",
"appendBuiltContent",
"(",
"ascent",
",",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
";",
"}",
"var",
"ascentWithNewPath",
"=",
"cons",
"(",
"namedNode",
"(",
"newDeepestName",
",",
"maybeNewDeepestNode",
")",
",",
"ascent",
")",
";",
"emitNodeOpened",
"(",
"ascentWithNewPath",
")",
";",
"return",
"ascentWithNewPath",
";",
"}"
] | For when we find a new key in the json.
@param {String|Number|Object} newDeepestName the key. If we are in an
array will be a number, otherwise a string. May take the special
value ROOT_PATH if the root node has just been found
@param {String|Number|Object|Array|Null|undefined} [maybeNewDeepestNode]
usually this won't be known so can be undefined. Can't use null
to represent unknown because null is a valid value in JSON | [
"For",
"when",
"we",
"find",
"a",
"new",
"key",
"in",
"the",
"json",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1468-L1486 |
5,179 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | nodeClosed | function nodeClosed( ascent ) {
emitNodeClosed( ascent);
return tail( ascent) ||
// If there are no nodes left in the ascent the root node
// just closed. Emit a special event for this:
emitRootClosed(nodeOf(head(ascent)));
} | javascript | function nodeClosed( ascent ) {
emitNodeClosed( ascent);
return tail( ascent) ||
// If there are no nodes left in the ascent the root node
// just closed. Emit a special event for this:
emitRootClosed(nodeOf(head(ascent)));
} | [
"function",
"nodeClosed",
"(",
"ascent",
")",
"{",
"emitNodeClosed",
"(",
"ascent",
")",
";",
"return",
"tail",
"(",
"ascent",
")",
"||",
"// If there are no nodes left in the ascent the root node",
"// just closed. Emit a special event for this: ",
"emitRootClosed",
"(",
"nodeOf",
"(",
"head",
"(",
"ascent",
")",
")",
")",
";",
"}"
] | For when the current node ends. | [
"For",
"when",
"the",
"current",
"node",
"ends",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1492-L1500 |
5,180 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | skip1 | function skip1(previousExpr) {
if( previousExpr == always ) {
/* If there is no previous expression this consume command
is at the start of the jsonPath.
Since JSONPath specifies what we'd like to find but not
necessarily everything leading down to it, when running
out of JSONPath to check against we default to true */
return always;
}
/** return true if the ascent we have contains only the JSON root,
* false otherwise
*/
function notAtRoot(ascent){
return headKey(ascent) != ROOT_PATH;
}
return lazyIntersection(
/* If we're already at the root but there are more
expressions to satisfy, can't consume any more. No match.
This check is why none of the other exprs have to be able
to handle empty lists; skip1 is the only evaluator that
moves onto the next token and it refuses to do so once it
reaches the last item in the list. */
notAtRoot,
/* We are not at the root of the ascent yet.
Move to the next level of the ascent by handing only
the tail to the previous expression */
compose2(previousExpr, tail)
);
} | javascript | function skip1(previousExpr) {
if( previousExpr == always ) {
/* If there is no previous expression this consume command
is at the start of the jsonPath.
Since JSONPath specifies what we'd like to find but not
necessarily everything leading down to it, when running
out of JSONPath to check against we default to true */
return always;
}
/** return true if the ascent we have contains only the JSON root,
* false otherwise
*/
function notAtRoot(ascent){
return headKey(ascent) != ROOT_PATH;
}
return lazyIntersection(
/* If we're already at the root but there are more
expressions to satisfy, can't consume any more. No match.
This check is why none of the other exprs have to be able
to handle empty lists; skip1 is the only evaluator that
moves onto the next token and it refuses to do so once it
reaches the last item in the list. */
notAtRoot,
/* We are not at the root of the ascent yet.
Move to the next level of the ascent by handing only
the tail to the previous expression */
compose2(previousExpr, tail)
);
} | [
"function",
"skip1",
"(",
"previousExpr",
")",
"{",
"if",
"(",
"previousExpr",
"==",
"always",
")",
"{",
"/* If there is no previous expression this consume command \n is at the start of the jsonPath.\n Since JSONPath specifies what we'd like to find but not \n necessarily everything leading down to it, when running\n out of JSONPath to check against we default to true */",
"return",
"always",
";",
"}",
"/** return true if the ascent we have contains only the JSON root,\n * false otherwise\n */",
"function",
"notAtRoot",
"(",
"ascent",
")",
"{",
"return",
"headKey",
"(",
"ascent",
")",
"!=",
"ROOT_PATH",
";",
"}",
"return",
"lazyIntersection",
"(",
"/* If we're already at the root but there are more \n expressions to satisfy, can't consume any more. No match.\n\n This check is why none of the other exprs have to be able \n to handle empty lists; skip1 is the only evaluator that \n moves onto the next token and it refuses to do so once it \n reaches the last item in the list. */",
"notAtRoot",
",",
"/* We are not at the root of the ascent yet.\n Move to the next level of the ascent by handing only \n the tail to the previous expression */",
"compose2",
"(",
"previousExpr",
",",
"tail",
")",
")",
";",
"}"
] | Create an evaluator function that moves onto the next item on the
lists. This function is the place where the logic to move up a
level in the ascent exists.
Eg, for JSONPath ".foo" we need skip1(nameClause(always, [,'foo'])) | [
"Create",
"an",
"evaluator",
"function",
"that",
"moves",
"onto",
"the",
"next",
"item",
"on",
"the",
"lists",
".",
"This",
"function",
"is",
"the",
"place",
"where",
"the",
"logic",
"to",
"move",
"up",
"a",
"level",
"in",
"the",
"ascent",
"exists",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1604-L1639 |
5,181 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | statementExpr | function statementExpr(lastClause) {
return function(ascent) {
// kick off the evaluation by passing through to the last clause
var exprMatch = lastClause(ascent);
return exprMatch === true ? head(ascent) : exprMatch;
};
} | javascript | function statementExpr(lastClause) {
return function(ascent) {
// kick off the evaluation by passing through to the last clause
var exprMatch = lastClause(ascent);
return exprMatch === true ? head(ascent) : exprMatch;
};
} | [
"function",
"statementExpr",
"(",
"lastClause",
")",
"{",
"return",
"function",
"(",
"ascent",
")",
"{",
"// kick off the evaluation by passing through to the last clause",
"var",
"exprMatch",
"=",
"lastClause",
"(",
"ascent",
")",
";",
"return",
"exprMatch",
"===",
"true",
"?",
"head",
"(",
"ascent",
")",
":",
"exprMatch",
";",
"}",
";",
"}"
] | Generate a statement wrapper to sit around the outermost
clause evaluator.
Handles the case where the capturing is implicit because the JSONPath
did not contain a '$' by returning the last node. | [
"Generate",
"a",
"statement",
"wrapper",
"to",
"sit",
"around",
"the",
"outermost",
"clause",
"evaluator",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1694-L1703 |
5,182 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | expressionsReader | function expressionsReader( exprs, parserGeneratedSoFar, detection ) {
// if exprs is zero-length foldR will pass back the
// parserGeneratedSoFar as-is so we don't need to treat
// this as a special case
return foldR(
function( parserGeneratedSoFar, expr ){
return expr(parserGeneratedSoFar, detection);
},
parserGeneratedSoFar,
exprs
);
} | javascript | function expressionsReader( exprs, parserGeneratedSoFar, detection ) {
// if exprs is zero-length foldR will pass back the
// parserGeneratedSoFar as-is so we don't need to treat
// this as a special case
return foldR(
function( parserGeneratedSoFar, expr ){
return expr(parserGeneratedSoFar, detection);
},
parserGeneratedSoFar,
exprs
);
} | [
"function",
"expressionsReader",
"(",
"exprs",
",",
"parserGeneratedSoFar",
",",
"detection",
")",
"{",
"// if exprs is zero-length foldR will pass back the ",
"// parserGeneratedSoFar as-is so we don't need to treat ",
"// this as a special case",
"return",
"foldR",
"(",
"function",
"(",
"parserGeneratedSoFar",
",",
"expr",
")",
"{",
"return",
"expr",
"(",
"parserGeneratedSoFar",
",",
"detection",
")",
";",
"}",
",",
"parserGeneratedSoFar",
",",
"exprs",
")",
";",
"}"
] | For when a token has been found in the JSONPath input.
Compiles the parser for that token and returns in combination with the
parser already generated.
@param {Function} exprs a list of the clause evaluator generators for
the token that was found
@param {Function} parserGeneratedSoFar the parser already found
@param {Array} detection the match given by the regex engine when
the feature was found | [
"For",
"when",
"a",
"token",
"has",
"been",
"found",
"in",
"the",
"JSONPath",
"input",
".",
"Compiles",
"the",
"parser",
"for",
"that",
"token",
"and",
"returns",
"in",
"combination",
"with",
"the",
"parser",
"already",
"generated",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1716-L1731 |
5,183 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | generateClauseReaderIfTokenFound | function generateClauseReaderIfTokenFound (
tokenDetector, clauseEvaluatorGenerators,
jsonPath, parserGeneratedSoFar, onSuccess) {
var detected = tokenDetector(jsonPath);
if(detected) {
var compiledParser = expressionsReader(
clauseEvaluatorGenerators,
parserGeneratedSoFar,
detected
),
remainingUnparsedJsonPath = jsonPath.substr(len(detected[0]));
return onSuccess(remainingUnparsedJsonPath, compiledParser);
}
} | javascript | function generateClauseReaderIfTokenFound (
tokenDetector, clauseEvaluatorGenerators,
jsonPath, parserGeneratedSoFar, onSuccess) {
var detected = tokenDetector(jsonPath);
if(detected) {
var compiledParser = expressionsReader(
clauseEvaluatorGenerators,
parserGeneratedSoFar,
detected
),
remainingUnparsedJsonPath = jsonPath.substr(len(detected[0]));
return onSuccess(remainingUnparsedJsonPath, compiledParser);
}
} | [
"function",
"generateClauseReaderIfTokenFound",
"(",
"tokenDetector",
",",
"clauseEvaluatorGenerators",
",",
"jsonPath",
",",
"parserGeneratedSoFar",
",",
"onSuccess",
")",
"{",
"var",
"detected",
"=",
"tokenDetector",
"(",
"jsonPath",
")",
";",
"if",
"(",
"detected",
")",
"{",
"var",
"compiledParser",
"=",
"expressionsReader",
"(",
"clauseEvaluatorGenerators",
",",
"parserGeneratedSoFar",
",",
"detected",
")",
",",
"remainingUnparsedJsonPath",
"=",
"jsonPath",
".",
"substr",
"(",
"len",
"(",
"detected",
"[",
"0",
"]",
")",
")",
";",
"return",
"onSuccess",
"(",
"remainingUnparsedJsonPath",
",",
"compiledParser",
")",
";",
"}",
"}"
] | If jsonPath matches the given detector function, creates a function which
evaluates against every clause in the clauseEvaluatorGenerators. The
created function is propagated to the onSuccess function, along with
the remaining unparsed JSONPath substring.
The intended use is to create a clauseMatcher by filling in
the first two arguments, thus providing a function that knows
some syntax to match and what kind of generator to create if it
finds it. The parameter list once completed is:
(jsonPath, parserGeneratedSoFar, onSuccess)
onSuccess may be compileJsonPathToFunction, to recursively continue
parsing after finding a match or returnFoundParser to stop here. | [
"If",
"jsonPath",
"matches",
"the",
"given",
"detector",
"function",
"creates",
"a",
"function",
"which",
"evaluates",
"against",
"every",
"clause",
"in",
"the",
"clauseEvaluatorGenerators",
".",
"The",
"created",
"function",
"is",
"propagated",
"to",
"the",
"onSuccess",
"function",
"along",
"with",
"the",
"remaining",
"unparsed",
"JSONPath",
"substring",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1749-L1768 |
5,184 | catapult-project/catapult | tracing/third_party/oboe/dist/oboe-node.js | compileJsonPathToFunction | function compileJsonPathToFunction( uncompiledJsonPath,
parserGeneratedSoFar ) {
/**
* On finding a match, if there is remaining text to be compiled
* we want to either continue parsing using a recursive call to
* compileJsonPathToFunction. Otherwise, we want to stop and return
* the parser that we have found so far.
*/
var onFind = uncompiledJsonPath
? compileJsonPathToFunction
: returnFoundParser;
return clauseForJsonPath(
uncompiledJsonPath,
parserGeneratedSoFar,
onFind
);
} | javascript | function compileJsonPathToFunction( uncompiledJsonPath,
parserGeneratedSoFar ) {
/**
* On finding a match, if there is remaining text to be compiled
* we want to either continue parsing using a recursive call to
* compileJsonPathToFunction. Otherwise, we want to stop and return
* the parser that we have found so far.
*/
var onFind = uncompiledJsonPath
? compileJsonPathToFunction
: returnFoundParser;
return clauseForJsonPath(
uncompiledJsonPath,
parserGeneratedSoFar,
onFind
);
} | [
"function",
"compileJsonPathToFunction",
"(",
"uncompiledJsonPath",
",",
"parserGeneratedSoFar",
")",
"{",
"/**\n * On finding a match, if there is remaining text to be compiled\n * we want to either continue parsing using a recursive call to \n * compileJsonPathToFunction. Otherwise, we want to stop and return \n * the parser that we have found so far.\n */",
"var",
"onFind",
"=",
"uncompiledJsonPath",
"?",
"compileJsonPathToFunction",
":",
"returnFoundParser",
";",
"return",
"clauseForJsonPath",
"(",
"uncompiledJsonPath",
",",
"parserGeneratedSoFar",
",",
"onFind",
")",
";",
"}"
] | Recursively compile a JSONPath expression.
This function serves as one of two possible values for the onSuccess
argument of generateClauseReaderIfTokenFound, meaning continue to
recursively compile. Otherwise, returnFoundParser is given and
compilation terminates. | [
"Recursively",
"compile",
"a",
"JSONPath",
"expression",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/dist/oboe-node.js#L1836-L1854 |
5,185 | catapult-project/catapult | third_party/vinn/third_party/parse5/lib/tree_construction/parser.js | callAdoptionAgency | function callAdoptionAgency(p, token) {
for (var i = 0; i < AA_OUTER_LOOP_ITER; i++) {
var formattingElementEntry = aaObtainFormattingElementEntry(p, token, formattingElementEntry);
if (!formattingElementEntry)
break;
var furthestBlock = aaObtainFurthestBlock(p, formattingElementEntry);
if (!furthestBlock)
break;
p.activeFormattingElements.bookmark = formattingElementEntry;
var lastElement = aaInnerLoop(p, furthestBlock, formattingElementEntry.element),
commonAncestor = p.openElements.getCommonAncestor(formattingElementEntry.element);
p.treeAdapter.detachNode(lastElement);
aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement);
aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry);
}
} | javascript | function callAdoptionAgency(p, token) {
for (var i = 0; i < AA_OUTER_LOOP_ITER; i++) {
var formattingElementEntry = aaObtainFormattingElementEntry(p, token, formattingElementEntry);
if (!formattingElementEntry)
break;
var furthestBlock = aaObtainFurthestBlock(p, formattingElementEntry);
if (!furthestBlock)
break;
p.activeFormattingElements.bookmark = formattingElementEntry;
var lastElement = aaInnerLoop(p, furthestBlock, formattingElementEntry.element),
commonAncestor = p.openElements.getCommonAncestor(formattingElementEntry.element);
p.treeAdapter.detachNode(lastElement);
aaInsertLastNodeInCommonAncestor(p, commonAncestor, lastElement);
aaReplaceFormattingElement(p, furthestBlock, formattingElementEntry);
}
} | [
"function",
"callAdoptionAgency",
"(",
"p",
",",
"token",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"AA_OUTER_LOOP_ITER",
";",
"i",
"++",
")",
"{",
"var",
"formattingElementEntry",
"=",
"aaObtainFormattingElementEntry",
"(",
"p",
",",
"token",
",",
"formattingElementEntry",
")",
";",
"if",
"(",
"!",
"formattingElementEntry",
")",
"break",
";",
"var",
"furthestBlock",
"=",
"aaObtainFurthestBlock",
"(",
"p",
",",
"formattingElementEntry",
")",
";",
"if",
"(",
"!",
"furthestBlock",
")",
"break",
";",
"p",
".",
"activeFormattingElements",
".",
"bookmark",
"=",
"formattingElementEntry",
";",
"var",
"lastElement",
"=",
"aaInnerLoop",
"(",
"p",
",",
"furthestBlock",
",",
"formattingElementEntry",
".",
"element",
")",
",",
"commonAncestor",
"=",
"p",
".",
"openElements",
".",
"getCommonAncestor",
"(",
"formattingElementEntry",
".",
"element",
")",
";",
"p",
".",
"treeAdapter",
".",
"detachNode",
"(",
"lastElement",
")",
";",
"aaInsertLastNodeInCommonAncestor",
"(",
"p",
",",
"commonAncestor",
",",
"lastElement",
")",
";",
"aaReplaceFormattingElement",
"(",
"p",
",",
"furthestBlock",
",",
"formattingElementEntry",
")",
";",
"}",
"}"
] | Algorithm entry point | [
"Algorithm",
"entry",
"point"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/vinn/third_party/parse5/lib/tree_construction/parser.js#L1002-L1023 |
5,186 | catapult-project/catapult | experimental/v8_tools/filter.js | readSingleFile | function readSingleFile(e) {
const file = e.target.files[0];
if (!file) {
return;
}
// Extract data from file and distribute it in some relevant structures:
// results for all guid-related( for now they are not
// divided in 3 parts depending on the type ) and
// all results with sample-value-related and
// map guid to value within the same structure
const reader = new FileReader();
reader.onload = function(e) {
const contents = extractData(e.target.result);
const sampleArr = contents.sampleValueArray;
const guidValueInfo = contents.guidValueInfo;
const metricAverage = new Map();
const allLabels = new Set();
for (const e of sampleArr) {
// This version of the tool focuses on analysing memory
// metrics, which contain a slightly different structure
// to the non-memory metrics.
if (e.name.startsWith('memory')) {
const { name, sampleValues, diagnostics } = e;
const { labels, stories } = diagnostics;
const label = guidValueInfo.get(labels)[0];
allLabels.add(label);
const story = guidValueInfo.get(stories)[0];
menu.significanceTester.add(name, label, story, sampleValues);
}
}
menu.allLabels = Array.from(allLabels);
let metricNames = [];
sampleArr.map(e => metricNames.push(e.name));
metricNames = _.uniq(metricNames);
// The content for the default table: with name
// of the metric, the average value of the sample values
// plus an id. The latest is used to expand the row.
// It may disappear later.
const tableElems = [];
let id = 1;
for (const name of metricNames) {
tableElems.push({
id: id++,
metric: name
});
}
const labelsResult = getMetricStoriesLabelsToValuesMap(
sampleArr, guidValueInfo);
const columnsForChosenDiagnostic = labelsResult.labelNames;
const metricToDiagnosticValuesMap = labelsResult.mapLabelToValues;
for (const elem of tableElems) {
if (metricToDiagnosticValuesMap.get(elem.metric) === undefined) {
continue;
}
for (const diagnostic of columnsForChosenDiagnostic) {
if (!metricToDiagnosticValuesMap.get(elem.metric).has(diagnostic)) {
continue;
}
elem[diagnostic] = fromBytesToMiB(average(metricToDiagnosticValuesMap
.get(elem.metric).get(diagnostic)));
}
}
app.state.gridData = tableElems;
app.defaultGridData = tableElems;
app.sampleArr = sampleArr;
app.guidValue = guidValueInfo;
app.columnsForChosenDiagnostic = columnsForChosenDiagnostic;
const result = parseAllMetrics(metricNames);
menu.sampelArr = sampleArr;
menu.guidValueInfo = guidValueInfo;
menu.browserOptions = result.browsers;
menu.subprocessOptions = result.subprocesses;
menu.componentMap = result.components;
menu.sizeMap = result.sizes;
menu.metricNames = result.names;
};
reader.readAsText(file);
} | javascript | function readSingleFile(e) {
const file = e.target.files[0];
if (!file) {
return;
}
// Extract data from file and distribute it in some relevant structures:
// results for all guid-related( for now they are not
// divided in 3 parts depending on the type ) and
// all results with sample-value-related and
// map guid to value within the same structure
const reader = new FileReader();
reader.onload = function(e) {
const contents = extractData(e.target.result);
const sampleArr = contents.sampleValueArray;
const guidValueInfo = contents.guidValueInfo;
const metricAverage = new Map();
const allLabels = new Set();
for (const e of sampleArr) {
// This version of the tool focuses on analysing memory
// metrics, which contain a slightly different structure
// to the non-memory metrics.
if (e.name.startsWith('memory')) {
const { name, sampleValues, diagnostics } = e;
const { labels, stories } = diagnostics;
const label = guidValueInfo.get(labels)[0];
allLabels.add(label);
const story = guidValueInfo.get(stories)[0];
menu.significanceTester.add(name, label, story, sampleValues);
}
}
menu.allLabels = Array.from(allLabels);
let metricNames = [];
sampleArr.map(e => metricNames.push(e.name));
metricNames = _.uniq(metricNames);
// The content for the default table: with name
// of the metric, the average value of the sample values
// plus an id. The latest is used to expand the row.
// It may disappear later.
const tableElems = [];
let id = 1;
for (const name of metricNames) {
tableElems.push({
id: id++,
metric: name
});
}
const labelsResult = getMetricStoriesLabelsToValuesMap(
sampleArr, guidValueInfo);
const columnsForChosenDiagnostic = labelsResult.labelNames;
const metricToDiagnosticValuesMap = labelsResult.mapLabelToValues;
for (const elem of tableElems) {
if (metricToDiagnosticValuesMap.get(elem.metric) === undefined) {
continue;
}
for (const diagnostic of columnsForChosenDiagnostic) {
if (!metricToDiagnosticValuesMap.get(elem.metric).has(diagnostic)) {
continue;
}
elem[diagnostic] = fromBytesToMiB(average(metricToDiagnosticValuesMap
.get(elem.metric).get(diagnostic)));
}
}
app.state.gridData = tableElems;
app.defaultGridData = tableElems;
app.sampleArr = sampleArr;
app.guidValue = guidValueInfo;
app.columnsForChosenDiagnostic = columnsForChosenDiagnostic;
const result = parseAllMetrics(metricNames);
menu.sampelArr = sampleArr;
menu.guidValueInfo = guidValueInfo;
menu.browserOptions = result.browsers;
menu.subprocessOptions = result.subprocesses;
menu.componentMap = result.components;
menu.sizeMap = result.sizes;
menu.metricNames = result.names;
};
reader.readAsText(file);
} | [
"function",
"readSingleFile",
"(",
"e",
")",
"{",
"const",
"file",
"=",
"e",
".",
"target",
".",
"files",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"file",
")",
"{",
"return",
";",
"}",
"// Extract data from file and distribute it in some relevant structures:",
"// results for all guid-related( for now they are not",
"// divided in 3 parts depending on the type ) and",
"// all results with sample-value-related and",
"// map guid to value within the same structure",
"const",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"onload",
"=",
"function",
"(",
"e",
")",
"{",
"const",
"contents",
"=",
"extractData",
"(",
"e",
".",
"target",
".",
"result",
")",
";",
"const",
"sampleArr",
"=",
"contents",
".",
"sampleValueArray",
";",
"const",
"guidValueInfo",
"=",
"contents",
".",
"guidValueInfo",
";",
"const",
"metricAverage",
"=",
"new",
"Map",
"(",
")",
";",
"const",
"allLabels",
"=",
"new",
"Set",
"(",
")",
";",
"for",
"(",
"const",
"e",
"of",
"sampleArr",
")",
"{",
"// This version of the tool focuses on analysing memory",
"// metrics, which contain a slightly different structure",
"// to the non-memory metrics.",
"if",
"(",
"e",
".",
"name",
".",
"startsWith",
"(",
"'memory'",
")",
")",
"{",
"const",
"{",
"name",
",",
"sampleValues",
",",
"diagnostics",
"}",
"=",
"e",
";",
"const",
"{",
"labels",
",",
"stories",
"}",
"=",
"diagnostics",
";",
"const",
"label",
"=",
"guidValueInfo",
".",
"get",
"(",
"labels",
")",
"[",
"0",
"]",
";",
"allLabels",
".",
"add",
"(",
"label",
")",
";",
"const",
"story",
"=",
"guidValueInfo",
".",
"get",
"(",
"stories",
")",
"[",
"0",
"]",
";",
"menu",
".",
"significanceTester",
".",
"add",
"(",
"name",
",",
"label",
",",
"story",
",",
"sampleValues",
")",
";",
"}",
"}",
"menu",
".",
"allLabels",
"=",
"Array",
".",
"from",
"(",
"allLabels",
")",
";",
"let",
"metricNames",
"=",
"[",
"]",
";",
"sampleArr",
".",
"map",
"(",
"e",
"=>",
"metricNames",
".",
"push",
"(",
"e",
".",
"name",
")",
")",
";",
"metricNames",
"=",
"_",
".",
"uniq",
"(",
"metricNames",
")",
";",
"// The content for the default table: with name",
"// of the metric, the average value of the sample values",
"// plus an id. The latest is used to expand the row.",
"// It may disappear later.",
"const",
"tableElems",
"=",
"[",
"]",
";",
"let",
"id",
"=",
"1",
";",
"for",
"(",
"const",
"name",
"of",
"metricNames",
")",
"{",
"tableElems",
".",
"push",
"(",
"{",
"id",
":",
"id",
"++",
",",
"metric",
":",
"name",
"}",
")",
";",
"}",
"const",
"labelsResult",
"=",
"getMetricStoriesLabelsToValuesMap",
"(",
"sampleArr",
",",
"guidValueInfo",
")",
";",
"const",
"columnsForChosenDiagnostic",
"=",
"labelsResult",
".",
"labelNames",
";",
"const",
"metricToDiagnosticValuesMap",
"=",
"labelsResult",
".",
"mapLabelToValues",
";",
"for",
"(",
"const",
"elem",
"of",
"tableElems",
")",
"{",
"if",
"(",
"metricToDiagnosticValuesMap",
".",
"get",
"(",
"elem",
".",
"metric",
")",
"===",
"undefined",
")",
"{",
"continue",
";",
"}",
"for",
"(",
"const",
"diagnostic",
"of",
"columnsForChosenDiagnostic",
")",
"{",
"if",
"(",
"!",
"metricToDiagnosticValuesMap",
".",
"get",
"(",
"elem",
".",
"metric",
")",
".",
"has",
"(",
"diagnostic",
")",
")",
"{",
"continue",
";",
"}",
"elem",
"[",
"diagnostic",
"]",
"=",
"fromBytesToMiB",
"(",
"average",
"(",
"metricToDiagnosticValuesMap",
".",
"get",
"(",
"elem",
".",
"metric",
")",
".",
"get",
"(",
"diagnostic",
")",
")",
")",
";",
"}",
"}",
"app",
".",
"state",
".",
"gridData",
"=",
"tableElems",
";",
"app",
".",
"defaultGridData",
"=",
"tableElems",
";",
"app",
".",
"sampleArr",
"=",
"sampleArr",
";",
"app",
".",
"guidValue",
"=",
"guidValueInfo",
";",
"app",
".",
"columnsForChosenDiagnostic",
"=",
"columnsForChosenDiagnostic",
";",
"const",
"result",
"=",
"parseAllMetrics",
"(",
"metricNames",
")",
";",
"menu",
".",
"sampelArr",
"=",
"sampleArr",
";",
"menu",
".",
"guidValueInfo",
"=",
"guidValueInfo",
";",
"menu",
".",
"browserOptions",
"=",
"result",
".",
"browsers",
";",
"menu",
".",
"subprocessOptions",
"=",
"result",
".",
"subprocesses",
";",
"menu",
".",
"componentMap",
"=",
"result",
".",
"components",
";",
"menu",
".",
"sizeMap",
"=",
"result",
".",
"sizes",
";",
"menu",
".",
"metricNames",
"=",
"result",
".",
"names",
";",
"}",
";",
"reader",
".",
"readAsText",
"(",
"file",
")",
";",
"}"
] | Load the content of the file and further display the data. | [
"Load",
"the",
"content",
"of",
"the",
"file",
"and",
"further",
"display",
"the",
"data",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/experimental/v8_tools/filter.js#L296-L380 |
5,187 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/template-stamp.js | applyTemplateContent | function applyTemplateContent(inst, node, nodeInfo) {
if (nodeInfo.templateInfo) {
node._templateInfo = nodeInfo.templateInfo;
}
} | javascript | function applyTemplateContent(inst, node, nodeInfo) {
if (nodeInfo.templateInfo) {
node._templateInfo = nodeInfo.templateInfo;
}
} | [
"function",
"applyTemplateContent",
"(",
"inst",
",",
"node",
",",
"nodeInfo",
")",
"{",
"if",
"(",
"nodeInfo",
".",
"templateInfo",
")",
"{",
"node",
".",
"_templateInfo",
"=",
"nodeInfo",
".",
"templateInfo",
";",
"}",
"}"
] | push configuration references at configure time | [
"push",
"configuration",
"references",
"at",
"configure",
"time"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/template-stamp.js#L75-L79 |
5,188 | catapult-project/catapult | tracing/third_party/oboe/src/detectCrossOrigin.browser.js | isCrossOrigin | function isCrossOrigin(pageLocation, ajaxHost) {
/*
* NB: defaultPort only knows http and https.
* Returns undefined otherwise.
*/
function defaultPort(protocol) {
return {'http:':80, 'https:':443}[protocol];
}
function portOf(location) {
// pageLocation should always have a protocol. ajaxHost if no port or
// protocol is specified, should use the port of the containing page
return location.port || defaultPort(location.protocol||pageLocation.protocol);
}
// if ajaxHost doesn't give a domain, port is the same as pageLocation
// it can't give a protocol but not a domain
// it can't give a port but not a domain
return !!( (ajaxHost.protocol && (ajaxHost.protocol != pageLocation.protocol)) ||
(ajaxHost.host && (ajaxHost.host != pageLocation.host)) ||
(ajaxHost.host && (portOf(ajaxHost) != portOf(pageLocation)))
);
} | javascript | function isCrossOrigin(pageLocation, ajaxHost) {
/*
* NB: defaultPort only knows http and https.
* Returns undefined otherwise.
*/
function defaultPort(protocol) {
return {'http:':80, 'https:':443}[protocol];
}
function portOf(location) {
// pageLocation should always have a protocol. ajaxHost if no port or
// protocol is specified, should use the port of the containing page
return location.port || defaultPort(location.protocol||pageLocation.protocol);
}
// if ajaxHost doesn't give a domain, port is the same as pageLocation
// it can't give a protocol but not a domain
// it can't give a port but not a domain
return !!( (ajaxHost.protocol && (ajaxHost.protocol != pageLocation.protocol)) ||
(ajaxHost.host && (ajaxHost.host != pageLocation.host)) ||
(ajaxHost.host && (portOf(ajaxHost) != portOf(pageLocation)))
);
} | [
"function",
"isCrossOrigin",
"(",
"pageLocation",
",",
"ajaxHost",
")",
"{",
"/*\n * NB: defaultPort only knows http and https.\n * Returns undefined otherwise.\n */",
"function",
"defaultPort",
"(",
"protocol",
")",
"{",
"return",
"{",
"'http:'",
":",
"80",
",",
"'https:'",
":",
"443",
"}",
"[",
"protocol",
"]",
";",
"}",
"function",
"portOf",
"(",
"location",
")",
"{",
"// pageLocation should always have a protocol. ajaxHost if no port or",
"// protocol is specified, should use the port of the containing page",
"return",
"location",
".",
"port",
"||",
"defaultPort",
"(",
"location",
".",
"protocol",
"||",
"pageLocation",
".",
"protocol",
")",
";",
"}",
"// if ajaxHost doesn't give a domain, port is the same as pageLocation",
"// it can't give a protocol but not a domain",
"// it can't give a port but not a domain",
"return",
"!",
"!",
"(",
"(",
"ajaxHost",
".",
"protocol",
"&&",
"(",
"ajaxHost",
".",
"protocol",
"!=",
"pageLocation",
".",
"protocol",
")",
")",
"||",
"(",
"ajaxHost",
".",
"host",
"&&",
"(",
"ajaxHost",
".",
"host",
"!=",
"pageLocation",
".",
"host",
")",
")",
"||",
"(",
"ajaxHost",
".",
"host",
"&&",
"(",
"portOf",
"(",
"ajaxHost",
")",
"!=",
"portOf",
"(",
"pageLocation",
")",
")",
")",
")",
";",
"}"
] | Detect if a given URL is cross-origin in the scope of the
current page.
Browser only (since cross-origin has no meaning in Node.js)
@param {Object} pageLocation - as in window.location
@param {Object} ajaxHost - an object like window.location describing the
origin of the url that we want to ajax in | [
"Detect",
"if",
"a",
"given",
"URL",
"is",
"cross",
"-",
"origin",
"in",
"the",
"scope",
"of",
"the",
"current",
"page",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/tracing/third_party/oboe/src/detectCrossOrigin.browser.js#L11-L36 |
5,189 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | ensureOwnEffectMap | function ensureOwnEffectMap(model, type) {
let effects = model[type];
if (!effects) {
effects = model[type] = {};
} else if (!model.hasOwnProperty(type)) {
effects = model[type] = Object.create(model[type]);
for (let p in effects) {
let protoFx = effects[p];
let instFx = effects[p] = Array(protoFx.length);
for (let i=0; i<protoFx.length; i++) {
instFx[i] = protoFx[i];
}
}
}
return effects;
} | javascript | function ensureOwnEffectMap(model, type) {
let effects = model[type];
if (!effects) {
effects = model[type] = {};
} else if (!model.hasOwnProperty(type)) {
effects = model[type] = Object.create(model[type]);
for (let p in effects) {
let protoFx = effects[p];
let instFx = effects[p] = Array(protoFx.length);
for (let i=0; i<protoFx.length; i++) {
instFx[i] = protoFx[i];
}
}
}
return effects;
} | [
"function",
"ensureOwnEffectMap",
"(",
"model",
",",
"type",
")",
"{",
"let",
"effects",
"=",
"model",
"[",
"type",
"]",
";",
"if",
"(",
"!",
"effects",
")",
"{",
"effects",
"=",
"model",
"[",
"type",
"]",
"=",
"{",
"}",
";",
"}",
"else",
"if",
"(",
"!",
"model",
".",
"hasOwnProperty",
"(",
"type",
")",
")",
"{",
"effects",
"=",
"model",
"[",
"type",
"]",
"=",
"Object",
".",
"create",
"(",
"model",
"[",
"type",
"]",
")",
";",
"for",
"(",
"let",
"p",
"in",
"effects",
")",
"{",
"let",
"protoFx",
"=",
"effects",
"[",
"p",
"]",
";",
"let",
"instFx",
"=",
"effects",
"[",
"p",
"]",
"=",
"Array",
"(",
"protoFx",
".",
"length",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"protoFx",
".",
"length",
";",
"i",
"++",
")",
"{",
"instFx",
"[",
"i",
"]",
"=",
"protoFx",
"[",
"i",
"]",
";",
"}",
"}",
"}",
"return",
"effects",
";",
"}"
] | eslint-disable-line no-unused-vars
Ensures that the model has an own-property map of effects for the given type.
The model may be a prototype or an instance.
Property effects are stored as arrays of effects by property in a map,
by named type on the model. e.g.
__computeEffects: {
foo: [ ... ],
bar: [ ... ]
}
If the model does not yet have an effect map for the type, one is created
and returned. If it does, but it is not an own property (i.e. the
prototype had effects), the the map is deeply cloned and the copy is
set on the model and returned, ready for new effects to be added.
@param {Object} model Prototype or instance
@param {string} type Property effect type
@return {Object} The own-property map of effects for the given type
@private | [
"eslint",
"-",
"disable",
"-",
"line",
"no",
"-",
"unused",
"-",
"vars",
"Ensures",
"that",
"the",
"model",
"has",
"an",
"own",
"-",
"property",
"map",
"of",
"effects",
"for",
"the",
"given",
"type",
".",
"The",
"model",
"may",
"be",
"a",
"prototype",
"or",
"an",
"instance",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L88-L103 |
5,190 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runEffectsForProperty | function runEffectsForProperty(inst, effects, dedupeId, prop, props, oldProps, hasPaths, extraArgs) {
let ran = false;
let rootProperty = hasPaths ? root$0(prop) : prop;
let fxs = effects[rootProperty];
if (fxs) {
for (let i=0, l=fxs.length, fx; (i<l) && (fx=fxs[i]); i++) {
if ((!fx.info || fx.info.lastRun !== dedupeId) &&
(!hasPaths || pathMatchesTrigger(prop, fx.trigger))) {
if (fx.info) {
fx.info.lastRun = dedupeId;
}
fx.fn(inst, prop, props, oldProps, fx.info, hasPaths, extraArgs);
ran = true;
}
}
}
return ran;
} | javascript | function runEffectsForProperty(inst, effects, dedupeId, prop, props, oldProps, hasPaths, extraArgs) {
let ran = false;
let rootProperty = hasPaths ? root$0(prop) : prop;
let fxs = effects[rootProperty];
if (fxs) {
for (let i=0, l=fxs.length, fx; (i<l) && (fx=fxs[i]); i++) {
if ((!fx.info || fx.info.lastRun !== dedupeId) &&
(!hasPaths || pathMatchesTrigger(prop, fx.trigger))) {
if (fx.info) {
fx.info.lastRun = dedupeId;
}
fx.fn(inst, prop, props, oldProps, fx.info, hasPaths, extraArgs);
ran = true;
}
}
}
return ran;
} | [
"function",
"runEffectsForProperty",
"(",
"inst",
",",
"effects",
",",
"dedupeId",
",",
"prop",
",",
"props",
",",
"oldProps",
",",
"hasPaths",
",",
"extraArgs",
")",
"{",
"let",
"ran",
"=",
"false",
";",
"let",
"rootProperty",
"=",
"hasPaths",
"?",
"root$0",
"(",
"prop",
")",
":",
"prop",
";",
"let",
"fxs",
"=",
"effects",
"[",
"rootProperty",
"]",
";",
"if",
"(",
"fxs",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"fxs",
".",
"length",
",",
"fx",
";",
"(",
"i",
"<",
"l",
")",
"&&",
"(",
"fx",
"=",
"fxs",
"[",
"i",
"]",
")",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"!",
"fx",
".",
"info",
"||",
"fx",
".",
"info",
".",
"lastRun",
"!==",
"dedupeId",
")",
"&&",
"(",
"!",
"hasPaths",
"||",
"pathMatchesTrigger",
"(",
"prop",
",",
"fx",
".",
"trigger",
")",
")",
")",
"{",
"if",
"(",
"fx",
".",
"info",
")",
"{",
"fx",
".",
"info",
".",
"lastRun",
"=",
"dedupeId",
";",
"}",
"fx",
".",
"fn",
"(",
"inst",
",",
"prop",
",",
"props",
",",
"oldProps",
",",
"fx",
".",
"info",
",",
"hasPaths",
",",
"extraArgs",
")",
";",
"ran",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"ran",
";",
"}"
] | Runs a list of effects for a given property.
@param {!PropertyEffectsType} inst The instance with effects to run
@param {Object} effects Object map of property-to-Array of effects
@param {number} dedupeId Counter used for de-duping effects
@param {string} prop Name of changed property
@param {*} props Changed properties
@param {*} oldProps Old properties
@param {boolean=} hasPaths True with `props` contains one or more paths
@param {*=} extraArgs Additional metadata to pass to effect function
@return {boolean} True if an effect ran for this property
@private | [
"Runs",
"a",
"list",
"of",
"effects",
"for",
"a",
"given",
"property",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L148-L165 |
5,191 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runObserverEffect | function runObserverEffect(inst, property, props, oldProps, info) {
let fn = typeof info.method === "string" ? inst[info.method] : info.method;
let changedProp = info.property;
if (fn) {
fn.call(inst, inst.__data[changedProp], oldProps[changedProp]);
} else if (!info.dynamicFn) {
console.warn('observer method `' + info.method + '` not defined');
}
} | javascript | function runObserverEffect(inst, property, props, oldProps, info) {
let fn = typeof info.method === "string" ? inst[info.method] : info.method;
let changedProp = info.property;
if (fn) {
fn.call(inst, inst.__data[changedProp], oldProps[changedProp]);
} else if (!info.dynamicFn) {
console.warn('observer method `' + info.method + '` not defined');
}
} | [
"function",
"runObserverEffect",
"(",
"inst",
",",
"property",
",",
"props",
",",
"oldProps",
",",
"info",
")",
"{",
"let",
"fn",
"=",
"typeof",
"info",
".",
"method",
"===",
"\"string\"",
"?",
"inst",
"[",
"info",
".",
"method",
"]",
":",
"info",
".",
"method",
";",
"let",
"changedProp",
"=",
"info",
".",
"property",
";",
"if",
"(",
"fn",
")",
"{",
"fn",
".",
"call",
"(",
"inst",
",",
"inst",
".",
"__data",
"[",
"changedProp",
"]",
",",
"oldProps",
"[",
"changedProp",
"]",
")",
";",
"}",
"else",
"if",
"(",
"!",
"info",
".",
"dynamicFn",
")",
"{",
"console",
".",
"warn",
"(",
"'observer method `'",
"+",
"info",
".",
"method",
"+",
"'` not defined'",
")",
";",
"}",
"}"
] | Implements the "observer" effect.
Calls the method with `info.methodName` on the instance, passing the
new and old values.
@param {!PropertyEffectsType} inst The instance the effect will be run on
@param {string} property Name of property
@param {Object} props Bag of current property changes
@param {Object} oldProps Bag of previous values for changed properties
@param {?} info Effect metadata
@return {void}
@private | [
"Implements",
"the",
"observer",
"effect",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L210-L218 |
5,192 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runNotifyEffects | function runNotifyEffects(inst, notifyProps, props, oldProps, hasPaths) {
// Notify
let fxs = inst[TYPES.NOTIFY];
let notified;
let id = dedupeId++;
// Try normal notify effects; if none, fall back to try path notification
for (let prop in notifyProps) {
if (notifyProps[prop]) {
if (fxs && runEffectsForProperty(inst, fxs, id, prop, props, oldProps, hasPaths)) {
notified = true;
} else if (hasPaths && notifyPath(inst, prop, props)) {
notified = true;
}
}
}
// Flush host if we actually notified and host was batching
// And the host has already initialized clients; this prevents
// an issue with a host observing data changes before clients are ready.
let host;
if (notified && (host = inst.__dataHost) && host._invalidateProperties) {
host._invalidateProperties();
}
} | javascript | function runNotifyEffects(inst, notifyProps, props, oldProps, hasPaths) {
// Notify
let fxs = inst[TYPES.NOTIFY];
let notified;
let id = dedupeId++;
// Try normal notify effects; if none, fall back to try path notification
for (let prop in notifyProps) {
if (notifyProps[prop]) {
if (fxs && runEffectsForProperty(inst, fxs, id, prop, props, oldProps, hasPaths)) {
notified = true;
} else if (hasPaths && notifyPath(inst, prop, props)) {
notified = true;
}
}
}
// Flush host if we actually notified and host was batching
// And the host has already initialized clients; this prevents
// an issue with a host observing data changes before clients are ready.
let host;
if (notified && (host = inst.__dataHost) && host._invalidateProperties) {
host._invalidateProperties();
}
} | [
"function",
"runNotifyEffects",
"(",
"inst",
",",
"notifyProps",
",",
"props",
",",
"oldProps",
",",
"hasPaths",
")",
"{",
"// Notify",
"let",
"fxs",
"=",
"inst",
"[",
"TYPES",
".",
"NOTIFY",
"]",
";",
"let",
"notified",
";",
"let",
"id",
"=",
"dedupeId",
"++",
";",
"// Try normal notify effects; if none, fall back to try path notification",
"for",
"(",
"let",
"prop",
"in",
"notifyProps",
")",
"{",
"if",
"(",
"notifyProps",
"[",
"prop",
"]",
")",
"{",
"if",
"(",
"fxs",
"&&",
"runEffectsForProperty",
"(",
"inst",
",",
"fxs",
",",
"id",
",",
"prop",
",",
"props",
",",
"oldProps",
",",
"hasPaths",
")",
")",
"{",
"notified",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"hasPaths",
"&&",
"notifyPath",
"(",
"inst",
",",
"prop",
",",
"props",
")",
")",
"{",
"notified",
"=",
"true",
";",
"}",
"}",
"}",
"// Flush host if we actually notified and host was batching",
"// And the host has already initialized clients; this prevents",
"// an issue with a host observing data changes before clients are ready.",
"let",
"host",
";",
"if",
"(",
"notified",
"&&",
"(",
"host",
"=",
"inst",
".",
"__dataHost",
")",
"&&",
"host",
".",
"_invalidateProperties",
")",
"{",
"host",
".",
"_invalidateProperties",
"(",
")",
";",
"}",
"}"
] | Runs "notify" effects for a set of changed properties.
This method differs from the generic `runEffects` method in that it
will dispatch path notification events in the case that the property
changed was a path and the root property for that path didn't have a
"notify" effect. This is to maintain 1.0 behavior that did not require
`notify: true` to ensure object sub-property notifications were
sent.
@param {!PropertyEffectsType} inst The instance with effects to run
@param {Object} notifyProps Bag of properties to notify
@param {Object} props Bag of current property changes
@param {Object} oldProps Bag of previous values for changed properties
@param {boolean} hasPaths True with `props` contains one or more paths
@return {void}
@private | [
"Runs",
"notify",
"effects",
"for",
"a",
"set",
"of",
"changed",
"properties",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L238-L260 |
5,193 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runNotifyEffect | function runNotifyEffect(inst, property, props, oldProps, info, hasPaths) {
let rootProperty = hasPaths ? root$0(property) : property;
let path = rootProperty != property ? property : null;
let value = path ? get$0(inst, path) : inst.__data[property];
if (path && value === undefined) {
value = props[property]; // specifically for .splices
}
dispatchNotifyEvent(inst, info.eventName, value, path);
} | javascript | function runNotifyEffect(inst, property, props, oldProps, info, hasPaths) {
let rootProperty = hasPaths ? root$0(property) : property;
let path = rootProperty != property ? property : null;
let value = path ? get$0(inst, path) : inst.__data[property];
if (path && value === undefined) {
value = props[property]; // specifically for .splices
}
dispatchNotifyEvent(inst, info.eventName, value, path);
} | [
"function",
"runNotifyEffect",
"(",
"inst",
",",
"property",
",",
"props",
",",
"oldProps",
",",
"info",
",",
"hasPaths",
")",
"{",
"let",
"rootProperty",
"=",
"hasPaths",
"?",
"root$0",
"(",
"property",
")",
":",
"property",
";",
"let",
"path",
"=",
"rootProperty",
"!=",
"property",
"?",
"property",
":",
"null",
";",
"let",
"value",
"=",
"path",
"?",
"get$0",
"(",
"inst",
",",
"path",
")",
":",
"inst",
".",
"__data",
"[",
"property",
"]",
";",
"if",
"(",
"path",
"&&",
"value",
"===",
"undefined",
")",
"{",
"value",
"=",
"props",
"[",
"property",
"]",
";",
"// specifically for .splices",
"}",
"dispatchNotifyEvent",
"(",
"inst",
",",
"info",
".",
"eventName",
",",
"value",
",",
"path",
")",
";",
"}"
] | Implements the "notify" effect.
Dispatches a non-bubbling event named `info.eventName` on the instance
with a detail object containing the new `value`.
@param {!PropertyEffectsType} inst The instance the effect will be run on
@param {string} property Name of property
@param {Object} props Bag of current property changes
@param {Object} oldProps Bag of previous values for changed properties
@param {?} info Effect metadata
@param {boolean} hasPaths True with `props` contains one or more paths
@return {void}
@private | [
"Implements",
"the",
"notify",
"effect",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L321-L329 |
5,194 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runReflectEffect | function runReflectEffect(inst, property, props, oldProps, info) {
let value = inst.__data[property];
if (sanitizeDOMValue) {
value = sanitizeDOMValue(value, info.attrName, 'attribute', /** @type {Node} */(inst));
}
inst._propertyToAttribute(property, info.attrName, value);
} | javascript | function runReflectEffect(inst, property, props, oldProps, info) {
let value = inst.__data[property];
if (sanitizeDOMValue) {
value = sanitizeDOMValue(value, info.attrName, 'attribute', /** @type {Node} */(inst));
}
inst._propertyToAttribute(property, info.attrName, value);
} | [
"function",
"runReflectEffect",
"(",
"inst",
",",
"property",
",",
"props",
",",
"oldProps",
",",
"info",
")",
"{",
"let",
"value",
"=",
"inst",
".",
"__data",
"[",
"property",
"]",
";",
"if",
"(",
"sanitizeDOMValue",
")",
"{",
"value",
"=",
"sanitizeDOMValue",
"(",
"value",
",",
"info",
".",
"attrName",
",",
"'attribute'",
",",
"/** @type {Node} */",
"(",
"inst",
")",
")",
";",
"}",
"inst",
".",
"_propertyToAttribute",
"(",
"property",
",",
"info",
".",
"attrName",
",",
"value",
")",
";",
"}"
] | Implements the "reflect" effect.
Sets the attribute named `info.attrName` to the given property value.
@param {!PropertyEffectsType} inst The instance the effect will be run on
@param {string} property Name of property
@param {Object} props Bag of current property changes
@param {Object} oldProps Bag of previous values for changed properties
@param {?} info Effect metadata
@return {void}
@private | [
"Implements",
"the",
"reflect",
"effect",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L380-L386 |
5,195 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runComputedEffects | function runComputedEffects(inst, changedProps, oldProps, hasPaths) {
let computeEffects = inst[TYPES.COMPUTE];
if (computeEffects) {
let inputProps = changedProps;
while (runEffects(inst, computeEffects, inputProps, oldProps, hasPaths)) {
Object.assign(oldProps, inst.__dataOld);
Object.assign(changedProps, inst.__dataPending);
inputProps = inst.__dataPending;
inst.__dataPending = null;
}
}
} | javascript | function runComputedEffects(inst, changedProps, oldProps, hasPaths) {
let computeEffects = inst[TYPES.COMPUTE];
if (computeEffects) {
let inputProps = changedProps;
while (runEffects(inst, computeEffects, inputProps, oldProps, hasPaths)) {
Object.assign(oldProps, inst.__dataOld);
Object.assign(changedProps, inst.__dataPending);
inputProps = inst.__dataPending;
inst.__dataPending = null;
}
}
} | [
"function",
"runComputedEffects",
"(",
"inst",
",",
"changedProps",
",",
"oldProps",
",",
"hasPaths",
")",
"{",
"let",
"computeEffects",
"=",
"inst",
"[",
"TYPES",
".",
"COMPUTE",
"]",
";",
"if",
"(",
"computeEffects",
")",
"{",
"let",
"inputProps",
"=",
"changedProps",
";",
"while",
"(",
"runEffects",
"(",
"inst",
",",
"computeEffects",
",",
"inputProps",
",",
"oldProps",
",",
"hasPaths",
")",
")",
"{",
"Object",
".",
"assign",
"(",
"oldProps",
",",
"inst",
".",
"__dataOld",
")",
";",
"Object",
".",
"assign",
"(",
"changedProps",
",",
"inst",
".",
"__dataPending",
")",
";",
"inputProps",
"=",
"inst",
".",
"__dataPending",
";",
"inst",
".",
"__dataPending",
"=",
"null",
";",
"}",
"}",
"}"
] | Runs "computed" effects for a set of changed properties.
This method differs from the generic `runEffects` method in that it
continues to run computed effects based on the output of each pass until
there are no more newly computed properties. This ensures that all
properties that will be computed by the initial set of changes are
computed before other effects (binding propagation, observers, and notify)
run.
@param {!PropertyEffectsType} inst The instance the effect will be run on
@param {!Object} changedProps Bag of changed properties
@param {!Object} oldProps Bag of previous values for changed properties
@param {boolean} hasPaths True with `props` contains one or more paths
@return {void}
@private | [
"Runs",
"computed",
"effects",
"for",
"a",
"set",
"of",
"changed",
"properties",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L405-L416 |
5,196 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | runComputedEffect | function runComputedEffect(inst, property, props, oldProps, info) {
let result = runMethodEffect(inst, property, props, oldProps, info);
let computedProp = info.methodInfo;
if (inst.__dataHasAccessor && inst.__dataHasAccessor[computedProp]) {
inst._setPendingProperty(computedProp, result, true);
} else {
inst[computedProp] = result;
}
} | javascript | function runComputedEffect(inst, property, props, oldProps, info) {
let result = runMethodEffect(inst, property, props, oldProps, info);
let computedProp = info.methodInfo;
if (inst.__dataHasAccessor && inst.__dataHasAccessor[computedProp]) {
inst._setPendingProperty(computedProp, result, true);
} else {
inst[computedProp] = result;
}
} | [
"function",
"runComputedEffect",
"(",
"inst",
",",
"property",
",",
"props",
",",
"oldProps",
",",
"info",
")",
"{",
"let",
"result",
"=",
"runMethodEffect",
"(",
"inst",
",",
"property",
",",
"props",
",",
"oldProps",
",",
"info",
")",
";",
"let",
"computedProp",
"=",
"info",
".",
"methodInfo",
";",
"if",
"(",
"inst",
".",
"__dataHasAccessor",
"&&",
"inst",
".",
"__dataHasAccessor",
"[",
"computedProp",
"]",
")",
"{",
"inst",
".",
"_setPendingProperty",
"(",
"computedProp",
",",
"result",
",",
"true",
")",
";",
"}",
"else",
"{",
"inst",
"[",
"computedProp",
"]",
"=",
"result",
";",
"}",
"}"
] | Implements the "computed property" effect by running the method with the
values of the arguments specified in the `info` object and setting the
return value to the computed property specified.
@param {!PropertyEffectsType} inst The instance the effect will be run on
@param {string} property Name of property
@param {Object} props Bag of current property changes
@param {Object} oldProps Bag of previous values for changed properties
@param {?} info Effect metadata
@return {void}
@private | [
"Implements",
"the",
"computed",
"property",
"effect",
"by",
"running",
"the",
"method",
"with",
"the",
"values",
"of",
"the",
"arguments",
"specified",
"in",
"the",
"info",
"object",
"and",
"setting",
"the",
"return",
"value",
"to",
"the",
"computed",
"property",
"specified",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L431-L439 |
5,197 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | computeLinkedPaths | function computeLinkedPaths(inst, path, value) {
let links = inst.__dataLinkedPaths;
if (links) {
let link;
for (let a in links) {
let b = links[a];
if (isDescendant(a, path)) {
link = translate(a, b, path);
inst._setPendingPropertyOrPath(link, value, true, true);
} else if (isDescendant(b, path)) {
link = translate(b, a, path);
inst._setPendingPropertyOrPath(link, value, true, true);
}
}
}
} | javascript | function computeLinkedPaths(inst, path, value) {
let links = inst.__dataLinkedPaths;
if (links) {
let link;
for (let a in links) {
let b = links[a];
if (isDescendant(a, path)) {
link = translate(a, b, path);
inst._setPendingPropertyOrPath(link, value, true, true);
} else if (isDescendant(b, path)) {
link = translate(b, a, path);
inst._setPendingPropertyOrPath(link, value, true, true);
}
}
}
} | [
"function",
"computeLinkedPaths",
"(",
"inst",
",",
"path",
",",
"value",
")",
"{",
"let",
"links",
"=",
"inst",
".",
"__dataLinkedPaths",
";",
"if",
"(",
"links",
")",
"{",
"let",
"link",
";",
"for",
"(",
"let",
"a",
"in",
"links",
")",
"{",
"let",
"b",
"=",
"links",
"[",
"a",
"]",
";",
"if",
"(",
"isDescendant",
"(",
"a",
",",
"path",
")",
")",
"{",
"link",
"=",
"translate",
"(",
"a",
",",
"b",
",",
"path",
")",
";",
"inst",
".",
"_setPendingPropertyOrPath",
"(",
"link",
",",
"value",
",",
"true",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"isDescendant",
"(",
"b",
",",
"path",
")",
")",
"{",
"link",
"=",
"translate",
"(",
"b",
",",
"a",
",",
"path",
")",
";",
"inst",
".",
"_setPendingPropertyOrPath",
"(",
"link",
",",
"value",
",",
"true",
",",
"true",
")",
";",
"}",
"}",
"}",
"}"
] | Computes path changes based on path links set up using the `linkPaths`
API.
@param {!PropertyEffectsType} inst The instance whose props are changing
@param {string | !Array<(string|number)>} path Path that has changed
@param {*} value Value of changed path
@return {void}
@private | [
"Computes",
"path",
"changes",
"based",
"on",
"path",
"links",
"set",
"up",
"using",
"the",
"linkPaths",
"API",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L451-L466 |
5,198 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | addEffectForBindingPart | function addEffectForBindingPart(constructor, templateInfo, binding, part, index) {
if (!part.literal) {
if (binding.kind === 'attribute' && binding.target[0] === '-') {
console.warn('Cannot set attribute ' + binding.target +
' because "-" is not a valid attribute starting character');
} else {
let dependencies = part.dependencies;
let info = { index, binding, part, evaluator: constructor };
for (let j=0; j<dependencies.length; j++) {
let trigger = dependencies[j];
if (typeof trigger == 'string') {
trigger = parseArg(trigger);
trigger.wildcard = true;
}
constructor._addTemplatePropertyEffect(templateInfo, trigger.rootProperty, {
fn: runBindingEffect,
info, trigger
});
}
}
}
} | javascript | function addEffectForBindingPart(constructor, templateInfo, binding, part, index) {
if (!part.literal) {
if (binding.kind === 'attribute' && binding.target[0] === '-') {
console.warn('Cannot set attribute ' + binding.target +
' because "-" is not a valid attribute starting character');
} else {
let dependencies = part.dependencies;
let info = { index, binding, part, evaluator: constructor };
for (let j=0; j<dependencies.length; j++) {
let trigger = dependencies[j];
if (typeof trigger == 'string') {
trigger = parseArg(trigger);
trigger.wildcard = true;
}
constructor._addTemplatePropertyEffect(templateInfo, trigger.rootProperty, {
fn: runBindingEffect,
info, trigger
});
}
}
}
} | [
"function",
"addEffectForBindingPart",
"(",
"constructor",
",",
"templateInfo",
",",
"binding",
",",
"part",
",",
"index",
")",
"{",
"if",
"(",
"!",
"part",
".",
"literal",
")",
"{",
"if",
"(",
"binding",
".",
"kind",
"===",
"'attribute'",
"&&",
"binding",
".",
"target",
"[",
"0",
"]",
"===",
"'-'",
")",
"{",
"console",
".",
"warn",
"(",
"'Cannot set attribute '",
"+",
"binding",
".",
"target",
"+",
"' because \"-\" is not a valid attribute starting character'",
")",
";",
"}",
"else",
"{",
"let",
"dependencies",
"=",
"part",
".",
"dependencies",
";",
"let",
"info",
"=",
"{",
"index",
",",
"binding",
",",
"part",
",",
"evaluator",
":",
"constructor",
"}",
";",
"for",
"(",
"let",
"j",
"=",
"0",
";",
"j",
"<",
"dependencies",
".",
"length",
";",
"j",
"++",
")",
"{",
"let",
"trigger",
"=",
"dependencies",
"[",
"j",
"]",
";",
"if",
"(",
"typeof",
"trigger",
"==",
"'string'",
")",
"{",
"trigger",
"=",
"parseArg",
"(",
"trigger",
")",
";",
"trigger",
".",
"wildcard",
"=",
"true",
";",
"}",
"constructor",
".",
"_addTemplatePropertyEffect",
"(",
"templateInfo",
",",
"trigger",
".",
"rootProperty",
",",
"{",
"fn",
":",
"runBindingEffect",
",",
"info",
",",
"trigger",
"}",
")",
";",
"}",
"}",
"}",
"}"
] | Adds property effects to the given `templateInfo` for the given binding
part.
@param {Function} constructor Class that `_parseTemplate` is currently
running on
@param {TemplateInfo} templateInfo Template metadata for current template
@param {!Binding} binding Binding metadata
@param {!BindingPart} part Binding part metadata
@param {number} index Index into `nodeInfoList` for this node
@return {void} | [
"Adds",
"property",
"effects",
"to",
"the",
"given",
"templateInfo",
"for",
"the",
"given",
"binding",
"part",
"."
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L519-L540 |
5,199 | catapult-project/catapult | third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js | computeBindingValue | function computeBindingValue(node, value, binding, part) {
if (binding.isCompound) {
let storage = node.__dataCompoundStorage[binding.target];
storage[part.compoundIndex] = value;
value = storage.join('');
}
if (binding.kind !== 'attribute') {
// Some browsers serialize `undefined` to `"undefined"`
if (binding.target === 'textContent' ||
(binding.target === 'value' &&
(node.localName === 'input' || node.localName === 'textarea'))) {
value = value == undefined ? '' : value;
}
}
return value;
} | javascript | function computeBindingValue(node, value, binding, part) {
if (binding.isCompound) {
let storage = node.__dataCompoundStorage[binding.target];
storage[part.compoundIndex] = value;
value = storage.join('');
}
if (binding.kind !== 'attribute') {
// Some browsers serialize `undefined` to `"undefined"`
if (binding.target === 'textContent' ||
(binding.target === 'value' &&
(node.localName === 'input' || node.localName === 'textarea'))) {
value = value == undefined ? '' : value;
}
}
return value;
} | [
"function",
"computeBindingValue",
"(",
"node",
",",
"value",
",",
"binding",
",",
"part",
")",
"{",
"if",
"(",
"binding",
".",
"isCompound",
")",
"{",
"let",
"storage",
"=",
"node",
".",
"__dataCompoundStorage",
"[",
"binding",
".",
"target",
"]",
";",
"storage",
"[",
"part",
".",
"compoundIndex",
"]",
"=",
"value",
";",
"value",
"=",
"storage",
".",
"join",
"(",
"''",
")",
";",
"}",
"if",
"(",
"binding",
".",
"kind",
"!==",
"'attribute'",
")",
"{",
"// Some browsers serialize `undefined` to `\"undefined\"`",
"if",
"(",
"binding",
".",
"target",
"===",
"'textContent'",
"||",
"(",
"binding",
".",
"target",
"===",
"'value'",
"&&",
"(",
"node",
".",
"localName",
"===",
"'input'",
"||",
"node",
".",
"localName",
"===",
"'textarea'",
")",
")",
")",
"{",
"value",
"=",
"value",
"==",
"undefined",
"?",
"''",
":",
"value",
";",
"}",
"}",
"return",
"value",
";",
"}"
] | Transforms an "binding" effect value based on compound & negation
effect metadata, as well as handling for special-case properties
@param {Node} node Node the value will be set to
@param {*} value Value to set
@param {!Binding} binding Binding metadata
@param {!BindingPart} part Binding part metadata
@return {*} Transformed value to set
@private | [
"Transforms",
"an",
"binding",
"effect",
"value",
"based",
"on",
"compound",
"&",
"negation",
"effect",
"metadata",
"as",
"well",
"as",
"handling",
"for",
"special",
"-",
"case",
"properties"
] | 992929ffccac68827869a497f01ee4d653ed4f25 | https://github.com/catapult-project/catapult/blob/992929ffccac68827869a497f01ee4d653ed4f25/third_party/polymer3/bower_components/polymer/lib/mixins/property-effects.js#L631-L646 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.