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
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,900 | angular/material | docs/app/js/codepen.js | Codepen | function Codepen($demoAngularScripts, $document, codepenDataAdapter) {
// The following URL used to be HTTP and not HTTPS to allow us to do localhost testing
// It's no longer working, for more info:
// https://blog.codepen.io/2017/03/31/codepen-going-https/
var CODEPEN_API = 'https://codepen.io/pen/define/';
return {
editOnCodepen: editOnCodepen
};
// Creates a codepen from the given demo model by posting to Codepen's API
// using a hidden form. The hidden form is necessary to avoid a CORS issue.
// See http://blog.codepen.io/documentation/api/prefill
function editOnCodepen(demo) {
var externalScripts = $demoAngularScripts.all();
externalScripts.push('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.js');
var data = codepenDataAdapter.translate(demo, externalScripts);
var form = buildForm(data);
$document.find('body').append(form);
form[0].submit();
form.remove();
}
// Builds a hidden form with data necessary to create a codepen.
function buildForm(data) {
var form = angular.element(
'<form style="display: none;" method="post" target="_blank" action="' +
CODEPEN_API +
'"></form>'
);
var input = '<input type="hidden" name="data" value="' + escapeJsonQuotes(data) + '" />';
form.append(input);
return form;
}
// Recommended by Codepen to escape quotes.
// See http://blog.codepen.io/documentation/api/prefill
function escapeJsonQuotes(json) {
return JSON.stringify(json)
.replace(/'/g, "&apos;")
.replace(/"/g, "&quot;")
/**
* Codepen was unescaping < (<) and > (>) which caused, on some demos,
* an unclosed elements (like <md-select>).
* Used different unicode lookalike characters so it won't be considered as an element
*/
.replace(/&lt;/g, "˂") // http://graphemica.com/%CB%82
.replace(/&gt;/g, "˃"); // http://graphemica.com/%CB%83
}
} | javascript | function Codepen($demoAngularScripts, $document, codepenDataAdapter) {
// The following URL used to be HTTP and not HTTPS to allow us to do localhost testing
// It's no longer working, for more info:
// https://blog.codepen.io/2017/03/31/codepen-going-https/
var CODEPEN_API = 'https://codepen.io/pen/define/';
return {
editOnCodepen: editOnCodepen
};
// Creates a codepen from the given demo model by posting to Codepen's API
// using a hidden form. The hidden form is necessary to avoid a CORS issue.
// See http://blog.codepen.io/documentation/api/prefill
function editOnCodepen(demo) {
var externalScripts = $demoAngularScripts.all();
externalScripts.push('https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.js');
var data = codepenDataAdapter.translate(demo, externalScripts);
var form = buildForm(data);
$document.find('body').append(form);
form[0].submit();
form.remove();
}
// Builds a hidden form with data necessary to create a codepen.
function buildForm(data) {
var form = angular.element(
'<form style="display: none;" method="post" target="_blank" action="' +
CODEPEN_API +
'"></form>'
);
var input = '<input type="hidden" name="data" value="' + escapeJsonQuotes(data) + '" />';
form.append(input);
return form;
}
// Recommended by Codepen to escape quotes.
// See http://blog.codepen.io/documentation/api/prefill
function escapeJsonQuotes(json) {
return JSON.stringify(json)
.replace(/'/g, "&apos;")
.replace(/"/g, "&quot;")
/**
* Codepen was unescaping < (<) and > (>) which caused, on some demos,
* an unclosed elements (like <md-select>).
* Used different unicode lookalike characters so it won't be considered as an element
*/
.replace(/&lt;/g, "˂") // http://graphemica.com/%CB%82
.replace(/&gt;/g, "˃"); // http://graphemica.com/%CB%83
}
} | [
"function",
"Codepen",
"(",
"$demoAngularScripts",
",",
"$document",
",",
"codepenDataAdapter",
")",
"{",
"// The following URL used to be HTTP and not HTTPS to allow us to do localhost testing",
"// It's no longer working, for more info:",
"// https://blog.codepen.io/2017/03/31/codepen-going-https/",
"var",
"CODEPEN_API",
"=",
"'https://codepen.io/pen/define/'",
";",
"return",
"{",
"editOnCodepen",
":",
"editOnCodepen",
"}",
";",
"// Creates a codepen from the given demo model by posting to Codepen's API",
"// using a hidden form. The hidden form is necessary to avoid a CORS issue.",
"// See http://blog.codepen.io/documentation/api/prefill",
"function",
"editOnCodepen",
"(",
"demo",
")",
"{",
"var",
"externalScripts",
"=",
"$demoAngularScripts",
".",
"all",
"(",
")",
";",
"externalScripts",
".",
"push",
"(",
"'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.js'",
")",
";",
"var",
"data",
"=",
"codepenDataAdapter",
".",
"translate",
"(",
"demo",
",",
"externalScripts",
")",
";",
"var",
"form",
"=",
"buildForm",
"(",
"data",
")",
";",
"$document",
".",
"find",
"(",
"'body'",
")",
".",
"append",
"(",
"form",
")",
";",
"form",
"[",
"0",
"]",
".",
"submit",
"(",
")",
";",
"form",
".",
"remove",
"(",
")",
";",
"}",
"// Builds a hidden form with data necessary to create a codepen.",
"function",
"buildForm",
"(",
"data",
")",
"{",
"var",
"form",
"=",
"angular",
".",
"element",
"(",
"'<form style=\"display: none;\" method=\"post\" target=\"_blank\" action=\"'",
"+",
"CODEPEN_API",
"+",
"'\"></form>'",
")",
";",
"var",
"input",
"=",
"'<input type=\"hidden\" name=\"data\" value=\"'",
"+",
"escapeJsonQuotes",
"(",
"data",
")",
"+",
"'\" />'",
";",
"form",
".",
"append",
"(",
"input",
")",
";",
"return",
"form",
";",
"}",
"// Recommended by Codepen to escape quotes.",
"// See http://blog.codepen.io/documentation/api/prefill",
"function",
"escapeJsonQuotes",
"(",
"json",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"json",
")",
".",
"replace",
"(",
"/",
"'",
"/",
"g",
",",
"\"&apos;\"",
")",
".",
"replace",
"(",
"/",
"\"",
"/",
"g",
",",
"\"&quot;\"",
")",
"/**\n * Codepen was unescaping < (<) and > (>) which caused, on some demos,\n * an unclosed elements (like <md-select>).\n * Used different unicode lookalike characters so it won't be considered as an element\n */",
".",
"replace",
"(",
"/",
"&lt;",
"/",
"g",
",",
"\"˂\"",
")",
"// http://graphemica.com/%CB%82",
".",
"replace",
"(",
"/",
"&gt;",
"/",
"g",
",",
"\"˃\"",
")",
";",
"// http://graphemica.com/%CB%83",
"}",
"}"
] | Provides a service to open a code example in codepen. | [
"Provides",
"a",
"service",
"to",
"open",
"a",
"code",
"example",
"in",
"codepen",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L7-L57 |
4,901 | angular/material | docs/app/js/codepen.js | buildForm | function buildForm(data) {
var form = angular.element(
'<form style="display: none;" method="post" target="_blank" action="' +
CODEPEN_API +
'"></form>'
);
var input = '<input type="hidden" name="data" value="' + escapeJsonQuotes(data) + '" />';
form.append(input);
return form;
} | javascript | function buildForm(data) {
var form = angular.element(
'<form style="display: none;" method="post" target="_blank" action="' +
CODEPEN_API +
'"></form>'
);
var input = '<input type="hidden" name="data" value="' + escapeJsonQuotes(data) + '" />';
form.append(input);
return form;
} | [
"function",
"buildForm",
"(",
"data",
")",
"{",
"var",
"form",
"=",
"angular",
".",
"element",
"(",
"'<form style=\"display: none;\" method=\"post\" target=\"_blank\" action=\"'",
"+",
"CODEPEN_API",
"+",
"'\"></form>'",
")",
";",
"var",
"input",
"=",
"'<input type=\"hidden\" name=\"data\" value=\"'",
"+",
"escapeJsonQuotes",
"(",
"data",
")",
"+",
"'\" />'",
";",
"form",
".",
"append",
"(",
"input",
")",
";",
"return",
"form",
";",
"}"
] | Builds a hidden form with data necessary to create a codepen. | [
"Builds",
"a",
"hidden",
"form",
"with",
"data",
"necessary",
"to",
"create",
"a",
"codepen",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L32-L41 |
4,902 | angular/material | docs/app/js/codepen.js | processHtml | function processHtml(demo) {
var allContent = demo.files.index.contents;
var processors = [
applyAngularAttributesToParentElement,
insertTemplatesAsScriptTags,
htmlEscapeAmpersand
];
processors.forEach(function(processor) {
allContent = processor(allContent, demo);
});
return allContent;
} | javascript | function processHtml(demo) {
var allContent = demo.files.index.contents;
var processors = [
applyAngularAttributesToParentElement,
insertTemplatesAsScriptTags,
htmlEscapeAmpersand
];
processors.forEach(function(processor) {
allContent = processor(allContent, demo);
});
return allContent;
} | [
"function",
"processHtml",
"(",
"demo",
")",
"{",
"var",
"allContent",
"=",
"demo",
".",
"files",
".",
"index",
".",
"contents",
";",
"var",
"processors",
"=",
"[",
"applyAngularAttributesToParentElement",
",",
"insertTemplatesAsScriptTags",
",",
"htmlEscapeAmpersand",
"]",
";",
"processors",
".",
"forEach",
"(",
"function",
"(",
"processor",
")",
"{",
"allContent",
"=",
"processor",
"(",
"allContent",
",",
"demo",
")",
";",
"}",
")",
";",
"return",
"allContent",
";",
"}"
] | Modifies index.html with necessary changes in order to display correctly in codepen See each processor to determine how each modifies the html | [
"Modifies",
"index",
".",
"html",
"with",
"necessary",
"changes",
"in",
"order",
"to",
"display",
"correctly",
"in",
"codepen",
"See",
"each",
"processor",
"to",
"determine",
"how",
"each",
"modifies",
"the",
"html"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L98-L113 |
4,903 | angular/material | docs/app/js/codepen.js | processJs | function processJs(jsFiles) {
var mergedJs = mergeFiles(jsFiles).join(' ');
var script = replaceDemoModuleWithCodepenModule(mergedJs);
return script;
} | javascript | function processJs(jsFiles) {
var mergedJs = mergeFiles(jsFiles).join(' ');
var script = replaceDemoModuleWithCodepenModule(mergedJs);
return script;
} | [
"function",
"processJs",
"(",
"jsFiles",
")",
"{",
"var",
"mergedJs",
"=",
"mergeFiles",
"(",
"jsFiles",
")",
".",
"join",
"(",
"' '",
")",
";",
"var",
"script",
"=",
"replaceDemoModuleWithCodepenModule",
"(",
"mergedJs",
")",
";",
"return",
"script",
";",
"}"
] | Applies modifications the javascript prior to sending to codepen. Currently merges js files and replaces the module with the Codepen module. See documentation for replaceDemoModuleWithCodepenModule. | [
"Applies",
"modifications",
"the",
"javascript",
"prior",
"to",
"sending",
"to",
"codepen",
".",
"Currently",
"merges",
"js",
"files",
"and",
"replaces",
"the",
"module",
"with",
"the",
"Codepen",
"module",
".",
"See",
"documentation",
"for",
"replaceDemoModuleWithCodepenModule",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L148-L152 |
4,904 | angular/material | docs/app/js/codepen.js | applyAngularAttributesToParentElement | function applyAngularAttributesToParentElement(html, demo) {
var tmp;
// Grab only the DIV for the demo...
angular.forEach(angular.element(html), function(it,key){
if ((it.nodeName != "SCRIPT") && (it.nodeName != "#text")) {
tmp = angular.element(it);
}
});
tmp.addClass(demo.id);
tmp.attr('ng-app', 'MyApp');
return tmp[0].outerHTML;
} | javascript | function applyAngularAttributesToParentElement(html, demo) {
var tmp;
// Grab only the DIV for the demo...
angular.forEach(angular.element(html), function(it,key){
if ((it.nodeName != "SCRIPT") && (it.nodeName != "#text")) {
tmp = angular.element(it);
}
});
tmp.addClass(demo.id);
tmp.attr('ng-app', 'MyApp');
return tmp[0].outerHTML;
} | [
"function",
"applyAngularAttributesToParentElement",
"(",
"html",
",",
"demo",
")",
"{",
"var",
"tmp",
";",
"// Grab only the DIV for the demo...",
"angular",
".",
"forEach",
"(",
"angular",
".",
"element",
"(",
"html",
")",
",",
"function",
"(",
"it",
",",
"key",
")",
"{",
"if",
"(",
"(",
"it",
".",
"nodeName",
"!=",
"\"SCRIPT\"",
")",
"&&",
"(",
"it",
".",
"nodeName",
"!=",
"\"#text\"",
")",
")",
"{",
"tmp",
"=",
"angular",
".",
"element",
"(",
"it",
")",
";",
"}",
"}",
")",
";",
"tmp",
".",
"addClass",
"(",
"demo",
".",
"id",
")",
";",
"tmp",
".",
"attr",
"(",
"'ng-app'",
",",
"'MyApp'",
")",
";",
"return",
"tmp",
"[",
"0",
"]",
".",
"outerHTML",
";",
"}"
] | Adds class to parent element so that styles are applied correctly Adds ng-app attribute. This is the same module name provided in the asset-cache.js | [
"Adds",
"class",
"to",
"parent",
"element",
"so",
"that",
"styles",
"are",
"applied",
"correctly",
"Adds",
"ng",
"-",
"app",
"attribute",
".",
"This",
"is",
"the",
"same",
"module",
"name",
"provided",
"in",
"the",
"asset",
"-",
"cache",
".",
"js"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L163-L176 |
4,905 | angular/material | docs/app/js/codepen.js | insertTemplatesAsScriptTags | function insertTemplatesAsScriptTags(indexHtml, demo) {
if (demo.files.html.length) {
var tmp = angular.element(indexHtml);
angular.forEach(demo.files.html, function(template) {
tmp.append("<script type='text/ng-template' id='" +
template.name + "'>" +
template.contents +
"</script>");
});
return tmp[0].outerHTML;
}
return indexHtml;
} | javascript | function insertTemplatesAsScriptTags(indexHtml, demo) {
if (demo.files.html.length) {
var tmp = angular.element(indexHtml);
angular.forEach(demo.files.html, function(template) {
tmp.append("<script type='text/ng-template' id='" +
template.name + "'>" +
template.contents +
"</script>");
});
return tmp[0].outerHTML;
}
return indexHtml;
} | [
"function",
"insertTemplatesAsScriptTags",
"(",
"indexHtml",
",",
"demo",
")",
"{",
"if",
"(",
"demo",
".",
"files",
".",
"html",
".",
"length",
")",
"{",
"var",
"tmp",
"=",
"angular",
".",
"element",
"(",
"indexHtml",
")",
";",
"angular",
".",
"forEach",
"(",
"demo",
".",
"files",
".",
"html",
",",
"function",
"(",
"template",
")",
"{",
"tmp",
".",
"append",
"(",
"\"<script type='text/ng-template' id='\"",
"+",
"template",
".",
"name",
"+",
"\"'>\"",
"+",
"template",
".",
"contents",
"+",
"\"</script>\"",
")",
";",
"}",
")",
";",
"return",
"tmp",
"[",
"0",
"]",
".",
"outerHTML",
";",
"}",
"return",
"indexHtml",
";",
"}"
] | Adds templates inline in the html, so that templates are cached in the example | [
"Adds",
"templates",
"inline",
"in",
"the",
"html",
"so",
"that",
"templates",
"are",
"cached",
"in",
"the",
"example"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/codepen.js#L179-L191 |
4,906 | angular/material | src/components/colors/colors.js | parseColor | function parseColor(color, contrast) {
contrast = contrast || false;
var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];
rgbValues = contrast ? rgbValues.contrast : rgbValues.value;
return $mdUtil.supplant('rgba({0}, {1}, {2}, {3})',
[rgbValues[0], rgbValues[1], rgbValues[2], rgbValues[3] || color.opacity]
);
} | javascript | function parseColor(color, contrast) {
contrast = contrast || false;
var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];
rgbValues = contrast ? rgbValues.contrast : rgbValues.value;
return $mdUtil.supplant('rgba({0}, {1}, {2}, {3})',
[rgbValues[0], rgbValues[1], rgbValues[2], rgbValues[3] || color.opacity]
);
} | [
"function",
"parseColor",
"(",
"color",
",",
"contrast",
")",
"{",
"contrast",
"=",
"contrast",
"||",
"false",
";",
"var",
"rgbValues",
"=",
"$mdTheming",
".",
"PALETTES",
"[",
"color",
".",
"palette",
"]",
"[",
"color",
".",
"hue",
"]",
";",
"rgbValues",
"=",
"contrast",
"?",
"rgbValues",
".",
"contrast",
":",
"rgbValues",
".",
"value",
";",
"return",
"$mdUtil",
".",
"supplant",
"(",
"'rgba({0}, {1}, {2}, {3})'",
",",
"[",
"rgbValues",
"[",
"0",
"]",
",",
"rgbValues",
"[",
"1",
"]",
",",
"rgbValues",
"[",
"2",
"]",
",",
"rgbValues",
"[",
"3",
"]",
"||",
"color",
".",
"opacity",
"]",
")",
";",
"}"
] | Return the parsed color
@param {{hue: *, theme: any, palette: *, opacity: (*|string|number)}} color hash map of color
definitions
@param {boolean=} contrast whether use contrast color for foreground. Defaults to false.
@returns {string} rgba color string | [
"Return",
"the",
"parsed",
"color"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/colors/colors.js#L120-L129 |
4,907 | angular/material | src/components/colors/colors.js | extractColorOptions | function extractColorOptions(expression) {
var parts = expression.split('-');
var hasTheme = angular.isDefined($mdTheming.THEMES[parts[0]]);
var theme = hasTheme ? parts.splice(0, 1)[0] : $mdTheming.defaultTheme();
return {
theme: theme,
palette: extractPalette(parts, theme),
hue: extractHue(parts, theme),
opacity: parts[2] || 1
};
} | javascript | function extractColorOptions(expression) {
var parts = expression.split('-');
var hasTheme = angular.isDefined($mdTheming.THEMES[parts[0]]);
var theme = hasTheme ? parts.splice(0, 1)[0] : $mdTheming.defaultTheme();
return {
theme: theme,
palette: extractPalette(parts, theme),
hue: extractHue(parts, theme),
opacity: parts[2] || 1
};
} | [
"function",
"extractColorOptions",
"(",
"expression",
")",
"{",
"var",
"parts",
"=",
"expression",
".",
"split",
"(",
"'-'",
")",
";",
"var",
"hasTheme",
"=",
"angular",
".",
"isDefined",
"(",
"$mdTheming",
".",
"THEMES",
"[",
"parts",
"[",
"0",
"]",
"]",
")",
";",
"var",
"theme",
"=",
"hasTheme",
"?",
"parts",
".",
"splice",
"(",
"0",
",",
"1",
")",
"[",
"0",
"]",
":",
"$mdTheming",
".",
"defaultTheme",
"(",
")",
";",
"return",
"{",
"theme",
":",
"theme",
",",
"palette",
":",
"extractPalette",
"(",
"parts",
",",
"theme",
")",
",",
"hue",
":",
"extractHue",
"(",
"parts",
",",
"theme",
")",
",",
"opacity",
":",
"parts",
"[",
"2",
"]",
"||",
"1",
"}",
";",
"}"
] | For the evaluated expression, extract the color parts into a hash map
@param {string} expression color expression like 'red-800', 'red-A200-0.3',
'myTheme-primary', or 'myTheme-primary-400'
@returns {{hue: *, theme: any, palette: *, opacity: (*|string|number)}} | [
"For",
"the",
"evaluated",
"expression",
"extract",
"the",
"color",
"parts",
"into",
"a",
"hash",
"map"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/colors/colors.js#L175-L186 |
4,908 | angular/material | src/components/colors/colors.js | extractPalette | function extractPalette(parts, theme) {
// If the next section is one of the palettes we assume it's a two word palette
// Two word palette can be also written in camelCase, forming camelCase to dash-case
var isTwoWord = parts.length > 1 && colorPalettes.indexOf(parts[1]) !== -1;
var palette = parts[0].replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
if (isTwoWord) palette = parts[0] + '-' + parts.splice(1, 1);
if (colorPalettes.indexOf(palette) === -1) {
// If the palette is not in the palette list it's one of primary/accent/warn/background
var scheme = $mdTheming.THEMES[theme].colors[palette];
if (!scheme) {
throw new Error($mdUtil.supplant(
'mdColors: couldn\'t find \'{palette}\' in the palettes.',
{palette: palette}));
}
palette = scheme.name;
}
return palette;
} | javascript | function extractPalette(parts, theme) {
// If the next section is one of the palettes we assume it's a two word palette
// Two word palette can be also written in camelCase, forming camelCase to dash-case
var isTwoWord = parts.length > 1 && colorPalettes.indexOf(parts[1]) !== -1;
var palette = parts[0].replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
if (isTwoWord) palette = parts[0] + '-' + parts.splice(1, 1);
if (colorPalettes.indexOf(palette) === -1) {
// If the palette is not in the palette list it's one of primary/accent/warn/background
var scheme = $mdTheming.THEMES[theme].colors[palette];
if (!scheme) {
throw new Error($mdUtil.supplant(
'mdColors: couldn\'t find \'{palette}\' in the palettes.',
{palette: palette}));
}
palette = scheme.name;
}
return palette;
} | [
"function",
"extractPalette",
"(",
"parts",
",",
"theme",
")",
"{",
"// If the next section is one of the palettes we assume it's a two word palette",
"// Two word palette can be also written in camelCase, forming camelCase to dash-case",
"var",
"isTwoWord",
"=",
"parts",
".",
"length",
">",
"1",
"&&",
"colorPalettes",
".",
"indexOf",
"(",
"parts",
"[",
"1",
"]",
")",
"!==",
"-",
"1",
";",
"var",
"palette",
"=",
"parts",
"[",
"0",
"]",
".",
"replace",
"(",
"/",
"([a-z])([A-Z])",
"/",
"g",
",",
"'$1-$2'",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"isTwoWord",
")",
"palette",
"=",
"parts",
"[",
"0",
"]",
"+",
"'-'",
"+",
"parts",
".",
"splice",
"(",
"1",
",",
"1",
")",
";",
"if",
"(",
"colorPalettes",
".",
"indexOf",
"(",
"palette",
")",
"===",
"-",
"1",
")",
"{",
"// If the palette is not in the palette list it's one of primary/accent/warn/background",
"var",
"scheme",
"=",
"$mdTheming",
".",
"THEMES",
"[",
"theme",
"]",
".",
"colors",
"[",
"palette",
"]",
";",
"if",
"(",
"!",
"scheme",
")",
"{",
"throw",
"new",
"Error",
"(",
"$mdUtil",
".",
"supplant",
"(",
"'mdColors: couldn\\'t find \\'{palette}\\' in the palettes.'",
",",
"{",
"palette",
":",
"palette",
"}",
")",
")",
";",
"}",
"palette",
"=",
"scheme",
".",
"name",
";",
"}",
"return",
"palette",
";",
"}"
] | Calculate the theme palette name
@param {Array} parts
@param {string} theme name
@return {string} | [
"Calculate",
"the",
"theme",
"palette",
"name"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/colors/colors.js#L194-L215 |
4,909 | angular/material | src/components/tabs/js/tabsController.js | compileTemplate | function compileTemplate () {
var template = $attrs.$mdTabsTemplate,
element = angular.element($element[0].querySelector('md-tab-data'));
element.html(template);
$compile(element.contents())(ctrl.parent);
delete $attrs.$mdTabsTemplate;
} | javascript | function compileTemplate () {
var template = $attrs.$mdTabsTemplate,
element = angular.element($element[0].querySelector('md-tab-data'));
element.html(template);
$compile(element.contents())(ctrl.parent);
delete $attrs.$mdTabsTemplate;
} | [
"function",
"compileTemplate",
"(",
")",
"{",
"var",
"template",
"=",
"$attrs",
".",
"$mdTabsTemplate",
",",
"element",
"=",
"angular",
".",
"element",
"(",
"$element",
"[",
"0",
"]",
".",
"querySelector",
"(",
"'md-tab-data'",
")",
")",
";",
"element",
".",
"html",
"(",
"template",
")",
";",
"$compile",
"(",
"element",
".",
"contents",
"(",
")",
")",
"(",
"ctrl",
".",
"parent",
")",
";",
"delete",
"$attrs",
".",
"$mdTabsTemplate",
";",
"}"
] | Compiles the template provided by the user. This is passed as an attribute from the tabs
directive's template function. | [
"Compiles",
"the",
"template",
"provided",
"by",
"the",
"user",
".",
"This",
"is",
"passed",
"as",
"an",
"attribute",
"from",
"the",
"tabs",
"directive",
"s",
"template",
"function",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L110-L117 |
4,910 | angular/material | src/components/tabs/js/tabsController.js | defineOneWayBinding | function defineOneWayBinding (key, handler) {
var attr = $attrs.$normalize('md-' + key);
if (handler) defineProperty(key, handler);
$attrs.$observe(attr, function (newValue) { ctrl[ key ] = newValue; });
} | javascript | function defineOneWayBinding (key, handler) {
var attr = $attrs.$normalize('md-' + key);
if (handler) defineProperty(key, handler);
$attrs.$observe(attr, function (newValue) { ctrl[ key ] = newValue; });
} | [
"function",
"defineOneWayBinding",
"(",
"key",
",",
"handler",
")",
"{",
"var",
"attr",
"=",
"$attrs",
".",
"$normalize",
"(",
"'md-'",
"+",
"key",
")",
";",
"if",
"(",
"handler",
")",
"defineProperty",
"(",
"key",
",",
"handler",
")",
";",
"$attrs",
".",
"$observe",
"(",
"attr",
",",
"function",
"(",
"newValue",
")",
"{",
"ctrl",
"[",
"key",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"}"
] | Creates a one-way binding manually rather than relying on AngularJS's isolated scope
@param key
@param handler | [
"Creates",
"a",
"one",
"-",
"way",
"binding",
"manually",
"rather",
"than",
"relying",
"on",
"AngularJS",
"s",
"isolated",
"scope"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L139-L143 |
4,911 | angular/material | src/components/tabs/js/tabsController.js | defineBooleanAttribute | function defineBooleanAttribute (key, handler) {
var attr = $attrs.$normalize('md-' + key);
if (handler) defineProperty(key, handler);
if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
$attrs.$observe(attr, updateValue);
function updateValue (newValue) {
ctrl[ key ] = newValue !== 'false';
}
} | javascript | function defineBooleanAttribute (key, handler) {
var attr = $attrs.$normalize('md-' + key);
if (handler) defineProperty(key, handler);
if ($attrs.hasOwnProperty(attr)) updateValue($attrs[attr]);
$attrs.$observe(attr, updateValue);
function updateValue (newValue) {
ctrl[ key ] = newValue !== 'false';
}
} | [
"function",
"defineBooleanAttribute",
"(",
"key",
",",
"handler",
")",
"{",
"var",
"attr",
"=",
"$attrs",
".",
"$normalize",
"(",
"'md-'",
"+",
"key",
")",
";",
"if",
"(",
"handler",
")",
"defineProperty",
"(",
"key",
",",
"handler",
")",
";",
"if",
"(",
"$attrs",
".",
"hasOwnProperty",
"(",
"attr",
")",
")",
"updateValue",
"(",
"$attrs",
"[",
"attr",
"]",
")",
";",
"$attrs",
".",
"$observe",
"(",
"attr",
",",
"updateValue",
")",
";",
"function",
"updateValue",
"(",
"newValue",
")",
"{",
"ctrl",
"[",
"key",
"]",
"=",
"newValue",
"!==",
"'false'",
";",
"}",
"}"
] | Defines boolean attributes with default value set to true. I.e. md-stretch-tabs with no value
will be treated as being truthy.
@param {string} key
@param {Function} handler | [
"Defines",
"boolean",
"attributes",
"with",
"default",
"value",
"set",
"to",
"true",
".",
"I",
".",
"e",
".",
"md",
"-",
"stretch",
"-",
"tabs",
"with",
"no",
"value",
"will",
"be",
"treated",
"as",
"being",
"truthy",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L151-L159 |
4,912 | angular/material | src/components/tabs/js/tabsController.js | handleFocusIndexChange | function handleFocusIndexChange (newIndex, oldIndex) {
if (newIndex === oldIndex) return;
if (!getElements().tabs[ newIndex ]) return;
adjustOffset();
redirectFocus();
} | javascript | function handleFocusIndexChange (newIndex, oldIndex) {
if (newIndex === oldIndex) return;
if (!getElements().tabs[ newIndex ]) return;
adjustOffset();
redirectFocus();
} | [
"function",
"handleFocusIndexChange",
"(",
"newIndex",
",",
"oldIndex",
")",
"{",
"if",
"(",
"newIndex",
"===",
"oldIndex",
")",
"return",
";",
"if",
"(",
"!",
"getElements",
"(",
")",
".",
"tabs",
"[",
"newIndex",
"]",
")",
"return",
";",
"adjustOffset",
"(",
")",
";",
"redirectFocus",
"(",
")",
";",
"}"
] | Update the UI whenever `ctrl.focusIndex` is updated
@param {number} newIndex
@param {number} oldIndex | [
"Update",
"the",
"UI",
"whenever",
"ctrl",
".",
"focusIndex",
"is",
"updated"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L248-L253 |
4,913 | angular/material | src/components/tabs/js/tabsController.js | handleResizeWhenVisible | function handleResizeWhenVisible () {
// if there is already a watcher waiting for resize, do nothing
if (handleResizeWhenVisible.watcher) return;
// otherwise, we will abuse the $watch function to check for visible
handleResizeWhenVisible.watcher = $scope.$watch(function () {
// since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates
$mdUtil.nextTick(function () {
// if the watcher has already run (ie. multiple digests in one cycle), do nothing
if (!handleResizeWhenVisible.watcher) return;
if ($element.prop('offsetParent')) {
handleResizeWhenVisible.watcher();
handleResizeWhenVisible.watcher = null;
handleWindowResize();
}
}, false);
});
} | javascript | function handleResizeWhenVisible () {
// if there is already a watcher waiting for resize, do nothing
if (handleResizeWhenVisible.watcher) return;
// otherwise, we will abuse the $watch function to check for visible
handleResizeWhenVisible.watcher = $scope.$watch(function () {
// since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates
$mdUtil.nextTick(function () {
// if the watcher has already run (ie. multiple digests in one cycle), do nothing
if (!handleResizeWhenVisible.watcher) return;
if ($element.prop('offsetParent')) {
handleResizeWhenVisible.watcher();
handleResizeWhenVisible.watcher = null;
handleWindowResize();
}
}, false);
});
} | [
"function",
"handleResizeWhenVisible",
"(",
")",
"{",
"// if there is already a watcher waiting for resize, do nothing",
"if",
"(",
"handleResizeWhenVisible",
".",
"watcher",
")",
"return",
";",
"// otherwise, we will abuse the $watch function to check for visible",
"handleResizeWhenVisible",
".",
"watcher",
"=",
"$scope",
".",
"$watch",
"(",
"function",
"(",
")",
"{",
"// since we are checking for DOM size, we use $mdUtil.nextTick() to wait for after the DOM updates",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"// if the watcher has already run (ie. multiple digests in one cycle), do nothing",
"if",
"(",
"!",
"handleResizeWhenVisible",
".",
"watcher",
")",
"return",
";",
"if",
"(",
"$element",
".",
"prop",
"(",
"'offsetParent'",
")",
")",
"{",
"handleResizeWhenVisible",
".",
"watcher",
"(",
")",
";",
"handleResizeWhenVisible",
".",
"watcher",
"=",
"null",
";",
"handleWindowResize",
"(",
")",
";",
"}",
"}",
",",
"false",
")",
";",
"}",
")",
";",
"}"
] | Queues up a call to `handleWindowResize` when a resize occurs while the tabs component is
hidden. | [
"Queues",
"up",
"a",
"call",
"to",
"handleWindowResize",
"when",
"a",
"resize",
"occurs",
"while",
"the",
"tabs",
"component",
"is",
"hidden",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L282-L300 |
4,914 | angular/material | src/components/tabs/js/tabsController.js | select | function select (index, canSkipClick) {
if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
// skip the click event if noSelectClick is enabled
if (canSkipClick && ctrl.noSelectClick) return;
// nextTick is required to prevent errors in user-defined click events
$mdUtil.nextTick(function () {
ctrl.tabs[ index ].element.triggerHandler('click');
}, false);
} | javascript | function select (index, canSkipClick) {
if (!locked) ctrl.focusIndex = ctrl.selectedIndex = index;
// skip the click event if noSelectClick is enabled
if (canSkipClick && ctrl.noSelectClick) return;
// nextTick is required to prevent errors in user-defined click events
$mdUtil.nextTick(function () {
ctrl.tabs[ index ].element.triggerHandler('click');
}, false);
} | [
"function",
"select",
"(",
"index",
",",
"canSkipClick",
")",
"{",
"if",
"(",
"!",
"locked",
")",
"ctrl",
".",
"focusIndex",
"=",
"ctrl",
".",
"selectedIndex",
"=",
"index",
";",
"// skip the click event if noSelectClick is enabled",
"if",
"(",
"canSkipClick",
"&&",
"ctrl",
".",
"noSelectClick",
")",
"return",
";",
"// nextTick is required to prevent errors in user-defined click events",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"ctrl",
".",
"tabs",
"[",
"index",
"]",
".",
"element",
".",
"triggerHandler",
"(",
"'click'",
")",
";",
"}",
",",
"false",
")",
";",
"}"
] | Update the selected index. Triggers a click event on the original `md-tab` element in order
to fire user-added click events if canSkipClick or `md-no-select-click` are false.
@param index
@param canSkipClick Optionally allow not firing the click event if `md-no-select-click` is also true. | [
"Update",
"the",
"selected",
"index",
".",
"Triggers",
"a",
"click",
"event",
"on",
"the",
"original",
"md",
"-",
"tab",
"element",
"in",
"order",
"to",
"fire",
"user",
"-",
"added",
"click",
"events",
"if",
"canSkipClick",
"or",
"md",
"-",
"no",
"-",
"select",
"-",
"click",
"are",
"false",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L339-L347 |
4,915 | angular/material | src/components/tabs/js/tabsController.js | scroll | function scroll (event) {
if (!ctrl.shouldPaginate) return;
event.preventDefault();
if (event.deltaY) {
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft + event.deltaY);
} else if (event.deltaX) {
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft + event.deltaX);
}
} | javascript | function scroll (event) {
if (!ctrl.shouldPaginate) return;
event.preventDefault();
if (event.deltaY) {
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft + event.deltaY);
} else if (event.deltaX) {
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft + event.deltaX);
}
} | [
"function",
"scroll",
"(",
"event",
")",
"{",
"if",
"(",
"!",
"ctrl",
".",
"shouldPaginate",
")",
"return",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"event",
".",
"deltaY",
")",
"{",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"ctrl",
".",
"offsetLeft",
"+",
"event",
".",
"deltaY",
")",
";",
"}",
"else",
"if",
"(",
"event",
".",
"deltaX",
")",
"{",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"ctrl",
".",
"offsetLeft",
"+",
"event",
".",
"deltaX",
")",
";",
"}",
"}"
] | When pagination is on, this makes sure the selected index is in view.
@param {WheelEvent} event | [
"When",
"pagination",
"is",
"on",
"this",
"makes",
"sure",
"the",
"selected",
"index",
"is",
"in",
"view",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L353-L361 |
4,916 | angular/material | src/components/tabs/js/tabsController.js | nextPage | function nextPage () {
if (!ctrl.canPageForward()) { return; }
var newOffset = MdTabsPaginationService.increasePageOffset(getElements(), ctrl.offsetLeft);
ctrl.offsetLeft = fixOffset(newOffset);
} | javascript | function nextPage () {
if (!ctrl.canPageForward()) { return; }
var newOffset = MdTabsPaginationService.increasePageOffset(getElements(), ctrl.offsetLeft);
ctrl.offsetLeft = fixOffset(newOffset);
} | [
"function",
"nextPage",
"(",
")",
"{",
"if",
"(",
"!",
"ctrl",
".",
"canPageForward",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"newOffset",
"=",
"MdTabsPaginationService",
".",
"increasePageOffset",
"(",
"getElements",
"(",
")",
",",
"ctrl",
".",
"offsetLeft",
")",
";",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"newOffset",
")",
";",
"}"
] | Slides the tabs over approximately one page forward. | [
"Slides",
"the",
"tabs",
"over",
"approximately",
"one",
"page",
"forward",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L366-L372 |
4,917 | angular/material | src/components/tabs/js/tabsController.js | previousPage | function previousPage () {
if (!ctrl.canPageBack()) { return; }
var newOffset = MdTabsPaginationService.decreasePageOffset(getElements(), ctrl.offsetLeft);
// Set the new offset
ctrl.offsetLeft = fixOffset(newOffset);
} | javascript | function previousPage () {
if (!ctrl.canPageBack()) { return; }
var newOffset = MdTabsPaginationService.decreasePageOffset(getElements(), ctrl.offsetLeft);
// Set the new offset
ctrl.offsetLeft = fixOffset(newOffset);
} | [
"function",
"previousPage",
"(",
")",
"{",
"if",
"(",
"!",
"ctrl",
".",
"canPageBack",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"newOffset",
"=",
"MdTabsPaginationService",
".",
"decreasePageOffset",
"(",
"getElements",
"(",
")",
",",
"ctrl",
".",
"offsetLeft",
")",
";",
"// Set the new offset",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"newOffset",
")",
";",
"}"
] | Slides the tabs over approximately one page backward. | [
"Slides",
"the",
"tabs",
"over",
"approximately",
"one",
"page",
"backward",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L377-L384 |
4,918 | angular/material | src/components/tabs/js/tabsController.js | handleWindowResize | function handleWindowResize () {
ctrl.lastSelectedIndex = ctrl.selectedIndex;
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
$mdUtil.nextTick(function () {
ctrl.updateInkBarStyles();
updatePagination();
});
} | javascript | function handleWindowResize () {
ctrl.lastSelectedIndex = ctrl.selectedIndex;
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
$mdUtil.nextTick(function () {
ctrl.updateInkBarStyles();
updatePagination();
});
} | [
"function",
"handleWindowResize",
"(",
")",
"{",
"ctrl",
".",
"lastSelectedIndex",
"=",
"ctrl",
".",
"selectedIndex",
";",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"ctrl",
".",
"offsetLeft",
")",
";",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"ctrl",
".",
"updateInkBarStyles",
"(",
")",
";",
"updatePagination",
"(",
")",
";",
"}",
")",
";",
"}"
] | Update size calculations when the window is resized. | [
"Update",
"size",
"calculations",
"when",
"the",
"window",
"is",
"resized",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L389-L397 |
4,919 | angular/material | src/components/tabs/js/tabsController.js | removeTab | function removeTab (tabData) {
if (destroyed) return;
var selectedIndex = ctrl.selectedIndex,
tab = ctrl.tabs.splice(tabData.getIndex(), 1)[ 0 ];
refreshIndex();
// when removing a tab, if the selected index did not change, we have to manually trigger the
// tab select/deselect events
if (ctrl.selectedIndex === selectedIndex) {
tab.scope.deselect();
ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
}
$mdUtil.nextTick(function () {
updatePagination();
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
});
} | javascript | function removeTab (tabData) {
if (destroyed) return;
var selectedIndex = ctrl.selectedIndex,
tab = ctrl.tabs.splice(tabData.getIndex(), 1)[ 0 ];
refreshIndex();
// when removing a tab, if the selected index did not change, we have to manually trigger the
// tab select/deselect events
if (ctrl.selectedIndex === selectedIndex) {
tab.scope.deselect();
ctrl.tabs[ ctrl.selectedIndex ] && ctrl.tabs[ ctrl.selectedIndex ].scope.select();
}
$mdUtil.nextTick(function () {
updatePagination();
ctrl.offsetLeft = fixOffset(ctrl.offsetLeft);
});
} | [
"function",
"removeTab",
"(",
"tabData",
")",
"{",
"if",
"(",
"destroyed",
")",
"return",
";",
"var",
"selectedIndex",
"=",
"ctrl",
".",
"selectedIndex",
",",
"tab",
"=",
"ctrl",
".",
"tabs",
".",
"splice",
"(",
"tabData",
".",
"getIndex",
"(",
")",
",",
"1",
")",
"[",
"0",
"]",
";",
"refreshIndex",
"(",
")",
";",
"// when removing a tab, if the selected index did not change, we have to manually trigger the",
"// tab select/deselect events",
"if",
"(",
"ctrl",
".",
"selectedIndex",
"===",
"selectedIndex",
")",
"{",
"tab",
".",
"scope",
".",
"deselect",
"(",
")",
";",
"ctrl",
".",
"tabs",
"[",
"ctrl",
".",
"selectedIndex",
"]",
"&&",
"ctrl",
".",
"tabs",
"[",
"ctrl",
".",
"selectedIndex",
"]",
".",
"scope",
".",
"select",
"(",
")",
";",
"}",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"updatePagination",
"(",
")",
";",
"ctrl",
".",
"offsetLeft",
"=",
"fixOffset",
"(",
"ctrl",
".",
"offsetLeft",
")",
";",
"}",
")",
";",
"}"
] | Remove a tab from the data and select the nearest valid tab.
@param {Object} tabData tab to remove | [
"Remove",
"a",
"tab",
"from",
"the",
"data",
"and",
"select",
"the",
"nearest",
"valid",
"tab",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L421-L436 |
4,920 | angular/material | src/components/tabs/js/tabsController.js | insertTab | function insertTab (tabData, index) {
var hasLoaded = loaded;
var proto = {
getIndex: function () { return ctrl.tabs.indexOf(tab); },
isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
hasFocus: function () {
return ctrl.styleTabItemFocus
&& ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
},
id: $mdUtil.nextUid(),
hasContent: !!(tabData.template && tabData.template.trim())
};
var tab = angular.extend(proto, tabData);
if (angular.isDefined(index)) {
ctrl.tabs.splice(index, 0, tab);
} else {
ctrl.tabs.push(tab);
}
processQueue();
updateHasContent();
$mdUtil.nextTick(function () {
updatePagination();
setAriaControls(tab);
// if autoselect is enabled, select the newly added tab
if (hasLoaded && ctrl.autoselect) {
$mdUtil.nextTick(function () {
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
});
}
});
return tab;
} | javascript | function insertTab (tabData, index) {
var hasLoaded = loaded;
var proto = {
getIndex: function () { return ctrl.tabs.indexOf(tab); },
isActive: function () { return this.getIndex() === ctrl.selectedIndex; },
isLeft: function () { return this.getIndex() < ctrl.selectedIndex; },
isRight: function () { return this.getIndex() > ctrl.selectedIndex; },
shouldRender: function () { return !ctrl.noDisconnect || this.isActive(); },
hasFocus: function () {
return ctrl.styleTabItemFocus
&& ctrl.hasFocus && this.getIndex() === ctrl.focusIndex;
},
id: $mdUtil.nextUid(),
hasContent: !!(tabData.template && tabData.template.trim())
};
var tab = angular.extend(proto, tabData);
if (angular.isDefined(index)) {
ctrl.tabs.splice(index, 0, tab);
} else {
ctrl.tabs.push(tab);
}
processQueue();
updateHasContent();
$mdUtil.nextTick(function () {
updatePagination();
setAriaControls(tab);
// if autoselect is enabled, select the newly added tab
if (hasLoaded && ctrl.autoselect) {
$mdUtil.nextTick(function () {
$mdUtil.nextTick(function () { select(ctrl.tabs.indexOf(tab)); });
});
}
});
return tab;
} | [
"function",
"insertTab",
"(",
"tabData",
",",
"index",
")",
"{",
"var",
"hasLoaded",
"=",
"loaded",
";",
"var",
"proto",
"=",
"{",
"getIndex",
":",
"function",
"(",
")",
"{",
"return",
"ctrl",
".",
"tabs",
".",
"indexOf",
"(",
"tab",
")",
";",
"}",
",",
"isActive",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"getIndex",
"(",
")",
"===",
"ctrl",
".",
"selectedIndex",
";",
"}",
",",
"isLeft",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"getIndex",
"(",
")",
"<",
"ctrl",
".",
"selectedIndex",
";",
"}",
",",
"isRight",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"getIndex",
"(",
")",
">",
"ctrl",
".",
"selectedIndex",
";",
"}",
",",
"shouldRender",
":",
"function",
"(",
")",
"{",
"return",
"!",
"ctrl",
".",
"noDisconnect",
"||",
"this",
".",
"isActive",
"(",
")",
";",
"}",
",",
"hasFocus",
":",
"function",
"(",
")",
"{",
"return",
"ctrl",
".",
"styleTabItemFocus",
"&&",
"ctrl",
".",
"hasFocus",
"&&",
"this",
".",
"getIndex",
"(",
")",
"===",
"ctrl",
".",
"focusIndex",
";",
"}",
",",
"id",
":",
"$mdUtil",
".",
"nextUid",
"(",
")",
",",
"hasContent",
":",
"!",
"!",
"(",
"tabData",
".",
"template",
"&&",
"tabData",
".",
"template",
".",
"trim",
"(",
")",
")",
"}",
";",
"var",
"tab",
"=",
"angular",
".",
"extend",
"(",
"proto",
",",
"tabData",
")",
";",
"if",
"(",
"angular",
".",
"isDefined",
"(",
"index",
")",
")",
"{",
"ctrl",
".",
"tabs",
".",
"splice",
"(",
"index",
",",
"0",
",",
"tab",
")",
";",
"}",
"else",
"{",
"ctrl",
".",
"tabs",
".",
"push",
"(",
"tab",
")",
";",
"}",
"processQueue",
"(",
")",
";",
"updateHasContent",
"(",
")",
";",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"updatePagination",
"(",
")",
";",
"setAriaControls",
"(",
"tab",
")",
";",
"// if autoselect is enabled, select the newly added tab",
"if",
"(",
"hasLoaded",
"&&",
"ctrl",
".",
"autoselect",
")",
"{",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"select",
"(",
"ctrl",
".",
"tabs",
".",
"indexOf",
"(",
"tab",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"tab",
";",
"}"
] | Create an entry in the tabs array for a new tab at the specified index.
@param {Object} tabData tab to insert
@param {number} index location to insert the new tab
@returns {Object} the inserted tab | [
"Create",
"an",
"entry",
"in",
"the",
"tabs",
"array",
"for",
"a",
"new",
"tab",
"at",
"the",
"specified",
"index",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L444-L481 |
4,921 | angular/material | src/components/tabs/js/tabsController.js | getElements | function getElements () {
var elements = {};
var node = $element[0];
// gather tab bar elements
elements.wrapper = node.querySelector('md-tabs-wrapper');
elements.canvas = elements.wrapper.querySelector('md-tabs-canvas');
elements.paging = elements.canvas.querySelector('md-pagination-wrapper');
elements.inkBar = elements.paging.querySelector('md-ink-bar');
elements.nextButton = node.querySelector('md-next-button');
elements.prevButton = node.querySelector('md-prev-button');
elements.contents = node.querySelectorAll('md-tabs-content-wrapper > md-tab-content');
elements.tabs = elements.paging.querySelectorAll('md-tab-item');
elements.dummies = elements.canvas.querySelectorAll('md-dummy-tab');
return elements;
} | javascript | function getElements () {
var elements = {};
var node = $element[0];
// gather tab bar elements
elements.wrapper = node.querySelector('md-tabs-wrapper');
elements.canvas = elements.wrapper.querySelector('md-tabs-canvas');
elements.paging = elements.canvas.querySelector('md-pagination-wrapper');
elements.inkBar = elements.paging.querySelector('md-ink-bar');
elements.nextButton = node.querySelector('md-next-button');
elements.prevButton = node.querySelector('md-prev-button');
elements.contents = node.querySelectorAll('md-tabs-content-wrapper > md-tab-content');
elements.tabs = elements.paging.querySelectorAll('md-tab-item');
elements.dummies = elements.canvas.querySelectorAll('md-dummy-tab');
return elements;
} | [
"function",
"getElements",
"(",
")",
"{",
"var",
"elements",
"=",
"{",
"}",
";",
"var",
"node",
"=",
"$element",
"[",
"0",
"]",
";",
"// gather tab bar elements",
"elements",
".",
"wrapper",
"=",
"node",
".",
"querySelector",
"(",
"'md-tabs-wrapper'",
")",
";",
"elements",
".",
"canvas",
"=",
"elements",
".",
"wrapper",
".",
"querySelector",
"(",
"'md-tabs-canvas'",
")",
";",
"elements",
".",
"paging",
"=",
"elements",
".",
"canvas",
".",
"querySelector",
"(",
"'md-pagination-wrapper'",
")",
";",
"elements",
".",
"inkBar",
"=",
"elements",
".",
"paging",
".",
"querySelector",
"(",
"'md-ink-bar'",
")",
";",
"elements",
".",
"nextButton",
"=",
"node",
".",
"querySelector",
"(",
"'md-next-button'",
")",
";",
"elements",
".",
"prevButton",
"=",
"node",
".",
"querySelector",
"(",
"'md-prev-button'",
")",
";",
"elements",
".",
"contents",
"=",
"node",
".",
"querySelectorAll",
"(",
"'md-tabs-content-wrapper > md-tab-content'",
")",
";",
"elements",
".",
"tabs",
"=",
"elements",
".",
"paging",
".",
"querySelectorAll",
"(",
"'md-tab-item'",
")",
";",
"elements",
".",
"dummies",
"=",
"elements",
".",
"canvas",
".",
"querySelectorAll",
"(",
"'md-dummy-tab'",
")",
";",
"return",
"elements",
";",
"}"
] | Getter methods
Gathers references to all of the DOM elements used by this controller.
@returns {Object} | [
"Getter",
"methods",
"Gathers",
"references",
"to",
"all",
"of",
"the",
"DOM",
"elements",
"used",
"by",
"this",
"controller",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L489-L506 |
4,922 | angular/material | src/components/tabs/js/tabsController.js | canPageForward | function canPageForward () {
var elements = getElements();
var lastTab = elements.tabs[ elements.tabs.length - 1 ];
if (isRtl()) {
return ctrl.offsetLeft < elements.paging.offsetWidth - elements.canvas.offsetWidth;
}
return lastTab && lastTab.offsetLeft + lastTab.offsetWidth > elements.canvas.clientWidth +
ctrl.offsetLeft;
} | javascript | function canPageForward () {
var elements = getElements();
var lastTab = elements.tabs[ elements.tabs.length - 1 ];
if (isRtl()) {
return ctrl.offsetLeft < elements.paging.offsetWidth - elements.canvas.offsetWidth;
}
return lastTab && lastTab.offsetLeft + lastTab.offsetWidth > elements.canvas.clientWidth +
ctrl.offsetLeft;
} | [
"function",
"canPageForward",
"(",
")",
"{",
"var",
"elements",
"=",
"getElements",
"(",
")",
";",
"var",
"lastTab",
"=",
"elements",
".",
"tabs",
"[",
"elements",
".",
"tabs",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"isRtl",
"(",
")",
")",
"{",
"return",
"ctrl",
".",
"offsetLeft",
"<",
"elements",
".",
"paging",
".",
"offsetWidth",
"-",
"elements",
".",
"canvas",
".",
"offsetWidth",
";",
"}",
"return",
"lastTab",
"&&",
"lastTab",
".",
"offsetLeft",
"+",
"lastTab",
".",
"offsetWidth",
">",
"elements",
".",
"canvas",
".",
"clientWidth",
"+",
"ctrl",
".",
"offsetLeft",
";",
"}"
] | Determines whether or not the right pagination arrow should be enabled.
@returns {*|boolean} | [
"Determines",
"whether",
"or",
"not",
"the",
"right",
"pagination",
"arrow",
"should",
"be",
"enabled",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L521-L531 |
4,923 | angular/material | src/components/tabs/js/tabsController.js | getFocusedTabId | function getFocusedTabId() {
var focusedTab = ctrl.tabs[ctrl.focusIndex];
if (!focusedTab || !focusedTab.id) {
return null;
}
return 'tab-item-' + focusedTab.id;
} | javascript | function getFocusedTabId() {
var focusedTab = ctrl.tabs[ctrl.focusIndex];
if (!focusedTab || !focusedTab.id) {
return null;
}
return 'tab-item-' + focusedTab.id;
} | [
"function",
"getFocusedTabId",
"(",
")",
"{",
"var",
"focusedTab",
"=",
"ctrl",
".",
"tabs",
"[",
"ctrl",
".",
"focusIndex",
"]",
";",
"if",
"(",
"!",
"focusedTab",
"||",
"!",
"focusedTab",
".",
"id",
")",
"{",
"return",
"null",
";",
"}",
"return",
"'tab-item-'",
"+",
"focusedTab",
".",
"id",
";",
"}"
] | Returns currently focused tab item's element ID | [
"Returns",
"currently",
"focused",
"tab",
"item",
"s",
"element",
"ID"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L536-L542 |
4,924 | angular/material | src/components/tabs/js/tabsController.js | shouldPaginate | function shouldPaginate () {
var shouldPaginate;
if (ctrl.noPagination || !loaded) return false;
var canvasWidth = $element.prop('clientWidth');
angular.forEach(getElements().tabs, function (tab) {
canvasWidth -= tab.offsetWidth;
});
shouldPaginate = canvasWidth < 0;
// Work around width calculation issues on IE11 when pagination is enabled.
// Don't do this on other browsers because it breaks scroll to new tab animation.
if ($mdUtil.msie) {
if (shouldPaginate) {
getElements().paging.style.width = '999999px';
} else {
getElements().paging.style.width = undefined;
}
}
return shouldPaginate;
} | javascript | function shouldPaginate () {
var shouldPaginate;
if (ctrl.noPagination || !loaded) return false;
var canvasWidth = $element.prop('clientWidth');
angular.forEach(getElements().tabs, function (tab) {
canvasWidth -= tab.offsetWidth;
});
shouldPaginate = canvasWidth < 0;
// Work around width calculation issues on IE11 when pagination is enabled.
// Don't do this on other browsers because it breaks scroll to new tab animation.
if ($mdUtil.msie) {
if (shouldPaginate) {
getElements().paging.style.width = '999999px';
} else {
getElements().paging.style.width = undefined;
}
}
return shouldPaginate;
} | [
"function",
"shouldPaginate",
"(",
")",
"{",
"var",
"shouldPaginate",
";",
"if",
"(",
"ctrl",
".",
"noPagination",
"||",
"!",
"loaded",
")",
"return",
"false",
";",
"var",
"canvasWidth",
"=",
"$element",
".",
"prop",
"(",
"'clientWidth'",
")",
";",
"angular",
".",
"forEach",
"(",
"getElements",
"(",
")",
".",
"tabs",
",",
"function",
"(",
"tab",
")",
"{",
"canvasWidth",
"-=",
"tab",
".",
"offsetWidth",
";",
"}",
")",
";",
"shouldPaginate",
"=",
"canvasWidth",
"<",
"0",
";",
"// Work around width calculation issues on IE11 when pagination is enabled.",
"// Don't do this on other browsers because it breaks scroll to new tab animation.",
"if",
"(",
"$mdUtil",
".",
"msie",
")",
"{",
"if",
"(",
"shouldPaginate",
")",
"{",
"getElements",
"(",
")",
".",
"paging",
".",
"style",
".",
"width",
"=",
"'999999px'",
";",
"}",
"else",
"{",
"getElements",
"(",
")",
".",
"paging",
".",
"style",
".",
"width",
"=",
"undefined",
";",
"}",
"}",
"return",
"shouldPaginate",
";",
"}"
] | Determines if pagination is necessary to display the tabs within the available space.
@returns {boolean} true if pagination is necessary, false otherwise | [
"Determines",
"if",
"pagination",
"is",
"necessary",
"to",
"display",
"the",
"tabs",
"within",
"the",
"available",
"space",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L572-L592 |
4,925 | angular/material | src/components/tabs/js/tabsController.js | getNearestSafeIndex | function getNearestSafeIndex (newIndex) {
if (newIndex === -1) return -1;
var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
i, tab;
for (i = 0; i <= maxOffset; i++) {
tab = ctrl.tabs[ newIndex + i ];
if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
tab = ctrl.tabs[ newIndex - i ];
if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
}
return newIndex;
} | javascript | function getNearestSafeIndex (newIndex) {
if (newIndex === -1) return -1;
var maxOffset = Math.max(ctrl.tabs.length - newIndex, newIndex),
i, tab;
for (i = 0; i <= maxOffset; i++) {
tab = ctrl.tabs[ newIndex + i ];
if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
tab = ctrl.tabs[ newIndex - i ];
if (tab && (tab.scope.disabled !== true)) return tab.getIndex();
}
return newIndex;
} | [
"function",
"getNearestSafeIndex",
"(",
"newIndex",
")",
"{",
"if",
"(",
"newIndex",
"===",
"-",
"1",
")",
"return",
"-",
"1",
";",
"var",
"maxOffset",
"=",
"Math",
".",
"max",
"(",
"ctrl",
".",
"tabs",
".",
"length",
"-",
"newIndex",
",",
"newIndex",
")",
",",
"i",
",",
"tab",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<=",
"maxOffset",
";",
"i",
"++",
")",
"{",
"tab",
"=",
"ctrl",
".",
"tabs",
"[",
"newIndex",
"+",
"i",
"]",
";",
"if",
"(",
"tab",
"&&",
"(",
"tab",
".",
"scope",
".",
"disabled",
"!==",
"true",
")",
")",
"return",
"tab",
".",
"getIndex",
"(",
")",
";",
"tab",
"=",
"ctrl",
".",
"tabs",
"[",
"newIndex",
"-",
"i",
"]",
";",
"if",
"(",
"tab",
"&&",
"(",
"tab",
".",
"scope",
".",
"disabled",
"!==",
"true",
")",
")",
"return",
"tab",
".",
"getIndex",
"(",
")",
";",
"}",
"return",
"newIndex",
";",
"}"
] | Finds the nearest tab index that is available. This is primarily used for when the active
tab is removed.
@param newIndex
@returns {*} | [
"Finds",
"the",
"nearest",
"tab",
"index",
"that",
"is",
"available",
".",
"This",
"is",
"primarily",
"used",
"for",
"when",
"the",
"active",
"tab",
"is",
"removed",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L600-L611 |
4,926 | angular/material | src/components/tabs/js/tabsController.js | updateTabOrder | function updateTabOrder () {
var selectedItem = ctrl.tabs[ ctrl.selectedIndex ],
focusItem = ctrl.tabs[ ctrl.focusIndex ];
ctrl.tabs = ctrl.tabs.sort(function (a, b) {
return a.index - b.index;
});
ctrl.selectedIndex = ctrl.tabs.indexOf(selectedItem);
ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
} | javascript | function updateTabOrder () {
var selectedItem = ctrl.tabs[ ctrl.selectedIndex ],
focusItem = ctrl.tabs[ ctrl.focusIndex ];
ctrl.tabs = ctrl.tabs.sort(function (a, b) {
return a.index - b.index;
});
ctrl.selectedIndex = ctrl.tabs.indexOf(selectedItem);
ctrl.focusIndex = ctrl.tabs.indexOf(focusItem);
} | [
"function",
"updateTabOrder",
"(",
")",
"{",
"var",
"selectedItem",
"=",
"ctrl",
".",
"tabs",
"[",
"ctrl",
".",
"selectedIndex",
"]",
",",
"focusItem",
"=",
"ctrl",
".",
"tabs",
"[",
"ctrl",
".",
"focusIndex",
"]",
";",
"ctrl",
".",
"tabs",
"=",
"ctrl",
".",
"tabs",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"index",
"-",
"b",
".",
"index",
";",
"}",
")",
";",
"ctrl",
".",
"selectedIndex",
"=",
"ctrl",
".",
"tabs",
".",
"indexOf",
"(",
"selectedItem",
")",
";",
"ctrl",
".",
"focusIndex",
"=",
"ctrl",
".",
"tabs",
".",
"indexOf",
"(",
"focusItem",
")",
";",
"}"
] | Re-orders the tabs and updates the selected and focus indexes to their new positions.
This is triggered by `tabDirective.js` when the user's tabs have been re-ordered. | [
"Re",
"-",
"orders",
"the",
"tabs",
"and",
"updates",
"the",
"selected",
"and",
"focus",
"indexes",
"to",
"their",
"new",
"positions",
".",
"This",
"is",
"triggered",
"by",
"tabDirective",
".",
"js",
"when",
"the",
"user",
"s",
"tabs",
"have",
"been",
"re",
"-",
"ordered",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L679-L687 |
4,927 | angular/material | src/components/tabs/js/tabsController.js | incrementIndex | function incrementIndex (inc, focus) {
var newIndex,
key = focus ? 'focusIndex' : 'selectedIndex',
index = ctrl[ key ];
for (newIndex = index + inc;
ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
newIndex += inc) { /* do nothing */ }
newIndex = (index + inc + ctrl.tabs.length) % ctrl.tabs.length;
if (ctrl.tabs[ newIndex ]) {
ctrl[ key ] = newIndex;
}
} | javascript | function incrementIndex (inc, focus) {
var newIndex,
key = focus ? 'focusIndex' : 'selectedIndex',
index = ctrl[ key ];
for (newIndex = index + inc;
ctrl.tabs[ newIndex ] && ctrl.tabs[ newIndex ].scope.disabled;
newIndex += inc) { /* do nothing */ }
newIndex = (index + inc + ctrl.tabs.length) % ctrl.tabs.length;
if (ctrl.tabs[ newIndex ]) {
ctrl[ key ] = newIndex;
}
} | [
"function",
"incrementIndex",
"(",
"inc",
",",
"focus",
")",
"{",
"var",
"newIndex",
",",
"key",
"=",
"focus",
"?",
"'focusIndex'",
":",
"'selectedIndex'",
",",
"index",
"=",
"ctrl",
"[",
"key",
"]",
";",
"for",
"(",
"newIndex",
"=",
"index",
"+",
"inc",
";",
"ctrl",
".",
"tabs",
"[",
"newIndex",
"]",
"&&",
"ctrl",
".",
"tabs",
"[",
"newIndex",
"]",
".",
"scope",
".",
"disabled",
";",
"newIndex",
"+=",
"inc",
")",
"{",
"/* do nothing */",
"}",
"newIndex",
"=",
"(",
"index",
"+",
"inc",
"+",
"ctrl",
".",
"tabs",
".",
"length",
")",
"%",
"ctrl",
".",
"tabs",
".",
"length",
";",
"if",
"(",
"ctrl",
".",
"tabs",
"[",
"newIndex",
"]",
")",
"{",
"ctrl",
"[",
"key",
"]",
"=",
"newIndex",
";",
"}",
"}"
] | This moves the selected or focus index left or right. This is used by the keydown handler.
@param {number} inc amount to increment
@param {boolean} focus true to increment the focus index, false to increment the selected index | [
"This",
"moves",
"the",
"selected",
"or",
"focus",
"index",
"left",
"or",
"right",
".",
"This",
"is",
"used",
"by",
"the",
"keydown",
"handler",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L694-L707 |
4,928 | angular/material | src/components/tabs/js/tabsController.js | redirectFocus | function redirectFocus () {
ctrl.styleTabItemFocus = ($mdInteraction.getLastInteractionType() === 'keyboard');
var tabToFocus = getElements().tabs[ctrl.focusIndex];
if (tabToFocus) {
tabToFocus.focus();
}
} | javascript | function redirectFocus () {
ctrl.styleTabItemFocus = ($mdInteraction.getLastInteractionType() === 'keyboard');
var tabToFocus = getElements().tabs[ctrl.focusIndex];
if (tabToFocus) {
tabToFocus.focus();
}
} | [
"function",
"redirectFocus",
"(",
")",
"{",
"ctrl",
".",
"styleTabItemFocus",
"=",
"(",
"$mdInteraction",
".",
"getLastInteractionType",
"(",
")",
"===",
"'keyboard'",
")",
";",
"var",
"tabToFocus",
"=",
"getElements",
"(",
")",
".",
"tabs",
"[",
"ctrl",
".",
"focusIndex",
"]",
";",
"if",
"(",
"tabToFocus",
")",
"{",
"tabToFocus",
".",
"focus",
"(",
")",
";",
"}",
"}"
] | This is used to forward focus to tab container elements. This method is necessary to avoid
animation issues when attempting to focus an item that is out of view. | [
"This",
"is",
"used",
"to",
"forward",
"focus",
"to",
"tab",
"container",
"elements",
".",
"This",
"method",
"is",
"necessary",
"to",
"avoid",
"animation",
"issues",
"when",
"attempting",
"to",
"focus",
"an",
"item",
"that",
"is",
"out",
"of",
"view",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L713-L719 |
4,929 | angular/material | src/components/tabs/js/tabsController.js | updateHasContent | function updateHasContent () {
var hasContent = false;
var i;
for (i = 0; i < ctrl.tabs.length; i++) {
if (ctrl.tabs[i].hasContent) {
hasContent = true;
break;
}
}
ctrl.hasContent = hasContent;
} | javascript | function updateHasContent () {
var hasContent = false;
var i;
for (i = 0; i < ctrl.tabs.length; i++) {
if (ctrl.tabs[i].hasContent) {
hasContent = true;
break;
}
}
ctrl.hasContent = hasContent;
} | [
"function",
"updateHasContent",
"(",
")",
"{",
"var",
"hasContent",
"=",
"false",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"ctrl",
".",
"tabs",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"ctrl",
".",
"tabs",
"[",
"i",
"]",
".",
"hasContent",
")",
"{",
"hasContent",
"=",
"true",
";",
"break",
";",
"}",
"}",
"ctrl",
".",
"hasContent",
"=",
"hasContent",
";",
"}"
] | Determines if the tab content area is needed. | [
"Determines",
"if",
"the",
"tab",
"content",
"area",
"is",
"needed",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L766-L778 |
4,930 | angular/material | src/components/tabs/js/tabsController.js | refreshIndex | function refreshIndex () {
ctrl.selectedIndex = getNearestSafeIndex(ctrl.selectedIndex);
ctrl.focusIndex = getNearestSafeIndex(ctrl.focusIndex);
} | javascript | function refreshIndex () {
ctrl.selectedIndex = getNearestSafeIndex(ctrl.selectedIndex);
ctrl.focusIndex = getNearestSafeIndex(ctrl.focusIndex);
} | [
"function",
"refreshIndex",
"(",
")",
"{",
"ctrl",
".",
"selectedIndex",
"=",
"getNearestSafeIndex",
"(",
"ctrl",
".",
"selectedIndex",
")",
";",
"ctrl",
".",
"focusIndex",
"=",
"getNearestSafeIndex",
"(",
"ctrl",
".",
"focusIndex",
")",
";",
"}"
] | Moves the indexes to their nearest valid values. | [
"Moves",
"the",
"indexes",
"to",
"their",
"nearest",
"valid",
"values",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L783-L786 |
4,931 | angular/material | src/components/tabs/js/tabsController.js | updateHeightFromContent | function updateHeightFromContent () {
if (!ctrl.dynamicHeight) return $element.css('height', '');
if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
var elements = getElements();
var tabContent = elements.contents[ ctrl.selectedIndex ],
contentHeight = tabContent ? tabContent.offsetHeight : 0,
tabsHeight = elements.wrapper.offsetHeight,
newHeight = contentHeight + tabsHeight,
currentHeight = $element.prop('clientHeight');
if (currentHeight === newHeight) return;
// Adjusts calculations for when the buttons are bottom-aligned since this relies on absolute
// positioning. This should probably be cleaned up if a cleaner solution is possible.
if ($element.attr('md-align-tabs') === 'bottom') {
currentHeight -= tabsHeight;
newHeight -= tabsHeight;
// Need to include bottom border in these calculations
if ($element.attr('md-border-bottom') !== undefined) {
++currentHeight;
}
}
// Lock during animation so the user can't change tabs
locked = true;
var fromHeight = { height: currentHeight + 'px' },
toHeight = { height: newHeight + 'px' };
// Set the height to the current, specific pixel height to fix a bug on iOS where the height
// first animates to 0, then back to the proper height causing a visual glitch
$element.css(fromHeight);
// Animate the height from the old to the new
$animateCss($element, {
from: fromHeight,
to: toHeight,
easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
duration: 0.5
}).start().done(function () {
// Then (to fix the same iOS issue as above), disable transitions and remove the specific
// pixel height so the height can size with browser width/content changes, etc.
$element.css({
transition: 'none',
height: ''
});
// In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
// enough to batch it for us instead of doing it immediately, which undoes the original
// transition: none)
$mdUtil.nextTick(function() {
$element.css('transition', '');
});
// And unlock so tab changes can occur
locked = false;
});
} | javascript | function updateHeightFromContent () {
if (!ctrl.dynamicHeight) return $element.css('height', '');
if (!ctrl.tabs.length) return queue.push(updateHeightFromContent);
var elements = getElements();
var tabContent = elements.contents[ ctrl.selectedIndex ],
contentHeight = tabContent ? tabContent.offsetHeight : 0,
tabsHeight = elements.wrapper.offsetHeight,
newHeight = contentHeight + tabsHeight,
currentHeight = $element.prop('clientHeight');
if (currentHeight === newHeight) return;
// Adjusts calculations for when the buttons are bottom-aligned since this relies on absolute
// positioning. This should probably be cleaned up if a cleaner solution is possible.
if ($element.attr('md-align-tabs') === 'bottom') {
currentHeight -= tabsHeight;
newHeight -= tabsHeight;
// Need to include bottom border in these calculations
if ($element.attr('md-border-bottom') !== undefined) {
++currentHeight;
}
}
// Lock during animation so the user can't change tabs
locked = true;
var fromHeight = { height: currentHeight + 'px' },
toHeight = { height: newHeight + 'px' };
// Set the height to the current, specific pixel height to fix a bug on iOS where the height
// first animates to 0, then back to the proper height causing a visual glitch
$element.css(fromHeight);
// Animate the height from the old to the new
$animateCss($element, {
from: fromHeight,
to: toHeight,
easing: 'cubic-bezier(0.35, 0, 0.25, 1)',
duration: 0.5
}).start().done(function () {
// Then (to fix the same iOS issue as above), disable transitions and remove the specific
// pixel height so the height can size with browser width/content changes, etc.
$element.css({
transition: 'none',
height: ''
});
// In the next tick, re-allow transitions (if we do it all at once, $element.css is "smart"
// enough to batch it for us instead of doing it immediately, which undoes the original
// transition: none)
$mdUtil.nextTick(function() {
$element.css('transition', '');
});
// And unlock so tab changes can occur
locked = false;
});
} | [
"function",
"updateHeightFromContent",
"(",
")",
"{",
"if",
"(",
"!",
"ctrl",
".",
"dynamicHeight",
")",
"return",
"$element",
".",
"css",
"(",
"'height'",
",",
"''",
")",
";",
"if",
"(",
"!",
"ctrl",
".",
"tabs",
".",
"length",
")",
"return",
"queue",
".",
"push",
"(",
"updateHeightFromContent",
")",
";",
"var",
"elements",
"=",
"getElements",
"(",
")",
";",
"var",
"tabContent",
"=",
"elements",
".",
"contents",
"[",
"ctrl",
".",
"selectedIndex",
"]",
",",
"contentHeight",
"=",
"tabContent",
"?",
"tabContent",
".",
"offsetHeight",
":",
"0",
",",
"tabsHeight",
"=",
"elements",
".",
"wrapper",
".",
"offsetHeight",
",",
"newHeight",
"=",
"contentHeight",
"+",
"tabsHeight",
",",
"currentHeight",
"=",
"$element",
".",
"prop",
"(",
"'clientHeight'",
")",
";",
"if",
"(",
"currentHeight",
"===",
"newHeight",
")",
"return",
";",
"// Adjusts calculations for when the buttons are bottom-aligned since this relies on absolute",
"// positioning. This should probably be cleaned up if a cleaner solution is possible.",
"if",
"(",
"$element",
".",
"attr",
"(",
"'md-align-tabs'",
")",
"===",
"'bottom'",
")",
"{",
"currentHeight",
"-=",
"tabsHeight",
";",
"newHeight",
"-=",
"tabsHeight",
";",
"// Need to include bottom border in these calculations",
"if",
"(",
"$element",
".",
"attr",
"(",
"'md-border-bottom'",
")",
"!==",
"undefined",
")",
"{",
"++",
"currentHeight",
";",
"}",
"}",
"// Lock during animation so the user can't change tabs",
"locked",
"=",
"true",
";",
"var",
"fromHeight",
"=",
"{",
"height",
":",
"currentHeight",
"+",
"'px'",
"}",
",",
"toHeight",
"=",
"{",
"height",
":",
"newHeight",
"+",
"'px'",
"}",
";",
"// Set the height to the current, specific pixel height to fix a bug on iOS where the height",
"// first animates to 0, then back to the proper height causing a visual glitch",
"$element",
".",
"css",
"(",
"fromHeight",
")",
";",
"// Animate the height from the old to the new",
"$animateCss",
"(",
"$element",
",",
"{",
"from",
":",
"fromHeight",
",",
"to",
":",
"toHeight",
",",
"easing",
":",
"'cubic-bezier(0.35, 0, 0.25, 1)'",
",",
"duration",
":",
"0.5",
"}",
")",
".",
"start",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"// Then (to fix the same iOS issue as above), disable transitions and remove the specific",
"// pixel height so the height can size with browser width/content changes, etc.",
"$element",
".",
"css",
"(",
"{",
"transition",
":",
"'none'",
",",
"height",
":",
"''",
"}",
")",
";",
"// In the next tick, re-allow transitions (if we do it all at once, $element.css is \"smart\"",
"// enough to batch it for us instead of doing it immediately, which undoes the original",
"// transition: none)",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"$element",
".",
"css",
"(",
"'transition'",
",",
"''",
")",
";",
"}",
")",
";",
"// And unlock so tab changes can occur",
"locked",
"=",
"false",
";",
"}",
")",
";",
"}"
] | Calculates the content height of the current tab.
@returns {*} | [
"Calculates",
"the",
"content",
"height",
"of",
"the",
"current",
"tab",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L792-L851 |
4,932 | angular/material | src/components/tabs/js/tabsController.js | updateInkBarStyles | function updateInkBarStyles (previousTotalWidth, previousWidthOfTabItems) {
if (ctrl.noInkBar) {
return;
}
var elements = getElements();
if (!elements.tabs[ ctrl.selectedIndex ]) {
angular.element(elements.inkBar).css({ left: 'auto', right: 'auto' });
return;
}
if (!ctrl.tabs.length) {
queue.push(ctrl.updateInkBarStyles);
return;
}
// If the element is not visible, we will not be able to calculate sizes until it becomes
// visible. We should treat that as a resize event rather than just updating the ink bar.
if (!$element.prop('offsetParent')) {
handleResizeWhenVisible();
return;
}
var index = ctrl.selectedIndex,
totalWidth = elements.paging.offsetWidth,
tab = elements.tabs[ index ],
left = tab.offsetLeft,
right = totalWidth - left - tab.offsetWidth;
if (ctrl.shouldCenterTabs) {
// We need to use the same calculate process as in the pagination wrapper, to avoid rounding
// deviations.
var totalWidthOfTabItems = calcTabsWidth(elements.tabs);
if (totalWidth > totalWidthOfTabItems &&
previousTotalWidth !== totalWidth &&
previousWidthOfTabItems !== totalWidthOfTabItems) {
$timeout(updateInkBarStyles, 0, true, totalWidth, totalWidthOfTabItems);
}
}
updateInkBarClassName();
angular.element(elements.inkBar).css({ left: left + 'px', right: right + 'px' });
} | javascript | function updateInkBarStyles (previousTotalWidth, previousWidthOfTabItems) {
if (ctrl.noInkBar) {
return;
}
var elements = getElements();
if (!elements.tabs[ ctrl.selectedIndex ]) {
angular.element(elements.inkBar).css({ left: 'auto', right: 'auto' });
return;
}
if (!ctrl.tabs.length) {
queue.push(ctrl.updateInkBarStyles);
return;
}
// If the element is not visible, we will not be able to calculate sizes until it becomes
// visible. We should treat that as a resize event rather than just updating the ink bar.
if (!$element.prop('offsetParent')) {
handleResizeWhenVisible();
return;
}
var index = ctrl.selectedIndex,
totalWidth = elements.paging.offsetWidth,
tab = elements.tabs[ index ],
left = tab.offsetLeft,
right = totalWidth - left - tab.offsetWidth;
if (ctrl.shouldCenterTabs) {
// We need to use the same calculate process as in the pagination wrapper, to avoid rounding
// deviations.
var totalWidthOfTabItems = calcTabsWidth(elements.tabs);
if (totalWidth > totalWidthOfTabItems &&
previousTotalWidth !== totalWidth &&
previousWidthOfTabItems !== totalWidthOfTabItems) {
$timeout(updateInkBarStyles, 0, true, totalWidth, totalWidthOfTabItems);
}
}
updateInkBarClassName();
angular.element(elements.inkBar).css({ left: left + 'px', right: right + 'px' });
} | [
"function",
"updateInkBarStyles",
"(",
"previousTotalWidth",
",",
"previousWidthOfTabItems",
")",
"{",
"if",
"(",
"ctrl",
".",
"noInkBar",
")",
"{",
"return",
";",
"}",
"var",
"elements",
"=",
"getElements",
"(",
")",
";",
"if",
"(",
"!",
"elements",
".",
"tabs",
"[",
"ctrl",
".",
"selectedIndex",
"]",
")",
"{",
"angular",
".",
"element",
"(",
"elements",
".",
"inkBar",
")",
".",
"css",
"(",
"{",
"left",
":",
"'auto'",
",",
"right",
":",
"'auto'",
"}",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"ctrl",
".",
"tabs",
".",
"length",
")",
"{",
"queue",
".",
"push",
"(",
"ctrl",
".",
"updateInkBarStyles",
")",
";",
"return",
";",
"}",
"// If the element is not visible, we will not be able to calculate sizes until it becomes",
"// visible. We should treat that as a resize event rather than just updating the ink bar.",
"if",
"(",
"!",
"$element",
".",
"prop",
"(",
"'offsetParent'",
")",
")",
"{",
"handleResizeWhenVisible",
"(",
")",
";",
"return",
";",
"}",
"var",
"index",
"=",
"ctrl",
".",
"selectedIndex",
",",
"totalWidth",
"=",
"elements",
".",
"paging",
".",
"offsetWidth",
",",
"tab",
"=",
"elements",
".",
"tabs",
"[",
"index",
"]",
",",
"left",
"=",
"tab",
".",
"offsetLeft",
",",
"right",
"=",
"totalWidth",
"-",
"left",
"-",
"tab",
".",
"offsetWidth",
";",
"if",
"(",
"ctrl",
".",
"shouldCenterTabs",
")",
"{",
"// We need to use the same calculate process as in the pagination wrapper, to avoid rounding",
"// deviations.",
"var",
"totalWidthOfTabItems",
"=",
"calcTabsWidth",
"(",
"elements",
".",
"tabs",
")",
";",
"if",
"(",
"totalWidth",
">",
"totalWidthOfTabItems",
"&&",
"previousTotalWidth",
"!==",
"totalWidth",
"&&",
"previousWidthOfTabItems",
"!==",
"totalWidthOfTabItems",
")",
"{",
"$timeout",
"(",
"updateInkBarStyles",
",",
"0",
",",
"true",
",",
"totalWidth",
",",
"totalWidthOfTabItems",
")",
";",
"}",
"}",
"updateInkBarClassName",
"(",
")",
";",
"angular",
".",
"element",
"(",
"elements",
".",
"inkBar",
")",
".",
"css",
"(",
"{",
"left",
":",
"left",
"+",
"'px'",
",",
"right",
":",
"right",
"+",
"'px'",
"}",
")",
";",
"}"
] | Repositions the ink bar to the selected tab.
Parameters are used when calling itself recursively when md-center-tabs is used as we need to
run two passes to properly center the tabs. These parameters ensure that we only run two passes
and that we don't run indefinitely.
@param {number=} previousTotalWidth previous width of pagination wrapper
@param {number=} previousWidthOfTabItems previous width of all tab items | [
"Repositions",
"the",
"ink",
"bar",
"to",
"the",
"selected",
"tab",
".",
"Parameters",
"are",
"used",
"when",
"calling",
"itself",
"recursively",
"when",
"md",
"-",
"center",
"-",
"tabs",
"is",
"used",
"as",
"we",
"need",
"to",
"run",
"two",
"passes",
"to",
"properly",
"center",
"the",
"tabs",
".",
"These",
"parameters",
"ensure",
"that",
"we",
"only",
"run",
"two",
"passes",
"and",
"that",
"we",
"don",
"t",
"run",
"indefinitely",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L861-L902 |
4,933 | angular/material | src/components/tabs/js/tabsController.js | attachRipple | function attachRipple (scope, element) {
var elements = getElements();
var options = { colorElement: angular.element(elements.inkBar) };
$mdTabInkRipple.attach(scope, element, options);
} | javascript | function attachRipple (scope, element) {
var elements = getElements();
var options = { colorElement: angular.element(elements.inkBar) };
$mdTabInkRipple.attach(scope, element, options);
} | [
"function",
"attachRipple",
"(",
"scope",
",",
"element",
")",
"{",
"var",
"elements",
"=",
"getElements",
"(",
")",
";",
"var",
"options",
"=",
"{",
"colorElement",
":",
"angular",
".",
"element",
"(",
"elements",
".",
"inkBar",
")",
"}",
";",
"$mdTabInkRipple",
".",
"attach",
"(",
"scope",
",",
"element",
",",
"options",
")",
";",
"}"
] | Attaches a ripple to the tab item element.
@param scope
@param element | [
"Attaches",
"a",
"ripple",
"to",
"the",
"tab",
"item",
"element",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L947-L951 |
4,934 | angular/material | src/components/tabs/js/tabsController.js | setAriaControls | function setAriaControls (tab) {
if (tab.hasContent) {
var nodes = $element[0].querySelectorAll('[md-tab-id="' + tab.id + '"]');
angular.element(nodes).attr('aria-controls', ctrl.tabContentPrefix + tab.id);
}
} | javascript | function setAriaControls (tab) {
if (tab.hasContent) {
var nodes = $element[0].querySelectorAll('[md-tab-id="' + tab.id + '"]');
angular.element(nodes).attr('aria-controls', ctrl.tabContentPrefix + tab.id);
}
} | [
"function",
"setAriaControls",
"(",
"tab",
")",
"{",
"if",
"(",
"tab",
".",
"hasContent",
")",
"{",
"var",
"nodes",
"=",
"$element",
"[",
"0",
"]",
".",
"querySelectorAll",
"(",
"'[md-tab-id=\"'",
"+",
"tab",
".",
"id",
"+",
"'\"]'",
")",
";",
"angular",
".",
"element",
"(",
"nodes",
")",
".",
"attr",
"(",
"'aria-controls'",
",",
"ctrl",
".",
"tabContentPrefix",
"+",
"tab",
".",
"id",
")",
";",
"}",
"}"
] | Sets the `aria-controls` attribute to the elements that correspond to the passed-in tab.
@param tab | [
"Sets",
"the",
"aria",
"-",
"controls",
"attribute",
"to",
"the",
"elements",
"that",
"correspond",
"to",
"the",
"passed",
"-",
"in",
"tab",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/js/tabsController.js#L957-L962 |
4,935 | angular/material | src/components/list/list.js | copyAttributes | function copyAttributes(source, destination, extraAttrs) {
var copiedAttrs = $mdUtil.prefixer([
'ng-if', 'ng-click', 'ng-dblclick', 'aria-label', 'ng-disabled', 'ui-sref',
'href', 'ng-href', 'rel', 'target', 'ng-attr-ui-sref', 'ui-sref-opts', 'download'
]);
if (extraAttrs) {
copiedAttrs = copiedAttrs.concat($mdUtil.prefixer(extraAttrs));
}
angular.forEach(copiedAttrs, function(attr) {
if (source.hasAttribute(attr)) {
destination.setAttribute(attr, source.getAttribute(attr));
source.removeAttribute(attr);
}
});
} | javascript | function copyAttributes(source, destination, extraAttrs) {
var copiedAttrs = $mdUtil.prefixer([
'ng-if', 'ng-click', 'ng-dblclick', 'aria-label', 'ng-disabled', 'ui-sref',
'href', 'ng-href', 'rel', 'target', 'ng-attr-ui-sref', 'ui-sref-opts', 'download'
]);
if (extraAttrs) {
copiedAttrs = copiedAttrs.concat($mdUtil.prefixer(extraAttrs));
}
angular.forEach(copiedAttrs, function(attr) {
if (source.hasAttribute(attr)) {
destination.setAttribute(attr, source.getAttribute(attr));
source.removeAttribute(attr);
}
});
} | [
"function",
"copyAttributes",
"(",
"source",
",",
"destination",
",",
"extraAttrs",
")",
"{",
"var",
"copiedAttrs",
"=",
"$mdUtil",
".",
"prefixer",
"(",
"[",
"'ng-if'",
",",
"'ng-click'",
",",
"'ng-dblclick'",
",",
"'aria-label'",
",",
"'ng-disabled'",
",",
"'ui-sref'",
",",
"'href'",
",",
"'ng-href'",
",",
"'rel'",
",",
"'target'",
",",
"'ng-attr-ui-sref'",
",",
"'ui-sref-opts'",
",",
"'download'",
"]",
")",
";",
"if",
"(",
"extraAttrs",
")",
"{",
"copiedAttrs",
"=",
"copiedAttrs",
".",
"concat",
"(",
"$mdUtil",
".",
"prefixer",
"(",
"extraAttrs",
")",
")",
";",
"}",
"angular",
".",
"forEach",
"(",
"copiedAttrs",
",",
"function",
"(",
"attr",
")",
"{",
"if",
"(",
"source",
".",
"hasAttribute",
"(",
"attr",
")",
")",
"{",
"destination",
".",
"setAttribute",
"(",
"attr",
",",
"source",
".",
"getAttribute",
"(",
"attr",
")",
")",
";",
"source",
".",
"removeAttribute",
"(",
"attr",
")",
";",
"}",
"}",
")",
";",
"}"
] | Copies attributes from a source element to the destination element
By default the function will copy the most necessary attributes, supported
by the button executor for clickable list items.
@param source Element with the specified attributes
@param destination Element which will retrieve the attributes
@param extraAttrs Additional attributes, which will be copied over. | [
"Copies",
"attributes",
"from",
"a",
"source",
"element",
"to",
"the",
"destination",
"element",
"By",
"default",
"the",
"function",
"will",
"copy",
"the",
"most",
"necessary",
"attributes",
"supported",
"by",
"the",
"button",
"executor",
"for",
"clickable",
"list",
"items",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/list/list.js#L406-L422 |
4,936 | angular/material | src/core/services/ripple/ripple.js | InkRippleCtrl | function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdUtil, $mdColorUtil) {
this.$window = $window;
this.$timeout = $timeout;
this.$mdUtil = $mdUtil;
this.$mdColorUtil = $mdColorUtil;
this.$scope = $scope;
this.$element = $element;
this.options = rippleOptions;
this.mousedown = false;
this.ripples = [];
this.timeout = null; // Stores a reference to the most-recent ripple timeout
this.lastRipple = null;
$mdUtil.valueOnUse(this, 'container', this.createContainer);
this.$element.addClass('md-ink-ripple');
// attach method for unit tests
($element.controller('mdInkRipple') || {}).createRipple = angular.bind(this, this.createRipple);
($element.controller('mdInkRipple') || {}).setColor = angular.bind(this, this.color);
this.bindEvents();
} | javascript | function InkRippleCtrl ($scope, $element, rippleOptions, $window, $timeout, $mdUtil, $mdColorUtil) {
this.$window = $window;
this.$timeout = $timeout;
this.$mdUtil = $mdUtil;
this.$mdColorUtil = $mdColorUtil;
this.$scope = $scope;
this.$element = $element;
this.options = rippleOptions;
this.mousedown = false;
this.ripples = [];
this.timeout = null; // Stores a reference to the most-recent ripple timeout
this.lastRipple = null;
$mdUtil.valueOnUse(this, 'container', this.createContainer);
this.$element.addClass('md-ink-ripple');
// attach method for unit tests
($element.controller('mdInkRipple') || {}).createRipple = angular.bind(this, this.createRipple);
($element.controller('mdInkRipple') || {}).setColor = angular.bind(this, this.color);
this.bindEvents();
} | [
"function",
"InkRippleCtrl",
"(",
"$scope",
",",
"$element",
",",
"rippleOptions",
",",
"$window",
",",
"$timeout",
",",
"$mdUtil",
",",
"$mdColorUtil",
")",
"{",
"this",
".",
"$window",
"=",
"$window",
";",
"this",
".",
"$timeout",
"=",
"$timeout",
";",
"this",
".",
"$mdUtil",
"=",
"$mdUtil",
";",
"this",
".",
"$mdColorUtil",
"=",
"$mdColorUtil",
";",
"this",
".",
"$scope",
"=",
"$scope",
";",
"this",
".",
"$element",
"=",
"$element",
";",
"this",
".",
"options",
"=",
"rippleOptions",
";",
"this",
".",
"mousedown",
"=",
"false",
";",
"this",
".",
"ripples",
"=",
"[",
"]",
";",
"this",
".",
"timeout",
"=",
"null",
";",
"// Stores a reference to the most-recent ripple timeout",
"this",
".",
"lastRipple",
"=",
"null",
";",
"$mdUtil",
".",
"valueOnUse",
"(",
"this",
",",
"'container'",
",",
"this",
".",
"createContainer",
")",
";",
"this",
".",
"$element",
".",
"addClass",
"(",
"'md-ink-ripple'",
")",
";",
"// attach method for unit tests",
"(",
"$element",
".",
"controller",
"(",
"'mdInkRipple'",
")",
"||",
"{",
"}",
")",
".",
"createRipple",
"=",
"angular",
".",
"bind",
"(",
"this",
",",
"this",
".",
"createRipple",
")",
";",
"(",
"$element",
".",
"controller",
"(",
"'mdInkRipple'",
")",
"||",
"{",
"}",
")",
".",
"setColor",
"=",
"angular",
".",
"bind",
"(",
"this",
",",
"this",
".",
"color",
")",
";",
"this",
".",
"bindEvents",
"(",
")",
";",
"}"
] | Controller used by the ripple service in order to apply ripples
@ngInject | [
"Controller",
"used",
"by",
"the",
"ripple",
"service",
"in",
"order",
"to",
"apply",
"ripples"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/ripple/ripple.js#L158-L180 |
4,937 | angular/material | src/core/services/ripple/ripple.js | getElementColor | function getElementColor () {
var items = self.options && self.options.colorElement ? self.options.colorElement : [];
var elem = items.length ? items[ 0 ] : self.$element[ 0 ];
return elem ? self.$window.getComputedStyle(elem).color : 'rgb(0,0,0)';
} | javascript | function getElementColor () {
var items = self.options && self.options.colorElement ? self.options.colorElement : [];
var elem = items.length ? items[ 0 ] : self.$element[ 0 ];
return elem ? self.$window.getComputedStyle(elem).color : 'rgb(0,0,0)';
} | [
"function",
"getElementColor",
"(",
")",
"{",
"var",
"items",
"=",
"self",
".",
"options",
"&&",
"self",
".",
"options",
".",
"colorElement",
"?",
"self",
".",
"options",
".",
"colorElement",
":",
"[",
"]",
";",
"var",
"elem",
"=",
"items",
".",
"length",
"?",
"items",
"[",
"0",
"]",
":",
"self",
".",
"$element",
"[",
"0",
"]",
";",
"return",
"elem",
"?",
"self",
".",
"$window",
".",
"getComputedStyle",
"(",
"elem",
")",
".",
"color",
":",
"'rgb(0,0,0)'",
";",
"}"
] | Finds the color element and returns its text color for use as default ripple color
@returns {string} | [
"Finds",
"the",
"color",
"element",
"and",
"returns",
"its",
"text",
"color",
"for",
"use",
"as",
"default",
"ripple",
"color"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/ripple/ripple.js#L214-L219 |
4,938 | angular/material | src/components/datepicker/js/dateLocaleProvider.js | defaultFormatDate | function defaultFormatDate(date, timezone) {
if (!date) {
return '';
}
// All of the dates created through ng-material *should* be set to midnight.
// If we encounter a date where the localeTime shows at 11pm instead of midnight,
// we have run into an issue with DST where we need to increment the hour by one:
// var d = new Date(1992, 9, 8, 0, 0, 0);
// d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
var localeTime = date.toLocaleTimeString();
var formatDate = date;
if (date.getHours() === 0 &&
(localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
}
return $filter('date')(formatDate, 'M/d/yyyy', timezone);
} | javascript | function defaultFormatDate(date, timezone) {
if (!date) {
return '';
}
// All of the dates created through ng-material *should* be set to midnight.
// If we encounter a date where the localeTime shows at 11pm instead of midnight,
// we have run into an issue with DST where we need to increment the hour by one:
// var d = new Date(1992, 9, 8, 0, 0, 0);
// d.toLocaleString(); // == "10/7/1992, 11:00:00 PM"
var localeTime = date.toLocaleTimeString();
var formatDate = date;
if (date.getHours() === 0 &&
(localeTime.indexOf('11:') !== -1 || localeTime.indexOf('23:') !== -1)) {
formatDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 1, 0, 0);
}
return $filter('date')(formatDate, 'M/d/yyyy', timezone);
} | [
"function",
"defaultFormatDate",
"(",
"date",
",",
"timezone",
")",
"{",
"if",
"(",
"!",
"date",
")",
"{",
"return",
"''",
";",
"}",
"// All of the dates created through ng-material *should* be set to midnight.",
"// If we encounter a date where the localeTime shows at 11pm instead of midnight,",
"// we have run into an issue with DST where we need to increment the hour by one:",
"// var d = new Date(1992, 9, 8, 0, 0, 0);",
"// d.toLocaleString(); // == \"10/7/1992, 11:00:00 PM\"",
"var",
"localeTime",
"=",
"date",
".",
"toLocaleTimeString",
"(",
")",
";",
"var",
"formatDate",
"=",
"date",
";",
"if",
"(",
"date",
".",
"getHours",
"(",
")",
"===",
"0",
"&&",
"(",
"localeTime",
".",
"indexOf",
"(",
"'11:'",
")",
"!==",
"-",
"1",
"||",
"localeTime",
".",
"indexOf",
"(",
"'23:'",
")",
"!==",
"-",
"1",
")",
")",
"{",
"formatDate",
"=",
"new",
"Date",
"(",
"date",
".",
"getFullYear",
"(",
")",
",",
"date",
".",
"getMonth",
"(",
")",
",",
"date",
".",
"getDate",
"(",
")",
",",
"1",
",",
"0",
",",
"0",
")",
";",
"}",
"return",
"$filter",
"(",
"'date'",
")",
"(",
"formatDate",
",",
"'M/d/yyyy'",
",",
"timezone",
")",
";",
"}"
] | Default date-to-string formatting function.
@param {!Date} date
@param {string=} timezone
@returns {string} | [
"Default",
"date",
"-",
"to",
"-",
"string",
"formatting",
"function",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/dateLocaleProvider.js#L195-L213 |
4,939 | angular/material | src/components/datepicker/js/dateLocaleProvider.js | defaultLongDateFormatter | function defaultLongDateFormatter(date) {
// Example: 'Thursday June 18 2015'
return [
service.days[date.getDay()],
service.months[date.getMonth()],
service.dates[date.getDate()],
date.getFullYear()
].join(' ');
} | javascript | function defaultLongDateFormatter(date) {
// Example: 'Thursday June 18 2015'
return [
service.days[date.getDay()],
service.months[date.getMonth()],
service.dates[date.getDate()],
date.getFullYear()
].join(' ');
} | [
"function",
"defaultLongDateFormatter",
"(",
"date",
")",
"{",
"// Example: 'Thursday June 18 2015'",
"return",
"[",
"service",
".",
"days",
"[",
"date",
".",
"getDay",
"(",
")",
"]",
",",
"service",
".",
"months",
"[",
"date",
".",
"getMonth",
"(",
")",
"]",
",",
"service",
".",
"dates",
"[",
"date",
".",
"getDate",
"(",
")",
"]",
",",
"date",
".",
"getFullYear",
"(",
")",
"]",
".",
"join",
"(",
"' '",
")",
";",
"}"
] | Default formatter for date cell aria-labels.
@param {!Date} date
@returns {string} | [
"Default",
"formatter",
"for",
"date",
"cell",
"aria",
"-",
"labels",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/dateLocaleProvider.js#L274-L282 |
4,940 | angular/material | src/components/datepicker/js/calendarMonth.js | calendarDirective | function calendarDirective() {
return {
template:
'<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
'<div class="md-calendar-scroll-mask">' +
'<md-virtual-repeat-container class="md-calendar-scroll-container" ' +
'md-offset-size="' + (TBODY_SINGLE_ROW_HEIGHT - TBODY_HEIGHT) + '">' +
'<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
'<tbody ' +
'md-calendar-month-body ' +
'role="rowgroup" ' +
'md-virtual-repeat="i in monthCtrl.items" ' +
'md-month-offset="$index" ' +
'class="md-calendar-month" ' +
'md-start-index="monthCtrl.getSelectedMonthIndex()" ' +
'md-item-size="' + TBODY_HEIGHT + '">' +
// The <tr> ensures that the <tbody> will always have the
// proper height, even if it's empty. If it's content is
// compiled, the <tr> will be overwritten.
'<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
'</tbody>' +
'</table>' +
'</md-virtual-repeat-container>' +
'</div>',
require: ['^^mdCalendar', 'mdCalendarMonth'],
controller: CalendarMonthCtrl,
controllerAs: 'monthCtrl',
bindToController: true,
link: function(scope, element, attrs, controllers) {
var calendarCtrl = controllers[0];
var monthCtrl = controllers[1];
monthCtrl.initialize(calendarCtrl);
}
};
} | javascript | function calendarDirective() {
return {
template:
'<table aria-hidden="true" class="md-calendar-day-header"><thead></thead></table>' +
'<div class="md-calendar-scroll-mask">' +
'<md-virtual-repeat-container class="md-calendar-scroll-container" ' +
'md-offset-size="' + (TBODY_SINGLE_ROW_HEIGHT - TBODY_HEIGHT) + '">' +
'<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
'<tbody ' +
'md-calendar-month-body ' +
'role="rowgroup" ' +
'md-virtual-repeat="i in monthCtrl.items" ' +
'md-month-offset="$index" ' +
'class="md-calendar-month" ' +
'md-start-index="monthCtrl.getSelectedMonthIndex()" ' +
'md-item-size="' + TBODY_HEIGHT + '">' +
// The <tr> ensures that the <tbody> will always have the
// proper height, even if it's empty. If it's content is
// compiled, the <tr> will be overwritten.
'<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
'</tbody>' +
'</table>' +
'</md-virtual-repeat-container>' +
'</div>',
require: ['^^mdCalendar', 'mdCalendarMonth'],
controller: CalendarMonthCtrl,
controllerAs: 'monthCtrl',
bindToController: true,
link: function(scope, element, attrs, controllers) {
var calendarCtrl = controllers[0];
var monthCtrl = controllers[1];
monthCtrl.initialize(calendarCtrl);
}
};
} | [
"function",
"calendarDirective",
"(",
")",
"{",
"return",
"{",
"template",
":",
"'<table aria-hidden=\"true\" class=\"md-calendar-day-header\"><thead></thead></table>'",
"+",
"'<div class=\"md-calendar-scroll-mask\">'",
"+",
"'<md-virtual-repeat-container class=\"md-calendar-scroll-container\" '",
"+",
"'md-offset-size=\"'",
"+",
"(",
"TBODY_SINGLE_ROW_HEIGHT",
"-",
"TBODY_HEIGHT",
")",
"+",
"'\">'",
"+",
"'<table role=\"grid\" tabindex=\"0\" class=\"md-calendar\" aria-readonly=\"true\">'",
"+",
"'<tbody '",
"+",
"'md-calendar-month-body '",
"+",
"'role=\"rowgroup\" '",
"+",
"'md-virtual-repeat=\"i in monthCtrl.items\" '",
"+",
"'md-month-offset=\"$index\" '",
"+",
"'class=\"md-calendar-month\" '",
"+",
"'md-start-index=\"monthCtrl.getSelectedMonthIndex()\" '",
"+",
"'md-item-size=\"'",
"+",
"TBODY_HEIGHT",
"+",
"'\">'",
"+",
"// The <tr> ensures that the <tbody> will always have the",
"// proper height, even if it's empty. If it's content is",
"// compiled, the <tr> will be overwritten.",
"'<tr aria-hidden=\"true\" md-force-height=\"\\''",
"+",
"TBODY_HEIGHT",
"+",
"'px\\'\"></tr>'",
"+",
"'</tbody>'",
"+",
"'</table>'",
"+",
"'</md-virtual-repeat-container>'",
"+",
"'</div>'",
",",
"require",
":",
"[",
"'^^mdCalendar'",
",",
"'mdCalendarMonth'",
"]",
",",
"controller",
":",
"CalendarMonthCtrl",
",",
"controllerAs",
":",
"'monthCtrl'",
",",
"bindToController",
":",
"true",
",",
"link",
":",
"function",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"controllers",
")",
"{",
"var",
"calendarCtrl",
"=",
"controllers",
"[",
"0",
"]",
";",
"var",
"monthCtrl",
"=",
"controllers",
"[",
"1",
"]",
";",
"monthCtrl",
".",
"initialize",
"(",
"calendarCtrl",
")",
";",
"}",
"}",
";",
"}"
] | Private directive that represents a list of months inside the calendar. | [
"Private",
"directive",
"that",
"represents",
"a",
"list",
"of",
"months",
"inside",
"the",
"calendar",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendarMonth.js#L20-L55 |
4,941 | angular/material | src/components/datepicker/js/calendarMonth.js | CalendarMonthCtrl | function CalendarMonthCtrl($element, $scope, $animate, $q,
$$mdDateUtil, $mdDateLocale) {
/** @final {!angular.JQLite} */
this.$element = $element;
/** @final {!angular.Scope} */
this.$scope = $scope;
/** @final {!angular.$animate} */
this.$animate = $animate;
/** @final {!angular.$q} */
this.$q = $q;
/** @final */
this.dateUtil = $$mdDateUtil;
/** @final */
this.dateLocale = $mdDateLocale;
/** @final {HTMLElement} */
this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
/** @type {boolean} */
this.isInitialized = false;
/** @type {boolean} */
this.isMonthTransitionInProgress = false;
var self = this;
/**
* Handles a click event on a date cell.
* Created here so that every cell can use the same function instance.
* @this {HTMLTableCellElement} The cell that was clicked.
*/
this.cellClickHandler = function() {
var timestamp = $$mdDateUtil.getTimestampFromNode(this);
self.$scope.$apply(function() {
self.calendarCtrl.setNgModelValue(timestamp);
});
};
/**
* Handles click events on the month headers. Switches
* the calendar to the year view.
* @this {HTMLTableCellElement} The cell that was clicked.
*/
this.headerClickHandler = function() {
self.calendarCtrl.setCurrentView('year', $$mdDateUtil.getTimestampFromNode(this));
};
} | javascript | function CalendarMonthCtrl($element, $scope, $animate, $q,
$$mdDateUtil, $mdDateLocale) {
/** @final {!angular.JQLite} */
this.$element = $element;
/** @final {!angular.Scope} */
this.$scope = $scope;
/** @final {!angular.$animate} */
this.$animate = $animate;
/** @final {!angular.$q} */
this.$q = $q;
/** @final */
this.dateUtil = $$mdDateUtil;
/** @final */
this.dateLocale = $mdDateLocale;
/** @final {HTMLElement} */
this.calendarScroller = $element[0].querySelector('.md-virtual-repeat-scroller');
/** @type {boolean} */
this.isInitialized = false;
/** @type {boolean} */
this.isMonthTransitionInProgress = false;
var self = this;
/**
* Handles a click event on a date cell.
* Created here so that every cell can use the same function instance.
* @this {HTMLTableCellElement} The cell that was clicked.
*/
this.cellClickHandler = function() {
var timestamp = $$mdDateUtil.getTimestampFromNode(this);
self.$scope.$apply(function() {
self.calendarCtrl.setNgModelValue(timestamp);
});
};
/**
* Handles click events on the month headers. Switches
* the calendar to the year view.
* @this {HTMLTableCellElement} The cell that was clicked.
*/
this.headerClickHandler = function() {
self.calendarCtrl.setCurrentView('year', $$mdDateUtil.getTimestampFromNode(this));
};
} | [
"function",
"CalendarMonthCtrl",
"(",
"$element",
",",
"$scope",
",",
"$animate",
",",
"$q",
",",
"$$mdDateUtil",
",",
"$mdDateLocale",
")",
"{",
"/** @final {!angular.JQLite} */",
"this",
".",
"$element",
"=",
"$element",
";",
"/** @final {!angular.Scope} */",
"this",
".",
"$scope",
"=",
"$scope",
";",
"/** @final {!angular.$animate} */",
"this",
".",
"$animate",
"=",
"$animate",
";",
"/** @final {!angular.$q} */",
"this",
".",
"$q",
"=",
"$q",
";",
"/** @final */",
"this",
".",
"dateUtil",
"=",
"$$mdDateUtil",
";",
"/** @final */",
"this",
".",
"dateLocale",
"=",
"$mdDateLocale",
";",
"/** @final {HTMLElement} */",
"this",
".",
"calendarScroller",
"=",
"$element",
"[",
"0",
"]",
".",
"querySelector",
"(",
"'.md-virtual-repeat-scroller'",
")",
";",
"/** @type {boolean} */",
"this",
".",
"isInitialized",
"=",
"false",
";",
"/** @type {boolean} */",
"this",
".",
"isMonthTransitionInProgress",
"=",
"false",
";",
"var",
"self",
"=",
"this",
";",
"/**\n * Handles a click event on a date cell.\n * Created here so that every cell can use the same function instance.\n * @this {HTMLTableCellElement} The cell that was clicked.\n */",
"this",
".",
"cellClickHandler",
"=",
"function",
"(",
")",
"{",
"var",
"timestamp",
"=",
"$$mdDateUtil",
".",
"getTimestampFromNode",
"(",
"this",
")",
";",
"self",
".",
"$scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"self",
".",
"calendarCtrl",
".",
"setNgModelValue",
"(",
"timestamp",
")",
";",
"}",
")",
";",
"}",
";",
"/**\n * Handles click events on the month headers. Switches\n * the calendar to the year view.\n * @this {HTMLTableCellElement} The cell that was clicked.\n */",
"this",
".",
"headerClickHandler",
"=",
"function",
"(",
")",
"{",
"self",
".",
"calendarCtrl",
".",
"setCurrentView",
"(",
"'year'",
",",
"$$mdDateUtil",
".",
"getTimestampFromNode",
"(",
"this",
")",
")",
";",
"}",
";",
"}"
] | Controller for the calendar month component.
@ngInject @constructor | [
"Controller",
"for",
"the",
"calendar",
"month",
"component",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendarMonth.js#L61-L113 |
4,942 | angular/material | src/components/navBar/navBar.js | MdNavItemController | function MdNavItemController($element) {
/** @private @const {!angular.JQLite} */
this._$element = $element;
// Data-bound variables
/** @const {?Function} */
this.mdNavClick;
/** @const {?string} */
this.mdNavHref;
/** @const {?string} */
this.mdNavSref;
/** @const {?Object} */
this.srefOpts;
/** @const {?string} */
this.name;
/** @type {string} */
this.navItemAriaLabel;
// State variables
/** @private {boolean} */
this._selected = false;
/** @private {boolean} */
this._focused = false;
} | javascript | function MdNavItemController($element) {
/** @private @const {!angular.JQLite} */
this._$element = $element;
// Data-bound variables
/** @const {?Function} */
this.mdNavClick;
/** @const {?string} */
this.mdNavHref;
/** @const {?string} */
this.mdNavSref;
/** @const {?Object} */
this.srefOpts;
/** @const {?string} */
this.name;
/** @type {string} */
this.navItemAriaLabel;
// State variables
/** @private {boolean} */
this._selected = false;
/** @private {boolean} */
this._focused = false;
} | [
"function",
"MdNavItemController",
"(",
"$element",
")",
"{",
"/** @private @const {!angular.JQLite} */",
"this",
".",
"_$element",
"=",
"$element",
";",
"// Data-bound variables",
"/** @const {?Function} */",
"this",
".",
"mdNavClick",
";",
"/** @const {?string} */",
"this",
".",
"mdNavHref",
";",
"/** @const {?string} */",
"this",
".",
"mdNavSref",
";",
"/** @const {?Object} */",
"this",
".",
"srefOpts",
";",
"/** @const {?string} */",
"this",
".",
"name",
";",
"/** @type {string} */",
"this",
".",
"navItemAriaLabel",
";",
"// State variables",
"/** @private {boolean} */",
"this",
".",
"_selected",
"=",
"false",
";",
"/** @private {boolean} */",
"this",
".",
"_focused",
"=",
"false",
";",
"}"
] | Controller for the nav-item component.
@param {!angular.JQLite} $element
@constructor
@final
@ngInject | [
"Controller",
"for",
"the",
"nav",
"-",
"item",
"component",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/navBar/navBar.js#L652-L681 |
4,943 | angular/material | src/core/services/meta/meta.js | mapExistingElement | function mapExistingElement(name) {
if (metaElements[name]) {
return true;
}
var element = document.getElementsByName(name)[0];
if (!element) {
return false;
}
metaElements[name] = angular.element(element);
return true;
} | javascript | function mapExistingElement(name) {
if (metaElements[name]) {
return true;
}
var element = document.getElementsByName(name)[0];
if (!element) {
return false;
}
metaElements[name] = angular.element(element);
return true;
} | [
"function",
"mapExistingElement",
"(",
"name",
")",
"{",
"if",
"(",
"metaElements",
"[",
"name",
"]",
")",
"{",
"return",
"true",
";",
"}",
"var",
"element",
"=",
"document",
".",
"getElementsByName",
"(",
"name",
")",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"element",
")",
"{",
"return",
"false",
";",
"}",
"metaElements",
"[",
"name",
"]",
"=",
"angular",
".",
"element",
"(",
"element",
")",
";",
"return",
"true",
";",
"}"
] | Checks if the requested element was written manually and maps it
@param {string} name meta tag 'name' attribute value
@returns {boolean} returns true if there is an element with the requested name | [
"Checks",
"if",
"the",
"requested",
"element",
"was",
"written",
"manually",
"and",
"maps",
"it"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/meta/meta.js#L44-L58 |
4,944 | angular/material | src/components/chips/demoContactChips/script.js | delayedQuerySearch | function delayedQuerySearch(criteria) {
if (!pendingSearch || !debounceSearch()) {
cancelSearch();
return pendingSearch = $q(function(resolve, reject) {
// Simulate async search... (after debouncing)
cancelSearch = reject;
$timeout(function() {
resolve(self.querySearch(criteria));
refreshDebounce();
}, Math.random() * 500, true);
});
}
return pendingSearch;
} | javascript | function delayedQuerySearch(criteria) {
if (!pendingSearch || !debounceSearch()) {
cancelSearch();
return pendingSearch = $q(function(resolve, reject) {
// Simulate async search... (after debouncing)
cancelSearch = reject;
$timeout(function() {
resolve(self.querySearch(criteria));
refreshDebounce();
}, Math.random() * 500, true);
});
}
return pendingSearch;
} | [
"function",
"delayedQuerySearch",
"(",
"criteria",
")",
"{",
"if",
"(",
"!",
"pendingSearch",
"||",
"!",
"debounceSearch",
"(",
")",
")",
"{",
"cancelSearch",
"(",
")",
";",
"return",
"pendingSearch",
"=",
"$q",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// Simulate async search... (after debouncing)",
"cancelSearch",
"=",
"reject",
";",
"$timeout",
"(",
"function",
"(",
")",
"{",
"resolve",
"(",
"self",
".",
"querySearch",
"(",
"criteria",
")",
")",
";",
"refreshDebounce",
"(",
")",
";",
"}",
",",
"Math",
".",
"random",
"(",
")",
"*",
"500",
",",
"true",
")",
";",
"}",
")",
";",
"}",
"return",
"pendingSearch",
";",
"}"
] | Async search for contacts
Also debounce the queries; since the md-contact-chips does not support this | [
"Async",
"search",
"for",
"contacts",
"Also",
"debounce",
"the",
"queries",
";",
"since",
"the",
"md",
"-",
"contact",
"-",
"chips",
"does",
"not",
"support",
"this"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/chips/demoContactChips/script.js#L41-L58 |
4,945 | angular/material | src/components/chips/js/contactChipsDirective.js | MdContactChips | function MdContactChips($mdTheming, $mdUtil) {
return {
template: function(element, attrs) {
return MD_CONTACT_CHIPS_TEMPLATE;
},
restrict: 'E',
controller: 'MdContactChipsCtrl',
controllerAs: '$mdContactChipsCtrl',
bindToController: true,
compile: compile,
scope: {
contactQuery: '&mdContacts',
placeholder: '@?',
secondaryPlaceholder: '@?',
contactName: '@mdContactName',
contactImage: '@mdContactImage',
contactEmail: '@mdContactEmail',
contacts: '=ngModel',
ngChange: '&?',
requireMatch: '=?mdRequireMatch',
minLength: '=?mdMinLength',
highlightFlags: '@?mdHighlightFlags',
chipAppendDelay: '@?mdChipAppendDelay',
separatorKeys: '=?mdSeparatorKeys',
removedMessage: '@?mdRemovedMessage',
inputAriaDescribedBy: '@?inputAriaDescribedby',
inputAriaLabelledBy: '@?inputAriaLabelledby',
inputAriaLabel: '@?',
containerHint: '@?',
containerEmptyHint: '@?',
deleteHint: '@?'
}
};
function compile(element, attr) {
return function postLink(scope, element, attrs, controllers) {
var contactChipsController = controllers;
$mdUtil.initOptionalProperties(scope, attr);
$mdTheming(element);
element.attr('tabindex', '-1');
attrs.$observe('mdChipAppendDelay', function(newValue) {
contactChipsController.chipAppendDelay = newValue;
});
};
}
} | javascript | function MdContactChips($mdTheming, $mdUtil) {
return {
template: function(element, attrs) {
return MD_CONTACT_CHIPS_TEMPLATE;
},
restrict: 'E',
controller: 'MdContactChipsCtrl',
controllerAs: '$mdContactChipsCtrl',
bindToController: true,
compile: compile,
scope: {
contactQuery: '&mdContacts',
placeholder: '@?',
secondaryPlaceholder: '@?',
contactName: '@mdContactName',
contactImage: '@mdContactImage',
contactEmail: '@mdContactEmail',
contacts: '=ngModel',
ngChange: '&?',
requireMatch: '=?mdRequireMatch',
minLength: '=?mdMinLength',
highlightFlags: '@?mdHighlightFlags',
chipAppendDelay: '@?mdChipAppendDelay',
separatorKeys: '=?mdSeparatorKeys',
removedMessage: '@?mdRemovedMessage',
inputAriaDescribedBy: '@?inputAriaDescribedby',
inputAriaLabelledBy: '@?inputAriaLabelledby',
inputAriaLabel: '@?',
containerHint: '@?',
containerEmptyHint: '@?',
deleteHint: '@?'
}
};
function compile(element, attr) {
return function postLink(scope, element, attrs, controllers) {
var contactChipsController = controllers;
$mdUtil.initOptionalProperties(scope, attr);
$mdTheming(element);
element.attr('tabindex', '-1');
attrs.$observe('mdChipAppendDelay', function(newValue) {
contactChipsController.chipAppendDelay = newValue;
});
};
}
} | [
"function",
"MdContactChips",
"(",
"$mdTheming",
",",
"$mdUtil",
")",
"{",
"return",
"{",
"template",
":",
"function",
"(",
"element",
",",
"attrs",
")",
"{",
"return",
"MD_CONTACT_CHIPS_TEMPLATE",
";",
"}",
",",
"restrict",
":",
"'E'",
",",
"controller",
":",
"'MdContactChipsCtrl'",
",",
"controllerAs",
":",
"'$mdContactChipsCtrl'",
",",
"bindToController",
":",
"true",
",",
"compile",
":",
"compile",
",",
"scope",
":",
"{",
"contactQuery",
":",
"'&mdContacts'",
",",
"placeholder",
":",
"'@?'",
",",
"secondaryPlaceholder",
":",
"'@?'",
",",
"contactName",
":",
"'@mdContactName'",
",",
"contactImage",
":",
"'@mdContactImage'",
",",
"contactEmail",
":",
"'@mdContactEmail'",
",",
"contacts",
":",
"'=ngModel'",
",",
"ngChange",
":",
"'&?'",
",",
"requireMatch",
":",
"'=?mdRequireMatch'",
",",
"minLength",
":",
"'=?mdMinLength'",
",",
"highlightFlags",
":",
"'@?mdHighlightFlags'",
",",
"chipAppendDelay",
":",
"'@?mdChipAppendDelay'",
",",
"separatorKeys",
":",
"'=?mdSeparatorKeys'",
",",
"removedMessage",
":",
"'@?mdRemovedMessage'",
",",
"inputAriaDescribedBy",
":",
"'@?inputAriaDescribedby'",
",",
"inputAriaLabelledBy",
":",
"'@?inputAriaLabelledby'",
",",
"inputAriaLabel",
":",
"'@?'",
",",
"containerHint",
":",
"'@?'",
",",
"containerEmptyHint",
":",
"'@?'",
",",
"deleteHint",
":",
"'@?'",
"}",
"}",
";",
"function",
"compile",
"(",
"element",
",",
"attr",
")",
"{",
"return",
"function",
"postLink",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"controllers",
")",
"{",
"var",
"contactChipsController",
"=",
"controllers",
";",
"$mdUtil",
".",
"initOptionalProperties",
"(",
"scope",
",",
"attr",
")",
";",
"$mdTheming",
"(",
"element",
")",
";",
"element",
".",
"attr",
"(",
"'tabindex'",
",",
"'-1'",
")",
";",
"attrs",
".",
"$observe",
"(",
"'mdChipAppendDelay'",
",",
"function",
"(",
"newValue",
")",
"{",
"contactChipsController",
".",
"chipAppendDelay",
"=",
"newValue",
";",
"}",
")",
";",
"}",
";",
"}",
"}"
] | MDContactChips Directive Definition
@param $mdTheming
@param $mdUtil
@returns {*}
@ngInject | [
"MDContactChips",
"Directive",
"Definition"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/chips/js/contactChipsDirective.js#L133-L181 |
4,946 | angular/material | src/components/autocomplete/js/autocompleteDirective.js | getRepeatMode | function getRepeatMode(modeStr) {
if (!modeStr) { return REPEAT_VIRTUAL; }
modeStr = modeStr.toLowerCase();
return REPEAT_MODES.indexOf(modeStr) > -1 ? modeStr : REPEAT_VIRTUAL;
} | javascript | function getRepeatMode(modeStr) {
if (!modeStr) { return REPEAT_VIRTUAL; }
modeStr = modeStr.toLowerCase();
return REPEAT_MODES.indexOf(modeStr) > -1 ? modeStr : REPEAT_VIRTUAL;
} | [
"function",
"getRepeatMode",
"(",
"modeStr",
")",
"{",
"if",
"(",
"!",
"modeStr",
")",
"{",
"return",
"REPEAT_VIRTUAL",
";",
"}",
"modeStr",
"=",
"modeStr",
".",
"toLowerCase",
"(",
")",
";",
"return",
"REPEAT_MODES",
".",
"indexOf",
"(",
"modeStr",
")",
">",
"-",
"1",
"?",
"modeStr",
":",
"REPEAT_VIRTUAL",
";",
"}"
] | get a valid repeat mode from an md-mode attribute string. | [
"get",
"a",
"valid",
"repeat",
"mode",
"from",
"an",
"md",
"-",
"mode",
"attribute",
"string",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/autocomplete/js/autocompleteDirective.js#L298-L302 |
4,947 | angular/material | src/core/util/util.js | function (target, key, expectedVal) {
var hasValue = false;
if (target && target.length) {
var computedStyles = $window.getComputedStyle(target[0]);
hasValue = angular.isDefined(computedStyles[key]) && (expectedVal ? computedStyles[key] == expectedVal : true);
}
return hasValue;
} | javascript | function (target, key, expectedVal) {
var hasValue = false;
if (target && target.length) {
var computedStyles = $window.getComputedStyle(target[0]);
hasValue = angular.isDefined(computedStyles[key]) && (expectedVal ? computedStyles[key] == expectedVal : true);
}
return hasValue;
} | [
"function",
"(",
"target",
",",
"key",
",",
"expectedVal",
")",
"{",
"var",
"hasValue",
"=",
"false",
";",
"if",
"(",
"target",
"&&",
"target",
".",
"length",
")",
"{",
"var",
"computedStyles",
"=",
"$window",
".",
"getComputedStyle",
"(",
"target",
"[",
"0",
"]",
")",
";",
"hasValue",
"=",
"angular",
".",
"isDefined",
"(",
"computedStyles",
"[",
"key",
"]",
")",
"&&",
"(",
"expectedVal",
"?",
"computedStyles",
"[",
"key",
"]",
"==",
"expectedVal",
":",
"true",
")",
";",
"}",
"return",
"hasValue",
";",
"}"
] | Checks if the target element has the requested style by key
@param {DOMElement|JQLite} target Target element
@param {string} key Style key
@param {string=} expectedVal Optional expected value
@returns {boolean} Whether the target element has the style or not | [
"Checks",
"if",
"the",
"target",
"element",
"has",
"the",
"requested",
"style",
"by",
"key"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L35-L44 |
|
4,948 | angular/material | src/core/util/util.js | function(nodes) {
nodes = nodes || [];
var results = [];
for (var i = 0; i < nodes.length; ++i) {
results.push(nodes.item(i));
}
return results;
} | javascript | function(nodes) {
nodes = nodes || [];
var results = [];
for (var i = 0; i < nodes.length; ++i) {
results.push(nodes.item(i));
}
return results;
} | [
"function",
"(",
"nodes",
")",
"{",
"nodes",
"=",
"nodes",
"||",
"[",
"]",
";",
"var",
"results",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nodes",
".",
"length",
";",
"++",
"i",
")",
"{",
"results",
".",
"push",
"(",
"nodes",
".",
"item",
"(",
"i",
")",
")",
";",
"}",
"return",
"results",
";",
"}"
] | Annoying method to copy nodes to an array, thanks to IE | [
"Annoying",
"method",
"to",
"copy",
"nodes",
"to",
"an",
"array",
"thanks",
"to",
"IE"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L144-L152 |
|
4,949 | angular/material | src/core/util/util.js | function(containerEl, attributeVal) {
var AUTO_FOCUS = this.prefixer('md-autofocus', true);
var elToFocus;
elToFocus = scanForFocusable(containerEl, attributeVal || AUTO_FOCUS);
if (!elToFocus && attributeVal != AUTO_FOCUS) {
// Scan for deprecated attribute
elToFocus = scanForFocusable(containerEl, this.prefixer('md-auto-focus', true));
if (!elToFocus) {
// Scan for fallback to 'universal' API
elToFocus = scanForFocusable(containerEl, AUTO_FOCUS);
}
}
return elToFocus;
/**
* Can target and nested children for specified Selector (attribute)
* whose value may be an expression that evaluates to True/False.
*/
function scanForFocusable(target, selector) {
var elFound, items = target[0].querySelectorAll(selector);
// Find the last child element with the focus attribute
if (items && items.length){
items.length && angular.forEach(items, function(it) {
it = angular.element(it);
// Check the element for the md-autofocus class to ensure any associated expression
// evaluated to true.
var isFocusable = it.hasClass('md-autofocus');
if (isFocusable) elFound = it;
});
}
return elFound;
}
} | javascript | function(containerEl, attributeVal) {
var AUTO_FOCUS = this.prefixer('md-autofocus', true);
var elToFocus;
elToFocus = scanForFocusable(containerEl, attributeVal || AUTO_FOCUS);
if (!elToFocus && attributeVal != AUTO_FOCUS) {
// Scan for deprecated attribute
elToFocus = scanForFocusable(containerEl, this.prefixer('md-auto-focus', true));
if (!elToFocus) {
// Scan for fallback to 'universal' API
elToFocus = scanForFocusable(containerEl, AUTO_FOCUS);
}
}
return elToFocus;
/**
* Can target and nested children for specified Selector (attribute)
* whose value may be an expression that evaluates to True/False.
*/
function scanForFocusable(target, selector) {
var elFound, items = target[0].querySelectorAll(selector);
// Find the last child element with the focus attribute
if (items && items.length){
items.length && angular.forEach(items, function(it) {
it = angular.element(it);
// Check the element for the md-autofocus class to ensure any associated expression
// evaluated to true.
var isFocusable = it.hasClass('md-autofocus');
if (isFocusable) elFound = it;
});
}
return elFound;
}
} | [
"function",
"(",
"containerEl",
",",
"attributeVal",
")",
"{",
"var",
"AUTO_FOCUS",
"=",
"this",
".",
"prefixer",
"(",
"'md-autofocus'",
",",
"true",
")",
";",
"var",
"elToFocus",
";",
"elToFocus",
"=",
"scanForFocusable",
"(",
"containerEl",
",",
"attributeVal",
"||",
"AUTO_FOCUS",
")",
";",
"if",
"(",
"!",
"elToFocus",
"&&",
"attributeVal",
"!=",
"AUTO_FOCUS",
")",
"{",
"// Scan for deprecated attribute",
"elToFocus",
"=",
"scanForFocusable",
"(",
"containerEl",
",",
"this",
".",
"prefixer",
"(",
"'md-auto-focus'",
",",
"true",
")",
")",
";",
"if",
"(",
"!",
"elToFocus",
")",
"{",
"// Scan for fallback to 'universal' API",
"elToFocus",
"=",
"scanForFocusable",
"(",
"containerEl",
",",
"AUTO_FOCUS",
")",
";",
"}",
"}",
"return",
"elToFocus",
";",
"/**\n * Can target and nested children for specified Selector (attribute)\n * whose value may be an expression that evaluates to True/False.\n */",
"function",
"scanForFocusable",
"(",
"target",
",",
"selector",
")",
"{",
"var",
"elFound",
",",
"items",
"=",
"target",
"[",
"0",
"]",
".",
"querySelectorAll",
"(",
"selector",
")",
";",
"// Find the last child element with the focus attribute",
"if",
"(",
"items",
"&&",
"items",
".",
"length",
")",
"{",
"items",
".",
"length",
"&&",
"angular",
".",
"forEach",
"(",
"items",
",",
"function",
"(",
"it",
")",
"{",
"it",
"=",
"angular",
".",
"element",
"(",
"it",
")",
";",
"// Check the element for the md-autofocus class to ensure any associated expression",
"// evaluated to true.",
"var",
"isFocusable",
"=",
"it",
".",
"hasClass",
"(",
"'md-autofocus'",
")",
";",
"if",
"(",
"isFocusable",
")",
"elFound",
"=",
"it",
";",
"}",
")",
";",
"}",
"return",
"elFound",
";",
"}",
"}"
] | Finds the proper focus target by searching the DOM.
@param containerEl
@param attributeVal
@returns {*} | [
"Finds",
"the",
"proper",
"focus",
"target",
"by",
"searching",
"the",
"DOM",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L176-L214 |
|
4,950 | angular/material | src/core/util/util.js | disableElementScroll | function disableElementScroll(element) {
element = angular.element(element || body);
var scrollMask;
if (options.disableScrollMask) {
scrollMask = element;
} else {
scrollMask = angular.element(
'<div class="md-scroll-mask">' +
' <div class="md-scroll-mask-bar"></div>' +
'</div>');
element.append(scrollMask);
}
scrollMask.on('wheel', preventDefault);
scrollMask.on('touchmove', preventDefault);
return function restoreElementScroll() {
scrollMask.off('wheel');
scrollMask.off('touchmove');
if (!options.disableScrollMask && scrollMask[0].parentNode) {
scrollMask[0].parentNode.removeChild(scrollMask[0]);
}
};
function preventDefault(e) {
e.preventDefault();
}
} | javascript | function disableElementScroll(element) {
element = angular.element(element || body);
var scrollMask;
if (options.disableScrollMask) {
scrollMask = element;
} else {
scrollMask = angular.element(
'<div class="md-scroll-mask">' +
' <div class="md-scroll-mask-bar"></div>' +
'</div>');
element.append(scrollMask);
}
scrollMask.on('wheel', preventDefault);
scrollMask.on('touchmove', preventDefault);
return function restoreElementScroll() {
scrollMask.off('wheel');
scrollMask.off('touchmove');
if (!options.disableScrollMask && scrollMask[0].parentNode) {
scrollMask[0].parentNode.removeChild(scrollMask[0]);
}
};
function preventDefault(e) {
e.preventDefault();
}
} | [
"function",
"disableElementScroll",
"(",
"element",
")",
"{",
"element",
"=",
"angular",
".",
"element",
"(",
"element",
"||",
"body",
")",
";",
"var",
"scrollMask",
";",
"if",
"(",
"options",
".",
"disableScrollMask",
")",
"{",
"scrollMask",
"=",
"element",
";",
"}",
"else",
"{",
"scrollMask",
"=",
"angular",
".",
"element",
"(",
"'<div class=\"md-scroll-mask\">'",
"+",
"' <div class=\"md-scroll-mask-bar\"></div>'",
"+",
"'</div>'",
")",
";",
"element",
".",
"append",
"(",
"scrollMask",
")",
";",
"}",
"scrollMask",
".",
"on",
"(",
"'wheel'",
",",
"preventDefault",
")",
";",
"scrollMask",
".",
"on",
"(",
"'touchmove'",
",",
"preventDefault",
")",
";",
"return",
"function",
"restoreElementScroll",
"(",
")",
"{",
"scrollMask",
".",
"off",
"(",
"'wheel'",
")",
";",
"scrollMask",
".",
"off",
"(",
"'touchmove'",
")",
";",
"if",
"(",
"!",
"options",
".",
"disableScrollMask",
"&&",
"scrollMask",
"[",
"0",
"]",
".",
"parentNode",
")",
"{",
"scrollMask",
"[",
"0",
"]",
".",
"parentNode",
".",
"removeChild",
"(",
"scrollMask",
"[",
"0",
"]",
")",
";",
"}",
"}",
";",
"function",
"preventDefault",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"}",
"}"
] | Creates a virtual scrolling mask to prevent touchmove, keyboard, scrollbar clicking,
and wheel events | [
"Creates",
"a",
"virtual",
"scrolling",
"mask",
"to",
"prevent",
"touchmove",
"keyboard",
"scrollbar",
"clicking",
"and",
"wheel",
"events"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L252-L282 |
4,951 | angular/material | src/core/util/util.js | disableBodyScroll | function disableBodyScroll() {
var documentElement = $document[0].documentElement;
var prevDocumentStyle = documentElement.style.cssText || '';
var prevBodyStyle = body.style.cssText || '';
var viewportTop = $mdUtil.getViewportTop();
$mdUtil.disableScrollAround._viewPortTop = viewportTop;
var clientWidth = body.clientWidth;
var hasVerticalScrollbar = body.scrollHeight > body.clientHeight + 1;
// Scroll may be set on <html> element (for example by overflow-y: scroll)
// but Chrome is reporting the scrollTop position always on <body>.
// scrollElement will allow to restore the scrollTop position to proper target.
var scrollElement = documentElement.scrollTop > 0 ? documentElement : body;
if (hasVerticalScrollbar) {
angular.element(body).css({
position: 'fixed',
width: '100%',
top: -viewportTop + 'px'
});
}
if (body.clientWidth < clientWidth) {
body.style.overflow = 'hidden';
}
return function restoreScroll() {
// Reset the inline style CSS to the previous.
body.style.cssText = prevBodyStyle;
documentElement.style.cssText = prevDocumentStyle;
// The scroll position while being fixed
scrollElement.scrollTop = viewportTop;
};
} | javascript | function disableBodyScroll() {
var documentElement = $document[0].documentElement;
var prevDocumentStyle = documentElement.style.cssText || '';
var prevBodyStyle = body.style.cssText || '';
var viewportTop = $mdUtil.getViewportTop();
$mdUtil.disableScrollAround._viewPortTop = viewportTop;
var clientWidth = body.clientWidth;
var hasVerticalScrollbar = body.scrollHeight > body.clientHeight + 1;
// Scroll may be set on <html> element (for example by overflow-y: scroll)
// but Chrome is reporting the scrollTop position always on <body>.
// scrollElement will allow to restore the scrollTop position to proper target.
var scrollElement = documentElement.scrollTop > 0 ? documentElement : body;
if (hasVerticalScrollbar) {
angular.element(body).css({
position: 'fixed',
width: '100%',
top: -viewportTop + 'px'
});
}
if (body.clientWidth < clientWidth) {
body.style.overflow = 'hidden';
}
return function restoreScroll() {
// Reset the inline style CSS to the previous.
body.style.cssText = prevBodyStyle;
documentElement.style.cssText = prevDocumentStyle;
// The scroll position while being fixed
scrollElement.scrollTop = viewportTop;
};
} | [
"function",
"disableBodyScroll",
"(",
")",
"{",
"var",
"documentElement",
"=",
"$document",
"[",
"0",
"]",
".",
"documentElement",
";",
"var",
"prevDocumentStyle",
"=",
"documentElement",
".",
"style",
".",
"cssText",
"||",
"''",
";",
"var",
"prevBodyStyle",
"=",
"body",
".",
"style",
".",
"cssText",
"||",
"''",
";",
"var",
"viewportTop",
"=",
"$mdUtil",
".",
"getViewportTop",
"(",
")",
";",
"$mdUtil",
".",
"disableScrollAround",
".",
"_viewPortTop",
"=",
"viewportTop",
";",
"var",
"clientWidth",
"=",
"body",
".",
"clientWidth",
";",
"var",
"hasVerticalScrollbar",
"=",
"body",
".",
"scrollHeight",
">",
"body",
".",
"clientHeight",
"+",
"1",
";",
"// Scroll may be set on <html> element (for example by overflow-y: scroll)",
"// but Chrome is reporting the scrollTop position always on <body>.",
"// scrollElement will allow to restore the scrollTop position to proper target.",
"var",
"scrollElement",
"=",
"documentElement",
".",
"scrollTop",
">",
"0",
"?",
"documentElement",
":",
"body",
";",
"if",
"(",
"hasVerticalScrollbar",
")",
"{",
"angular",
".",
"element",
"(",
"body",
")",
".",
"css",
"(",
"{",
"position",
":",
"'fixed'",
",",
"width",
":",
"'100%'",
",",
"top",
":",
"-",
"viewportTop",
"+",
"'px'",
"}",
")",
";",
"}",
"if",
"(",
"body",
".",
"clientWidth",
"<",
"clientWidth",
")",
"{",
"body",
".",
"style",
".",
"overflow",
"=",
"'hidden'",
";",
"}",
"return",
"function",
"restoreScroll",
"(",
")",
"{",
"// Reset the inline style CSS to the previous.",
"body",
".",
"style",
".",
"cssText",
"=",
"prevBodyStyle",
";",
"documentElement",
".",
"style",
".",
"cssText",
"=",
"prevDocumentStyle",
";",
"// The scroll position while being fixed",
"scrollElement",
".",
"scrollTop",
"=",
"viewportTop",
";",
"}",
";",
"}"
] | Converts the body to a position fixed block and translate it to the proper scroll position | [
"Converts",
"the",
"body",
"to",
"a",
"position",
"fixed",
"block",
"and",
"translate",
"it",
"to",
"the",
"proper",
"scroll",
"position"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L285-L321 |
4,952 | angular/material | src/core/util/util.js | function(element) {
var node = element[0] || element;
document.addEventListener('click', function focusOnClick(ev) {
if (ev.target === node && ev.$focus) {
node.focus();
ev.stopImmediatePropagation();
ev.preventDefault();
node.removeEventListener('click', focusOnClick);
}
}, true);
var newEvent = document.createEvent('MouseEvents');
newEvent.initMouseEvent('click', false, true, window, {}, 0, 0, 0, 0,
false, false, false, false, 0, null);
newEvent.$material = true;
newEvent.$focus = true;
node.dispatchEvent(newEvent);
} | javascript | function(element) {
var node = element[0] || element;
document.addEventListener('click', function focusOnClick(ev) {
if (ev.target === node && ev.$focus) {
node.focus();
ev.stopImmediatePropagation();
ev.preventDefault();
node.removeEventListener('click', focusOnClick);
}
}, true);
var newEvent = document.createEvent('MouseEvents');
newEvent.initMouseEvent('click', false, true, window, {}, 0, 0, 0, 0,
false, false, false, false, 0, null);
newEvent.$material = true;
newEvent.$focus = true;
node.dispatchEvent(newEvent);
} | [
"function",
"(",
"element",
")",
"{",
"var",
"node",
"=",
"element",
"[",
"0",
"]",
"||",
"element",
";",
"document",
".",
"addEventListener",
"(",
"'click'",
",",
"function",
"focusOnClick",
"(",
"ev",
")",
"{",
"if",
"(",
"ev",
".",
"target",
"===",
"node",
"&&",
"ev",
".",
"$focus",
")",
"{",
"node",
".",
"focus",
"(",
")",
";",
"ev",
".",
"stopImmediatePropagation",
"(",
")",
";",
"ev",
".",
"preventDefault",
"(",
")",
";",
"node",
".",
"removeEventListener",
"(",
"'click'",
",",
"focusOnClick",
")",
";",
"}",
"}",
",",
"true",
")",
";",
"var",
"newEvent",
"=",
"document",
".",
"createEvent",
"(",
"'MouseEvents'",
")",
";",
"newEvent",
".",
"initMouseEvent",
"(",
"'click'",
",",
"false",
",",
"true",
",",
"window",
",",
"{",
"}",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"false",
",",
"false",
",",
"false",
",",
"false",
",",
"0",
",",
"null",
")",
";",
"newEvent",
".",
"$material",
"=",
"true",
";",
"newEvent",
".",
"$focus",
"=",
"true",
";",
"node",
".",
"dispatchEvent",
"(",
"newEvent",
")",
";",
"}"
] | Mobile safari only allows you to set focus in click event listeners... | [
"Mobile",
"safari",
"only",
"allows",
"you",
"to",
"set",
"focus",
"in",
"click",
"event",
"listeners",
"..."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L349-L367 |
|
4,953 | angular/material | src/core/util/util.js | throttle | function throttle(func, delay) {
var recent;
return function throttled() {
var context = this;
var args = arguments;
var now = $mdUtil.now();
if (!recent || (now - recent > delay)) {
func.apply(context, args);
recent = now;
}
};
} | javascript | function throttle(func, delay) {
var recent;
return function throttled() {
var context = this;
var args = arguments;
var now = $mdUtil.now();
if (!recent || (now - recent > delay)) {
func.apply(context, args);
recent = now;
}
};
} | [
"function",
"throttle",
"(",
"func",
",",
"delay",
")",
"{",
"var",
"recent",
";",
"return",
"function",
"throttled",
"(",
")",
"{",
"var",
"context",
"=",
"this",
";",
"var",
"args",
"=",
"arguments",
";",
"var",
"now",
"=",
"$mdUtil",
".",
"now",
"(",
")",
";",
"if",
"(",
"!",
"recent",
"||",
"(",
"now",
"-",
"recent",
">",
"delay",
")",
")",
"{",
"func",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"recent",
"=",
"now",
";",
"}",
"}",
";",
"}"
] | Returns a function that can only be triggered every `delay` milliseconds. In other words, the function will not be called unless it has been more than `delay` milliseconds since the last call. | [
"Returns",
"a",
"function",
"that",
"can",
"only",
"be",
"triggered",
"every",
"delay",
"milliseconds",
".",
"In",
"other",
"words",
"the",
"function",
"will",
"not",
"be",
"called",
"unless",
"it",
"has",
"been",
"more",
"than",
"delay",
"milliseconds",
"since",
"the",
"last",
"call",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L447-L459 |
4,954 | angular/material | src/core/util/util.js | reconnectScope | function reconnectScope(scope) {
if (!scope) return;
// we can't disconnect the root node or scope already disconnected
if (scope.$root === scope) return;
if (!scope.$$disconnected) return;
var child = scope;
var parent = child.$parent;
child.$$disconnected = false;
// See Scope.$new for this logic...
child.$$prevSibling = parent.$$childTail;
if (parent.$$childHead) {
parent.$$childTail.$$nextSibling = child;
parent.$$childTail = child;
} else {
parent.$$childHead = parent.$$childTail = child;
}
} | javascript | function reconnectScope(scope) {
if (!scope) return;
// we can't disconnect the root node or scope already disconnected
if (scope.$root === scope) return;
if (!scope.$$disconnected) return;
var child = scope;
var parent = child.$parent;
child.$$disconnected = false;
// See Scope.$new for this logic...
child.$$prevSibling = parent.$$childTail;
if (parent.$$childHead) {
parent.$$childTail.$$nextSibling = child;
parent.$$childTail = child;
} else {
parent.$$childHead = parent.$$childTail = child;
}
} | [
"function",
"reconnectScope",
"(",
"scope",
")",
"{",
"if",
"(",
"!",
"scope",
")",
"return",
";",
"// we can't disconnect the root node or scope already disconnected",
"if",
"(",
"scope",
".",
"$root",
"===",
"scope",
")",
"return",
";",
"if",
"(",
"!",
"scope",
".",
"$$disconnected",
")",
"return",
";",
"var",
"child",
"=",
"scope",
";",
"var",
"parent",
"=",
"child",
".",
"$parent",
";",
"child",
".",
"$$disconnected",
"=",
"false",
";",
"// See Scope.$new for this logic...",
"child",
".",
"$$prevSibling",
"=",
"parent",
".",
"$$childTail",
";",
"if",
"(",
"parent",
".",
"$$childHead",
")",
"{",
"parent",
".",
"$$childTail",
".",
"$$nextSibling",
"=",
"child",
";",
"parent",
".",
"$$childTail",
"=",
"child",
";",
"}",
"else",
"{",
"parent",
".",
"$$childHead",
"=",
"parent",
".",
"$$childTail",
"=",
"child",
";",
"}",
"}"
] | Undo the effects of disconnectScope above. | [
"Undo",
"the",
"effects",
"of",
"disconnectScope",
"above",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L519-L538 |
4,955 | angular/material | src/core/util/util.js | scanChildren | function scanChildren(element) {
var found;
if (element) {
for (var i = 0, len = element.length; i < len; i++) {
var target = element[i];
if (!found) {
for (var j = 0, numChild = target.childNodes.length; j < numChild; j++) {
found = found || scanTree([target.childNodes[j]]);
}
}
}
}
return found;
} | javascript | function scanChildren(element) {
var found;
if (element) {
for (var i = 0, len = element.length; i < len; i++) {
var target = element[i];
if (!found) {
for (var j = 0, numChild = target.childNodes.length; j < numChild; j++) {
found = found || scanTree([target.childNodes[j]]);
}
}
}
}
return found;
} | [
"function",
"scanChildren",
"(",
"element",
")",
"{",
"var",
"found",
";",
"if",
"(",
"element",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"element",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"target",
"=",
"element",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"found",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
",",
"numChild",
"=",
"target",
".",
"childNodes",
".",
"length",
";",
"j",
"<",
"numChild",
";",
"j",
"++",
")",
"{",
"found",
"=",
"found",
"||",
"scanTree",
"(",
"[",
"target",
".",
"childNodes",
"[",
"j",
"]",
"]",
")",
";",
"}",
"}",
"}",
"}",
"return",
"found",
";",
"}"
] | Scan children of specified node | [
"Scan",
"children",
"of",
"specified",
"node"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L629-L642 |
4,956 | angular/material | src/core/util/util.js | function(scope, attr, defaults) {
defaults = defaults || {};
angular.forEach(scope.$$isolateBindings, function(binding, key) {
if (binding.optional && angular.isUndefined(scope[key])) {
var attrIsDefined = angular.isDefined(attr[binding.attrName]);
scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined;
}
});
} | javascript | function(scope, attr, defaults) {
defaults = defaults || {};
angular.forEach(scope.$$isolateBindings, function(binding, key) {
if (binding.optional && angular.isUndefined(scope[key])) {
var attrIsDefined = angular.isDefined(attr[binding.attrName]);
scope[key] = angular.isDefined(defaults[key]) ? defaults[key] : attrIsDefined;
}
});
} | [
"function",
"(",
"scope",
",",
"attr",
",",
"defaults",
")",
"{",
"defaults",
"=",
"defaults",
"||",
"{",
"}",
";",
"angular",
".",
"forEach",
"(",
"scope",
".",
"$$isolateBindings",
",",
"function",
"(",
"binding",
",",
"key",
")",
"{",
"if",
"(",
"binding",
".",
"optional",
"&&",
"angular",
".",
"isUndefined",
"(",
"scope",
"[",
"key",
"]",
")",
")",
"{",
"var",
"attrIsDefined",
"=",
"angular",
".",
"isDefined",
"(",
"attr",
"[",
"binding",
".",
"attrName",
"]",
")",
";",
"scope",
"[",
"key",
"]",
"=",
"angular",
".",
"isDefined",
"(",
"defaults",
"[",
"key",
"]",
")",
"?",
"defaults",
"[",
"key",
"]",
":",
"attrIsDefined",
";",
"}",
"}",
")",
";",
"}"
] | Give optional properties with no value a boolean true if attr provided or false otherwise | [
"Give",
"optional",
"properties",
"with",
"no",
"value",
"a",
"boolean",
"true",
"if",
"attr",
"provided",
"or",
"false",
"otherwise"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L649-L657 |
|
4,957 | angular/material | src/core/util/util.js | processQueue | function processQueue() {
var queue = nextTick.queue;
var digest = nextTick.digest;
nextTick.queue = [];
nextTick.timeout = null;
nextTick.digest = false;
queue.forEach(function(queueItem) {
var skip = queueItem.scope && queueItem.scope.$$destroyed;
if (!skip) {
queueItem.callback();
}
});
if (digest) $rootScope.$digest();
} | javascript | function processQueue() {
var queue = nextTick.queue;
var digest = nextTick.digest;
nextTick.queue = [];
nextTick.timeout = null;
nextTick.digest = false;
queue.forEach(function(queueItem) {
var skip = queueItem.scope && queueItem.scope.$$destroyed;
if (!skip) {
queueItem.callback();
}
});
if (digest) $rootScope.$digest();
} | [
"function",
"processQueue",
"(",
")",
"{",
"var",
"queue",
"=",
"nextTick",
".",
"queue",
";",
"var",
"digest",
"=",
"nextTick",
".",
"digest",
";",
"nextTick",
".",
"queue",
"=",
"[",
"]",
";",
"nextTick",
".",
"timeout",
"=",
"null",
";",
"nextTick",
".",
"digest",
"=",
"false",
";",
"queue",
".",
"forEach",
"(",
"function",
"(",
"queueItem",
")",
"{",
"var",
"skip",
"=",
"queueItem",
".",
"scope",
"&&",
"queueItem",
".",
"scope",
".",
"$$destroyed",
";",
"if",
"(",
"!",
"skip",
")",
"{",
"queueItem",
".",
"callback",
"(",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"digest",
")",
"$rootScope",
".",
"$digest",
"(",
")",
";",
"}"
] | Grab a copy of the current queue
Clear the queue for future use
Process the existing queue
Trigger digest if necessary | [
"Grab",
"a",
"copy",
"of",
"the",
"current",
"queue",
"Clear",
"the",
"queue",
"for",
"future",
"use",
"Process",
"the",
"existing",
"queue",
"Trigger",
"digest",
"if",
"necessary"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L695-L711 |
4,958 | angular/material | src/core/util/util.js | function (element) {
var parent = element.parent();
// jqLite might return a non-null, but still empty, parent; so check for parent and length
while (hasComputedStyle(parent, 'pointer-events', 'none')) {
parent = parent.parent();
}
return parent;
} | javascript | function (element) {
var parent = element.parent();
// jqLite might return a non-null, but still empty, parent; so check for parent and length
while (hasComputedStyle(parent, 'pointer-events', 'none')) {
parent = parent.parent();
}
return parent;
} | [
"function",
"(",
"element",
")",
"{",
"var",
"parent",
"=",
"element",
".",
"parent",
"(",
")",
";",
"// jqLite might return a non-null, but still empty, parent; so check for parent and length",
"while",
"(",
"hasComputedStyle",
"(",
"parent",
",",
"'pointer-events'",
",",
"'none'",
")",
")",
"{",
"parent",
"=",
"parent",
".",
"parent",
"(",
")",
";",
"}",
"return",
"parent",
";",
"}"
] | Scan up dom hierarchy for enabled parent; | [
"Scan",
"up",
"dom",
"hierarchy",
"for",
"enabled",
"parent",
";"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L733-L742 |
|
4,959 | angular/material | src/core/util/util.js | function() {
var stickyProp;
var testEl = angular.element('<div>');
$document[0].body.appendChild(testEl[0]);
var stickyProps = ['sticky', '-webkit-sticky'];
for (var i = 0; i < stickyProps.length; ++i) {
testEl.css({
position: stickyProps[i],
top: 0,
'z-index': 2
});
if (testEl.css('position') == stickyProps[i]) {
stickyProp = stickyProps[i];
break;
}
}
testEl.remove();
return stickyProp;
} | javascript | function() {
var stickyProp;
var testEl = angular.element('<div>');
$document[0].body.appendChild(testEl[0]);
var stickyProps = ['sticky', '-webkit-sticky'];
for (var i = 0; i < stickyProps.length; ++i) {
testEl.css({
position: stickyProps[i],
top: 0,
'z-index': 2
});
if (testEl.css('position') == stickyProps[i]) {
stickyProp = stickyProps[i];
break;
}
}
testEl.remove();
return stickyProp;
} | [
"function",
"(",
")",
"{",
"var",
"stickyProp",
";",
"var",
"testEl",
"=",
"angular",
".",
"element",
"(",
"'<div>'",
")",
";",
"$document",
"[",
"0",
"]",
".",
"body",
".",
"appendChild",
"(",
"testEl",
"[",
"0",
"]",
")",
";",
"var",
"stickyProps",
"=",
"[",
"'sticky'",
",",
"'-webkit-sticky'",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"stickyProps",
".",
"length",
";",
"++",
"i",
")",
"{",
"testEl",
".",
"css",
"(",
"{",
"position",
":",
"stickyProps",
"[",
"i",
"]",
",",
"top",
":",
"0",
",",
"'z-index'",
":",
"2",
"}",
")",
";",
"if",
"(",
"testEl",
".",
"css",
"(",
"'position'",
")",
"==",
"stickyProps",
"[",
"i",
"]",
")",
"{",
"stickyProp",
"=",
"stickyProps",
"[",
"i",
"]",
";",
"break",
";",
"}",
"}",
"testEl",
".",
"remove",
"(",
")",
";",
"return",
"stickyProp",
";",
"}"
] | Checks if the current browser is natively supporting the `sticky` position.
@returns {string} supported sticky property name | [
"Checks",
"if",
"the",
"current",
"browser",
"is",
"natively",
"supporting",
"the",
"sticky",
"position",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L757-L779 |
|
4,960 | angular/material | src/core/util/util.js | function(element) {
var parent = $mdUtil.getClosest(element, 'form');
var form = parent ? angular.element(parent).controller('form') : null;
return form ? form.$submitted : false;
} | javascript | function(element) {
var parent = $mdUtil.getClosest(element, 'form');
var form = parent ? angular.element(parent).controller('form') : null;
return form ? form.$submitted : false;
} | [
"function",
"(",
"element",
")",
"{",
"var",
"parent",
"=",
"$mdUtil",
".",
"getClosest",
"(",
"element",
",",
"'form'",
")",
";",
"var",
"form",
"=",
"parent",
"?",
"angular",
".",
"element",
"(",
"parent",
")",
".",
"controller",
"(",
"'form'",
")",
":",
"null",
";",
"return",
"form",
"?",
"form",
".",
"$submitted",
":",
"false",
";",
"}"
] | Returns true if the parent form of the element has been submitted.
@param element An AngularJS or HTML5 element.
@returns {boolean} | [
"Returns",
"true",
"if",
"the",
"parent",
"form",
"of",
"the",
"element",
"has",
"been",
"submitted",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L803-L808 |
|
4,961 | angular/material | src/core/util/util.js | function(element, scrollEnd, duration) {
var scrollStart = element.scrollTop;
var scrollChange = scrollEnd - scrollStart;
var scrollingDown = scrollStart < scrollEnd;
var startTime = $mdUtil.now();
$$rAF(scrollChunk);
function scrollChunk() {
var newPosition = calculateNewPosition();
element.scrollTop = newPosition;
if (scrollingDown ? newPosition < scrollEnd : newPosition > scrollEnd) {
$$rAF(scrollChunk);
}
}
function calculateNewPosition() {
var easeDuration = duration || 1000;
var currentTime = $mdUtil.now() - startTime;
return ease(currentTime, scrollStart, scrollChange, easeDuration);
}
function ease(currentTime, start, change, duration) {
// If the duration has passed (which can occur if our app loses focus due to $$rAF), jump
// straight to the proper position
if (currentTime > duration) {
return start + change;
}
var ts = (currentTime /= duration) * currentTime;
var tc = ts * currentTime;
return start + change * (-2 * tc + 3 * ts);
}
} | javascript | function(element, scrollEnd, duration) {
var scrollStart = element.scrollTop;
var scrollChange = scrollEnd - scrollStart;
var scrollingDown = scrollStart < scrollEnd;
var startTime = $mdUtil.now();
$$rAF(scrollChunk);
function scrollChunk() {
var newPosition = calculateNewPosition();
element.scrollTop = newPosition;
if (scrollingDown ? newPosition < scrollEnd : newPosition > scrollEnd) {
$$rAF(scrollChunk);
}
}
function calculateNewPosition() {
var easeDuration = duration || 1000;
var currentTime = $mdUtil.now() - startTime;
return ease(currentTime, scrollStart, scrollChange, easeDuration);
}
function ease(currentTime, start, change, duration) {
// If the duration has passed (which can occur if our app loses focus due to $$rAF), jump
// straight to the proper position
if (currentTime > duration) {
return start + change;
}
var ts = (currentTime /= duration) * currentTime;
var tc = ts * currentTime;
return start + change * (-2 * tc + 3 * ts);
}
} | [
"function",
"(",
"element",
",",
"scrollEnd",
",",
"duration",
")",
"{",
"var",
"scrollStart",
"=",
"element",
".",
"scrollTop",
";",
"var",
"scrollChange",
"=",
"scrollEnd",
"-",
"scrollStart",
";",
"var",
"scrollingDown",
"=",
"scrollStart",
"<",
"scrollEnd",
";",
"var",
"startTime",
"=",
"$mdUtil",
".",
"now",
"(",
")",
";",
"$$rAF",
"(",
"scrollChunk",
")",
";",
"function",
"scrollChunk",
"(",
")",
"{",
"var",
"newPosition",
"=",
"calculateNewPosition",
"(",
")",
";",
"element",
".",
"scrollTop",
"=",
"newPosition",
";",
"if",
"(",
"scrollingDown",
"?",
"newPosition",
"<",
"scrollEnd",
":",
"newPosition",
">",
"scrollEnd",
")",
"{",
"$$rAF",
"(",
"scrollChunk",
")",
";",
"}",
"}",
"function",
"calculateNewPosition",
"(",
")",
"{",
"var",
"easeDuration",
"=",
"duration",
"||",
"1000",
";",
"var",
"currentTime",
"=",
"$mdUtil",
".",
"now",
"(",
")",
"-",
"startTime",
";",
"return",
"ease",
"(",
"currentTime",
",",
"scrollStart",
",",
"scrollChange",
",",
"easeDuration",
")",
";",
"}",
"function",
"ease",
"(",
"currentTime",
",",
"start",
",",
"change",
",",
"duration",
")",
"{",
"// If the duration has passed (which can occur if our app loses focus due to $$rAF), jump",
"// straight to the proper position",
"if",
"(",
"currentTime",
">",
"duration",
")",
"{",
"return",
"start",
"+",
"change",
";",
"}",
"var",
"ts",
"=",
"(",
"currentTime",
"/=",
"duration",
")",
"*",
"currentTime",
";",
"var",
"tc",
"=",
"ts",
"*",
"currentTime",
";",
"return",
"start",
"+",
"change",
"*",
"(",
"-",
"2",
"*",
"tc",
"+",
"3",
"*",
"ts",
")",
";",
"}",
"}"
] | Animate the requested element's scrollTop to the requested scrollPosition with basic easing.
@param {!Element} element The element to scroll.
@param {number} scrollEnd The new/final scroll position.
@param {number=} duration Duration of the scroll. Default is 1000ms. | [
"Animate",
"the",
"requested",
"element",
"s",
"scrollTop",
"to",
"the",
"requested",
"scrollPosition",
"with",
"basic",
"easing",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L817-L854 |
|
4,962 | angular/material | src/core/util/util.js | function(array) {
if (!array) { return; }
return array.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
} | javascript | function(array) {
if (!array) { return; }
return array.filter(function(value, index, self) {
return self.indexOf(value) === index;
});
} | [
"function",
"(",
"array",
")",
"{",
"if",
"(",
"!",
"array",
")",
"{",
"return",
";",
"}",
"return",
"array",
".",
"filter",
"(",
"function",
"(",
"value",
",",
"index",
",",
"self",
")",
"{",
"return",
"self",
".",
"indexOf",
"(",
"value",
")",
"===",
"index",
";",
"}",
")",
";",
"}"
] | Provides an easy mechanism for removing duplicates from an array.
var myArray = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4];
$mdUtil.uniq(myArray) => [1, 2, 3, 4]
@param {array} array The array whose unique values should be returned.
@returns {array} A copy of the array containing only unique values. | [
"Provides",
"an",
"easy",
"mechanism",
"for",
"removing",
"duplicates",
"from",
"an",
"array",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L867-L873 |
|
4,963 | angular/material | src/core/util/util.js | function(element) {
// For SVG or Symbol elements, innerHTML returns `undefined` in IE.
// Reference: https://stackoverflow.com/q/28129956/633107
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
var serializer = new XMLSerializer();
return Array.prototype.map.call(element.childNodes, function (child) {
return serializer.serializeToString(child);
}).join('');
} | javascript | function(element) {
// For SVG or Symbol elements, innerHTML returns `undefined` in IE.
// Reference: https://stackoverflow.com/q/28129956/633107
// The XMLSerializer API is supported on IE11 and is the recommended workaround.
var serializer = new XMLSerializer();
return Array.prototype.map.call(element.childNodes, function (child) {
return serializer.serializeToString(child);
}).join('');
} | [
"function",
"(",
"element",
")",
"{",
"// For SVG or Symbol elements, innerHTML returns `undefined` in IE.",
"// Reference: https://stackoverflow.com/q/28129956/633107",
"// The XMLSerializer API is supported on IE11 and is the recommended workaround.",
"var",
"serializer",
"=",
"new",
"XMLSerializer",
"(",
")",
";",
"return",
"Array",
".",
"prototype",
".",
"map",
".",
"call",
"(",
"element",
".",
"childNodes",
",",
"function",
"(",
"child",
")",
"{",
"return",
"serializer",
".",
"serializeToString",
"(",
"child",
")",
";",
"}",
")",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Gets the inner HTML content of the given HTMLElement.
Only intended for use with SVG or Symbol elements in IE11.
@param {Element} element
@returns {string} the inner HTML of the element passed in | [
"Gets",
"the",
"inner",
"HTML",
"content",
"of",
"the",
"given",
"HTMLElement",
".",
"Only",
"intended",
"for",
"use",
"with",
"SVG",
"or",
"Symbol",
"elements",
"in",
"IE11",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/util.js#L881-L890 |
|
4,964 | angular/material | src/components/autocomplete/autocomplete.spec.js | fakeItemMatch | function fakeItemMatch() {
var matches = [];
for (var i = 0; i < dropdownItems; i++) {
matches.push('Item ' + i);
}
return matches;
} | javascript | function fakeItemMatch() {
var matches = [];
for (var i = 0; i < dropdownItems; i++) {
matches.push('Item ' + i);
}
return matches;
} | [
"function",
"fakeItemMatch",
"(",
")",
"{",
"var",
"matches",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"dropdownItems",
";",
"i",
"++",
")",
"{",
"matches",
".",
"push",
"(",
"'Item '",
"+",
"i",
")",
";",
"}",
"return",
"matches",
";",
"}"
] | Function to create fake matches with the given dropdown items.
Useful when running tests against the dropdown max items calculations.
@returns {Array} Fake matches. | [
"Function",
"to",
"create",
"fake",
"matches",
"with",
"the",
"given",
"dropdown",
"items",
".",
"Useful",
"when",
"running",
"tests",
"against",
"the",
"dropdown",
"max",
"items",
"calculations",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/autocomplete/autocomplete.spec.js#L2456-L2464 |
4,965 | angular/material | src/components/input/input.js | calculateInputValueLength | function calculateInputValueLength(value) {
value = ngTrim && !isPasswordInput && angular.isString(value) ? value.trim() : value;
if (value === undefined || value === null) {
value = '';
}
return String(value).length;
} | javascript | function calculateInputValueLength(value) {
value = ngTrim && !isPasswordInput && angular.isString(value) ? value.trim() : value;
if (value === undefined || value === null) {
value = '';
}
return String(value).length;
} | [
"function",
"calculateInputValueLength",
"(",
"value",
")",
"{",
"value",
"=",
"ngTrim",
"&&",
"!",
"isPasswordInput",
"&&",
"angular",
".",
"isString",
"(",
"value",
")",
"?",
"value",
".",
"trim",
"(",
")",
":",
"value",
";",
"if",
"(",
"value",
"===",
"undefined",
"||",
"value",
"===",
"null",
")",
"{",
"value",
"=",
"''",
";",
"}",
"return",
"String",
"(",
"value",
")",
".",
"length",
";",
"}"
] | Calculate the input value's length after coercing it to a string
and trimming it if appropriate.
@param value {*} the input's value
@returns {number} calculated length of the input's value | [
"Calculate",
"the",
"input",
"value",
"s",
"length",
"after",
"coercing",
"it",
"to",
"a",
"string",
"and",
"trimming",
"it",
"if",
"appropriate",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/input/input.js#L733-L739 |
4,966 | angular/material | src/components/datepicker/js/calendarYear.js | calendarDirective | function calendarDirective() {
return {
template:
'<div class="md-calendar-scroll-mask">' +
'<md-virtual-repeat-container class="md-calendar-scroll-container">' +
'<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
'<tbody ' +
'md-calendar-year-body ' +
'role="rowgroup" ' +
'md-virtual-repeat="i in yearCtrl.items" ' +
'md-year-offset="$index" class="md-calendar-year" ' +
'md-start-index="yearCtrl.getFocusedYearIndex()" ' +
'md-item-size="' + TBODY_HEIGHT + '">' +
// The <tr> ensures that the <tbody> will have the proper
// height, even though it may be empty.
'<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
'</tbody>' +
'</table>' +
'</md-virtual-repeat-container>' +
'</div>',
require: ['^^mdCalendar', 'mdCalendarYear'],
controller: CalendarYearCtrl,
controllerAs: 'yearCtrl',
bindToController: true,
link: function(scope, element, attrs, controllers) {
var calendarCtrl = controllers[0];
var yearCtrl = controllers[1];
yearCtrl.initialize(calendarCtrl);
}
};
} | javascript | function calendarDirective() {
return {
template:
'<div class="md-calendar-scroll-mask">' +
'<md-virtual-repeat-container class="md-calendar-scroll-container">' +
'<table role="grid" tabindex="0" class="md-calendar" aria-readonly="true">' +
'<tbody ' +
'md-calendar-year-body ' +
'role="rowgroup" ' +
'md-virtual-repeat="i in yearCtrl.items" ' +
'md-year-offset="$index" class="md-calendar-year" ' +
'md-start-index="yearCtrl.getFocusedYearIndex()" ' +
'md-item-size="' + TBODY_HEIGHT + '">' +
// The <tr> ensures that the <tbody> will have the proper
// height, even though it may be empty.
'<tr aria-hidden="true" md-force-height="\'' + TBODY_HEIGHT + 'px\'"></tr>' +
'</tbody>' +
'</table>' +
'</md-virtual-repeat-container>' +
'</div>',
require: ['^^mdCalendar', 'mdCalendarYear'],
controller: CalendarYearCtrl,
controllerAs: 'yearCtrl',
bindToController: true,
link: function(scope, element, attrs, controllers) {
var calendarCtrl = controllers[0];
var yearCtrl = controllers[1];
yearCtrl.initialize(calendarCtrl);
}
};
} | [
"function",
"calendarDirective",
"(",
")",
"{",
"return",
"{",
"template",
":",
"'<div class=\"md-calendar-scroll-mask\">'",
"+",
"'<md-virtual-repeat-container class=\"md-calendar-scroll-container\">'",
"+",
"'<table role=\"grid\" tabindex=\"0\" class=\"md-calendar\" aria-readonly=\"true\">'",
"+",
"'<tbody '",
"+",
"'md-calendar-year-body '",
"+",
"'role=\"rowgroup\" '",
"+",
"'md-virtual-repeat=\"i in yearCtrl.items\" '",
"+",
"'md-year-offset=\"$index\" class=\"md-calendar-year\" '",
"+",
"'md-start-index=\"yearCtrl.getFocusedYearIndex()\" '",
"+",
"'md-item-size=\"'",
"+",
"TBODY_HEIGHT",
"+",
"'\">'",
"+",
"// The <tr> ensures that the <tbody> will have the proper",
"// height, even though it may be empty.",
"'<tr aria-hidden=\"true\" md-force-height=\"\\''",
"+",
"TBODY_HEIGHT",
"+",
"'px\\'\"></tr>'",
"+",
"'</tbody>'",
"+",
"'</table>'",
"+",
"'</md-virtual-repeat-container>'",
"+",
"'</div>'",
",",
"require",
":",
"[",
"'^^mdCalendar'",
",",
"'mdCalendarYear'",
"]",
",",
"controller",
":",
"CalendarYearCtrl",
",",
"controllerAs",
":",
"'yearCtrl'",
",",
"bindToController",
":",
"true",
",",
"link",
":",
"function",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"controllers",
")",
"{",
"var",
"calendarCtrl",
"=",
"controllers",
"[",
"0",
"]",
";",
"var",
"yearCtrl",
"=",
"controllers",
"[",
"1",
"]",
";",
"yearCtrl",
".",
"initialize",
"(",
"calendarCtrl",
")",
";",
"}",
"}",
";",
"}"
] | Private component, representing a list of years in the calendar. | [
"Private",
"component",
"representing",
"a",
"list",
"of",
"years",
"in",
"the",
"calendar",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendarYear.js#L14-L44 |
4,967 | angular/material | src/components/panel/panel.js | definePreset | function definePreset(name, preset) {
if (!name || !preset) {
throw new Error('mdPanelProvider: The panel preset definition is ' +
'malformed. The name and preset object are required.');
} else if (_presets.hasOwnProperty(name)) {
throw new Error('mdPanelProvider: The panel preset you have requested ' +
'has already been defined.');
}
// Delete any property on the preset that is not allowed.
delete preset.id;
delete preset.position;
delete preset.animation;
_presets[name] = preset;
} | javascript | function definePreset(name, preset) {
if (!name || !preset) {
throw new Error('mdPanelProvider: The panel preset definition is ' +
'malformed. The name and preset object are required.');
} else if (_presets.hasOwnProperty(name)) {
throw new Error('mdPanelProvider: The panel preset you have requested ' +
'has already been defined.');
}
// Delete any property on the preset that is not allowed.
delete preset.id;
delete preset.position;
delete preset.animation;
_presets[name] = preset;
} | [
"function",
"definePreset",
"(",
"name",
",",
"preset",
")",
"{",
"if",
"(",
"!",
"name",
"||",
"!",
"preset",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdPanelProvider: The panel preset definition is '",
"+",
"'malformed. The name and preset object are required.'",
")",
";",
"}",
"else",
"if",
"(",
"_presets",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'mdPanelProvider: The panel preset you have requested '",
"+",
"'has already been defined.'",
")",
";",
"}",
"// Delete any property on the preset that is not allowed.",
"delete",
"preset",
".",
"id",
";",
"delete",
"preset",
".",
"position",
";",
"delete",
"preset",
".",
"animation",
";",
"_presets",
"[",
"name",
"]",
"=",
"preset",
";",
"}"
] | Takes the passed in panel configuration object and adds it to the `_presets`
object at the specified name.
@param {string} name Name of the preset to set.
@param {!Object} preset Specific configuration object that can contain any
and all of the parameters available within the `$mdPanel.create` method.
However, parameters that pertain to id, position, animation, and user
interaction are not allowed and will be removed from the preset
configuration. | [
"Takes",
"the",
"passed",
"in",
"panel",
"configuration",
"object",
"and",
"adds",
"it",
"to",
"the",
"_presets",
"object",
"at",
"the",
"specified",
"name",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/panel/panel.js#L966-L981 |
4,968 | angular/material | src/components/panel/panel.js | getComputedTranslations | function getComputedTranslations(el, property) {
// The transform being returned by `getComputedStyle` is in the format:
// `matrix(a, b, c, d, translateX, translateY)` if defined and `none`
// if the element doesn't have a transform.
var transform = getComputedStyle(el[0] || el)[property];
var openIndex = transform.indexOf('(');
var closeIndex = transform.lastIndexOf(')');
var output = { x: 0, y: 0 };
if (openIndex > -1 && closeIndex > -1) {
var parsedValues = transform
.substring(openIndex + 1, closeIndex)
.split(', ')
.slice(-2);
output.x = parseInt(parsedValues[0]);
output.y = parseInt(parsedValues[1]);
}
return output;
} | javascript | function getComputedTranslations(el, property) {
// The transform being returned by `getComputedStyle` is in the format:
// `matrix(a, b, c, d, translateX, translateY)` if defined and `none`
// if the element doesn't have a transform.
var transform = getComputedStyle(el[0] || el)[property];
var openIndex = transform.indexOf('(');
var closeIndex = transform.lastIndexOf(')');
var output = { x: 0, y: 0 };
if (openIndex > -1 && closeIndex > -1) {
var parsedValues = transform
.substring(openIndex + 1, closeIndex)
.split(', ')
.slice(-2);
output.x = parseInt(parsedValues[0]);
output.y = parseInt(parsedValues[1]);
}
return output;
} | [
"function",
"getComputedTranslations",
"(",
"el",
",",
"property",
")",
"{",
"// The transform being returned by `getComputedStyle` is in the format:",
"// `matrix(a, b, c, d, translateX, translateY)` if defined and `none`",
"// if the element doesn't have a transform.",
"var",
"transform",
"=",
"getComputedStyle",
"(",
"el",
"[",
"0",
"]",
"||",
"el",
")",
"[",
"property",
"]",
";",
"var",
"openIndex",
"=",
"transform",
".",
"indexOf",
"(",
"'('",
")",
";",
"var",
"closeIndex",
"=",
"transform",
".",
"lastIndexOf",
"(",
"')'",
")",
";",
"var",
"output",
"=",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
";",
"if",
"(",
"openIndex",
">",
"-",
"1",
"&&",
"closeIndex",
">",
"-",
"1",
")",
"{",
"var",
"parsedValues",
"=",
"transform",
".",
"substring",
"(",
"openIndex",
"+",
"1",
",",
"closeIndex",
")",
".",
"split",
"(",
"', '",
")",
".",
"slice",
"(",
"-",
"2",
")",
";",
"output",
".",
"x",
"=",
"parseInt",
"(",
"parsedValues",
"[",
"0",
"]",
")",
";",
"output",
".",
"y",
"=",
"parseInt",
"(",
"parsedValues",
"[",
"1",
"]",
")",
";",
"}",
"return",
"output",
";",
"}"
] | Gets the computed values for an element's translateX and translateY in px.
@param {!angular.JQLite|!Element} el
@param {string} property
@return {{x: number, y: number}} | [
"Gets",
"the",
"computed",
"values",
"for",
"an",
"element",
"s",
"translateX",
"and",
"translateY",
"in",
"px",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/panel/panel.js#L3530-L3550 |
4,969 | angular/material | docs/app/js/anchor.js | createContentURL | function createContentURL() {
var path = '';
var name = element.text();
// Use $window.location.pathname to get the path with the baseURL included.
// $location.path() does not include the baseURL. This is important to support how the docs
// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
if (scope.$root.$window && scope.$root.$window.location) {
path = scope.$root.$window.location.pathname;
}
name = name
.trim() // Trim text due to browsers extra whitespace.
.replace(/'/g, '') // Transform apostrophes words to a single one.
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
.toLowerCase(); // Link should be lower-case for accessible URL.
scope.name = name;
scope.href = path + '#' + name;
} | javascript | function createContentURL() {
var path = '';
var name = element.text();
// Use $window.location.pathname to get the path with the baseURL included.
// $location.path() does not include the baseURL. This is important to support how the docs
// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.
if (scope.$root.$window && scope.$root.$window.location) {
path = scope.$root.$window.location.pathname;
}
name = name
.trim() // Trim text due to browsers extra whitespace.
.replace(/'/g, '') // Transform apostrophes words to a single one.
.replace(unsafeCharRegex, '-') // Replace unsafe chars with a dash symbol.
.replace(/-{2,}/g, '-') // Remove repeating dash symbols.
.replace(/^-|-$/g, '') // Remove preceding or ending dashes.
.toLowerCase(); // Link should be lower-case for accessible URL.
scope.name = name;
scope.href = path + '#' + name;
} | [
"function",
"createContentURL",
"(",
")",
"{",
"var",
"path",
"=",
"''",
";",
"var",
"name",
"=",
"element",
".",
"text",
"(",
")",
";",
"// Use $window.location.pathname to get the path with the baseURL included.",
"// $location.path() does not include the baseURL. This is important to support how the docs",
"// are deployed with baseURLs like /latest, /HEAD, /1.1.13, etc.",
"if",
"(",
"scope",
".",
"$root",
".",
"$window",
"&&",
"scope",
".",
"$root",
".",
"$window",
".",
"location",
")",
"{",
"path",
"=",
"scope",
".",
"$root",
".",
"$window",
".",
"location",
".",
"pathname",
";",
"}",
"name",
"=",
"name",
".",
"trim",
"(",
")",
"// Trim text due to browsers extra whitespace.",
".",
"replace",
"(",
"/",
"'",
"/",
"g",
",",
"''",
")",
"// Transform apostrophes words to a single one.",
".",
"replace",
"(",
"unsafeCharRegex",
",",
"'-'",
")",
"// Replace unsafe chars with a dash symbol.",
".",
"replace",
"(",
"/",
"-{2,}",
"/",
"g",
",",
"'-'",
")",
"// Remove repeating dash symbols.",
".",
"replace",
"(",
"/",
"^-|-$",
"/",
"g",
",",
"''",
")",
"// Remove preceding or ending dashes.",
".",
"toLowerCase",
"(",
")",
";",
"// Link should be lower-case for accessible URL.",
"scope",
".",
"name",
"=",
"name",
";",
"scope",
".",
"href",
"=",
"path",
"+",
"'#'",
"+",
"name",
";",
"}"
] | Creates URL from the text content of the element and writes it into the scope. | [
"Creates",
"URL",
"from",
"the",
"text",
"content",
"of",
"the",
"element",
"and",
"writes",
"it",
"into",
"the",
"scope",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/docs/app/js/anchor.js#L43-L61 |
4,970 | angular/material | src/components/autocomplete/js/autocompleteParentScopeDirective.js | watchVariable | function watchVariable(variable, alias) {
newScope[alias] = scope[variable];
scope.$watch(variable, function(value) {
$mdUtil.nextTick(function() {
newScope[alias] = value;
});
});
} | javascript | function watchVariable(variable, alias) {
newScope[alias] = scope[variable];
scope.$watch(variable, function(value) {
$mdUtil.nextTick(function() {
newScope[alias] = value;
});
});
} | [
"function",
"watchVariable",
"(",
"variable",
",",
"alias",
")",
"{",
"newScope",
"[",
"alias",
"]",
"=",
"scope",
"[",
"variable",
"]",
";",
"scope",
".",
"$watch",
"(",
"variable",
",",
"function",
"(",
"value",
")",
"{",
"$mdUtil",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"newScope",
"[",
"alias",
"]",
"=",
"value",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Creates a watcher for variables that are copied from the parent scope
@param variable
@param alias | [
"Creates",
"a",
"watcher",
"for",
"variables",
"that",
"are",
"copied",
"from",
"the",
"parent",
"scope"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/autocomplete/js/autocompleteParentScopeDirective.js#L36-L44 |
4,971 | angular/material | src/core/services/layout/layout.js | buildCloakInterceptor | function buildCloakInterceptor(className) {
return ['$timeout', function($timeout){
return {
restrict : 'A',
priority : -10, // run after normal ng-cloak
compile : function(element) {
if (!config.enabled) return angular.noop;
// Re-add the cloak
element.addClass(className);
return function(scope, element) {
// Wait while layout injectors configure, then uncloak
// NOTE: $rAF does not delay enough... and this is a 1x-only event,
// $timeout is acceptable.
$timeout(function(){
element.removeClass(className);
}, 10, false);
};
}
};
}];
} | javascript | function buildCloakInterceptor(className) {
return ['$timeout', function($timeout){
return {
restrict : 'A',
priority : -10, // run after normal ng-cloak
compile : function(element) {
if (!config.enabled) return angular.noop;
// Re-add the cloak
element.addClass(className);
return function(scope, element) {
// Wait while layout injectors configure, then uncloak
// NOTE: $rAF does not delay enough... and this is a 1x-only event,
// $timeout is acceptable.
$timeout(function(){
element.removeClass(className);
}, 10, false);
};
}
};
}];
} | [
"function",
"buildCloakInterceptor",
"(",
"className",
")",
"{",
"return",
"[",
"'$timeout'",
",",
"function",
"(",
"$timeout",
")",
"{",
"return",
"{",
"restrict",
":",
"'A'",
",",
"priority",
":",
"-",
"10",
",",
"// run after normal ng-cloak",
"compile",
":",
"function",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"config",
".",
"enabled",
")",
"return",
"angular",
".",
"noop",
";",
"// Re-add the cloak",
"element",
".",
"addClass",
"(",
"className",
")",
";",
"return",
"function",
"(",
"scope",
",",
"element",
")",
"{",
"// Wait while layout injectors configure, then uncloak",
"// NOTE: $rAF does not delay enough... and this is a 1x-only event,",
"// $timeout is acceptable.",
"$timeout",
"(",
"function",
"(",
")",
"{",
"element",
".",
"removeClass",
"(",
"className",
")",
";",
"}",
",",
"10",
",",
"false",
")",
";",
"}",
";",
"}",
"}",
";",
"}",
"]",
";",
"}"
] | Tail-hook ngCloak to delay the uncloaking while Layout transformers
finish processing. Eliminates flicker with Material.Layouts | [
"Tail",
"-",
"hook",
"ngCloak",
"to",
"delay",
"the",
"uncloaking",
"while",
"Layout",
"transformers",
"finish",
"processing",
".",
"Eliminates",
"flicker",
"with",
"Material",
".",
"Layouts"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L215-L237 |
4,972 | angular/material | src/core/services/layout/layout.js | function(element) {
if (!config.enabled) return angular.noop;
// Re-add the cloak
element.addClass(className);
return function(scope, element) {
// Wait while layout injectors configure, then uncloak
// NOTE: $rAF does not delay enough... and this is a 1x-only event,
// $timeout is acceptable.
$timeout(function(){
element.removeClass(className);
}, 10, false);
};
} | javascript | function(element) {
if (!config.enabled) return angular.noop;
// Re-add the cloak
element.addClass(className);
return function(scope, element) {
// Wait while layout injectors configure, then uncloak
// NOTE: $rAF does not delay enough... and this is a 1x-only event,
// $timeout is acceptable.
$timeout(function(){
element.removeClass(className);
}, 10, false);
};
} | [
"function",
"(",
"element",
")",
"{",
"if",
"(",
"!",
"config",
".",
"enabled",
")",
"return",
"angular",
".",
"noop",
";",
"// Re-add the cloak",
"element",
".",
"addClass",
"(",
"className",
")",
";",
"return",
"function",
"(",
"scope",
",",
"element",
")",
"{",
"// Wait while layout injectors configure, then uncloak",
"// NOTE: $rAF does not delay enough... and this is a 1x-only event,",
"// $timeout is acceptable.",
"$timeout",
"(",
"function",
"(",
")",
"{",
"element",
".",
"removeClass",
"(",
"className",
")",
";",
"}",
",",
"10",
",",
"false",
")",
";",
"}",
";",
"}"
] | run after normal ng-cloak | [
"run",
"after",
"normal",
"ng",
"-",
"cloak"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L220-L234 |
|
4,973 | angular/material | src/core/services/layout/layout.js | updateClassWithValue | function updateClassWithValue(element, className) {
var lastClass;
return function updateClassFn(newValue) {
var value = validateAttributeValue(className, newValue || "");
if (angular.isDefined(value)) {
if (lastClass) element.removeClass(lastClass);
lastClass = !value ? className : className + "-" + value.trim().replace(WHITESPACE, "-");
element.addClass(lastClass);
}
};
} | javascript | function updateClassWithValue(element, className) {
var lastClass;
return function updateClassFn(newValue) {
var value = validateAttributeValue(className, newValue || "");
if (angular.isDefined(value)) {
if (lastClass) element.removeClass(lastClass);
lastClass = !value ? className : className + "-" + value.trim().replace(WHITESPACE, "-");
element.addClass(lastClass);
}
};
} | [
"function",
"updateClassWithValue",
"(",
"element",
",",
"className",
")",
"{",
"var",
"lastClass",
";",
"return",
"function",
"updateClassFn",
"(",
"newValue",
")",
"{",
"var",
"value",
"=",
"validateAttributeValue",
"(",
"className",
",",
"newValue",
"||",
"\"\"",
")",
";",
"if",
"(",
"angular",
".",
"isDefined",
"(",
"value",
")",
")",
"{",
"if",
"(",
"lastClass",
")",
"element",
".",
"removeClass",
"(",
"lastClass",
")",
";",
"lastClass",
"=",
"!",
"value",
"?",
"className",
":",
"className",
"+",
"\"-\"",
"+",
"value",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"WHITESPACE",
",",
"\"-\"",
")",
";",
"element",
".",
"addClass",
"(",
"lastClass",
")",
";",
"}",
"}",
";",
"}"
] | After link-phase, do NOT remove deprecated layout attribute selector.
Instead watch the attribute so interpolated data-bindings to layout
selectors will continue to be supported.
$observe() the className and update with new class (after removing the last one)
e.g. `layout="{{layoutDemo.direction}}"` will update...
NOTE: The value must match one of the specified styles in the CSS.
For example `flex-gt-md="{{size}}` where `scope.size == 47` will NOT work since
only breakpoints for 0, 5, 10, 15... 100, 33, 34, 66, 67 are defined. | [
"After",
"link",
"-",
"phase",
"do",
"NOT",
"remove",
"deprecated",
"layout",
"attribute",
"selector",
".",
"Instead",
"watch",
"the",
"attribute",
"so",
"interpolated",
"data",
"-",
"bindings",
"to",
"layout",
"selectors",
"will",
"continue",
"to",
"be",
"supported",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L356-L367 |
4,974 | angular/material | src/core/services/layout/layout.js | warnAttrNotSupported | function warnAttrNotSupported(className) {
var parts = className.split("-");
return ["$log", function($log) {
$log.warn(className + "has been deprecated. Please use a `" + parts[0] + "-gt-<xxx>` variant.");
return angular.noop;
}];
} | javascript | function warnAttrNotSupported(className) {
var parts = className.split("-");
return ["$log", function($log) {
$log.warn(className + "has been deprecated. Please use a `" + parts[0] + "-gt-<xxx>` variant.");
return angular.noop;
}];
} | [
"function",
"warnAttrNotSupported",
"(",
"className",
")",
"{",
"var",
"parts",
"=",
"className",
".",
"split",
"(",
"\"-\"",
")",
";",
"return",
"[",
"\"$log\"",
",",
"function",
"(",
"$log",
")",
"{",
"$log",
".",
"warn",
"(",
"className",
"+",
"\"has been deprecated. Please use a `\"",
"+",
"parts",
"[",
"0",
"]",
"+",
"\"-gt-<xxx>` variant.\"",
")",
";",
"return",
"angular",
".",
"noop",
";",
"}",
"]",
";",
"}"
] | Provide console warning that this layout attribute has been deprecated | [
"Provide",
"console",
"warning",
"that",
"this",
"layout",
"attribute",
"has",
"been",
"deprecated"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L373-L379 |
4,975 | angular/material | src/core/services/layout/layout.js | validateAttributeValue | function validateAttributeValue(className, value, updateFn) {
var origValue;
if (!needsInterpolation(value)) {
switch (className.replace(SUFFIXES,"")) {
case 'layout' :
if (!findIn(value, LAYOUT_OPTIONS)) {
value = LAYOUT_OPTIONS[0]; // 'row';
}
break;
case 'flex' :
if (!findIn(value, FLEX_OPTIONS)) {
if (isNaN(value)) {
value = '';
}
}
break;
case 'flex-offset' :
case 'flex-order' :
if (!value || isNaN(+value)) {
value = '0';
}
break;
case 'layout-align' :
var axis = extractAlignAxis(value);
value = $mdUtil.supplant("{main}-{cross}",axis);
break;
case 'layout-padding' :
case 'layout-margin' :
case 'layout-fill' :
case 'layout-wrap' :
case 'layout-nowrap' :
value = '';
break;
}
if (value != origValue) {
(updateFn || angular.noop)(value);
}
}
return value ? value.trim() : "";
} | javascript | function validateAttributeValue(className, value, updateFn) {
var origValue;
if (!needsInterpolation(value)) {
switch (className.replace(SUFFIXES,"")) {
case 'layout' :
if (!findIn(value, LAYOUT_OPTIONS)) {
value = LAYOUT_OPTIONS[0]; // 'row';
}
break;
case 'flex' :
if (!findIn(value, FLEX_OPTIONS)) {
if (isNaN(value)) {
value = '';
}
}
break;
case 'flex-offset' :
case 'flex-order' :
if (!value || isNaN(+value)) {
value = '0';
}
break;
case 'layout-align' :
var axis = extractAlignAxis(value);
value = $mdUtil.supplant("{main}-{cross}",axis);
break;
case 'layout-padding' :
case 'layout-margin' :
case 'layout-fill' :
case 'layout-wrap' :
case 'layout-nowrap' :
value = '';
break;
}
if (value != origValue) {
(updateFn || angular.noop)(value);
}
}
return value ? value.trim() : "";
} | [
"function",
"validateAttributeValue",
"(",
"className",
",",
"value",
",",
"updateFn",
")",
"{",
"var",
"origValue",
";",
"if",
"(",
"!",
"needsInterpolation",
"(",
"value",
")",
")",
"{",
"switch",
"(",
"className",
".",
"replace",
"(",
"SUFFIXES",
",",
"\"\"",
")",
")",
"{",
"case",
"'layout'",
":",
"if",
"(",
"!",
"findIn",
"(",
"value",
",",
"LAYOUT_OPTIONS",
")",
")",
"{",
"value",
"=",
"LAYOUT_OPTIONS",
"[",
"0",
"]",
";",
"// 'row';",
"}",
"break",
";",
"case",
"'flex'",
":",
"if",
"(",
"!",
"findIn",
"(",
"value",
",",
"FLEX_OPTIONS",
")",
")",
"{",
"if",
"(",
"isNaN",
"(",
"value",
")",
")",
"{",
"value",
"=",
"''",
";",
"}",
"}",
"break",
";",
"case",
"'flex-offset'",
":",
"case",
"'flex-order'",
":",
"if",
"(",
"!",
"value",
"||",
"isNaN",
"(",
"+",
"value",
")",
")",
"{",
"value",
"=",
"'0'",
";",
"}",
"break",
";",
"case",
"'layout-align'",
":",
"var",
"axis",
"=",
"extractAlignAxis",
"(",
"value",
")",
";",
"value",
"=",
"$mdUtil",
".",
"supplant",
"(",
"\"{main}-{cross}\"",
",",
"axis",
")",
";",
"break",
";",
"case",
"'layout-padding'",
":",
"case",
"'layout-margin'",
":",
"case",
"'layout-fill'",
":",
"case",
"'layout-wrap'",
":",
"case",
"'layout-nowrap'",
":",
"value",
"=",
"''",
";",
"break",
";",
"}",
"if",
"(",
"value",
"!=",
"origValue",
")",
"{",
"(",
"updateFn",
"||",
"angular",
".",
"noop",
")",
"(",
"value",
")",
";",
"}",
"}",
"return",
"value",
"?",
"value",
".",
"trim",
"(",
")",
":",
"\"\"",
";",
"}"
] | For the Layout attribute value, validate or replace with default
fallback value | [
"For",
"the",
"Layout",
"attribute",
"value",
"validate",
"or",
"replace",
"with",
"default",
"fallback",
"value"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L409-L455 |
4,976 | angular/material | src/core/services/layout/layout.js | buildUpdateFn | function buildUpdateFn(element, className, attrs) {
return function updateAttrValue(fallback) {
if (!needsInterpolation(fallback)) {
// Do not modify the element's attribute value; so
// uses '<ui-layout layout="/api/sidebar.html" />' will not
// be affected. Just update the attrs value.
attrs[attrs.$normalize(className)] = fallback;
}
};
} | javascript | function buildUpdateFn(element, className, attrs) {
return function updateAttrValue(fallback) {
if (!needsInterpolation(fallback)) {
// Do not modify the element's attribute value; so
// uses '<ui-layout layout="/api/sidebar.html" />' will not
// be affected. Just update the attrs value.
attrs[attrs.$normalize(className)] = fallback;
}
};
} | [
"function",
"buildUpdateFn",
"(",
"element",
",",
"className",
",",
"attrs",
")",
"{",
"return",
"function",
"updateAttrValue",
"(",
"fallback",
")",
"{",
"if",
"(",
"!",
"needsInterpolation",
"(",
"fallback",
")",
")",
"{",
"// Do not modify the element's attribute value; so",
"// uses '<ui-layout layout=\"/api/sidebar.html\" />' will not",
"// be affected. Just update the attrs value.",
"attrs",
"[",
"attrs",
".",
"$normalize",
"(",
"className",
")",
"]",
"=",
"fallback",
";",
"}",
"}",
";",
"}"
] | Replace current attribute value with fallback value | [
"Replace",
"current",
"attribute",
"value",
"with",
"fallback",
"value"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/layout/layout.js#L460-L469 |
4,977 | angular/material | src/components/slider/slider.js | positionToPercent | function positionToPercent(position) {
var offset = vertical ? sliderDimensions.top : sliderDimensions.left;
var size = vertical ? sliderDimensions.height : sliderDimensions.width;
var calc = (position - offset) / size;
if (!vertical && $mdUtil.bidi() === 'rtl') {
calc = 1 - calc;
}
return Math.max(0, Math.min(1, vertical ? 1 - calc : calc));
} | javascript | function positionToPercent(position) {
var offset = vertical ? sliderDimensions.top : sliderDimensions.left;
var size = vertical ? sliderDimensions.height : sliderDimensions.width;
var calc = (position - offset) / size;
if (!vertical && $mdUtil.bidi() === 'rtl') {
calc = 1 - calc;
}
return Math.max(0, Math.min(1, vertical ? 1 - calc : calc));
} | [
"function",
"positionToPercent",
"(",
"position",
")",
"{",
"var",
"offset",
"=",
"vertical",
"?",
"sliderDimensions",
".",
"top",
":",
"sliderDimensions",
".",
"left",
";",
"var",
"size",
"=",
"vertical",
"?",
"sliderDimensions",
".",
"height",
":",
"sliderDimensions",
".",
"width",
";",
"var",
"calc",
"=",
"(",
"position",
"-",
"offset",
")",
"/",
"size",
";",
"if",
"(",
"!",
"vertical",
"&&",
"$mdUtil",
".",
"bidi",
"(",
")",
"===",
"'rtl'",
")",
"{",
"calc",
"=",
"1",
"-",
"calc",
";",
"}",
"return",
"Math",
".",
"max",
"(",
"0",
",",
"Math",
".",
"min",
"(",
"1",
",",
"vertical",
"?",
"1",
"-",
"calc",
":",
"calc",
")",
")",
";",
"}"
] | Convert position on slider to percentage value of offset from beginning...
@param position
@returns {number} | [
"Convert",
"position",
"on",
"slider",
"to",
"percentage",
"value",
"of",
"offset",
"from",
"beginning",
"..."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/slider/slider.js#L645-L655 |
4,978 | angular/material | src/components/slider/slider.js | percentToValue | function percentToValue(percent) {
var adjustedPercent = invert ? (1 - percent) : percent;
return (min + adjustedPercent * (max - min));
} | javascript | function percentToValue(percent) {
var adjustedPercent = invert ? (1 - percent) : percent;
return (min + adjustedPercent * (max - min));
} | [
"function",
"percentToValue",
"(",
"percent",
")",
"{",
"var",
"adjustedPercent",
"=",
"invert",
"?",
"(",
"1",
"-",
"percent",
")",
":",
"percent",
";",
"return",
"(",
"min",
"+",
"adjustedPercent",
"*",
"(",
"max",
"-",
"min",
")",
")",
";",
"}"
] | Convert percentage offset on slide to equivalent model value
@param percent
@returns {*} | [
"Convert",
"percentage",
"offset",
"on",
"slide",
"to",
"equivalent",
"model",
"value"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/slider/slider.js#L662-L665 |
4,979 | angular/material | src/core/services/aria/aria.js | expect | function expect(element, attrName, defaultValue) {
var node = angular.element(element)[0] || element;
// if node exists and neither it nor its children have the attribute
if (node &&
((!node.hasAttribute(attrName) ||
node.getAttribute(attrName).length === 0) &&
!childHasAttribute(node, attrName))) {
defaultValue = angular.isString(defaultValue) ? defaultValue.trim() : '';
if (defaultValue.length) {
element.attr(attrName, defaultValue);
} else if (showWarnings) {
$log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
}
}
} | javascript | function expect(element, attrName, defaultValue) {
var node = angular.element(element)[0] || element;
// if node exists and neither it nor its children have the attribute
if (node &&
((!node.hasAttribute(attrName) ||
node.getAttribute(attrName).length === 0) &&
!childHasAttribute(node, attrName))) {
defaultValue = angular.isString(defaultValue) ? defaultValue.trim() : '';
if (defaultValue.length) {
element.attr(attrName, defaultValue);
} else if (showWarnings) {
$log.warn('ARIA: Attribute "', attrName, '", required for accessibility, is missing on node:', node);
}
}
} | [
"function",
"expect",
"(",
"element",
",",
"attrName",
",",
"defaultValue",
")",
"{",
"var",
"node",
"=",
"angular",
".",
"element",
"(",
"element",
")",
"[",
"0",
"]",
"||",
"element",
";",
"// if node exists and neither it nor its children have the attribute",
"if",
"(",
"node",
"&&",
"(",
"(",
"!",
"node",
".",
"hasAttribute",
"(",
"attrName",
")",
"||",
"node",
".",
"getAttribute",
"(",
"attrName",
")",
".",
"length",
"===",
"0",
")",
"&&",
"!",
"childHasAttribute",
"(",
"node",
",",
"attrName",
")",
")",
")",
"{",
"defaultValue",
"=",
"angular",
".",
"isString",
"(",
"defaultValue",
")",
"?",
"defaultValue",
".",
"trim",
"(",
")",
":",
"''",
";",
"if",
"(",
"defaultValue",
".",
"length",
")",
"{",
"element",
".",
"attr",
"(",
"attrName",
",",
"defaultValue",
")",
";",
"}",
"else",
"if",
"(",
"showWarnings",
")",
"{",
"$log",
".",
"warn",
"(",
"'ARIA: Attribute \"'",
",",
"attrName",
",",
"'\", required for accessibility, is missing on node:'",
",",
"node",
")",
";",
"}",
"}",
"}"
] | Check if expected attribute has been specified on the target element or child
@param element
@param attrName
@param {optional} defaultValue What to set the attr to if no value is found | [
"Check",
"if",
"expected",
"attribute",
"has",
"been",
"specified",
"on",
"the",
"target",
"element",
"or",
"child"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/aria/aria.js#L80-L98 |
4,980 | angular/material | src/core/services/aria/aria.js | hasAriaLabel | function hasAriaLabel(element) {
var node = angular.element(element)[0] || element;
/* Check if compatible node type (ie: not HTML Document node) */
if (!node.hasAttribute) {
return false;
}
/* Check label or description attributes */
return node.hasAttribute('aria-label') || node.hasAttribute('aria-labelledby') || node.hasAttribute('aria-describedby');
} | javascript | function hasAriaLabel(element) {
var node = angular.element(element)[0] || element;
/* Check if compatible node type (ie: not HTML Document node) */
if (!node.hasAttribute) {
return false;
}
/* Check label or description attributes */
return node.hasAttribute('aria-label') || node.hasAttribute('aria-labelledby') || node.hasAttribute('aria-describedby');
} | [
"function",
"hasAriaLabel",
"(",
"element",
")",
"{",
"var",
"node",
"=",
"angular",
".",
"element",
"(",
"element",
")",
"[",
"0",
"]",
"||",
"element",
";",
"/* Check if compatible node type (ie: not HTML Document node) */",
"if",
"(",
"!",
"node",
".",
"hasAttribute",
")",
"{",
"return",
"false",
";",
"}",
"/* Check label or description attributes */",
"return",
"node",
".",
"hasAttribute",
"(",
"'aria-label'",
")",
"||",
"node",
".",
"hasAttribute",
"(",
"'aria-labelledby'",
")",
"||",
"node",
".",
"hasAttribute",
"(",
"'aria-describedby'",
")",
";",
"}"
] | Check if expected element has aria label attribute
@param element | [
"Check",
"if",
"expected",
"element",
"has",
"aria",
"label",
"attribute"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/aria/aria.js#L181-L191 |
4,981 | angular/material | src/core/services/aria/aria.js | parentHasAriaLabel | function parentHasAriaLabel(element, level) {
level = level || 1;
var node = angular.element(element)[0] || element;
if (!node.parentNode) {
return false;
}
if (performCheck(node.parentNode)) {
return true;
}
level--;
if (level) {
return parentHasAriaLabel(node.parentNode, level);
}
return false;
function performCheck(parentNode) {
if (!hasAriaLabel(parentNode)) {
return false;
}
/* Perform role blacklist check */
if (parentNode.hasAttribute('role')) {
switch (parentNode.getAttribute('role').toLowerCase()) {
case 'command':
case 'definition':
case 'directory':
case 'grid':
case 'list':
case 'listitem':
case 'log':
case 'marquee':
case 'menu':
case 'menubar':
case 'note':
case 'presentation':
case 'separator':
case 'scrollbar':
case 'status':
case 'tablist':
return false;
}
}
/* Perform tagName blacklist check */
switch (parentNode.tagName.toLowerCase()) {
case 'abbr':
case 'acronym':
case 'address':
case 'applet':
case 'audio':
case 'b':
case 'bdi':
case 'bdo':
case 'big':
case 'blockquote':
case 'br':
case 'canvas':
case 'caption':
case 'center':
case 'cite':
case 'code':
case 'col':
case 'data':
case 'dd':
case 'del':
case 'dfn':
case 'dir':
case 'div':
case 'dl':
case 'em':
case 'embed':
case 'fieldset':
case 'figcaption':
case 'font':
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6':
case 'hgroup':
case 'html':
case 'i':
case 'ins':
case 'isindex':
case 'kbd':
case 'keygen':
case 'label':
case 'legend':
case 'li':
case 'map':
case 'mark':
case 'menu':
case 'object':
case 'ol':
case 'output':
case 'pre':
case 'presentation':
case 'q':
case 'rt':
case 'ruby':
case 'samp':
case 'small':
case 'source':
case 'span':
case 'status':
case 'strike':
case 'strong':
case 'sub':
case 'sup':
case 'svg':
case 'tbody':
case 'td':
case 'th':
case 'thead':
case 'time':
case 'tr':
case 'track':
case 'tt':
case 'ul':
case 'var':
return false;
}
return true;
}
} | javascript | function parentHasAriaLabel(element, level) {
level = level || 1;
var node = angular.element(element)[0] || element;
if (!node.parentNode) {
return false;
}
if (performCheck(node.parentNode)) {
return true;
}
level--;
if (level) {
return parentHasAriaLabel(node.parentNode, level);
}
return false;
function performCheck(parentNode) {
if (!hasAriaLabel(parentNode)) {
return false;
}
/* Perform role blacklist check */
if (parentNode.hasAttribute('role')) {
switch (parentNode.getAttribute('role').toLowerCase()) {
case 'command':
case 'definition':
case 'directory':
case 'grid':
case 'list':
case 'listitem':
case 'log':
case 'marquee':
case 'menu':
case 'menubar':
case 'note':
case 'presentation':
case 'separator':
case 'scrollbar':
case 'status':
case 'tablist':
return false;
}
}
/* Perform tagName blacklist check */
switch (parentNode.tagName.toLowerCase()) {
case 'abbr':
case 'acronym':
case 'address':
case 'applet':
case 'audio':
case 'b':
case 'bdi':
case 'bdo':
case 'big':
case 'blockquote':
case 'br':
case 'canvas':
case 'caption':
case 'center':
case 'cite':
case 'code':
case 'col':
case 'data':
case 'dd':
case 'del':
case 'dfn':
case 'dir':
case 'div':
case 'dl':
case 'em':
case 'embed':
case 'fieldset':
case 'figcaption':
case 'font':
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6':
case 'hgroup':
case 'html':
case 'i':
case 'ins':
case 'isindex':
case 'kbd':
case 'keygen':
case 'label':
case 'legend':
case 'li':
case 'map':
case 'mark':
case 'menu':
case 'object':
case 'ol':
case 'output':
case 'pre':
case 'presentation':
case 'q':
case 'rt':
case 'ruby':
case 'samp':
case 'small':
case 'source':
case 'span':
case 'status':
case 'strike':
case 'strong':
case 'sub':
case 'sup':
case 'svg':
case 'tbody':
case 'td':
case 'th':
case 'thead':
case 'time':
case 'tr':
case 'track':
case 'tt':
case 'ul':
case 'var':
return false;
}
return true;
}
} | [
"function",
"parentHasAriaLabel",
"(",
"element",
",",
"level",
")",
"{",
"level",
"=",
"level",
"||",
"1",
";",
"var",
"node",
"=",
"angular",
".",
"element",
"(",
"element",
")",
"[",
"0",
"]",
"||",
"element",
";",
"if",
"(",
"!",
"node",
".",
"parentNode",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"performCheck",
"(",
"node",
".",
"parentNode",
")",
")",
"{",
"return",
"true",
";",
"}",
"level",
"--",
";",
"if",
"(",
"level",
")",
"{",
"return",
"parentHasAriaLabel",
"(",
"node",
".",
"parentNode",
",",
"level",
")",
";",
"}",
"return",
"false",
";",
"function",
"performCheck",
"(",
"parentNode",
")",
"{",
"if",
"(",
"!",
"hasAriaLabel",
"(",
"parentNode",
")",
")",
"{",
"return",
"false",
";",
"}",
"/* Perform role blacklist check */",
"if",
"(",
"parentNode",
".",
"hasAttribute",
"(",
"'role'",
")",
")",
"{",
"switch",
"(",
"parentNode",
".",
"getAttribute",
"(",
"'role'",
")",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'command'",
":",
"case",
"'definition'",
":",
"case",
"'directory'",
":",
"case",
"'grid'",
":",
"case",
"'list'",
":",
"case",
"'listitem'",
":",
"case",
"'log'",
":",
"case",
"'marquee'",
":",
"case",
"'menu'",
":",
"case",
"'menubar'",
":",
"case",
"'note'",
":",
"case",
"'presentation'",
":",
"case",
"'separator'",
":",
"case",
"'scrollbar'",
":",
"case",
"'status'",
":",
"case",
"'tablist'",
":",
"return",
"false",
";",
"}",
"}",
"/* Perform tagName blacklist check */",
"switch",
"(",
"parentNode",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'abbr'",
":",
"case",
"'acronym'",
":",
"case",
"'address'",
":",
"case",
"'applet'",
":",
"case",
"'audio'",
":",
"case",
"'b'",
":",
"case",
"'bdi'",
":",
"case",
"'bdo'",
":",
"case",
"'big'",
":",
"case",
"'blockquote'",
":",
"case",
"'br'",
":",
"case",
"'canvas'",
":",
"case",
"'caption'",
":",
"case",
"'center'",
":",
"case",
"'cite'",
":",
"case",
"'code'",
":",
"case",
"'col'",
":",
"case",
"'data'",
":",
"case",
"'dd'",
":",
"case",
"'del'",
":",
"case",
"'dfn'",
":",
"case",
"'dir'",
":",
"case",
"'div'",
":",
"case",
"'dl'",
":",
"case",
"'em'",
":",
"case",
"'embed'",
":",
"case",
"'fieldset'",
":",
"case",
"'figcaption'",
":",
"case",
"'font'",
":",
"case",
"'h1'",
":",
"case",
"'h2'",
":",
"case",
"'h3'",
":",
"case",
"'h4'",
":",
"case",
"'h5'",
":",
"case",
"'h6'",
":",
"case",
"'hgroup'",
":",
"case",
"'html'",
":",
"case",
"'i'",
":",
"case",
"'ins'",
":",
"case",
"'isindex'",
":",
"case",
"'kbd'",
":",
"case",
"'keygen'",
":",
"case",
"'label'",
":",
"case",
"'legend'",
":",
"case",
"'li'",
":",
"case",
"'map'",
":",
"case",
"'mark'",
":",
"case",
"'menu'",
":",
"case",
"'object'",
":",
"case",
"'ol'",
":",
"case",
"'output'",
":",
"case",
"'pre'",
":",
"case",
"'presentation'",
":",
"case",
"'q'",
":",
"case",
"'rt'",
":",
"case",
"'ruby'",
":",
"case",
"'samp'",
":",
"case",
"'small'",
":",
"case",
"'source'",
":",
"case",
"'span'",
":",
"case",
"'status'",
":",
"case",
"'strike'",
":",
"case",
"'strong'",
":",
"case",
"'sub'",
":",
"case",
"'sup'",
":",
"case",
"'svg'",
":",
"case",
"'tbody'",
":",
"case",
"'td'",
":",
"case",
"'th'",
":",
"case",
"'thead'",
":",
"case",
"'time'",
":",
"case",
"'tr'",
":",
"case",
"'track'",
":",
"case",
"'tt'",
":",
"case",
"'ul'",
":",
"case",
"'var'",
":",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"}"
] | Check if expected element's parent has aria label attribute and has valid role and tagName
@param element
@param {optional} level Number of levels deep search should be performed | [
"Check",
"if",
"expected",
"element",
"s",
"parent",
"has",
"aria",
"label",
"attribute",
"and",
"has",
"valid",
"role",
"and",
"tagName"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/aria/aria.js#L198-L321 |
4,982 | angular/material | src/core/util/autofocus.js | updateExpression | function updateExpression(value) {
// Rather than passing undefined to the jqLite toggle class function we explicitly set the
// value to true. Otherwise the class will be just toggled instead of being forced.
if (angular.isUndefined(value)) {
value = true;
}
element.toggleClass('md-autofocus', !!value);
} | javascript | function updateExpression(value) {
// Rather than passing undefined to the jqLite toggle class function we explicitly set the
// value to true. Otherwise the class will be just toggled instead of being forced.
if (angular.isUndefined(value)) {
value = true;
}
element.toggleClass('md-autofocus', !!value);
} | [
"function",
"updateExpression",
"(",
"value",
")",
"{",
"// Rather than passing undefined to the jqLite toggle class function we explicitly set the",
"// value to true. Otherwise the class will be just toggled instead of being forced.",
"if",
"(",
"angular",
".",
"isUndefined",
"(",
"value",
")",
")",
"{",
"value",
"=",
"true",
";",
"}",
"element",
".",
"toggleClass",
"(",
"'md-autofocus'",
",",
"!",
"!",
"value",
")",
";",
"}"
] | Updates the autofocus class which is used to determine whether the attribute
expression evaluates to true or false.
@param {string|boolean} value Attribute Value | [
"Updates",
"the",
"autofocus",
"class",
"which",
"is",
"used",
"to",
"determine",
"whether",
"the",
"attribute",
"expression",
"evaluates",
"to",
"true",
"or",
"false",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/util/autofocus.js#L117-L126 |
4,983 | angular/material | config/ngModuleData.js | buildScanner | function buildScanner(pattern) {
return function findPatternIn(content) {
let dependencies;
const match = pattern.exec(content || '');
const moduleName = match ? match[1].replace(/'/gi,'') : null;
const depsMatch = match && match[2] && match[2].trim();
if (depsMatch) {
dependencies = depsMatch.split(/\s*,\s*/).map(function(dep) {
dep = dep.trim().slice(1, -1); // remove quotes
return dep;
});
}
return match ? {
name : moduleName || '',
module : moduleName || '',
dependencies : dependencies || []
} : null;
};
} | javascript | function buildScanner(pattern) {
return function findPatternIn(content) {
let dependencies;
const match = pattern.exec(content || '');
const moduleName = match ? match[1].replace(/'/gi,'') : null;
const depsMatch = match && match[2] && match[2].trim();
if (depsMatch) {
dependencies = depsMatch.split(/\s*,\s*/).map(function(dep) {
dep = dep.trim().slice(1, -1); // remove quotes
return dep;
});
}
return match ? {
name : moduleName || '',
module : moduleName || '',
dependencies : dependencies || []
} : null;
};
} | [
"function",
"buildScanner",
"(",
"pattern",
")",
"{",
"return",
"function",
"findPatternIn",
"(",
"content",
")",
"{",
"let",
"dependencies",
";",
"const",
"match",
"=",
"pattern",
".",
"exec",
"(",
"content",
"||",
"''",
")",
";",
"const",
"moduleName",
"=",
"match",
"?",
"match",
"[",
"1",
"]",
".",
"replace",
"(",
"/",
"'",
"/",
"gi",
",",
"''",
")",
":",
"null",
";",
"const",
"depsMatch",
"=",
"match",
"&&",
"match",
"[",
"2",
"]",
"&&",
"match",
"[",
"2",
"]",
".",
"trim",
"(",
")",
";",
"if",
"(",
"depsMatch",
")",
"{",
"dependencies",
"=",
"depsMatch",
".",
"split",
"(",
"/",
"\\s*,\\s*",
"/",
")",
".",
"map",
"(",
"function",
"(",
"dep",
")",
"{",
"dep",
"=",
"dep",
".",
"trim",
"(",
")",
".",
"slice",
"(",
"1",
",",
"-",
"1",
")",
";",
"// remove quotes",
"return",
"dep",
";",
"}",
")",
";",
"}",
"return",
"match",
"?",
"{",
"name",
":",
"moduleName",
"||",
"''",
",",
"module",
":",
"moduleName",
"||",
"''",
",",
"dependencies",
":",
"dependencies",
"||",
"[",
"]",
"}",
":",
"null",
";",
"}",
";",
"}"
] | Find module definition s that match the module definition pattern | [
"Find",
"module",
"definition",
"s",
"that",
"match",
"the",
"module",
"definition",
"pattern"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/config/ngModuleData.js#L21-L42 |
4,984 | angular/material | src/components/progressCircular/js/progressCircularDirective.js | getDashLength | function getDashLength(diameter, strokeWidth, value, limit) {
return (diameter - strokeWidth) * $window.Math.PI * ((3 * (limit || 100) / 100) - (value/100));
} | javascript | function getDashLength(diameter, strokeWidth, value, limit) {
return (diameter - strokeWidth) * $window.Math.PI * ((3 * (limit || 100) / 100) - (value/100));
} | [
"function",
"getDashLength",
"(",
"diameter",
",",
"strokeWidth",
",",
"value",
",",
"limit",
")",
"{",
"return",
"(",
"diameter",
"-",
"strokeWidth",
")",
"*",
"$window",
".",
"Math",
".",
"PI",
"*",
"(",
"(",
"3",
"*",
"(",
"limit",
"||",
"100",
")",
"/",
"100",
")",
"-",
"(",
"value",
"/",
"100",
")",
")",
";",
"}"
] | Return stroke length for progress circle
@param {number} diameter Diameter of the container.
@param {number} strokeWidth Stroke width to be used when drawing circle
@param {number} value Percentage of circle (between 0 and 100)
@param {number} limit Max percentage for circle
@returns {number} Stroke length for progres circle | [
"Return",
"stroke",
"length",
"for",
"progress",
"circle"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/progressCircular/js/progressCircularDirective.js#L337-L339 |
4,985 | angular/material | src/components/tooltip/tooltip.js | MdTooltipRegistry | function MdTooltipRegistry() {
var listeners = {};
var ngWindow = angular.element(window);
return {
register: register,
deregister: deregister
};
/**
* Global event handler that dispatches the registered handlers in the
* service.
* @param {!Event} event Event object passed in by the browser
*/
function globalEventHandler(event) {
if (listeners[event.type]) {
listeners[event.type].forEach(function(currentHandler) {
currentHandler.call(this, event);
}, this);
}
}
/**
* Registers a new handler with the service.
* @param {string} type Type of event to be registered.
* @param {!Function} handler Event handler.
* @param {boolean} useCapture Whether to use event capturing.
*/
function register(type, handler, useCapture) {
var handlers = listeners[type] = listeners[type] || [];
if (!handlers.length) {
useCapture ? window.addEventListener(type, globalEventHandler, true) :
ngWindow.on(type, globalEventHandler);
}
if (handlers.indexOf(handler) === -1) {
handlers.push(handler);
}
}
/**
* Removes an event handler from the service.
* @param {string} type Type of event handler.
* @param {!Function} handler The event handler itself.
* @param {boolean} useCapture Whether the event handler used event capturing.
*/
function deregister(type, handler, useCapture) {
var handlers = listeners[type];
var index = handlers ? handlers.indexOf(handler) : -1;
if (index > -1) {
handlers.splice(index, 1);
if (handlers.length === 0) {
useCapture ? window.removeEventListener(type, globalEventHandler, true) :
ngWindow.off(type, globalEventHandler);
}
}
}
} | javascript | function MdTooltipRegistry() {
var listeners = {};
var ngWindow = angular.element(window);
return {
register: register,
deregister: deregister
};
/**
* Global event handler that dispatches the registered handlers in the
* service.
* @param {!Event} event Event object passed in by the browser
*/
function globalEventHandler(event) {
if (listeners[event.type]) {
listeners[event.type].forEach(function(currentHandler) {
currentHandler.call(this, event);
}, this);
}
}
/**
* Registers a new handler with the service.
* @param {string} type Type of event to be registered.
* @param {!Function} handler Event handler.
* @param {boolean} useCapture Whether to use event capturing.
*/
function register(type, handler, useCapture) {
var handlers = listeners[type] = listeners[type] || [];
if (!handlers.length) {
useCapture ? window.addEventListener(type, globalEventHandler, true) :
ngWindow.on(type, globalEventHandler);
}
if (handlers.indexOf(handler) === -1) {
handlers.push(handler);
}
}
/**
* Removes an event handler from the service.
* @param {string} type Type of event handler.
* @param {!Function} handler The event handler itself.
* @param {boolean} useCapture Whether the event handler used event capturing.
*/
function deregister(type, handler, useCapture) {
var handlers = listeners[type];
var index = handlers ? handlers.indexOf(handler) : -1;
if (index > -1) {
handlers.splice(index, 1);
if (handlers.length === 0) {
useCapture ? window.removeEventListener(type, globalEventHandler, true) :
ngWindow.off(type, globalEventHandler);
}
}
}
} | [
"function",
"MdTooltipRegistry",
"(",
")",
"{",
"var",
"listeners",
"=",
"{",
"}",
";",
"var",
"ngWindow",
"=",
"angular",
".",
"element",
"(",
"window",
")",
";",
"return",
"{",
"register",
":",
"register",
",",
"deregister",
":",
"deregister",
"}",
";",
"/**\n * Global event handler that dispatches the registered handlers in the\n * service.\n * @param {!Event} event Event object passed in by the browser\n */",
"function",
"globalEventHandler",
"(",
"event",
")",
"{",
"if",
"(",
"listeners",
"[",
"event",
".",
"type",
"]",
")",
"{",
"listeners",
"[",
"event",
".",
"type",
"]",
".",
"forEach",
"(",
"function",
"(",
"currentHandler",
")",
"{",
"currentHandler",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"}",
",",
"this",
")",
";",
"}",
"}",
"/**\n * Registers a new handler with the service.\n * @param {string} type Type of event to be registered.\n * @param {!Function} handler Event handler.\n * @param {boolean} useCapture Whether to use event capturing.\n */",
"function",
"register",
"(",
"type",
",",
"handler",
",",
"useCapture",
")",
"{",
"var",
"handlers",
"=",
"listeners",
"[",
"type",
"]",
"=",
"listeners",
"[",
"type",
"]",
"||",
"[",
"]",
";",
"if",
"(",
"!",
"handlers",
".",
"length",
")",
"{",
"useCapture",
"?",
"window",
".",
"addEventListener",
"(",
"type",
",",
"globalEventHandler",
",",
"true",
")",
":",
"ngWindow",
".",
"on",
"(",
"type",
",",
"globalEventHandler",
")",
";",
"}",
"if",
"(",
"handlers",
".",
"indexOf",
"(",
"handler",
")",
"===",
"-",
"1",
")",
"{",
"handlers",
".",
"push",
"(",
"handler",
")",
";",
"}",
"}",
"/**\n * Removes an event handler from the service.\n * @param {string} type Type of event handler.\n * @param {!Function} handler The event handler itself.\n * @param {boolean} useCapture Whether the event handler used event capturing.\n */",
"function",
"deregister",
"(",
"type",
",",
"handler",
",",
"useCapture",
")",
"{",
"var",
"handlers",
"=",
"listeners",
"[",
"type",
"]",
";",
"var",
"index",
"=",
"handlers",
"?",
"handlers",
".",
"indexOf",
"(",
"handler",
")",
":",
"-",
"1",
";",
"if",
"(",
"index",
">",
"-",
"1",
")",
"{",
"handlers",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"if",
"(",
"handlers",
".",
"length",
"===",
"0",
")",
"{",
"useCapture",
"?",
"window",
".",
"removeEventListener",
"(",
"type",
",",
"globalEventHandler",
",",
"true",
")",
":",
"ngWindow",
".",
"off",
"(",
"type",
",",
"globalEventHandler",
")",
";",
"}",
"}",
"}",
"}"
] | Service that is used to reduce the amount of listeners that are being
registered on the `window` by the tooltip component. Works by collecting
the individual event handlers and dispatching them from a global handler.
@ngInject | [
"Service",
"that",
"is",
"used",
"to",
"reduce",
"the",
"amount",
"of",
"listeners",
"that",
"are",
"being",
"registered",
"on",
"the",
"window",
"by",
"the",
"tooltip",
"component",
".",
"Works",
"by",
"collecting",
"the",
"individual",
"event",
"handlers",
"and",
"dispatching",
"them",
"from",
"a",
"global",
"handler",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tooltip/tooltip.js#L423-L483 |
4,986 | angular/material | src/components/tooltip/tooltip.js | globalEventHandler | function globalEventHandler(event) {
if (listeners[event.type]) {
listeners[event.type].forEach(function(currentHandler) {
currentHandler.call(this, event);
}, this);
}
} | javascript | function globalEventHandler(event) {
if (listeners[event.type]) {
listeners[event.type].forEach(function(currentHandler) {
currentHandler.call(this, event);
}, this);
}
} | [
"function",
"globalEventHandler",
"(",
"event",
")",
"{",
"if",
"(",
"listeners",
"[",
"event",
".",
"type",
"]",
")",
"{",
"listeners",
"[",
"event",
".",
"type",
"]",
".",
"forEach",
"(",
"function",
"(",
"currentHandler",
")",
"{",
"currentHandler",
".",
"call",
"(",
"this",
",",
"event",
")",
";",
"}",
",",
"this",
")",
";",
"}",
"}"
] | Global event handler that dispatches the registered handlers in the
service.
@param {!Event} event Event object passed in by the browser | [
"Global",
"event",
"handler",
"that",
"dispatches",
"the",
"registered",
"handlers",
"in",
"the",
"service",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tooltip/tooltip.js#L437-L443 |
4,987 | angular/material | src/components/tooltip/tooltip.js | register | function register(type, handler, useCapture) {
var handlers = listeners[type] = listeners[type] || [];
if (!handlers.length) {
useCapture ? window.addEventListener(type, globalEventHandler, true) :
ngWindow.on(type, globalEventHandler);
}
if (handlers.indexOf(handler) === -1) {
handlers.push(handler);
}
} | javascript | function register(type, handler, useCapture) {
var handlers = listeners[type] = listeners[type] || [];
if (!handlers.length) {
useCapture ? window.addEventListener(type, globalEventHandler, true) :
ngWindow.on(type, globalEventHandler);
}
if (handlers.indexOf(handler) === -1) {
handlers.push(handler);
}
} | [
"function",
"register",
"(",
"type",
",",
"handler",
",",
"useCapture",
")",
"{",
"var",
"handlers",
"=",
"listeners",
"[",
"type",
"]",
"=",
"listeners",
"[",
"type",
"]",
"||",
"[",
"]",
";",
"if",
"(",
"!",
"handlers",
".",
"length",
")",
"{",
"useCapture",
"?",
"window",
".",
"addEventListener",
"(",
"type",
",",
"globalEventHandler",
",",
"true",
")",
":",
"ngWindow",
".",
"on",
"(",
"type",
",",
"globalEventHandler",
")",
";",
"}",
"if",
"(",
"handlers",
".",
"indexOf",
"(",
"handler",
")",
"===",
"-",
"1",
")",
"{",
"handlers",
".",
"push",
"(",
"handler",
")",
";",
"}",
"}"
] | Registers a new handler with the service.
@param {string} type Type of event to be registered.
@param {!Function} handler Event handler.
@param {boolean} useCapture Whether to use event capturing. | [
"Registers",
"a",
"new",
"handler",
"with",
"the",
"service",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tooltip/tooltip.js#L451-L462 |
4,988 | angular/material | src/components/tooltip/tooltip.js | deregister | function deregister(type, handler, useCapture) {
var handlers = listeners[type];
var index = handlers ? handlers.indexOf(handler) : -1;
if (index > -1) {
handlers.splice(index, 1);
if (handlers.length === 0) {
useCapture ? window.removeEventListener(type, globalEventHandler, true) :
ngWindow.off(type, globalEventHandler);
}
}
} | javascript | function deregister(type, handler, useCapture) {
var handlers = listeners[type];
var index = handlers ? handlers.indexOf(handler) : -1;
if (index > -1) {
handlers.splice(index, 1);
if (handlers.length === 0) {
useCapture ? window.removeEventListener(type, globalEventHandler, true) :
ngWindow.off(type, globalEventHandler);
}
}
} | [
"function",
"deregister",
"(",
"type",
",",
"handler",
",",
"useCapture",
")",
"{",
"var",
"handlers",
"=",
"listeners",
"[",
"type",
"]",
";",
"var",
"index",
"=",
"handlers",
"?",
"handlers",
".",
"indexOf",
"(",
"handler",
")",
":",
"-",
"1",
";",
"if",
"(",
"index",
">",
"-",
"1",
")",
"{",
"handlers",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"if",
"(",
"handlers",
".",
"length",
"===",
"0",
")",
"{",
"useCapture",
"?",
"window",
".",
"removeEventListener",
"(",
"type",
",",
"globalEventHandler",
",",
"true",
")",
":",
"ngWindow",
".",
"off",
"(",
"type",
",",
"globalEventHandler",
")",
";",
"}",
"}",
"}"
] | Removes an event handler from the service.
@param {string} type Type of event handler.
@param {!Function} handler The event handler itself.
@param {boolean} useCapture Whether the event handler used event capturing. | [
"Removes",
"an",
"event",
"handler",
"from",
"the",
"service",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tooltip/tooltip.js#L470-L482 |
4,989 | angular/material | src/components/datepicker/js/calendar.spec.js | findCellByLabel | function findCellByLabel(monthElement, day) {
var tds = monthElement.querySelectorAll('td');
var td;
for (var i = 0; i < tds.length; i++) {
td = tds[i];
if (td.textContent === day.toString()) {
return td;
}
}
} | javascript | function findCellByLabel(monthElement, day) {
var tds = monthElement.querySelectorAll('td');
var td;
for (var i = 0; i < tds.length; i++) {
td = tds[i];
if (td.textContent === day.toString()) {
return td;
}
}
} | [
"function",
"findCellByLabel",
"(",
"monthElement",
",",
"day",
")",
"{",
"var",
"tds",
"=",
"monthElement",
".",
"querySelectorAll",
"(",
"'td'",
")",
";",
"var",
"td",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"tds",
".",
"length",
";",
"i",
"++",
")",
"{",
"td",
"=",
"tds",
"[",
"i",
"]",
";",
"if",
"(",
"td",
".",
"textContent",
"===",
"day",
".",
"toString",
"(",
")",
")",
"{",
"return",
"td",
";",
"}",
"}",
"}"
] | Finds a td given a label. | [
"Finds",
"a",
"td",
"given",
"a",
"label",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendar.spec.js#L44-L54 |
4,990 | angular/material | src/components/datepicker/js/calendar.spec.js | findMonthElement | function findMonthElement(element, date) {
var months = element.querySelectorAll('[md-calendar-month-body]');
var monthHeader = dateLocale.monthHeaderFormatter(date);
var month;
for (var i = 0; i < months.length; i++) {
month = months[i];
if (month.querySelector('tr:first-child td:first-child').textContent === monthHeader) {
return month;
}
}
return null;
} | javascript | function findMonthElement(element, date) {
var months = element.querySelectorAll('[md-calendar-month-body]');
var monthHeader = dateLocale.monthHeaderFormatter(date);
var month;
for (var i = 0; i < months.length; i++) {
month = months[i];
if (month.querySelector('tr:first-child td:first-child').textContent === monthHeader) {
return month;
}
}
return null;
} | [
"function",
"findMonthElement",
"(",
"element",
",",
"date",
")",
"{",
"var",
"months",
"=",
"element",
".",
"querySelectorAll",
"(",
"'[md-calendar-month-body]'",
")",
";",
"var",
"monthHeader",
"=",
"dateLocale",
".",
"monthHeaderFormatter",
"(",
"date",
")",
";",
"var",
"month",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"months",
".",
"length",
";",
"i",
"++",
")",
"{",
"month",
"=",
"months",
"[",
"i",
"]",
";",
"if",
"(",
"month",
".",
"querySelector",
"(",
"'tr:first-child td:first-child'",
")",
".",
"textContent",
"===",
"monthHeader",
")",
"{",
"return",
"month",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Finds a month `tbody` in the calendar element given a date. | [
"Finds",
"a",
"month",
"tbody",
"in",
"the",
"calendar",
"element",
"given",
"a",
"date",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendar.spec.js#L59-L71 |
4,991 | angular/material | src/components/datepicker/js/calendar.spec.js | findYearElement | function findYearElement(parent, year) {
var node = parent[0] || parent;
var years = node.querySelectorAll('[md-calendar-year-body]');
var yearHeader = year.toString();
var target;
for (var i = 0; i < years.length; i++) {
target = years[i];
if (target.querySelector('.md-calendar-month-label').textContent === yearHeader) {
return target;
}
}
return null;
} | javascript | function findYearElement(parent, year) {
var node = parent[0] || parent;
var years = node.querySelectorAll('[md-calendar-year-body]');
var yearHeader = year.toString();
var target;
for (var i = 0; i < years.length; i++) {
target = years[i];
if (target.querySelector('.md-calendar-month-label').textContent === yearHeader) {
return target;
}
}
return null;
} | [
"function",
"findYearElement",
"(",
"parent",
",",
"year",
")",
"{",
"var",
"node",
"=",
"parent",
"[",
"0",
"]",
"||",
"parent",
";",
"var",
"years",
"=",
"node",
".",
"querySelectorAll",
"(",
"'[md-calendar-year-body]'",
")",
";",
"var",
"yearHeader",
"=",
"year",
".",
"toString",
"(",
")",
";",
"var",
"target",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"years",
".",
"length",
";",
"i",
"++",
")",
"{",
"target",
"=",
"years",
"[",
"i",
"]",
";",
"if",
"(",
"target",
".",
"querySelector",
"(",
"'.md-calendar-month-label'",
")",
".",
"textContent",
"===",
"yearHeader",
")",
"{",
"return",
"target",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find the `tbody` for a year in the calendar. | [
"Find",
"the",
"tbody",
"for",
"a",
"year",
"in",
"the",
"calendar",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendar.spec.js#L74-L87 |
4,992 | angular/material | src/components/datepicker/js/calendar.spec.js | createElement | function createElement(parentScope, templateOverride) {
var directiveScope = parentScope || $rootScope.$new();
var template = templateOverride || '<md-calendar md-min-date="minDate" md-max-date="maxDate" ' +
'ng-model="myDate"></md-calendar>';
var attachedElement = angular.element(template);
document.body.appendChild(attachedElement[0]);
var newElement = $compile(attachedElement)(directiveScope);
attachedCalendarElements.push(newElement);
applyDateChange();
return newElement;
} | javascript | function createElement(parentScope, templateOverride) {
var directiveScope = parentScope || $rootScope.$new();
var template = templateOverride || '<md-calendar md-min-date="minDate" md-max-date="maxDate" ' +
'ng-model="myDate"></md-calendar>';
var attachedElement = angular.element(template);
document.body.appendChild(attachedElement[0]);
var newElement = $compile(attachedElement)(directiveScope);
attachedCalendarElements.push(newElement);
applyDateChange();
return newElement;
} | [
"function",
"createElement",
"(",
"parentScope",
",",
"templateOverride",
")",
"{",
"var",
"directiveScope",
"=",
"parentScope",
"||",
"$rootScope",
".",
"$new",
"(",
")",
";",
"var",
"template",
"=",
"templateOverride",
"||",
"'<md-calendar md-min-date=\"minDate\" md-max-date=\"maxDate\" '",
"+",
"'ng-model=\"myDate\"></md-calendar>'",
";",
"var",
"attachedElement",
"=",
"angular",
".",
"element",
"(",
"template",
")",
";",
"document",
".",
"body",
".",
"appendChild",
"(",
"attachedElement",
"[",
"0",
"]",
")",
";",
"var",
"newElement",
"=",
"$compile",
"(",
"attachedElement",
")",
"(",
"directiveScope",
")",
";",
"attachedCalendarElements",
".",
"push",
"(",
"newElement",
")",
";",
"applyDateChange",
"(",
")",
";",
"return",
"newElement",
";",
"}"
] | Creates and compiles an md-calendar element. | [
"Creates",
"and",
"compiles",
"an",
"md",
"-",
"calendar",
"element",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendar.spec.js#L99-L109 |
4,993 | angular/material | src/components/datepicker/js/calendar.spec.js | dispatchKeyEvent | function dispatchKeyEvent(keyCode, opt_modifiers) {
var mod = opt_modifiers || {};
angular.element(element).triggerHandler({
type: 'keydown',
keyCode: keyCode,
which: keyCode,
ctrlKey: mod.ctrl,
altKey: mod.alt,
metaKey: mod.meta,
shortKey: mod.shift
});
} | javascript | function dispatchKeyEvent(keyCode, opt_modifiers) {
var mod = opt_modifiers || {};
angular.element(element).triggerHandler({
type: 'keydown',
keyCode: keyCode,
which: keyCode,
ctrlKey: mod.ctrl,
altKey: mod.alt,
metaKey: mod.meta,
shortKey: mod.shift
});
} | [
"function",
"dispatchKeyEvent",
"(",
"keyCode",
",",
"opt_modifiers",
")",
"{",
"var",
"mod",
"=",
"opt_modifiers",
"||",
"{",
"}",
";",
"angular",
".",
"element",
"(",
"element",
")",
".",
"triggerHandler",
"(",
"{",
"type",
":",
"'keydown'",
",",
"keyCode",
":",
"keyCode",
",",
"which",
":",
"keyCode",
",",
"ctrlKey",
":",
"mod",
".",
"ctrl",
",",
"altKey",
":",
"mod",
".",
"alt",
",",
"metaKey",
":",
"mod",
".",
"meta",
",",
"shortKey",
":",
"mod",
".",
"shift",
"}",
")",
";",
"}"
] | Dispatches a KeyboardEvent for the calendar.
@param {number} keyCode
@param {Object=} opt_modifiers | [
"Dispatches",
"a",
"KeyboardEvent",
"for",
"the",
"calendar",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/datepicker/js/calendar.spec.js#L116-L129 |
4,994 | angular/material | src/components/tabs/tabsPaginationService.js | decreasePageOffset | function decreasePageOffset(elements, currentOffset) {
var canvas = elements.canvas,
tabOffsets = getTabOffsets(elements),
i, firstVisibleTabOffset;
// Find the first fully visible tab in offset range
for (i = 0; i < tabOffsets.length; i++) {
if (tabOffsets[i] >= currentOffset) {
firstVisibleTabOffset = tabOffsets[i];
break;
}
}
// Return (the first visible tab offset - the tabs container width) without going negative
return Math.max(0, firstVisibleTabOffset - canvas.clientWidth);
} | javascript | function decreasePageOffset(elements, currentOffset) {
var canvas = elements.canvas,
tabOffsets = getTabOffsets(elements),
i, firstVisibleTabOffset;
// Find the first fully visible tab in offset range
for (i = 0; i < tabOffsets.length; i++) {
if (tabOffsets[i] >= currentOffset) {
firstVisibleTabOffset = tabOffsets[i];
break;
}
}
// Return (the first visible tab offset - the tabs container width) without going negative
return Math.max(0, firstVisibleTabOffset - canvas.clientWidth);
} | [
"function",
"decreasePageOffset",
"(",
"elements",
",",
"currentOffset",
")",
"{",
"var",
"canvas",
"=",
"elements",
".",
"canvas",
",",
"tabOffsets",
"=",
"getTabOffsets",
"(",
"elements",
")",
",",
"i",
",",
"firstVisibleTabOffset",
";",
"// Find the first fully visible tab in offset range",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tabOffsets",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"tabOffsets",
"[",
"i",
"]",
">=",
"currentOffset",
")",
"{",
"firstVisibleTabOffset",
"=",
"tabOffsets",
"[",
"i",
"]",
";",
"break",
";",
"}",
"}",
"// Return (the first visible tab offset - the tabs container width) without going negative",
"return",
"Math",
".",
"max",
"(",
"0",
",",
"firstVisibleTabOffset",
"-",
"canvas",
".",
"clientWidth",
")",
";",
"}"
] | Returns the offset for the next decreasing page.
@param elements
@param currentOffset
@returns {number} | [
"Returns",
"the",
"offset",
"for",
"the",
"next",
"decreasing",
"page",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/tabsPaginationService.js#L38-L53 |
4,995 | angular/material | src/components/tabs/tabsPaginationService.js | increasePageOffset | function increasePageOffset(elements, currentOffset) {
var canvas = elements.canvas,
maxOffset = getTotalTabsWidth(elements) - canvas.clientWidth,
tabOffsets = getTabOffsets(elements),
i, firstHiddenTabOffset;
// Find the first partially (or fully) invisible tab
for (i = 0; i < tabOffsets.length, tabOffsets[i] <= currentOffset + canvas.clientWidth; i++) {
firstHiddenTabOffset = tabOffsets[i];
}
// Return the offset of the first hidden tab, or the maximum offset (whichever is smaller)
return Math.min(maxOffset, firstHiddenTabOffset);
} | javascript | function increasePageOffset(elements, currentOffset) {
var canvas = elements.canvas,
maxOffset = getTotalTabsWidth(elements) - canvas.clientWidth,
tabOffsets = getTabOffsets(elements),
i, firstHiddenTabOffset;
// Find the first partially (or fully) invisible tab
for (i = 0; i < tabOffsets.length, tabOffsets[i] <= currentOffset + canvas.clientWidth; i++) {
firstHiddenTabOffset = tabOffsets[i];
}
// Return the offset of the first hidden tab, or the maximum offset (whichever is smaller)
return Math.min(maxOffset, firstHiddenTabOffset);
} | [
"function",
"increasePageOffset",
"(",
"elements",
",",
"currentOffset",
")",
"{",
"var",
"canvas",
"=",
"elements",
".",
"canvas",
",",
"maxOffset",
"=",
"getTotalTabsWidth",
"(",
"elements",
")",
"-",
"canvas",
".",
"clientWidth",
",",
"tabOffsets",
"=",
"getTabOffsets",
"(",
"elements",
")",
",",
"i",
",",
"firstHiddenTabOffset",
";",
"// Find the first partially (or fully) invisible tab",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"tabOffsets",
".",
"length",
",",
"tabOffsets",
"[",
"i",
"]",
"<=",
"currentOffset",
"+",
"canvas",
".",
"clientWidth",
";",
"i",
"++",
")",
"{",
"firstHiddenTabOffset",
"=",
"tabOffsets",
"[",
"i",
"]",
";",
"}",
"// Return the offset of the first hidden tab, or the maximum offset (whichever is smaller)",
"return",
"Math",
".",
"min",
"(",
"maxOffset",
",",
"firstHiddenTabOffset",
")",
";",
"}"
] | Returns the offset for the next increasing page.
@param elements
@param currentOffset
@returns {number} | [
"Returns",
"the",
"offset",
"for",
"the",
"next",
"increasing",
"page",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/tabsPaginationService.js#L62-L75 |
4,996 | angular/material | src/components/tabs/tabsPaginationService.js | getTabOffsets | function getTabOffsets(elements) {
var i, tab, currentOffset = 0, offsets = [];
for (i = 0; i < elements.tabs.length; i++) {
tab = elements.tabs[i];
offsets.push(currentOffset);
currentOffset += tab.offsetWidth;
}
return offsets;
} | javascript | function getTabOffsets(elements) {
var i, tab, currentOffset = 0, offsets = [];
for (i = 0; i < elements.tabs.length; i++) {
tab = elements.tabs[i];
offsets.push(currentOffset);
currentOffset += tab.offsetWidth;
}
return offsets;
} | [
"function",
"getTabOffsets",
"(",
"elements",
")",
"{",
"var",
"i",
",",
"tab",
",",
"currentOffset",
"=",
"0",
",",
"offsets",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"elements",
".",
"tabs",
".",
"length",
";",
"i",
"++",
")",
"{",
"tab",
"=",
"elements",
".",
"tabs",
"[",
"i",
"]",
";",
"offsets",
".",
"push",
"(",
"currentOffset",
")",
";",
"currentOffset",
"+=",
"tab",
".",
"offsetWidth",
";",
"}",
"return",
"offsets",
";",
"}"
] | Returns the offsets of all of the tabs based on their widths.
@param elements
@returns {number[]} | [
"Returns",
"the",
"offsets",
"of",
"all",
"of",
"the",
"tabs",
"based",
"on",
"their",
"widths",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/tabsPaginationService.js#L83-L93 |
4,997 | angular/material | src/components/tabs/tabsPaginationService.js | getTotalTabsWidth | function getTotalTabsWidth(elements) {
var sum = 0, i, tab;
for (i = 0; i < elements.tabs.length; i++) {
tab = elements.tabs[i];
sum += tab.offsetWidth;
}
return sum;
} | javascript | function getTotalTabsWidth(elements) {
var sum = 0, i, tab;
for (i = 0; i < elements.tabs.length; i++) {
tab = elements.tabs[i];
sum += tab.offsetWidth;
}
return sum;
} | [
"function",
"getTotalTabsWidth",
"(",
"elements",
")",
"{",
"var",
"sum",
"=",
"0",
",",
"i",
",",
"tab",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"elements",
".",
"tabs",
".",
"length",
";",
"i",
"++",
")",
"{",
"tab",
"=",
"elements",
".",
"tabs",
"[",
"i",
"]",
";",
"sum",
"+=",
"tab",
".",
"offsetWidth",
";",
"}",
"return",
"sum",
";",
"}"
] | Sum the width of all tabs.
@param elements
@returns {number} | [
"Sum",
"the",
"width",
"of",
"all",
"tabs",
"."
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/components/tabs/tabsPaginationService.js#L101-L110 |
4,998 | angular/material | src/core/services/theming/theming.js | function() {
return angular.extend({ }, themeConfig, {
defaultTheme : defaultTheme,
alwaysWatchTheme : alwaysWatchTheme,
registeredStyles : [].concat(themeConfig.registeredStyles)
});
} | javascript | function() {
return angular.extend({ }, themeConfig, {
defaultTheme : defaultTheme,
alwaysWatchTheme : alwaysWatchTheme,
registeredStyles : [].concat(themeConfig.registeredStyles)
});
} | [
"function",
"(",
")",
"{",
"return",
"angular",
".",
"extend",
"(",
"{",
"}",
",",
"themeConfig",
",",
"{",
"defaultTheme",
":",
"defaultTheme",
",",
"alwaysWatchTheme",
":",
"alwaysWatchTheme",
",",
"registeredStyles",
":",
"[",
"]",
".",
"concat",
"(",
"themeConfig",
".",
"registeredStyles",
")",
"}",
")",
";",
"}"
] | return a read-only clone of the current theme configuration | [
"return",
"a",
"read",
"-",
"only",
"clone",
"of",
"the",
"current",
"theme",
"configuration"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/theming/theming.js#L297-L303 |
|
4,999 | angular/material | src/core/services/theming/theming.js | checkPaletteValid | function checkPaletteValid(name, map) {
var missingColors = VALID_HUE_VALUES.filter(function(field) {
return !map[field];
});
if (missingColors.length) {
throw new Error("Missing colors %1 in palette %2!"
.replace('%1', missingColors.join(', '))
.replace('%2', name));
}
return map;
} | javascript | function checkPaletteValid(name, map) {
var missingColors = VALID_HUE_VALUES.filter(function(field) {
return !map[field];
});
if (missingColors.length) {
throw new Error("Missing colors %1 in palette %2!"
.replace('%1', missingColors.join(', '))
.replace('%2', name));
}
return map;
} | [
"function",
"checkPaletteValid",
"(",
"name",
",",
"map",
")",
"{",
"var",
"missingColors",
"=",
"VALID_HUE_VALUES",
".",
"filter",
"(",
"function",
"(",
"field",
")",
"{",
"return",
"!",
"map",
"[",
"field",
"]",
";",
"}",
")",
";",
"if",
"(",
"missingColors",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Missing colors %1 in palette %2!\"",
".",
"replace",
"(",
"'%1'",
",",
"missingColors",
".",
"join",
"(",
"', '",
")",
")",
".",
"replace",
"(",
"'%2'",
",",
"name",
")",
")",
";",
"}",
"return",
"map",
";",
"}"
] | Make sure that palette has all required hues | [
"Make",
"sure",
"that",
"palette",
"has",
"all",
"required",
"hues"
] | 84ac558674e73958be84312444c48d9f823f6684 | https://github.com/angular/material/blob/84ac558674e73958be84312444c48d9f823f6684/src/core/services/theming/theming.js#L441-L452 |
Subsets and Splits