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
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
11,500
|
nordnet/cordova-hot-code-push
|
scripts/beforePluginInstallHook.js
|
suggestCliInstallation
|
function suggestCliInstallation() {
console.log('---------CHCP-------------');
console.log('To make the development process easier for you - we developed a CLI client for our plugin.');
console.log('To install it, please, use command:');
console.log('npm install -g cordova-hot-code-push-cli');
console.log('For more information please visit https://github.com/nordnet/cordova-hot-code-push-cli');
console.log('--------------------------');
}
|
javascript
|
function suggestCliInstallation() {
console.log('---------CHCP-------------');
console.log('To make the development process easier for you - we developed a CLI client for our plugin.');
console.log('To install it, please, use command:');
console.log('npm install -g cordova-hot-code-push-cli');
console.log('For more information please visit https://github.com/nordnet/cordova-hot-code-push-cli');
console.log('--------------------------');
}
|
[
"function",
"suggestCliInstallation",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'---------CHCP-------------'",
")",
";",
"console",
".",
"log",
"(",
"'To make the development process easier for you - we developed a CLI client for our plugin.'",
")",
";",
"console",
".",
"log",
"(",
"'To install it, please, use command:'",
")",
";",
"console",
".",
"log",
"(",
"'npm install -g cordova-hot-code-push-cli'",
")",
";",
"console",
".",
"log",
"(",
"'For more information please visit https://github.com/nordnet/cordova-hot-code-push-cli'",
")",
";",
"console",
".",
"log",
"(",
"'--------------------------'",
")",
";",
"}"
] |
Show message, that developer should install CLI client for the plugin, so it would be easier to use.
|
[
"Show",
"message",
"that",
"developer",
"should",
"install",
"CLI",
"client",
"for",
"the",
"plugin",
"so",
"it",
"would",
"be",
"easier",
"to",
"use",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/beforePluginInstallHook.js#L31-L38
|
11,501
|
nordnet/cordova-hot-code-push
|
scripts/beforePluginInstallHook.js
|
isInstallationAlreadyPerformed
|
function isInstallationAlreadyPerformed(ctx) {
var pathToInstallFlag = path.join(ctx.opts.projectRoot, 'plugins', ctx.opts.plugin.id, INSTALLATION_FLAG_FILE_NAME);
try {
fs.accessSync(pathToInstallFlag, fs.F_OK);
return true;
} catch (err) {
return false;
}
}
|
javascript
|
function isInstallationAlreadyPerformed(ctx) {
var pathToInstallFlag = path.join(ctx.opts.projectRoot, 'plugins', ctx.opts.plugin.id, INSTALLATION_FLAG_FILE_NAME);
try {
fs.accessSync(pathToInstallFlag, fs.F_OK);
return true;
} catch (err) {
return false;
}
}
|
[
"function",
"isInstallationAlreadyPerformed",
"(",
"ctx",
")",
"{",
"var",
"pathToInstallFlag",
"=",
"path",
".",
"join",
"(",
"ctx",
".",
"opts",
".",
"projectRoot",
",",
"'plugins'",
",",
"ctx",
".",
"opts",
".",
"plugin",
".",
"id",
",",
"INSTALLATION_FLAG_FILE_NAME",
")",
";",
"try",
"{",
"fs",
".",
"accessSync",
"(",
"pathToInstallFlag",
",",
"fs",
".",
"F_OK",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
region mark that we installed npm packages
Check if we already executed this hook.
@param {Object} ctx - cordova context
@return {Boolean} true if already executed; otherwise - false
|
[
"region",
"mark",
"that",
"we",
"installed",
"npm",
"packages",
"Check",
"if",
"we",
"already",
"executed",
"this",
"hook",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/beforePluginInstallHook.js#L49-L57
|
11,502
|
nordnet/cordova-hot-code-push
|
scripts/beforePluginInstallHook.js
|
createPluginInstalledFlag
|
function createPluginInstalledFlag(ctx) {
var pathToInstallFlag = path.join(ctx.opts.projectRoot, 'plugins', ctx.opts.plugin.id, INSTALLATION_FLAG_FILE_NAME);
fs.closeSync(fs.openSync(pathToInstallFlag, 'w'));
}
|
javascript
|
function createPluginInstalledFlag(ctx) {
var pathToInstallFlag = path.join(ctx.opts.projectRoot, 'plugins', ctx.opts.plugin.id, INSTALLATION_FLAG_FILE_NAME);
fs.closeSync(fs.openSync(pathToInstallFlag, 'w'));
}
|
[
"function",
"createPluginInstalledFlag",
"(",
"ctx",
")",
"{",
"var",
"pathToInstallFlag",
"=",
"path",
".",
"join",
"(",
"ctx",
".",
"opts",
".",
"projectRoot",
",",
"'plugins'",
",",
"ctx",
".",
"opts",
".",
"plugin",
".",
"id",
",",
"INSTALLATION_FLAG_FILE_NAME",
")",
";",
"fs",
".",
"closeSync",
"(",
"fs",
".",
"openSync",
"(",
"pathToInstallFlag",
",",
"'w'",
")",
")",
";",
"}"
] |
Create empty file - indicator, that we tried to install dependency modules after installation.
We have to do that, or this hook is gonna be called on any plugin installation.
|
[
"Create",
"empty",
"file",
"-",
"indicator",
"that",
"we",
"tried",
"to",
"install",
"dependency",
"modules",
"after",
"installation",
".",
"We",
"have",
"to",
"do",
"that",
"or",
"this",
"hook",
"is",
"gonna",
"be",
"called",
"on",
"any",
"plugin",
"installation",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/beforePluginInstallHook.js#L63-L67
|
11,503
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpConfigXmlReader.js
|
readOptions
|
function readOptions(ctx) {
var configFilePath = path.join(ctx.opts.projectRoot, 'config.xml');
var configXmlContent = xmlHelper.readXmlAsJson(configFilePath, true);
return parseConfig(configXmlContent);
}
|
javascript
|
function readOptions(ctx) {
var configFilePath = path.join(ctx.opts.projectRoot, 'config.xml');
var configXmlContent = xmlHelper.readXmlAsJson(configFilePath, true);
return parseConfig(configXmlContent);
}
|
[
"function",
"readOptions",
"(",
"ctx",
")",
"{",
"var",
"configFilePath",
"=",
"path",
".",
"join",
"(",
"ctx",
".",
"opts",
".",
"projectRoot",
",",
"'config.xml'",
")",
";",
"var",
"configXmlContent",
"=",
"xmlHelper",
".",
"readXmlAsJson",
"(",
"configFilePath",
",",
"true",
")",
";",
"return",
"parseConfig",
"(",
"configXmlContent",
")",
";",
"}"
] |
region Public API
Read plugin options from config.xml.
If none is specified - default options are returned.
@param {Object} ctx - cordova context object
@return {Object} plugin prefereces
|
[
"region",
"Public",
"API",
"Read",
"plugin",
"options",
"from",
"config",
".",
"xml",
".",
"If",
"none",
"is",
"specified",
"-",
"default",
"options",
"are",
"returned",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpConfigXmlReader.js#L24-L29
|
11,504
|
nordnet/cordova-hot-code-push
|
www/chcp.js
|
broadcastEventFromNative
|
function broadcastEventFromNative(nativeMessage) {
var params = {};
if (nativeMessage.error != null) {
params.error = nativeMessage.error;
}
var chcpEvent = new CustomEvent(nativeMessage.action, {
'detail': params
});
document.dispatchEvent(chcpEvent);
}
|
javascript
|
function broadcastEventFromNative(nativeMessage) {
var params = {};
if (nativeMessage.error != null) {
params.error = nativeMessage.error;
}
var chcpEvent = new CustomEvent(nativeMessage.action, {
'detail': params
});
document.dispatchEvent(chcpEvent);
}
|
[
"function",
"broadcastEventFromNative",
"(",
"nativeMessage",
")",
"{",
"var",
"params",
"=",
"{",
"}",
";",
"if",
"(",
"nativeMessage",
".",
"error",
"!=",
"null",
")",
"{",
"params",
".",
"error",
"=",
"nativeMessage",
".",
"error",
";",
"}",
"var",
"chcpEvent",
"=",
"new",
"CustomEvent",
"(",
"nativeMessage",
".",
"action",
",",
"{",
"'detail'",
":",
"params",
"}",
")",
";",
"document",
".",
"dispatchEvent",
"(",
"chcpEvent",
")",
";",
"}"
] |
Broadcast event that was received from the native side.
@param {Object} arguments, received from the native side
|
[
"Broadcast",
"event",
"that",
"was",
"received",
"from",
"the",
"native",
"side",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/www/chcp.js#L126-L136
|
11,505
|
nordnet/cordova-hot-code-push
|
www/chcp.js
|
function(options, callback) {
if (options === undefined || options == null) {
return;
}
callNativeMethod(pluginNativeMethod.CONFIGURE, options, callback);
}
|
javascript
|
function(options, callback) {
if (options === undefined || options == null) {
return;
}
callNativeMethod(pluginNativeMethod.CONFIGURE, options, callback);
}
|
[
"function",
"(",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"options",
"===",
"undefined",
"||",
"options",
"==",
"null",
")",
"{",
"return",
";",
"}",
"callNativeMethod",
"(",
"pluginNativeMethod",
".",
"CONFIGURE",
",",
"options",
",",
"callback",
")",
";",
"}"
] |
DEPRECATED! WILL BE REMOVED EVENTUALLY!
If you want to set config-url - use chcp.fetchUpdate(callback, options).
If you want to set auto-download/auto-install preference - do it in config.xml instead of this method.
Set plugin options.
Options are send to the native side.
As soon as they are processed - callback is called.
@param {Object} options - options to set
@param {Callback(error)} callback - callback to call when options are set
|
[
"DEPRECATED!",
"WILL",
"BE",
"REMOVED",
"EVENTUALLY!"
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/www/chcp.js#L201-L207
|
|
11,506
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpConfigXmlWriter.js
|
setup
|
function setup(context) {
cordovaContext = context;
platforms = context.opts.platforms;
projectRoot = context.opts.projectRoot;
}
|
javascript
|
function setup(context) {
cordovaContext = context;
platforms = context.opts.platforms;
projectRoot = context.opts.projectRoot;
}
|
[
"function",
"setup",
"(",
"context",
")",
"{",
"cordovaContext",
"=",
"context",
";",
"platforms",
"=",
"context",
".",
"opts",
".",
"platforms",
";",
"projectRoot",
"=",
"context",
".",
"opts",
".",
"projectRoot",
";",
"}"
] |
region Private API
Initialize module.
@param {Object} cordovaContext - cordova context instance
|
[
"region",
"Private",
"API",
"Initialize",
"module",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpConfigXmlWriter.js#L38-L42
|
11,507
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpConfigXmlWriter.js
|
getProjectName
|
function getProjectName(ctx, projectRoot) {
var cordova_util = ctx.requireCordovaModule('cordova-lib/src/cordova/util');
var xml = cordova_util.projectConfig(projectRoot);
var ConfigParser;
// If we are running Cordova 5.4 or abova - use parser from cordova-common.
// Otherwise - from cordova-lib.
try {
ConfigParser = ctx.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser');
} catch (e) {
ConfigParser = ctx.requireCordovaModule('cordova-lib/src/configparser/ConfigParser')
}
return new ConfigParser(xml).name();
}
|
javascript
|
function getProjectName(ctx, projectRoot) {
var cordova_util = ctx.requireCordovaModule('cordova-lib/src/cordova/util');
var xml = cordova_util.projectConfig(projectRoot);
var ConfigParser;
// If we are running Cordova 5.4 or abova - use parser from cordova-common.
// Otherwise - from cordova-lib.
try {
ConfigParser = ctx.requireCordovaModule('cordova-common/src/ConfigParser/ConfigParser');
} catch (e) {
ConfigParser = ctx.requireCordovaModule('cordova-lib/src/configparser/ConfigParser')
}
return new ConfigParser(xml).name();
}
|
[
"function",
"getProjectName",
"(",
"ctx",
",",
"projectRoot",
")",
"{",
"var",
"cordova_util",
"=",
"ctx",
".",
"requireCordovaModule",
"(",
"'cordova-lib/src/cordova/util'",
")",
";",
"var",
"xml",
"=",
"cordova_util",
".",
"projectConfig",
"(",
"projectRoot",
")",
";",
"var",
"ConfigParser",
";",
"// If we are running Cordova 5.4 or abova - use parser from cordova-common.",
"// Otherwise - from cordova-lib.",
"try",
"{",
"ConfigParser",
"=",
"ctx",
".",
"requireCordovaModule",
"(",
"'cordova-common/src/ConfigParser/ConfigParser'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"ConfigParser",
"=",
"ctx",
".",
"requireCordovaModule",
"(",
"'cordova-lib/src/configparser/ConfigParser'",
")",
"}",
"return",
"new",
"ConfigParser",
"(",
"xml",
")",
".",
"name",
"(",
")",
";",
"}"
] |
Get name of the current project.
@param {Object} ctx - cordova context instance
@param {String} projectRoot - current root of the project
@return {String} name of the project
|
[
"Get",
"name",
"of",
"the",
"current",
"project",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpConfigXmlWriter.js#L52-L66
|
11,508
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpConfigXmlWriter.js
|
getPlatformSpecificConfigXml
|
function getPlatformSpecificConfigXml(platform) {
var configFilePath = null;
switch (platform) {
case 'ios':
{
configFilePath = pathToIosConfigXml();
break;
}
case 'android':
{
configFilePath = pathToAndroidConfigXml();
break;
}
}
return configFilePath;
}
|
javascript
|
function getPlatformSpecificConfigXml(platform) {
var configFilePath = null;
switch (platform) {
case 'ios':
{
configFilePath = pathToIosConfigXml();
break;
}
case 'android':
{
configFilePath = pathToAndroidConfigXml();
break;
}
}
return configFilePath;
}
|
[
"function",
"getPlatformSpecificConfigXml",
"(",
"platform",
")",
"{",
"var",
"configFilePath",
"=",
"null",
";",
"switch",
"(",
"platform",
")",
"{",
"case",
"'ios'",
":",
"{",
"configFilePath",
"=",
"pathToIosConfigXml",
"(",
")",
";",
"break",
";",
"}",
"case",
"'android'",
":",
"{",
"configFilePath",
"=",
"pathToAndroidConfigXml",
"(",
")",
";",
"break",
";",
"}",
"}",
"return",
"configFilePath",
";",
"}"
] |
Get path to platform-specific config.xml file.
@param {String} platform - for what platform we need config.xml
@return {String} absolute path to config.xml
|
[
"Get",
"path",
"to",
"platform",
"-",
"specific",
"config",
".",
"xml",
"file",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpConfigXmlWriter.js#L94-L110
|
11,509
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpConfigXmlWriter.js
|
injectOptions
|
function injectOptions(options) {
platforms.forEach(function(platform) {
var configXmlFilePath = getPlatformSpecificConfigXml(platform);
if (configXmlFilePath == null) {
return;
}
// read data from config.xml
var configData = xmlHelper.readXmlAsJson(configXmlFilePath);
if (configData == null) {
console.warn('Configuration file ' + configXmlFilePath + ' not found');
return;
}
// inject new options
var chcpXmlConfig = {};
for (var preferenceName in options) {
injectPreference(chcpXmlConfig, preferenceName, options[preferenceName]);
}
// write them back to config.xml
configData.widget['chcp'] = [];
configData.widget.chcp.push(chcpXmlConfig);
xmlHelper.writeJsonAsXml(configData, configXmlFilePath);
});
}
|
javascript
|
function injectOptions(options) {
platforms.forEach(function(platform) {
var configXmlFilePath = getPlatformSpecificConfigXml(platform);
if (configXmlFilePath == null) {
return;
}
// read data from config.xml
var configData = xmlHelper.readXmlAsJson(configXmlFilePath);
if (configData == null) {
console.warn('Configuration file ' + configXmlFilePath + ' not found');
return;
}
// inject new options
var chcpXmlConfig = {};
for (var preferenceName in options) {
injectPreference(chcpXmlConfig, preferenceName, options[preferenceName]);
}
// write them back to config.xml
configData.widget['chcp'] = [];
configData.widget.chcp.push(chcpXmlConfig);
xmlHelper.writeJsonAsXml(configData, configXmlFilePath);
});
}
|
[
"function",
"injectOptions",
"(",
"options",
")",
"{",
"platforms",
".",
"forEach",
"(",
"function",
"(",
"platform",
")",
"{",
"var",
"configXmlFilePath",
"=",
"getPlatformSpecificConfigXml",
"(",
"platform",
")",
";",
"if",
"(",
"configXmlFilePath",
"==",
"null",
")",
"{",
"return",
";",
"}",
"// read data from config.xml",
"var",
"configData",
"=",
"xmlHelper",
".",
"readXmlAsJson",
"(",
"configXmlFilePath",
")",
";",
"if",
"(",
"configData",
"==",
"null",
")",
"{",
"console",
".",
"warn",
"(",
"'Configuration file '",
"+",
"configXmlFilePath",
"+",
"' not found'",
")",
";",
"return",
";",
"}",
"// inject new options",
"var",
"chcpXmlConfig",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"preferenceName",
"in",
"options",
")",
"{",
"injectPreference",
"(",
"chcpXmlConfig",
",",
"preferenceName",
",",
"options",
"[",
"preferenceName",
"]",
")",
";",
"}",
"// write them back to config.xml",
"configData",
".",
"widget",
"[",
"'chcp'",
"]",
"=",
"[",
"]",
";",
"configData",
".",
"widget",
".",
"chcp",
".",
"push",
"(",
"chcpXmlConfig",
")",
";",
"xmlHelper",
".",
"writeJsonAsXml",
"(",
"configData",
",",
"configXmlFilePath",
")",
";",
"}",
")",
";",
"}"
] |
Write provided options into config.xml file for each platform.
@param {Object} options - plugin options
|
[
"Write",
"provided",
"options",
"into",
"config",
".",
"xml",
"file",
"for",
"each",
"platform",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpConfigXmlWriter.js#L117-L142
|
11,510
|
nordnet/cordova-hot-code-push
|
scripts/afterPrepareHook.js
|
processConsoleOptions
|
function processConsoleOptions(ctx) {
var consoleOptions = ctx.opts.options;
// If we are using Cordova 5.3.3 or lower - arguments are array of strings.
// Will be removed after some time.
if (consoleOptions instanceof Array) {
return processConsoleOptions_cordova_53(consoleOptions);
}
// for newer version of Cordova - they are an object of properties
return processConsoleOptions_cordova_54(consoleOptions);
}
|
javascript
|
function processConsoleOptions(ctx) {
var consoleOptions = ctx.opts.options;
// If we are using Cordova 5.3.3 or lower - arguments are array of strings.
// Will be removed after some time.
if (consoleOptions instanceof Array) {
return processConsoleOptions_cordova_53(consoleOptions);
}
// for newer version of Cordova - they are an object of properties
return processConsoleOptions_cordova_54(consoleOptions);
}
|
[
"function",
"processConsoleOptions",
"(",
"ctx",
")",
"{",
"var",
"consoleOptions",
"=",
"ctx",
".",
"opts",
".",
"options",
";",
"// If we are using Cordova 5.3.3 or lower - arguments are array of strings.",
"// Will be removed after some time.",
"if",
"(",
"consoleOptions",
"instanceof",
"Array",
")",
"{",
"return",
"processConsoleOptions_cordova_53",
"(",
"consoleOptions",
")",
";",
"}",
"// for newer version of Cordova - they are an object of properties",
"return",
"processConsoleOptions_cordova_54",
"(",
"consoleOptions",
")",
";",
"}"
] |
Read arguments from console.
We are reading only plugin-related preferences.
@param {Object} ctx - cordova context object
@return {Object} parsed arguments; if none were provided - default options are returned
|
[
"Read",
"arguments",
"from",
"console",
".",
"We",
"are",
"reading",
"only",
"plugin",
"-",
"related",
"preferences",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/afterPrepareHook.js#L48-L59
|
11,511
|
nordnet/cordova-hot-code-push
|
scripts/afterPrepareHook.js
|
prepareWithCustomBuildOption
|
function prepareWithCustomBuildOption(ctx, optionName, chcpXmlOptions) {
if (optionName.length == 0) {
return false;
}
var buildConfig = chcpBuildOptions.getBuildConfigurationByName(ctx, optionName);
if (buildConfig == null) {
console.warn('Build configuration for "' + optionName + '" not found in chcp.options. Ignoring it.');
return false;
}
console.log('Using config from chcp.options:');
console.log(JSON.stringify(buildConfig, null, 2));
mergeBuildOptions(chcpXmlOptions, buildConfig);
console.log('Resulting config will contain the following preferences:');
console.log(JSON.stringify(chcpXmlOptions, null, 2));
chcpConfigXmlWriter.writeOptions(ctx, chcpXmlOptions);
return true;
}
|
javascript
|
function prepareWithCustomBuildOption(ctx, optionName, chcpXmlOptions) {
if (optionName.length == 0) {
return false;
}
var buildConfig = chcpBuildOptions.getBuildConfigurationByName(ctx, optionName);
if (buildConfig == null) {
console.warn('Build configuration for "' + optionName + '" not found in chcp.options. Ignoring it.');
return false;
}
console.log('Using config from chcp.options:');
console.log(JSON.stringify(buildConfig, null, 2));
mergeBuildOptions(chcpXmlOptions, buildConfig);
console.log('Resulting config will contain the following preferences:');
console.log(JSON.stringify(chcpXmlOptions, null, 2));
chcpConfigXmlWriter.writeOptions(ctx, chcpXmlOptions);
return true;
}
|
[
"function",
"prepareWithCustomBuildOption",
"(",
"ctx",
",",
"optionName",
",",
"chcpXmlOptions",
")",
"{",
"if",
"(",
"optionName",
".",
"length",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"var",
"buildConfig",
"=",
"chcpBuildOptions",
".",
"getBuildConfigurationByName",
"(",
"ctx",
",",
"optionName",
")",
";",
"if",
"(",
"buildConfig",
"==",
"null",
")",
"{",
"console",
".",
"warn",
"(",
"'Build configuration for \"'",
"+",
"optionName",
"+",
"'\" not found in chcp.options. Ignoring it.'",
")",
";",
"return",
"false",
";",
"}",
"console",
".",
"log",
"(",
"'Using config from chcp.options:'",
")",
";",
"console",
".",
"log",
"(",
"JSON",
".",
"stringify",
"(",
"buildConfig",
",",
"null",
",",
"2",
")",
")",
";",
"mergeBuildOptions",
"(",
"chcpXmlOptions",
",",
"buildConfig",
")",
";",
"console",
".",
"log",
"(",
"'Resulting config will contain the following preferences:'",
")",
";",
"console",
".",
"log",
"(",
"JSON",
".",
"stringify",
"(",
"chcpXmlOptions",
",",
"null",
",",
"2",
")",
")",
";",
"chcpConfigXmlWriter",
".",
"writeOptions",
"(",
"ctx",
",",
"chcpXmlOptions",
")",
";",
"return",
"true",
";",
"}"
] |
Try to inject build options according to the arguments from the console.
@param {Object} ctx - cordova context object
@param {String} optionName - build option name from console; will be mapped to configuration from chcpbuild.options file
@return {boolean} true - if build option is found and we successfully injected it into config.xml; otherwise - false
|
[
"Try",
"to",
"inject",
"build",
"options",
"according",
"to",
"the",
"arguments",
"from",
"the",
"console",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/afterPrepareHook.js#L127-L149
|
11,512
|
nordnet/cordova-hot-code-push
|
scripts/lib/iosWKWebViewEngineSupport.js
|
setWKWebViewEngineMacro
|
function setWKWebViewEngineMacro(cordovaContext) {
init(cordovaContext);
// injecting options in project file
var projectFile = loadProjectFile();
setMacro(projectFile.xcode);
projectFile.write();
}
|
javascript
|
function setWKWebViewEngineMacro(cordovaContext) {
init(cordovaContext);
// injecting options in project file
var projectFile = loadProjectFile();
setMacro(projectFile.xcode);
projectFile.write();
}
|
[
"function",
"setWKWebViewEngineMacro",
"(",
"cordovaContext",
")",
"{",
"init",
"(",
"cordovaContext",
")",
";",
"// injecting options in project file",
"var",
"projectFile",
"=",
"loadProjectFile",
"(",
")",
";",
"setMacro",
"(",
"projectFile",
".",
"xcode",
")",
";",
"projectFile",
".",
"write",
"(",
")",
";",
"}"
] |
Define preprocessor macro for WKWebViewEngine.
@param {Object} cordovaContext - cordova context
|
[
"Define",
"preprocessor",
"macro",
"for",
"WKWebViewEngine",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/iosWKWebViewEngineSupport.js#L27-L34
|
11,513
|
nordnet/cordova-hot-code-push
|
scripts/lib/iosWKWebViewEngineSupport.js
|
init
|
function init(ctx) {
context = ctx;
projectRoot = ctx.opts.projectRoot;
projectName = getProjectName(ctx, projectRoot);
iosPlatformPath = path.join(projectRoot, 'platforms', 'ios');
var wkWebViewPluginPath = path.join(projectRoot, 'plugins', WKWEBVIEW_PLUGIN_NAME);
isWkWebViewEngineUsed = isDirectoryExists(wkWebViewPluginPath) ? 1 : 0;
}
|
javascript
|
function init(ctx) {
context = ctx;
projectRoot = ctx.opts.projectRoot;
projectName = getProjectName(ctx, projectRoot);
iosPlatformPath = path.join(projectRoot, 'platforms', 'ios');
var wkWebViewPluginPath = path.join(projectRoot, 'plugins', WKWEBVIEW_PLUGIN_NAME);
isWkWebViewEngineUsed = isDirectoryExists(wkWebViewPluginPath) ? 1 : 0;
}
|
[
"function",
"init",
"(",
"ctx",
")",
"{",
"context",
"=",
"ctx",
";",
"projectRoot",
"=",
"ctx",
".",
"opts",
".",
"projectRoot",
";",
"projectName",
"=",
"getProjectName",
"(",
"ctx",
",",
"projectRoot",
")",
";",
"iosPlatformPath",
"=",
"path",
".",
"join",
"(",
"projectRoot",
",",
"'platforms'",
",",
"'ios'",
")",
";",
"var",
"wkWebViewPluginPath",
"=",
"path",
".",
"join",
"(",
"projectRoot",
",",
"'plugins'",
",",
"WKWEBVIEW_PLUGIN_NAME",
")",
";",
"isWkWebViewEngineUsed",
"=",
"isDirectoryExists",
"(",
"wkWebViewPluginPath",
")",
"?",
"1",
":",
"0",
";",
"}"
] |
region General private methods
Initialize before execution.
@param {Object} ctx - cordova context instance
|
[
"region",
"General",
"private",
"methods",
"Initialize",
"before",
"execution",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/iosWKWebViewEngineSupport.js#L43-L51
|
11,514
|
nordnet/cordova-hot-code-push
|
scripts/lib/iosWKWebViewEngineSupport.js
|
setMacro
|
function setMacro(xcodeProject) {
var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
var config;
var buildSettings;
for (config in configurations) {
buildSettings = configurations[config].buildSettings;
var preprocessorDefs = buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] ? buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] : [];
if (!preprocessorDefs.length && !isWkWebViewEngineUsed) {
continue;
}
if (!Array.isArray(preprocessorDefs)) {
preprocessorDefs = [preprocessorDefs];
}
var isModified = false;
var injectedDefinition = strFormat('"%s=%d"', WKWEBVIEW_MACRO, isWkWebViewEngineUsed);
preprocessorDefs.forEach(function(item, idx) {
if (item.indexOf(WKWEBVIEW_MACRO) !== -1) {
preprocessorDefs[idx] = injectedDefinition;
isModified = true;
}
});
if (!isModified) {
preprocessorDefs.push(injectedDefinition);
}
if (preprocessorDefs.length === 1) {
buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessorDefs[0];
} else {
buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessorDefs;
}
}
}
|
javascript
|
function setMacro(xcodeProject) {
var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
var config;
var buildSettings;
for (config in configurations) {
buildSettings = configurations[config].buildSettings;
var preprocessorDefs = buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] ? buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] : [];
if (!preprocessorDefs.length && !isWkWebViewEngineUsed) {
continue;
}
if (!Array.isArray(preprocessorDefs)) {
preprocessorDefs = [preprocessorDefs];
}
var isModified = false;
var injectedDefinition = strFormat('"%s=%d"', WKWEBVIEW_MACRO, isWkWebViewEngineUsed);
preprocessorDefs.forEach(function(item, idx) {
if (item.indexOf(WKWEBVIEW_MACRO) !== -1) {
preprocessorDefs[idx] = injectedDefinition;
isModified = true;
}
});
if (!isModified) {
preprocessorDefs.push(injectedDefinition);
}
if (preprocessorDefs.length === 1) {
buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessorDefs[0];
} else {
buildSettings['GCC_PREPROCESSOR_DEFINITIONS'] = preprocessorDefs;
}
}
}
|
[
"function",
"setMacro",
"(",
"xcodeProject",
")",
"{",
"var",
"configurations",
"=",
"nonComments",
"(",
"xcodeProject",
".",
"pbxXCBuildConfigurationSection",
"(",
")",
")",
";",
"var",
"config",
";",
"var",
"buildSettings",
";",
"for",
"(",
"config",
"in",
"configurations",
")",
"{",
"buildSettings",
"=",
"configurations",
"[",
"config",
"]",
".",
"buildSettings",
";",
"var",
"preprocessorDefs",
"=",
"buildSettings",
"[",
"'GCC_PREPROCESSOR_DEFINITIONS'",
"]",
"?",
"buildSettings",
"[",
"'GCC_PREPROCESSOR_DEFINITIONS'",
"]",
":",
"[",
"]",
";",
"if",
"(",
"!",
"preprocessorDefs",
".",
"length",
"&&",
"!",
"isWkWebViewEngineUsed",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"preprocessorDefs",
")",
")",
"{",
"preprocessorDefs",
"=",
"[",
"preprocessorDefs",
"]",
";",
"}",
"var",
"isModified",
"=",
"false",
";",
"var",
"injectedDefinition",
"=",
"strFormat",
"(",
"'\"%s=%d\"'",
",",
"WKWEBVIEW_MACRO",
",",
"isWkWebViewEngineUsed",
")",
";",
"preprocessorDefs",
".",
"forEach",
"(",
"function",
"(",
"item",
",",
"idx",
")",
"{",
"if",
"(",
"item",
".",
"indexOf",
"(",
"WKWEBVIEW_MACRO",
")",
"!==",
"-",
"1",
")",
"{",
"preprocessorDefs",
"[",
"idx",
"]",
"=",
"injectedDefinition",
";",
"isModified",
"=",
"true",
";",
"}",
"}",
")",
";",
"if",
"(",
"!",
"isModified",
")",
"{",
"preprocessorDefs",
".",
"push",
"(",
"injectedDefinition",
")",
";",
"}",
"if",
"(",
"preprocessorDefs",
".",
"length",
"===",
"1",
")",
"{",
"buildSettings",
"[",
"'GCC_PREPROCESSOR_DEFINITIONS'",
"]",
"=",
"preprocessorDefs",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"buildSettings",
"[",
"'GCC_PREPROCESSOR_DEFINITIONS'",
"]",
"=",
"preprocessorDefs",
";",
"}",
"}",
"}"
] |
region Macros injection
Inject WKWebView macro into project configuration file.
@param {Object} xcodeProject - xcode project file instance
|
[
"region",
"Macros",
"injection",
"Inject",
"WKWebView",
"macro",
"into",
"project",
"configuration",
"file",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/iosWKWebViewEngineSupport.js#L167-L202
|
11,515
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpBuildOptions.js
|
getBuildConfigurationByName
|
function getBuildConfigurationByName(ctx, buildName) {
// load options from the chcpbuild.options file
var chcpBuildOptions = getBuildOptionsFromConfig(ctx);
if (chcpBuildOptions == null) {
return null;
}
var resultConfig = chcpBuildOptions[buildName];
if (!resultConfig) {
return null;
}
// backwards capability
// TODO: remove this in the next versions
if (resultConfig['config-file'] && !resultConfig['config-file']['url']) {
var url = resultConfig['config-file'];
resultConfig['config-file'] = {
'url': url
};
}
return resultConfig;
}
|
javascript
|
function getBuildConfigurationByName(ctx, buildName) {
// load options from the chcpbuild.options file
var chcpBuildOptions = getBuildOptionsFromConfig(ctx);
if (chcpBuildOptions == null) {
return null;
}
var resultConfig = chcpBuildOptions[buildName];
if (!resultConfig) {
return null;
}
// backwards capability
// TODO: remove this in the next versions
if (resultConfig['config-file'] && !resultConfig['config-file']['url']) {
var url = resultConfig['config-file'];
resultConfig['config-file'] = {
'url': url
};
}
return resultConfig;
}
|
[
"function",
"getBuildConfigurationByName",
"(",
"ctx",
",",
"buildName",
")",
"{",
"// load options from the chcpbuild.options file",
"var",
"chcpBuildOptions",
"=",
"getBuildOptionsFromConfig",
"(",
"ctx",
")",
";",
"if",
"(",
"chcpBuildOptions",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"var",
"resultConfig",
"=",
"chcpBuildOptions",
"[",
"buildName",
"]",
";",
"if",
"(",
"!",
"resultConfig",
")",
"{",
"return",
"null",
";",
"}",
"// backwards capability",
"// TODO: remove this in the next versions",
"if",
"(",
"resultConfig",
"[",
"'config-file'",
"]",
"&&",
"!",
"resultConfig",
"[",
"'config-file'",
"]",
"[",
"'url'",
"]",
")",
"{",
"var",
"url",
"=",
"resultConfig",
"[",
"'config-file'",
"]",
";",
"resultConfig",
"[",
"'config-file'",
"]",
"=",
"{",
"'url'",
":",
"url",
"}",
";",
"}",
"return",
"resultConfig",
";",
"}"
] |
region Public API
Generate build options depending on the options, provided in console.
@param {String} buildName - build identifier
@return {Object} build options; null - if none are found
|
[
"region",
"Public",
"API",
"Generate",
"build",
"options",
"depending",
"on",
"the",
"options",
"provided",
"in",
"console",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpBuildOptions.js#L22-L44
|
11,516
|
nordnet/cordova-hot-code-push
|
scripts/lib/chcpBuildOptions.js
|
getBuildOptionsFromConfig
|
function getBuildOptionsFromConfig(ctx) {
var chcpBuildOptionsFilePath = path.join(ctx.opts.projectRoot, OPTIONS_FILE_NAME);
return readObjectFromFile(chcpBuildOptionsFilePath);
}
|
javascript
|
function getBuildOptionsFromConfig(ctx) {
var chcpBuildOptionsFilePath = path.join(ctx.opts.projectRoot, OPTIONS_FILE_NAME);
return readObjectFromFile(chcpBuildOptionsFilePath);
}
|
[
"function",
"getBuildOptionsFromConfig",
"(",
"ctx",
")",
"{",
"var",
"chcpBuildOptionsFilePath",
"=",
"path",
".",
"join",
"(",
"ctx",
".",
"opts",
".",
"projectRoot",
",",
"OPTIONS_FILE_NAME",
")",
";",
"return",
"readObjectFromFile",
"(",
"chcpBuildOptionsFilePath",
")",
";",
"}"
] |
region Private API
Read options, listed in chcpbuild.options file.
@return {Object} options from chcpbuild.options file
|
[
"region",
"Private",
"API",
"Read",
"options",
"listed",
"in",
"chcpbuild",
".",
"options",
"file",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/chcpBuildOptions.js#L55-L59
|
11,517
|
nordnet/cordova-hot-code-push
|
scripts/lib/xmlHelper.js
|
writeJsonAsXml
|
function writeJsonAsXml(jsData, filePath, options) {
var xmlBuilder = new xml2js.Builder(options);
var changedXmlData = xmlBuilder.buildObject(jsData);
var isSaved = true;
try {
fs.writeFileSync(filePath, changedXmlData);
} catch (err) {
console.log(err);
isSaved = false;
}
return isSaved;
}
|
javascript
|
function writeJsonAsXml(jsData, filePath, options) {
var xmlBuilder = new xml2js.Builder(options);
var changedXmlData = xmlBuilder.buildObject(jsData);
var isSaved = true;
try {
fs.writeFileSync(filePath, changedXmlData);
} catch (err) {
console.log(err);
isSaved = false;
}
return isSaved;
}
|
[
"function",
"writeJsonAsXml",
"(",
"jsData",
",",
"filePath",
",",
"options",
")",
"{",
"var",
"xmlBuilder",
"=",
"new",
"xml2js",
".",
"Builder",
"(",
"options",
")",
";",
"var",
"changedXmlData",
"=",
"xmlBuilder",
".",
"buildObject",
"(",
"jsData",
")",
";",
"var",
"isSaved",
"=",
"true",
";",
"try",
"{",
"fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"changedXmlData",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"isSaved",
"=",
"false",
";",
"}",
"return",
"isSaved",
";",
"}"
] |
Write JSON object as xml into the specified file.
@param {Object} jsData - JSON object to write
@param {String} filePath - path to the xml file where data should be saved
@param {Object} options - xml options
@return {boolean} true - if data saved to file; false - otherwise
|
[
"Write",
"JSON",
"object",
"as",
"xml",
"into",
"the",
"specified",
"file",
"."
] |
0163767206f4cf97f49257e2ad599bf0ba61f43d
|
https://github.com/nordnet/cordova-hot-code-push/blob/0163767206f4cf97f49257e2ad599bf0ba61f43d/scripts/lib/xmlHelper.js#L57-L70
|
11,518
|
distillpub/template
|
src/transforms/typeset.js
|
acceptNode
|
function acceptNode(node) {
var parent = node.parentElement;
var isMath = (parent && parent.getAttribute && parent.getAttribute('class')) ? parent.getAttribute('class').includes('katex') || parent.getAttribute('class').includes('MathJax') : false;
return parent &&
parent.nodeName !== 'SCRIPT' &&
parent.nodeName !== 'STYLE' &&
parent.nodeName !== 'CODE' &&
parent.nodeName !== 'PRE' &&
parent.nodeName !== 'SPAN' &&
parent.nodeName !== 'D-HEADER' &&
parent.nodeName !== 'D-BYLINE' &&
parent.nodeName !== 'D-MATH' &&
parent.nodeName !== 'D-CODE' &&
parent.nodeName !== 'D-BIBLIOGRAPHY' &&
parent.nodeName !== 'D-FOOTER' &&
parent.nodeName !== 'D-APPENDIX' &&
parent.nodeName !== 'D-FRONTMATTER' &&
parent.nodeName !== 'D-TOC' &&
parent.nodeType !== 8 && //comment nodes
!isMath;
}
|
javascript
|
function acceptNode(node) {
var parent = node.parentElement;
var isMath = (parent && parent.getAttribute && parent.getAttribute('class')) ? parent.getAttribute('class').includes('katex') || parent.getAttribute('class').includes('MathJax') : false;
return parent &&
parent.nodeName !== 'SCRIPT' &&
parent.nodeName !== 'STYLE' &&
parent.nodeName !== 'CODE' &&
parent.nodeName !== 'PRE' &&
parent.nodeName !== 'SPAN' &&
parent.nodeName !== 'D-HEADER' &&
parent.nodeName !== 'D-BYLINE' &&
parent.nodeName !== 'D-MATH' &&
parent.nodeName !== 'D-CODE' &&
parent.nodeName !== 'D-BIBLIOGRAPHY' &&
parent.nodeName !== 'D-FOOTER' &&
parent.nodeName !== 'D-APPENDIX' &&
parent.nodeName !== 'D-FRONTMATTER' &&
parent.nodeName !== 'D-TOC' &&
parent.nodeType !== 8 && //comment nodes
!isMath;
}
|
[
"function",
"acceptNode",
"(",
"node",
")",
"{",
"var",
"parent",
"=",
"node",
".",
"parentElement",
";",
"var",
"isMath",
"=",
"(",
"parent",
"&&",
"parent",
".",
"getAttribute",
"&&",
"parent",
".",
"getAttribute",
"(",
"'class'",
")",
")",
"?",
"parent",
".",
"getAttribute",
"(",
"'class'",
")",
".",
"includes",
"(",
"'katex'",
")",
"||",
"parent",
".",
"getAttribute",
"(",
"'class'",
")",
".",
"includes",
"(",
"'MathJax'",
")",
":",
"false",
";",
"return",
"parent",
"&&",
"parent",
".",
"nodeName",
"!==",
"'SCRIPT'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'STYLE'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'CODE'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'PRE'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'SPAN'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-HEADER'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-BYLINE'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-MATH'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-CODE'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-BIBLIOGRAPHY'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-FOOTER'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-APPENDIX'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-FRONTMATTER'",
"&&",
"parent",
".",
"nodeName",
"!==",
"'D-TOC'",
"&&",
"parent",
".",
"nodeType",
"!==",
"8",
"&&",
"//comment nodes",
"!",
"isMath",
";",
"}"
] |
2018-07-11 shancarter@ and ludwigschubert@ no longer know what this was meant to accomplish if it was trying to not replace text in any child nodes of those listed here, then it does not accomplish that.
|
[
"2018",
"-",
"07",
"-",
"11",
"shancarter"
] |
042da68b9ab9cbbe42fcce3f38b58f1a305dd415
|
https://github.com/distillpub/template/blob/042da68b9ab9cbbe42fcce3f38b58f1a305dd415/src/transforms/typeset.js#L38-L58
|
11,519
|
googlearchive/vrview
|
src/embed/world-renderer.js
|
WorldRenderer
|
function WorldRenderer(params) {
this.init_(params.hideFullscreenButton);
this.sphereRenderer = new SphereRenderer(this.scene);
this.hotspotRenderer = new HotspotRenderer(this);
this.hotspotRenderer.on('focus', this.onHotspotFocus_.bind(this));
this.hotspotRenderer.on('blur', this.onHotspotBlur_.bind(this));
this.reticleRenderer = new ReticleRenderer(this.camera);
// Get the VR Display as soon as we initialize.
navigator.getVRDisplays().then(function(displays) {
if (displays.length > 0) {
this.vrDisplay = displays[0];
}
}.bind(this));
}
|
javascript
|
function WorldRenderer(params) {
this.init_(params.hideFullscreenButton);
this.sphereRenderer = new SphereRenderer(this.scene);
this.hotspotRenderer = new HotspotRenderer(this);
this.hotspotRenderer.on('focus', this.onHotspotFocus_.bind(this));
this.hotspotRenderer.on('blur', this.onHotspotBlur_.bind(this));
this.reticleRenderer = new ReticleRenderer(this.camera);
// Get the VR Display as soon as we initialize.
navigator.getVRDisplays().then(function(displays) {
if (displays.length > 0) {
this.vrDisplay = displays[0];
}
}.bind(this));
}
|
[
"function",
"WorldRenderer",
"(",
"params",
")",
"{",
"this",
".",
"init_",
"(",
"params",
".",
"hideFullscreenButton",
")",
";",
"this",
".",
"sphereRenderer",
"=",
"new",
"SphereRenderer",
"(",
"this",
".",
"scene",
")",
";",
"this",
".",
"hotspotRenderer",
"=",
"new",
"HotspotRenderer",
"(",
"this",
")",
";",
"this",
".",
"hotspotRenderer",
".",
"on",
"(",
"'focus'",
",",
"this",
".",
"onHotspotFocus_",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"hotspotRenderer",
".",
"on",
"(",
"'blur'",
",",
"this",
".",
"onHotspotBlur_",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"reticleRenderer",
"=",
"new",
"ReticleRenderer",
"(",
"this",
".",
"camera",
")",
";",
"// Get the VR Display as soon as we initialize.",
"navigator",
".",
"getVRDisplays",
"(",
")",
".",
"then",
"(",
"function",
"(",
"displays",
")",
"{",
"if",
"(",
"displays",
".",
"length",
">",
"0",
")",
"{",
"this",
".",
"vrDisplay",
"=",
"displays",
"[",
"0",
"]",
";",
"}",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] |
The main WebGL rendering entry point. Manages the scene, camera, VR-related
rendering updates. Interacts with the WebVRManager.
Coordinates the other renderers: SphereRenderer, HotspotRenderer,
ReticleRenderer.
Also manages the AdaptivePlayer and VideoProxy.
Emits the following events:
load: when the scene is loaded.
error: if there is an error loading the scene.
modechange(Boolean isVR): if the mode (eg. VR, fullscreen, etc) changes.
|
[
"The",
"main",
"WebGL",
"rendering",
"entry",
"point",
".",
"Manages",
"the",
"scene",
"camera",
"VR",
"-",
"related",
"rendering",
"updates",
".",
"Interacts",
"with",
"the",
"WebVRManager",
"."
] |
610e20c825f65f9a266da399b154d18e7c31de3f
|
https://github.com/googlearchive/vrview/blob/610e20c825f65f9a266da399b154d18e7c31de3f/src/embed/world-renderer.js#L43-L59
|
11,520
|
googlearchive/vrview
|
src/api/player.js
|
Player
|
function Player(selector, contentInfo) {
// Create a VR View iframe depending on the parameters.
var iframe = this.createIframe_(contentInfo);
this.iframe = iframe;
var parentEl = document.querySelector(selector);
parentEl.appendChild(iframe);
// Make a sender as well, for relying commands to the child IFrame.
this.sender = new IFrameMessageSender(iframe);
// Listen to messages from the IFrame.
window.addEventListener('message', this.onMessage_.bind(this), false);
// Expose a public .isPaused attribute.
this.isPaused = false;
// Expose a public .isMuted attribute.
this.isMuted = false;
if (typeof contentInfo.muted !== 'undefined') {
this.isMuted = contentInfo.muted;
}
// Other public attributes
this.currentTime = 0;
this.duration = 0;
this.volume = contentInfo.volume != undefined ? contentInfo.volume : 1;
if (Util.isIOS()) {
this.injectFullscreenStylesheet_();
}
}
|
javascript
|
function Player(selector, contentInfo) {
// Create a VR View iframe depending on the parameters.
var iframe = this.createIframe_(contentInfo);
this.iframe = iframe;
var parentEl = document.querySelector(selector);
parentEl.appendChild(iframe);
// Make a sender as well, for relying commands to the child IFrame.
this.sender = new IFrameMessageSender(iframe);
// Listen to messages from the IFrame.
window.addEventListener('message', this.onMessage_.bind(this), false);
// Expose a public .isPaused attribute.
this.isPaused = false;
// Expose a public .isMuted attribute.
this.isMuted = false;
if (typeof contentInfo.muted !== 'undefined') {
this.isMuted = contentInfo.muted;
}
// Other public attributes
this.currentTime = 0;
this.duration = 0;
this.volume = contentInfo.volume != undefined ? contentInfo.volume : 1;
if (Util.isIOS()) {
this.injectFullscreenStylesheet_();
}
}
|
[
"function",
"Player",
"(",
"selector",
",",
"contentInfo",
")",
"{",
"// Create a VR View iframe depending on the parameters.",
"var",
"iframe",
"=",
"this",
".",
"createIframe_",
"(",
"contentInfo",
")",
";",
"this",
".",
"iframe",
"=",
"iframe",
";",
"var",
"parentEl",
"=",
"document",
".",
"querySelector",
"(",
"selector",
")",
";",
"parentEl",
".",
"appendChild",
"(",
"iframe",
")",
";",
"// Make a sender as well, for relying commands to the child IFrame.",
"this",
".",
"sender",
"=",
"new",
"IFrameMessageSender",
"(",
"iframe",
")",
";",
"// Listen to messages from the IFrame.",
"window",
".",
"addEventListener",
"(",
"'message'",
",",
"this",
".",
"onMessage_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"// Expose a public .isPaused attribute.",
"this",
".",
"isPaused",
"=",
"false",
";",
"// Expose a public .isMuted attribute.",
"this",
".",
"isMuted",
"=",
"false",
";",
"if",
"(",
"typeof",
"contentInfo",
".",
"muted",
"!==",
"'undefined'",
")",
"{",
"this",
".",
"isMuted",
"=",
"contentInfo",
".",
"muted",
";",
"}",
"// Other public attributes",
"this",
".",
"currentTime",
"=",
"0",
";",
"this",
".",
"duration",
"=",
"0",
";",
"this",
".",
"volume",
"=",
"contentInfo",
".",
"volume",
"!=",
"undefined",
"?",
"contentInfo",
".",
"volume",
":",
"1",
";",
"if",
"(",
"Util",
".",
"isIOS",
"(",
")",
")",
"{",
"this",
".",
"injectFullscreenStylesheet_",
"(",
")",
";",
"}",
"}"
] |
Entry point for the VR View JS API.
Emits the following events:
ready: When the player is loaded.
modechange: When the viewing mode changes (normal, fullscreen, VR).
click (id): When a hotspot is clicked.
|
[
"Entry",
"point",
"for",
"the",
"VR",
"View",
"JS",
"API",
"."
] |
610e20c825f65f9a266da399b154d18e7c31de3f
|
https://github.com/googlearchive/vrview/blob/610e20c825f65f9a266da399b154d18e7c31de3f/src/api/player.js#L33-L64
|
11,521
|
googlearchive/vrview
|
src/embed/hotspot-renderer.js
|
HotspotRenderer
|
function HotspotRenderer(worldRenderer) {
this.worldRenderer = worldRenderer;
this.scene = worldRenderer.scene;
// Note: this event must be added to document.body and not to window for it to
// work inside iOS iframes.
var body = document.body;
// Bind events for hotspot interaction.
if (!Util.isMobile()) {
// Only enable mouse events on desktop.
body.addEventListener('mousedown', this.onMouseDown_.bind(this), false);
body.addEventListener('mousemove', this.onMouseMove_.bind(this), false);
body.addEventListener('mouseup', this.onMouseUp_.bind(this), false);
}
body.addEventListener('touchstart', this.onTouchStart_.bind(this), false);
body.addEventListener('touchend', this.onTouchEnd_.bind(this), false);
// Add a placeholder for hotspots.
this.hotspotRoot = new THREE.Object3D();
// Align the center with the center of the camera too.
this.hotspotRoot.rotation.y = Math.PI / 2;
this.scene.add(this.hotspotRoot);
// All hotspot IDs.
this.hotspots = {};
// Currently selected hotspots.
this.selectedHotspots = {};
// Hotspots that the last touchstart / mousedown event happened for.
this.downHotspots = {};
// For raycasting. Initialize mouse to be off screen initially.
this.pointer = new THREE.Vector2(1, 1);
this.raycaster = new THREE.Raycaster();
}
|
javascript
|
function HotspotRenderer(worldRenderer) {
this.worldRenderer = worldRenderer;
this.scene = worldRenderer.scene;
// Note: this event must be added to document.body and not to window for it to
// work inside iOS iframes.
var body = document.body;
// Bind events for hotspot interaction.
if (!Util.isMobile()) {
// Only enable mouse events on desktop.
body.addEventListener('mousedown', this.onMouseDown_.bind(this), false);
body.addEventListener('mousemove', this.onMouseMove_.bind(this), false);
body.addEventListener('mouseup', this.onMouseUp_.bind(this), false);
}
body.addEventListener('touchstart', this.onTouchStart_.bind(this), false);
body.addEventListener('touchend', this.onTouchEnd_.bind(this), false);
// Add a placeholder for hotspots.
this.hotspotRoot = new THREE.Object3D();
// Align the center with the center of the camera too.
this.hotspotRoot.rotation.y = Math.PI / 2;
this.scene.add(this.hotspotRoot);
// All hotspot IDs.
this.hotspots = {};
// Currently selected hotspots.
this.selectedHotspots = {};
// Hotspots that the last touchstart / mousedown event happened for.
this.downHotspots = {};
// For raycasting. Initialize mouse to be off screen initially.
this.pointer = new THREE.Vector2(1, 1);
this.raycaster = new THREE.Raycaster();
}
|
[
"function",
"HotspotRenderer",
"(",
"worldRenderer",
")",
"{",
"this",
".",
"worldRenderer",
"=",
"worldRenderer",
";",
"this",
".",
"scene",
"=",
"worldRenderer",
".",
"scene",
";",
"// Note: this event must be added to document.body and not to window for it to",
"// work inside iOS iframes.",
"var",
"body",
"=",
"document",
".",
"body",
";",
"// Bind events for hotspot interaction.",
"if",
"(",
"!",
"Util",
".",
"isMobile",
"(",
")",
")",
"{",
"// Only enable mouse events on desktop.",
"body",
".",
"addEventListener",
"(",
"'mousedown'",
",",
"this",
".",
"onMouseDown_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"body",
".",
"addEventListener",
"(",
"'mousemove'",
",",
"this",
".",
"onMouseMove_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"body",
".",
"addEventListener",
"(",
"'mouseup'",
",",
"this",
".",
"onMouseUp_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"}",
"body",
".",
"addEventListener",
"(",
"'touchstart'",
",",
"this",
".",
"onTouchStart_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"body",
".",
"addEventListener",
"(",
"'touchend'",
",",
"this",
".",
"onTouchEnd_",
".",
"bind",
"(",
"this",
")",
",",
"false",
")",
";",
"// Add a placeholder for hotspots.",
"this",
".",
"hotspotRoot",
"=",
"new",
"THREE",
".",
"Object3D",
"(",
")",
";",
"// Align the center with the center of the camera too.",
"this",
".",
"hotspotRoot",
".",
"rotation",
".",
"y",
"=",
"Math",
".",
"PI",
"/",
"2",
";",
"this",
".",
"scene",
".",
"add",
"(",
"this",
".",
"hotspotRoot",
")",
";",
"// All hotspot IDs.",
"this",
".",
"hotspots",
"=",
"{",
"}",
";",
"// Currently selected hotspots.",
"this",
".",
"selectedHotspots",
"=",
"{",
"}",
";",
"// Hotspots that the last touchstart / mousedown event happened for.",
"this",
".",
"downHotspots",
"=",
"{",
"}",
";",
"// For raycasting. Initialize mouse to be off screen initially.",
"this",
".",
"pointer",
"=",
"new",
"THREE",
".",
"Vector2",
"(",
"1",
",",
"1",
")",
";",
"this",
".",
"raycaster",
"=",
"new",
"THREE",
".",
"Raycaster",
"(",
")",
";",
"}"
] |
Responsible for rectangular hot spots that the user can interact with.
Specific duties:
Adding and removing hotspots.
Rendering the hotspots (debug mode only).
Notifying when hotspots are interacted with.
Emits the following events:
click (id): a hotspot is clicked.
focus (id): a hotspot is focused.
blur (id): a hotspot is no longer hovered over.
|
[
"Responsible",
"for",
"rectangular",
"hot",
"spots",
"that",
"the",
"user",
"can",
"interact",
"with",
"."
] |
610e20c825f65f9a266da399b154d18e7c31de3f
|
https://github.com/googlearchive/vrview/blob/610e20c825f65f9a266da399b154d18e7c31de3f/src/embed/hotspot-renderer.js#L48-L83
|
11,522
|
googlearchive/vrview
|
src/embed/scene-info.js
|
SceneInfo
|
function SceneInfo(opt_params) {
var params = opt_params || {};
params.player = {
loop: opt_params.loop,
volume: opt_params.volume,
muted: opt_params.muted
};
this.image = params.image !== undefined ? encodeURI(params.image) : undefined;
this.preview = params.preview !== undefined ? encodeURI(params.preview) : undefined;
this.video = params.video !== undefined ? encodeURI(params.video) : undefined;
this.defaultYaw = THREE.Math.degToRad(params.defaultYaw || 0);
this.isStereo = Util.parseBoolean(params.isStereo);
this.isYawOnly = Util.parseBoolean(params.isYawOnly);
this.isDebug = Util.parseBoolean(params.isDebug);
this.isVROff = Util.parseBoolean(params.isVROff);
this.isAutopanOff = Util.parseBoolean(params.isAutopanOff);
this.loop = Util.parseBoolean(params.player.loop);
this.volume = parseFloat(
params.player.volume ? params.player.volume : '1');
this.muted = Util.parseBoolean(params.player.muted);
this.hideFullscreenButton = Util.parseBoolean(params.hideFullscreenButton);
}
|
javascript
|
function SceneInfo(opt_params) {
var params = opt_params || {};
params.player = {
loop: opt_params.loop,
volume: opt_params.volume,
muted: opt_params.muted
};
this.image = params.image !== undefined ? encodeURI(params.image) : undefined;
this.preview = params.preview !== undefined ? encodeURI(params.preview) : undefined;
this.video = params.video !== undefined ? encodeURI(params.video) : undefined;
this.defaultYaw = THREE.Math.degToRad(params.defaultYaw || 0);
this.isStereo = Util.parseBoolean(params.isStereo);
this.isYawOnly = Util.parseBoolean(params.isYawOnly);
this.isDebug = Util.parseBoolean(params.isDebug);
this.isVROff = Util.parseBoolean(params.isVROff);
this.isAutopanOff = Util.parseBoolean(params.isAutopanOff);
this.loop = Util.parseBoolean(params.player.loop);
this.volume = parseFloat(
params.player.volume ? params.player.volume : '1');
this.muted = Util.parseBoolean(params.player.muted);
this.hideFullscreenButton = Util.parseBoolean(params.hideFullscreenButton);
}
|
[
"function",
"SceneInfo",
"(",
"opt_params",
")",
"{",
"var",
"params",
"=",
"opt_params",
"||",
"{",
"}",
";",
"params",
".",
"player",
"=",
"{",
"loop",
":",
"opt_params",
".",
"loop",
",",
"volume",
":",
"opt_params",
".",
"volume",
",",
"muted",
":",
"opt_params",
".",
"muted",
"}",
";",
"this",
".",
"image",
"=",
"params",
".",
"image",
"!==",
"undefined",
"?",
"encodeURI",
"(",
"params",
".",
"image",
")",
":",
"undefined",
";",
"this",
".",
"preview",
"=",
"params",
".",
"preview",
"!==",
"undefined",
"?",
"encodeURI",
"(",
"params",
".",
"preview",
")",
":",
"undefined",
";",
"this",
".",
"video",
"=",
"params",
".",
"video",
"!==",
"undefined",
"?",
"encodeURI",
"(",
"params",
".",
"video",
")",
":",
"undefined",
";",
"this",
".",
"defaultYaw",
"=",
"THREE",
".",
"Math",
".",
"degToRad",
"(",
"params",
".",
"defaultYaw",
"||",
"0",
")",
";",
"this",
".",
"isStereo",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"isStereo",
")",
";",
"this",
".",
"isYawOnly",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"isYawOnly",
")",
";",
"this",
".",
"isDebug",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"isDebug",
")",
";",
"this",
".",
"isVROff",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"isVROff",
")",
";",
"this",
".",
"isAutopanOff",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"isAutopanOff",
")",
";",
"this",
".",
"loop",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"player",
".",
"loop",
")",
";",
"this",
".",
"volume",
"=",
"parseFloat",
"(",
"params",
".",
"player",
".",
"volume",
"?",
"params",
".",
"player",
".",
"volume",
":",
"'1'",
")",
";",
"this",
".",
"muted",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"player",
".",
"muted",
")",
";",
"this",
".",
"hideFullscreenButton",
"=",
"Util",
".",
"parseBoolean",
"(",
"params",
".",
"hideFullscreenButton",
")",
";",
"}"
] |
Contains all information about a given scene.
|
[
"Contains",
"all",
"information",
"about",
"a",
"given",
"scene",
"."
] |
610e20c825f65f9a266da399b154d18e7c31de3f
|
https://github.com/googlearchive/vrview/blob/610e20c825f65f9a266da399b154d18e7c31de3f/src/embed/scene-info.js#L37-L60
|
11,523
|
expressjs/cookie-session
|
index.js
|
cookieSession
|
function cookieSession (options) {
var opts = options || {}
// cookie name
var name = opts.name || 'session'
// secrets
var keys = opts.keys
if (!keys && opts.secret) keys = [opts.secret]
// defaults
if (opts.overwrite == null) opts.overwrite = true
if (opts.httpOnly == null) opts.httpOnly = true
if (opts.signed == null) opts.signed = true
if (!keys && opts.signed) throw new Error('.keys required.')
debug('session options %j', opts)
return function _cookieSession (req, res, next) {
var cookies = new Cookies(req, res, {
keys: keys
})
var sess
// to pass to Session()
req.sessionCookies = cookies
req.sessionOptions = Object.create(opts)
req.sessionKey = name
// define req.session getter / setter
Object.defineProperty(req, 'session', {
configurable: true,
enumerable: true,
get: getSession,
set: setSession
})
function getSession () {
// already retrieved
if (sess) {
return sess
}
// unset
if (sess === false) {
return null
}
// get or create session
return (sess = tryGetSession(req) || createSession(req))
}
function setSession (val) {
if (val == null) {
// unset session
sess = false
return val
}
if (typeof val === 'object') {
// create a new session
sess = Session.create(this, val)
return sess
}
throw new Error('req.session can only be set as null or an object.')
}
onHeaders(res, function setHeaders () {
if (sess === undefined) {
// not accessed
return
}
try {
if (sess === false) {
// remove
cookies.set(name, '', req.sessionOptions)
} else if ((!sess.isNew || sess.isPopulated) && sess.isChanged) {
// save populated or non-new changed session
sess.save()
}
} catch (e) {
debug('error saving session %s', e.message)
}
})
next()
}
}
|
javascript
|
function cookieSession (options) {
var opts = options || {}
// cookie name
var name = opts.name || 'session'
// secrets
var keys = opts.keys
if (!keys && opts.secret) keys = [opts.secret]
// defaults
if (opts.overwrite == null) opts.overwrite = true
if (opts.httpOnly == null) opts.httpOnly = true
if (opts.signed == null) opts.signed = true
if (!keys && opts.signed) throw new Error('.keys required.')
debug('session options %j', opts)
return function _cookieSession (req, res, next) {
var cookies = new Cookies(req, res, {
keys: keys
})
var sess
// to pass to Session()
req.sessionCookies = cookies
req.sessionOptions = Object.create(opts)
req.sessionKey = name
// define req.session getter / setter
Object.defineProperty(req, 'session', {
configurable: true,
enumerable: true,
get: getSession,
set: setSession
})
function getSession () {
// already retrieved
if (sess) {
return sess
}
// unset
if (sess === false) {
return null
}
// get or create session
return (sess = tryGetSession(req) || createSession(req))
}
function setSession (val) {
if (val == null) {
// unset session
sess = false
return val
}
if (typeof val === 'object') {
// create a new session
sess = Session.create(this, val)
return sess
}
throw new Error('req.session can only be set as null or an object.')
}
onHeaders(res, function setHeaders () {
if (sess === undefined) {
// not accessed
return
}
try {
if (sess === false) {
// remove
cookies.set(name, '', req.sessionOptions)
} else if ((!sess.isNew || sess.isPopulated) && sess.isChanged) {
// save populated or non-new changed session
sess.save()
}
} catch (e) {
debug('error saving session %s', e.message)
}
})
next()
}
}
|
[
"function",
"cookieSession",
"(",
"options",
")",
"{",
"var",
"opts",
"=",
"options",
"||",
"{",
"}",
"// cookie name",
"var",
"name",
"=",
"opts",
".",
"name",
"||",
"'session'",
"// secrets",
"var",
"keys",
"=",
"opts",
".",
"keys",
"if",
"(",
"!",
"keys",
"&&",
"opts",
".",
"secret",
")",
"keys",
"=",
"[",
"opts",
".",
"secret",
"]",
"// defaults",
"if",
"(",
"opts",
".",
"overwrite",
"==",
"null",
")",
"opts",
".",
"overwrite",
"=",
"true",
"if",
"(",
"opts",
".",
"httpOnly",
"==",
"null",
")",
"opts",
".",
"httpOnly",
"=",
"true",
"if",
"(",
"opts",
".",
"signed",
"==",
"null",
")",
"opts",
".",
"signed",
"=",
"true",
"if",
"(",
"!",
"keys",
"&&",
"opts",
".",
"signed",
")",
"throw",
"new",
"Error",
"(",
"'.keys required.'",
")",
"debug",
"(",
"'session options %j'",
",",
"opts",
")",
"return",
"function",
"_cookieSession",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"cookies",
"=",
"new",
"Cookies",
"(",
"req",
",",
"res",
",",
"{",
"keys",
":",
"keys",
"}",
")",
"var",
"sess",
"// to pass to Session()",
"req",
".",
"sessionCookies",
"=",
"cookies",
"req",
".",
"sessionOptions",
"=",
"Object",
".",
"create",
"(",
"opts",
")",
"req",
".",
"sessionKey",
"=",
"name",
"// define req.session getter / setter",
"Object",
".",
"defineProperty",
"(",
"req",
",",
"'session'",
",",
"{",
"configurable",
":",
"true",
",",
"enumerable",
":",
"true",
",",
"get",
":",
"getSession",
",",
"set",
":",
"setSession",
"}",
")",
"function",
"getSession",
"(",
")",
"{",
"// already retrieved",
"if",
"(",
"sess",
")",
"{",
"return",
"sess",
"}",
"// unset",
"if",
"(",
"sess",
"===",
"false",
")",
"{",
"return",
"null",
"}",
"// get or create session",
"return",
"(",
"sess",
"=",
"tryGetSession",
"(",
"req",
")",
"||",
"createSession",
"(",
"req",
")",
")",
"}",
"function",
"setSession",
"(",
"val",
")",
"{",
"if",
"(",
"val",
"==",
"null",
")",
"{",
"// unset session",
"sess",
"=",
"false",
"return",
"val",
"}",
"if",
"(",
"typeof",
"val",
"===",
"'object'",
")",
"{",
"// create a new session",
"sess",
"=",
"Session",
".",
"create",
"(",
"this",
",",
"val",
")",
"return",
"sess",
"}",
"throw",
"new",
"Error",
"(",
"'req.session can only be set as null or an object.'",
")",
"}",
"onHeaders",
"(",
"res",
",",
"function",
"setHeaders",
"(",
")",
"{",
"if",
"(",
"sess",
"===",
"undefined",
")",
"{",
"// not accessed",
"return",
"}",
"try",
"{",
"if",
"(",
"sess",
"===",
"false",
")",
"{",
"// remove",
"cookies",
".",
"set",
"(",
"name",
",",
"''",
",",
"req",
".",
"sessionOptions",
")",
"}",
"else",
"if",
"(",
"(",
"!",
"sess",
".",
"isNew",
"||",
"sess",
".",
"isPopulated",
")",
"&&",
"sess",
".",
"isChanged",
")",
"{",
"// save populated or non-new changed session",
"sess",
".",
"save",
"(",
")",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"debug",
"(",
"'error saving session %s'",
",",
"e",
".",
"message",
")",
"}",
"}",
")",
"next",
"(",
")",
"}",
"}"
] |
Create a new cookie session middleware.
@param {object} [options]
@param {boolean} [options.httpOnly=true]
@param {array} [options.keys]
@param {string} [options.name=session] Name of the cookie to use
@param {boolean} [options.overwrite=true]
@param {string} [options.secret]
@param {boolean} [options.signed=true]
@return {function} middleware
@public
|
[
"Create",
"a",
"new",
"cookie",
"session",
"middleware",
"."
] |
add5791673964540a5283e7abc553d6840f7adf8
|
https://github.com/expressjs/cookie-session/blob/add5791673964540a5283e7abc553d6840f7adf8/index.js#L41-L131
|
11,524
|
expressjs/cookie-session
|
index.js
|
Session
|
function Session (ctx, obj) {
Object.defineProperty(this, '_ctx', {
value: ctx
})
if (obj) {
for (var key in obj) {
this[key] = obj[key]
}
}
}
|
javascript
|
function Session (ctx, obj) {
Object.defineProperty(this, '_ctx', {
value: ctx
})
if (obj) {
for (var key in obj) {
this[key] = obj[key]
}
}
}
|
[
"function",
"Session",
"(",
"ctx",
",",
"obj",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
",",
"'_ctx'",
",",
"{",
"value",
":",
"ctx",
"}",
")",
"if",
"(",
"obj",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"obj",
")",
"{",
"this",
"[",
"key",
"]",
"=",
"obj",
"[",
"key",
"]",
"}",
"}",
"}"
] |
Session model.
@param {Context} ctx
@param {Object} obj
@private
|
[
"Session",
"model",
"."
] |
add5791673964540a5283e7abc553d6840f7adf8
|
https://github.com/expressjs/cookie-session/blob/add5791673964540a5283e7abc553d6840f7adf8/index.js#L141-L151
|
11,525
|
expressjs/cookie-session
|
index.js
|
decode
|
function decode (string) {
var body = Buffer.from(string, 'base64').toString('utf8')
return JSON.parse(body)
}
|
javascript
|
function decode (string) {
var body = Buffer.from(string, 'base64').toString('utf8')
return JSON.parse(body)
}
|
[
"function",
"decode",
"(",
"string",
")",
"{",
"var",
"body",
"=",
"Buffer",
".",
"from",
"(",
"string",
",",
"'base64'",
")",
".",
"toString",
"(",
"'utf8'",
")",
"return",
"JSON",
".",
"parse",
"(",
"body",
")",
"}"
] |
Decode the base64 cookie value to an object.
@param {String} string
@return {Object}
@private
|
[
"Decode",
"the",
"base64",
"cookie",
"value",
"to",
"an",
"object",
"."
] |
add5791673964540a5283e7abc553d6840f7adf8
|
https://github.com/expressjs/cookie-session/blob/add5791673964540a5283e7abc553d6840f7adf8/index.js#L289-L292
|
11,526
|
expressjs/cookie-session
|
index.js
|
encode
|
function encode (body) {
var str = JSON.stringify(body)
return Buffer.from(str).toString('base64')
}
|
javascript
|
function encode (body) {
var str = JSON.stringify(body)
return Buffer.from(str).toString('base64')
}
|
[
"function",
"encode",
"(",
"body",
")",
"{",
"var",
"str",
"=",
"JSON",
".",
"stringify",
"(",
"body",
")",
"return",
"Buffer",
".",
"from",
"(",
"str",
")",
".",
"toString",
"(",
"'base64'",
")",
"}"
] |
Encode an object into a base64-encoded JSON string.
@param {Object} body
@return {String}
@private
|
[
"Encode",
"an",
"object",
"into",
"a",
"base64",
"-",
"encoded",
"JSON",
"string",
"."
] |
add5791673964540a5283e7abc553d6840f7adf8
|
https://github.com/expressjs/cookie-session/blob/add5791673964540a5283e7abc553d6840f7adf8/index.js#L302-L305
|
11,527
|
expressjs/cookie-session
|
index.js
|
tryGetSession
|
function tryGetSession (req) {
var cookies = req.sessionCookies
var name = req.sessionKey
var opts = req.sessionOptions
var str = cookies.get(name, opts)
if (!str) {
return undefined
}
debug('parse %s', str)
try {
return Session.deserialize(req, str)
} catch (err) {
return undefined
}
}
|
javascript
|
function tryGetSession (req) {
var cookies = req.sessionCookies
var name = req.sessionKey
var opts = req.sessionOptions
var str = cookies.get(name, opts)
if (!str) {
return undefined
}
debug('parse %s', str)
try {
return Session.deserialize(req, str)
} catch (err) {
return undefined
}
}
|
[
"function",
"tryGetSession",
"(",
"req",
")",
"{",
"var",
"cookies",
"=",
"req",
".",
"sessionCookies",
"var",
"name",
"=",
"req",
".",
"sessionKey",
"var",
"opts",
"=",
"req",
".",
"sessionOptions",
"var",
"str",
"=",
"cookies",
".",
"get",
"(",
"name",
",",
"opts",
")",
"if",
"(",
"!",
"str",
")",
"{",
"return",
"undefined",
"}",
"debug",
"(",
"'parse %s'",
",",
"str",
")",
"try",
"{",
"return",
"Session",
".",
"deserialize",
"(",
"req",
",",
"str",
")",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
"undefined",
"}",
"}"
] |
Try getting a session from a request.
@private
|
[
"Try",
"getting",
"a",
"session",
"from",
"a",
"request",
"."
] |
add5791673964540a5283e7abc553d6840f7adf8
|
https://github.com/expressjs/cookie-session/blob/add5791673964540a5283e7abc553d6840f7adf8/index.js#L312-L330
|
11,528
|
bfintal/Counter-Up
|
jquery.counterup.js
|
function() {
$this.text($this.data('counterup-nums').shift());
if ($this.data('counterup-nums').length) {
setTimeout($this.data('counterup-func'), $settings.delay);
} else {
delete $this.data('counterup-nums');
$this.data('counterup-nums', null);
$this.data('counterup-func', null);
}
}
|
javascript
|
function() {
$this.text($this.data('counterup-nums').shift());
if ($this.data('counterup-nums').length) {
setTimeout($this.data('counterup-func'), $settings.delay);
} else {
delete $this.data('counterup-nums');
$this.data('counterup-nums', null);
$this.data('counterup-func', null);
}
}
|
[
"function",
"(",
")",
"{",
"$this",
".",
"text",
"(",
"$this",
".",
"data",
"(",
"'counterup-nums'",
")",
".",
"shift",
"(",
")",
")",
";",
"if",
"(",
"$this",
".",
"data",
"(",
"'counterup-nums'",
")",
".",
"length",
")",
"{",
"setTimeout",
"(",
"$this",
".",
"data",
"(",
"'counterup-func'",
")",
",",
"$settings",
".",
"delay",
")",
";",
"}",
"else",
"{",
"delete",
"$this",
".",
"data",
"(",
"'counterup-nums'",
")",
";",
"$this",
".",
"data",
"(",
"'counterup-nums'",
",",
"null",
")",
";",
"$this",
".",
"data",
"(",
"'counterup-func'",
",",
"null",
")",
";",
"}",
"}"
] |
Updates the number until we're done
|
[
"Updates",
"the",
"number",
"until",
"we",
"re",
"done"
] |
496d5a038a2b8838e6037896a90a2a5d74bc2a89
|
https://github.com/bfintal/Counter-Up/blob/496d5a038a2b8838e6037896a90a2a5d74bc2a89/jquery.counterup.js#L61-L70
|
|
11,529
|
instructure/pdf-annotate.js
|
src/UI/edit.js
|
destroyEditOverlay
|
function destroyEditOverlay() {
if (overlay) {
overlay.parentNode.removeChild(overlay);
overlay = null;
}
document.removeEventListener('click', handleDocumentClick);
document.removeEventListener('keyup', handleDocumentKeyup);
document.removeEventListener('mousedown', handleDocumentMousedown);
document.removeEventListener('mousemove', handleDocumentMousemove);
document.removeEventListener('mouseup', handleDocumentMouseup);
enableUserSelect();
}
|
javascript
|
function destroyEditOverlay() {
if (overlay) {
overlay.parentNode.removeChild(overlay);
overlay = null;
}
document.removeEventListener('click', handleDocumentClick);
document.removeEventListener('keyup', handleDocumentKeyup);
document.removeEventListener('mousedown', handleDocumentMousedown);
document.removeEventListener('mousemove', handleDocumentMousemove);
document.removeEventListener('mouseup', handleDocumentMouseup);
enableUserSelect();
}
|
[
"function",
"destroyEditOverlay",
"(",
")",
"{",
"if",
"(",
"overlay",
")",
"{",
"overlay",
".",
"parentNode",
".",
"removeChild",
"(",
"overlay",
")",
";",
"overlay",
"=",
"null",
";",
"}",
"document",
".",
"removeEventListener",
"(",
"'click'",
",",
"handleDocumentClick",
")",
";",
"document",
".",
"removeEventListener",
"(",
"'keyup'",
",",
"handleDocumentKeyup",
")",
";",
"document",
".",
"removeEventListener",
"(",
"'mousedown'",
",",
"handleDocumentMousedown",
")",
";",
"document",
".",
"removeEventListener",
"(",
"'mousemove'",
",",
"handleDocumentMousemove",
")",
";",
"document",
".",
"removeEventListener",
"(",
"'mouseup'",
",",
"handleDocumentMouseup",
")",
";",
"enableUserSelect",
"(",
")",
";",
"}"
] |
Destroy the edit overlay if it exists.
|
[
"Destroy",
"the",
"edit",
"overlay",
"if",
"it",
"exists",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/edit.js#L95-L107
|
11,530
|
instructure/pdf-annotate.js
|
src/UI/edit.js
|
deleteAnnotation
|
function deleteAnnotation() {
if (!overlay) { return; }
let annotationId = overlay.getAttribute('data-target-id');
let nodes = document.querySelectorAll(`[data-pdf-annotate-id="${annotationId}"]`);
let svg = overlay.parentNode.querySelector('svg.annotationLayer');
let { documentId } = getMetadata(svg);
[...nodes].forEach((n) => {
n.parentNode.removeChild(n);
});
PDFJSAnnotate.getStoreAdapter().deleteAnnotation(documentId, annotationId);
destroyEditOverlay();
}
|
javascript
|
function deleteAnnotation() {
if (!overlay) { return; }
let annotationId = overlay.getAttribute('data-target-id');
let nodes = document.querySelectorAll(`[data-pdf-annotate-id="${annotationId}"]`);
let svg = overlay.parentNode.querySelector('svg.annotationLayer');
let { documentId } = getMetadata(svg);
[...nodes].forEach((n) => {
n.parentNode.removeChild(n);
});
PDFJSAnnotate.getStoreAdapter().deleteAnnotation(documentId, annotationId);
destroyEditOverlay();
}
|
[
"function",
"deleteAnnotation",
"(",
")",
"{",
"if",
"(",
"!",
"overlay",
")",
"{",
"return",
";",
"}",
"let",
"annotationId",
"=",
"overlay",
".",
"getAttribute",
"(",
"'data-target-id'",
")",
";",
"let",
"nodes",
"=",
"document",
".",
"querySelectorAll",
"(",
"`",
"${",
"annotationId",
"}",
"`",
")",
";",
"let",
"svg",
"=",
"overlay",
".",
"parentNode",
".",
"querySelector",
"(",
"'svg.annotationLayer'",
")",
";",
"let",
"{",
"documentId",
"}",
"=",
"getMetadata",
"(",
"svg",
")",
";",
"[",
"...",
"nodes",
"]",
".",
"forEach",
"(",
"(",
"n",
")",
"=>",
"{",
"n",
".",
"parentNode",
".",
"removeChild",
"(",
"n",
")",
";",
"}",
")",
";",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"deleteAnnotation",
"(",
"documentId",
",",
"annotationId",
")",
";",
"destroyEditOverlay",
"(",
")",
";",
"}"
] |
Delete currently selected annotation
|
[
"Delete",
"currently",
"selected",
"annotation"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/edit.js#L112-L127
|
11,531
|
instructure/pdf-annotate.js
|
src/UI/edit.js
|
handleDocumentClick
|
function handleDocumentClick(e) {
if (!findSVGAtPoint(e.clientX, e.clientY)) { return; }
// Remove current overlay
let overlay = document.getElementById('pdf-annotate-edit-overlay');
if (overlay) {
if (isDragging || e.target === overlay) {
return;
}
destroyEditOverlay();
}
}
|
javascript
|
function handleDocumentClick(e) {
if (!findSVGAtPoint(e.clientX, e.clientY)) { return; }
// Remove current overlay
let overlay = document.getElementById('pdf-annotate-edit-overlay');
if (overlay) {
if (isDragging || e.target === overlay) {
return;
}
destroyEditOverlay();
}
}
|
[
"function",
"handleDocumentClick",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"findSVGAtPoint",
"(",
"e",
".",
"clientX",
",",
"e",
".",
"clientY",
")",
")",
"{",
"return",
";",
"}",
"// Remove current overlay",
"let",
"overlay",
"=",
"document",
".",
"getElementById",
"(",
"'pdf-annotate-edit-overlay'",
")",
";",
"if",
"(",
"overlay",
")",
"{",
"if",
"(",
"isDragging",
"||",
"e",
".",
"target",
"===",
"overlay",
")",
"{",
"return",
";",
"}",
"destroyEditOverlay",
"(",
")",
";",
"}",
"}"
] |
Handle document.click event
@param {Event} e The DOM event that needs to be handled
|
[
"Handle",
"document",
".",
"click",
"event"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/edit.js#L134-L146
|
11,532
|
instructure/pdf-annotate.js
|
src/UI/text.js
|
saveText
|
function saveText() {
if (input.value.trim().length > 0) {
let clientX = parseInt(input.style.left, 10);
let clientY = parseInt(input.style.top, 10);
let svg = findSVGAtPoint(clientX, clientY);
if (!svg) {
return;
}
let { documentId, pageNumber } = getMetadata(svg);
let rect = svg.getBoundingClientRect();
let annotation = Object.assign({
type: 'textbox',
size: _textSize,
color: _textColor,
content: input.value.trim()
}, scaleDown(svg, {
x: clientX - rect.left,
y: clientY - rect.top,
width: input.offsetWidth,
height: input.offsetHeight
})
);
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
appendChild(svg, annotation);
});
}
closeInput();
}
|
javascript
|
function saveText() {
if (input.value.trim().length > 0) {
let clientX = parseInt(input.style.left, 10);
let clientY = parseInt(input.style.top, 10);
let svg = findSVGAtPoint(clientX, clientY);
if (!svg) {
return;
}
let { documentId, pageNumber } = getMetadata(svg);
let rect = svg.getBoundingClientRect();
let annotation = Object.assign({
type: 'textbox',
size: _textSize,
color: _textColor,
content: input.value.trim()
}, scaleDown(svg, {
x: clientX - rect.left,
y: clientY - rect.top,
width: input.offsetWidth,
height: input.offsetHeight
})
);
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
appendChild(svg, annotation);
});
}
closeInput();
}
|
[
"function",
"saveText",
"(",
")",
"{",
"if",
"(",
"input",
".",
"value",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
")",
"{",
"let",
"clientX",
"=",
"parseInt",
"(",
"input",
".",
"style",
".",
"left",
",",
"10",
")",
";",
"let",
"clientY",
"=",
"parseInt",
"(",
"input",
".",
"style",
".",
"top",
",",
"10",
")",
";",
"let",
"svg",
"=",
"findSVGAtPoint",
"(",
"clientX",
",",
"clientY",
")",
";",
"if",
"(",
"!",
"svg",
")",
"{",
"return",
";",
"}",
"let",
"{",
"documentId",
",",
"pageNumber",
"}",
"=",
"getMetadata",
"(",
"svg",
")",
";",
"let",
"rect",
"=",
"svg",
".",
"getBoundingClientRect",
"(",
")",
";",
"let",
"annotation",
"=",
"Object",
".",
"assign",
"(",
"{",
"type",
":",
"'textbox'",
",",
"size",
":",
"_textSize",
",",
"color",
":",
"_textColor",
",",
"content",
":",
"input",
".",
"value",
".",
"trim",
"(",
")",
"}",
",",
"scaleDown",
"(",
"svg",
",",
"{",
"x",
":",
"clientX",
"-",
"rect",
".",
"left",
",",
"y",
":",
"clientY",
"-",
"rect",
".",
"top",
",",
"width",
":",
"input",
".",
"offsetWidth",
",",
"height",
":",
"input",
".",
"offsetHeight",
"}",
")",
")",
";",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"addAnnotation",
"(",
"documentId",
",",
"pageNumber",
",",
"annotation",
")",
".",
"then",
"(",
"(",
"annotation",
")",
"=>",
"{",
"appendChild",
"(",
"svg",
",",
"annotation",
")",
";",
"}",
")",
";",
"}",
"closeInput",
"(",
")",
";",
"}"
] |
Save a text annotation from input
|
[
"Save",
"a",
"text",
"annotation",
"from",
"input"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/text.js#L65-L96
|
11,533
|
instructure/pdf-annotate.js
|
src/UI/text.js
|
closeInput
|
function closeInput() {
if (input) {
input.removeEventListener('blur', handleInputBlur);
input.removeEventListener('keyup', handleInputKeyup);
document.body.removeChild(input);
input = null;
}
}
|
javascript
|
function closeInput() {
if (input) {
input.removeEventListener('blur', handleInputBlur);
input.removeEventListener('keyup', handleInputKeyup);
document.body.removeChild(input);
input = null;
}
}
|
[
"function",
"closeInput",
"(",
")",
"{",
"if",
"(",
"input",
")",
"{",
"input",
".",
"removeEventListener",
"(",
"'blur'",
",",
"handleInputBlur",
")",
";",
"input",
".",
"removeEventListener",
"(",
"'keyup'",
",",
"handleInputKeyup",
")",
";",
"document",
".",
"body",
".",
"removeChild",
"(",
"input",
")",
";",
"input",
"=",
"null",
";",
"}",
"}"
] |
Close the input
|
[
"Close",
"the",
"input"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/text.js#L101-L108
|
11,534
|
instructure/pdf-annotate.js
|
src/render/appendChild.js
|
transform
|
function transform(node, viewport) {
let trans = getTranslation(viewport);
// Let SVG natively transform the element
node.setAttribute('transform', `scale(${viewport.scale}) rotate(${viewport.rotation}) translate(${trans.x}, ${trans.y})`);
// Manually adjust x/y for nested SVG nodes
if (!isFirefox && node.nodeName.toLowerCase() === 'svg') {
node.setAttribute('x', parseInt(node.getAttribute('x'), 10) * viewport.scale);
node.setAttribute('y', parseInt(node.getAttribute('y'), 10) * viewport.scale);
let x = parseInt(node.getAttribute('x', 10));
let y = parseInt(node.getAttribute('y', 10));
let width = parseInt(node.getAttribute('width'), 10);
let height = parseInt(node.getAttribute('height'), 10);
let path = node.querySelector('path');
let svg = path.parentNode;
// Scale width/height
[node, svg, path, node.querySelector('rect')].forEach((n) => {
n.setAttribute('width', parseInt(n.getAttribute('width'), 10) * viewport.scale);
n.setAttribute('height', parseInt(n.getAttribute('height'), 10) * viewport.scale);
});
// Transform path but keep scale at 100% since it will be handled natively
transform(path, objectAssign({}, viewport, { scale: 1 }));
switch(viewport.rotation % 360) {
case 90:
node.setAttribute('x', viewport.width - y - width);
node.setAttribute('y', x);
svg.setAttribute('x', 1);
svg.setAttribute('y', 0);
break;
case 180:
node.setAttribute('x', viewport.width - x - width);
node.setAttribute('y', viewport.height - y - height);
svg.setAttribute('y', 2);
break;
case 270:
node.setAttribute('x', y);
node.setAttribute('y', viewport.height - x - height);
svg.setAttribute('x', -1);
svg.setAttribute('y', 0);
break;
}
}
return node;
}
|
javascript
|
function transform(node, viewport) {
let trans = getTranslation(viewport);
// Let SVG natively transform the element
node.setAttribute('transform', `scale(${viewport.scale}) rotate(${viewport.rotation}) translate(${trans.x}, ${trans.y})`);
// Manually adjust x/y for nested SVG nodes
if (!isFirefox && node.nodeName.toLowerCase() === 'svg') {
node.setAttribute('x', parseInt(node.getAttribute('x'), 10) * viewport.scale);
node.setAttribute('y', parseInt(node.getAttribute('y'), 10) * viewport.scale);
let x = parseInt(node.getAttribute('x', 10));
let y = parseInt(node.getAttribute('y', 10));
let width = parseInt(node.getAttribute('width'), 10);
let height = parseInt(node.getAttribute('height'), 10);
let path = node.querySelector('path');
let svg = path.parentNode;
// Scale width/height
[node, svg, path, node.querySelector('rect')].forEach((n) => {
n.setAttribute('width', parseInt(n.getAttribute('width'), 10) * viewport.scale);
n.setAttribute('height', parseInt(n.getAttribute('height'), 10) * viewport.scale);
});
// Transform path but keep scale at 100% since it will be handled natively
transform(path, objectAssign({}, viewport, { scale: 1 }));
switch(viewport.rotation % 360) {
case 90:
node.setAttribute('x', viewport.width - y - width);
node.setAttribute('y', x);
svg.setAttribute('x', 1);
svg.setAttribute('y', 0);
break;
case 180:
node.setAttribute('x', viewport.width - x - width);
node.setAttribute('y', viewport.height - y - height);
svg.setAttribute('y', 2);
break;
case 270:
node.setAttribute('x', y);
node.setAttribute('y', viewport.height - x - height);
svg.setAttribute('x', -1);
svg.setAttribute('y', 0);
break;
}
}
return node;
}
|
[
"function",
"transform",
"(",
"node",
",",
"viewport",
")",
"{",
"let",
"trans",
"=",
"getTranslation",
"(",
"viewport",
")",
";",
"// Let SVG natively transform the element",
"node",
".",
"setAttribute",
"(",
"'transform'",
",",
"`",
"${",
"viewport",
".",
"scale",
"}",
"${",
"viewport",
".",
"rotation",
"}",
"${",
"trans",
".",
"x",
"}",
"${",
"trans",
".",
"y",
"}",
"`",
")",
";",
"// Manually adjust x/y for nested SVG nodes",
"if",
"(",
"!",
"isFirefox",
"&&",
"node",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
"===",
"'svg'",
")",
"{",
"node",
".",
"setAttribute",
"(",
"'x'",
",",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'x'",
")",
",",
"10",
")",
"*",
"viewport",
".",
"scale",
")",
";",
"node",
".",
"setAttribute",
"(",
"'y'",
",",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'y'",
")",
",",
"10",
")",
"*",
"viewport",
".",
"scale",
")",
";",
"let",
"x",
"=",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'x'",
",",
"10",
")",
")",
";",
"let",
"y",
"=",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'y'",
",",
"10",
")",
")",
";",
"let",
"width",
"=",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'width'",
")",
",",
"10",
")",
";",
"let",
"height",
"=",
"parseInt",
"(",
"node",
".",
"getAttribute",
"(",
"'height'",
")",
",",
"10",
")",
";",
"let",
"path",
"=",
"node",
".",
"querySelector",
"(",
"'path'",
")",
";",
"let",
"svg",
"=",
"path",
".",
"parentNode",
";",
"// Scale width/height",
"[",
"node",
",",
"svg",
",",
"path",
",",
"node",
".",
"querySelector",
"(",
"'rect'",
")",
"]",
".",
"forEach",
"(",
"(",
"n",
")",
"=>",
"{",
"n",
".",
"setAttribute",
"(",
"'width'",
",",
"parseInt",
"(",
"n",
".",
"getAttribute",
"(",
"'width'",
")",
",",
"10",
")",
"*",
"viewport",
".",
"scale",
")",
";",
"n",
".",
"setAttribute",
"(",
"'height'",
",",
"parseInt",
"(",
"n",
".",
"getAttribute",
"(",
"'height'",
")",
",",
"10",
")",
"*",
"viewport",
".",
"scale",
")",
";",
"}",
")",
";",
"// Transform path but keep scale at 100% since it will be handled natively",
"transform",
"(",
"path",
",",
"objectAssign",
"(",
"{",
"}",
",",
"viewport",
",",
"{",
"scale",
":",
"1",
"}",
")",
")",
";",
"switch",
"(",
"viewport",
".",
"rotation",
"%",
"360",
")",
"{",
"case",
"90",
":",
"node",
".",
"setAttribute",
"(",
"'x'",
",",
"viewport",
".",
"width",
"-",
"y",
"-",
"width",
")",
";",
"node",
".",
"setAttribute",
"(",
"'y'",
",",
"x",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'x'",
",",
"1",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'y'",
",",
"0",
")",
";",
"break",
";",
"case",
"180",
":",
"node",
".",
"setAttribute",
"(",
"'x'",
",",
"viewport",
".",
"width",
"-",
"x",
"-",
"width",
")",
";",
"node",
".",
"setAttribute",
"(",
"'y'",
",",
"viewport",
".",
"height",
"-",
"y",
"-",
"height",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'y'",
",",
"2",
")",
";",
"break",
";",
"case",
"270",
":",
"node",
".",
"setAttribute",
"(",
"'x'",
",",
"y",
")",
";",
"node",
".",
"setAttribute",
"(",
"'y'",
",",
"viewport",
".",
"height",
"-",
"x",
"-",
"height",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'x'",
",",
"-",
"1",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'y'",
",",
"0",
")",
";",
"break",
";",
"}",
"}",
"return",
"node",
";",
"}"
] |
Transform the rotation and scale of a node using SVG's native transform attribute.
@param {Node} node The node to be transformed
@param {Object} viewport The page's viewport data
@return {Node}
|
[
"Transform",
"the",
"rotation",
"and",
"scale",
"of",
"a",
"node",
"using",
"SVG",
"s",
"native",
"transform",
"attribute",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/render/appendChild.js#L51-L100
|
11,535
|
instructure/pdf-annotate.js
|
src/UI/page.js
|
scalePage
|
function scalePage(pageNumber, viewport, context) {
let page = document.getElementById(`pageContainer${pageNumber}`);
let canvas = page.querySelector('.canvasWrapper canvas');
let svg = page.querySelector('.annotationLayer');
let wrapper = page.querySelector('.canvasWrapper');
let textLayer = page.querySelector('.textLayer');
let outputScale = getOutputScale(context);
let transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
let sfx = approximateFraction(outputScale.sx);
let sfy = approximateFraction(outputScale.sy);
// Adjust width/height for scale
page.style.visibility = '';
canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
canvas.style.height = roundToDivide(viewport.height, sfx[1]) + 'px';
svg.setAttribute('width', viewport.width);
svg.setAttribute('height', viewport.height);
svg.style.width = `${viewport.width}px`;
svg.style.height = `${viewport.height}px`;
page.style.width = `${viewport.width}px`;
page.style.height = `${viewport.height}px`;
wrapper.style.width = `${viewport.width}px`;
wrapper.style.height = `${viewport.height}px`;
textLayer.style.width = `${viewport.width}px`;
textLayer.style.height = `${viewport.height}px`;
return transform;
}
|
javascript
|
function scalePage(pageNumber, viewport, context) {
let page = document.getElementById(`pageContainer${pageNumber}`);
let canvas = page.querySelector('.canvasWrapper canvas');
let svg = page.querySelector('.annotationLayer');
let wrapper = page.querySelector('.canvasWrapper');
let textLayer = page.querySelector('.textLayer');
let outputScale = getOutputScale(context);
let transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
let sfx = approximateFraction(outputScale.sx);
let sfy = approximateFraction(outputScale.sy);
// Adjust width/height for scale
page.style.visibility = '';
canvas.width = roundToDivide(viewport.width * outputScale.sx, sfx[0]);
canvas.height = roundToDivide(viewport.height * outputScale.sy, sfy[0]);
canvas.style.width = roundToDivide(viewport.width, sfx[1]) + 'px';
canvas.style.height = roundToDivide(viewport.height, sfx[1]) + 'px';
svg.setAttribute('width', viewport.width);
svg.setAttribute('height', viewport.height);
svg.style.width = `${viewport.width}px`;
svg.style.height = `${viewport.height}px`;
page.style.width = `${viewport.width}px`;
page.style.height = `${viewport.height}px`;
wrapper.style.width = `${viewport.width}px`;
wrapper.style.height = `${viewport.height}px`;
textLayer.style.width = `${viewport.width}px`;
textLayer.style.height = `${viewport.height}px`;
return transform;
}
|
[
"function",
"scalePage",
"(",
"pageNumber",
",",
"viewport",
",",
"context",
")",
"{",
"let",
"page",
"=",
"document",
".",
"getElementById",
"(",
"`",
"${",
"pageNumber",
"}",
"`",
")",
";",
"let",
"canvas",
"=",
"page",
".",
"querySelector",
"(",
"'.canvasWrapper canvas'",
")",
";",
"let",
"svg",
"=",
"page",
".",
"querySelector",
"(",
"'.annotationLayer'",
")",
";",
"let",
"wrapper",
"=",
"page",
".",
"querySelector",
"(",
"'.canvasWrapper'",
")",
";",
"let",
"textLayer",
"=",
"page",
".",
"querySelector",
"(",
"'.textLayer'",
")",
";",
"let",
"outputScale",
"=",
"getOutputScale",
"(",
"context",
")",
";",
"let",
"transform",
"=",
"!",
"outputScale",
".",
"scaled",
"?",
"null",
":",
"[",
"outputScale",
".",
"sx",
",",
"0",
",",
"0",
",",
"outputScale",
".",
"sy",
",",
"0",
",",
"0",
"]",
";",
"let",
"sfx",
"=",
"approximateFraction",
"(",
"outputScale",
".",
"sx",
")",
";",
"let",
"sfy",
"=",
"approximateFraction",
"(",
"outputScale",
".",
"sy",
")",
";",
"// Adjust width/height for scale",
"page",
".",
"style",
".",
"visibility",
"=",
"''",
";",
"canvas",
".",
"width",
"=",
"roundToDivide",
"(",
"viewport",
".",
"width",
"*",
"outputScale",
".",
"sx",
",",
"sfx",
"[",
"0",
"]",
")",
";",
"canvas",
".",
"height",
"=",
"roundToDivide",
"(",
"viewport",
".",
"height",
"*",
"outputScale",
".",
"sy",
",",
"sfy",
"[",
"0",
"]",
")",
";",
"canvas",
".",
"style",
".",
"width",
"=",
"roundToDivide",
"(",
"viewport",
".",
"width",
",",
"sfx",
"[",
"1",
"]",
")",
"+",
"'px'",
";",
"canvas",
".",
"style",
".",
"height",
"=",
"roundToDivide",
"(",
"viewport",
".",
"height",
",",
"sfx",
"[",
"1",
"]",
")",
"+",
"'px'",
";",
"svg",
".",
"setAttribute",
"(",
"'width'",
",",
"viewport",
".",
"width",
")",
";",
"svg",
".",
"setAttribute",
"(",
"'height'",
",",
"viewport",
".",
"height",
")",
";",
"svg",
".",
"style",
".",
"width",
"=",
"`",
"${",
"viewport",
".",
"width",
"}",
"`",
";",
"svg",
".",
"style",
".",
"height",
"=",
"`",
"${",
"viewport",
".",
"height",
"}",
"`",
";",
"page",
".",
"style",
".",
"width",
"=",
"`",
"${",
"viewport",
".",
"width",
"}",
"`",
";",
"page",
".",
"style",
".",
"height",
"=",
"`",
"${",
"viewport",
".",
"height",
"}",
"`",
";",
"wrapper",
".",
"style",
".",
"width",
"=",
"`",
"${",
"viewport",
".",
"width",
"}",
"`",
";",
"wrapper",
".",
"style",
".",
"height",
"=",
"`",
"${",
"viewport",
".",
"height",
"}",
"`",
";",
"textLayer",
".",
"style",
".",
"width",
"=",
"`",
"${",
"viewport",
".",
"width",
"}",
"`",
";",
"textLayer",
".",
"style",
".",
"height",
"=",
"`",
"${",
"viewport",
".",
"height",
"}",
"`",
";",
"return",
"transform",
";",
"}"
] |
Scale the elements of a page.
@param {Number} pageNumber The page number to be scaled
@param {Object} viewport The viewport of the PDF page (see pdfPage.getViewport(scale, rotate))
@param {Object} context The canvas context that the PDF page is rendered to
@return {Array} The transform data for rendering the PDF page
|
[
"Scale",
"the",
"elements",
"of",
"a",
"page",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/page.js#L112-L141
|
11,536
|
instructure/pdf-annotate.js
|
src/a11y/insertElementWithinElement.js
|
textLayerElementFromPoint
|
function textLayerElementFromPoint(x, y, pageNumber) {
let svg = document.querySelector(`svg[data-pdf-annotate-page="${pageNumber}"]`);
let rect = svg.getBoundingClientRect();
y = scaleUp(svg, {y}).y + rect.top;
x = scaleUp(svg, {x}).x + rect.left;
return [...svg.parentNode.querySelectorAll('.textLayer [data-canvas-width]')].filter((el) => {
return pointIntersectsRect(x, y, el.getBoundingClientRect());
})[0];
}
|
javascript
|
function textLayerElementFromPoint(x, y, pageNumber) {
let svg = document.querySelector(`svg[data-pdf-annotate-page="${pageNumber}"]`);
let rect = svg.getBoundingClientRect();
y = scaleUp(svg, {y}).y + rect.top;
x = scaleUp(svg, {x}).x + rect.left;
return [...svg.parentNode.querySelectorAll('.textLayer [data-canvas-width]')].filter((el) => {
return pointIntersectsRect(x, y, el.getBoundingClientRect());
})[0];
}
|
[
"function",
"textLayerElementFromPoint",
"(",
"x",
",",
"y",
",",
"pageNumber",
")",
"{",
"let",
"svg",
"=",
"document",
".",
"querySelector",
"(",
"`",
"${",
"pageNumber",
"}",
"`",
")",
";",
"let",
"rect",
"=",
"svg",
".",
"getBoundingClientRect",
"(",
")",
";",
"y",
"=",
"scaleUp",
"(",
"svg",
",",
"{",
"y",
"}",
")",
".",
"y",
"+",
"rect",
".",
"top",
";",
"x",
"=",
"scaleUp",
"(",
"svg",
",",
"{",
"x",
"}",
")",
".",
"x",
"+",
"rect",
".",
"left",
";",
"return",
"[",
"...",
"svg",
".",
"parentNode",
".",
"querySelectorAll",
"(",
"'.textLayer [data-canvas-width]'",
")",
"]",
".",
"filter",
"(",
"(",
"el",
")",
"=>",
"{",
"return",
"pointIntersectsRect",
"(",
"x",
",",
"y",
",",
"el",
".",
"getBoundingClientRect",
"(",
")",
")",
";",
"}",
")",
"[",
"0",
"]",
";",
"}"
] |
Get a text layer element at a given point on a page
@param {Number} x The x coordinate of the point
@param {Number} y The y coordinate of the point
@param {Number} pageNumber The page to limit elements to
@return {Element} First text layer element found at the point
|
[
"Get",
"a",
"text",
"layer",
"element",
"at",
"a",
"given",
"point",
"on",
"a",
"page"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/a11y/insertElementWithinElement.js#L84-L92
|
11,537
|
instructure/pdf-annotate.js
|
src/UI/pen.js
|
savePoint
|
function savePoint(x, y) {
let svg = findSVGAtPoint(x, y);
if (!svg) {
return;
}
let rect = svg.getBoundingClientRect();
let point = scaleDown(svg, {
x: x - rect.left,
y: y - rect.top
});
lines.push([point.x, point.y]);
if (lines.length <= 1) {
return;
}
if (path) {
svg.removeChild(path);
}
path = appendChild(svg, {
type: 'drawing',
color: _penColor,
width: _penSize,
lines
});
}
|
javascript
|
function savePoint(x, y) {
let svg = findSVGAtPoint(x, y);
if (!svg) {
return;
}
let rect = svg.getBoundingClientRect();
let point = scaleDown(svg, {
x: x - rect.left,
y: y - rect.top
});
lines.push([point.x, point.y]);
if (lines.length <= 1) {
return;
}
if (path) {
svg.removeChild(path);
}
path = appendChild(svg, {
type: 'drawing',
color: _penColor,
width: _penSize,
lines
});
}
|
[
"function",
"savePoint",
"(",
"x",
",",
"y",
")",
"{",
"let",
"svg",
"=",
"findSVGAtPoint",
"(",
"x",
",",
"y",
")",
";",
"if",
"(",
"!",
"svg",
")",
"{",
"return",
";",
"}",
"let",
"rect",
"=",
"svg",
".",
"getBoundingClientRect",
"(",
")",
";",
"let",
"point",
"=",
"scaleDown",
"(",
"svg",
",",
"{",
"x",
":",
"x",
"-",
"rect",
".",
"left",
",",
"y",
":",
"y",
"-",
"rect",
".",
"top",
"}",
")",
";",
"lines",
".",
"push",
"(",
"[",
"point",
".",
"x",
",",
"point",
".",
"y",
"]",
")",
";",
"if",
"(",
"lines",
".",
"length",
"<=",
"1",
")",
"{",
"return",
";",
"}",
"if",
"(",
"path",
")",
"{",
"svg",
".",
"removeChild",
"(",
"path",
")",
";",
"}",
"path",
"=",
"appendChild",
"(",
"svg",
",",
"{",
"type",
":",
"'drawing'",
",",
"color",
":",
"_penColor",
",",
"width",
":",
"_penSize",
",",
"lines",
"}",
")",
";",
"}"
] |
Save a point to the line being drawn.
@param {Number} x The x coordinate of the point
@param {Number} y The y coordinate of the point
|
[
"Save",
"a",
"point",
"to",
"the",
"line",
"being",
"drawn",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/pen.js#L87-L115
|
11,538
|
instructure/pdf-annotate.js
|
src/a11y/renderScreenReaderHints.js
|
sortByLinePoint
|
function sortByLinePoint(a, b) {
let lineA = a.lines[0];
let lineB = b.lines[0];
return sortByPoint(
{x: lineA[0], y: lineA[1]},
{x: lineB[0], y: lineB[1]}
);
}
|
javascript
|
function sortByLinePoint(a, b) {
let lineA = a.lines[0];
let lineB = b.lines[0];
return sortByPoint(
{x: lineA[0], y: lineA[1]},
{x: lineB[0], y: lineB[1]}
);
}
|
[
"function",
"sortByLinePoint",
"(",
"a",
",",
"b",
")",
"{",
"let",
"lineA",
"=",
"a",
".",
"lines",
"[",
"0",
"]",
";",
"let",
"lineB",
"=",
"b",
".",
"lines",
"[",
"0",
"]",
";",
"return",
"sortByPoint",
"(",
"{",
"x",
":",
"lineA",
"[",
"0",
"]",
",",
"y",
":",
"lineA",
"[",
"1",
"]",
"}",
",",
"{",
"x",
":",
"lineB",
"[",
"0",
"]",
",",
"y",
":",
"lineB",
"[",
"1",
"]",
"}",
")",
";",
"}"
] |
Sort annotation by it's first line
|
[
"Sort",
"annotation",
"by",
"it",
"s",
"first",
"line"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/a11y/renderScreenReaderHints.js#L42-L49
|
11,539
|
instructure/pdf-annotate.js
|
src/UI/point.js
|
savePoint
|
function savePoint() {
if (input.value.trim().length > 0) {
let clientX = parseInt(input.style.left, 10);
let clientY = parseInt(input.style.top, 10);
let content = input.value.trim();
let svg = findSVGAtPoint(clientX, clientY);
if (!svg) {
return;
}
let rect = svg.getBoundingClientRect();
let { documentId, pageNumber } = getMetadata(svg);
let annotation = Object.assign({
type: 'point'
}, scaleDown(svg, {
x: clientX - rect.left,
y: clientY - rect.top
})
);
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
PDFJSAnnotate.getStoreAdapter().addComment(
documentId,
annotation.uuid,
content
);
appendChild(svg, annotation);
});
}
closeInput();
}
|
javascript
|
function savePoint() {
if (input.value.trim().length > 0) {
let clientX = parseInt(input.style.left, 10);
let clientY = parseInt(input.style.top, 10);
let content = input.value.trim();
let svg = findSVGAtPoint(clientX, clientY);
if (!svg) {
return;
}
let rect = svg.getBoundingClientRect();
let { documentId, pageNumber } = getMetadata(svg);
let annotation = Object.assign({
type: 'point'
}, scaleDown(svg, {
x: clientX - rect.left,
y: clientY - rect.top
})
);
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
PDFJSAnnotate.getStoreAdapter().addComment(
documentId,
annotation.uuid,
content
);
appendChild(svg, annotation);
});
}
closeInput();
}
|
[
"function",
"savePoint",
"(",
")",
"{",
"if",
"(",
"input",
".",
"value",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
")",
"{",
"let",
"clientX",
"=",
"parseInt",
"(",
"input",
".",
"style",
".",
"left",
",",
"10",
")",
";",
"let",
"clientY",
"=",
"parseInt",
"(",
"input",
".",
"style",
".",
"top",
",",
"10",
")",
";",
"let",
"content",
"=",
"input",
".",
"value",
".",
"trim",
"(",
")",
";",
"let",
"svg",
"=",
"findSVGAtPoint",
"(",
"clientX",
",",
"clientY",
")",
";",
"if",
"(",
"!",
"svg",
")",
"{",
"return",
";",
"}",
"let",
"rect",
"=",
"svg",
".",
"getBoundingClientRect",
"(",
")",
";",
"let",
"{",
"documentId",
",",
"pageNumber",
"}",
"=",
"getMetadata",
"(",
"svg",
")",
";",
"let",
"annotation",
"=",
"Object",
".",
"assign",
"(",
"{",
"type",
":",
"'point'",
"}",
",",
"scaleDown",
"(",
"svg",
",",
"{",
"x",
":",
"clientX",
"-",
"rect",
".",
"left",
",",
"y",
":",
"clientY",
"-",
"rect",
".",
"top",
"}",
")",
")",
";",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"addAnnotation",
"(",
"documentId",
",",
"pageNumber",
",",
"annotation",
")",
".",
"then",
"(",
"(",
"annotation",
")",
"=>",
"{",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"addComment",
"(",
"documentId",
",",
"annotation",
".",
"uuid",
",",
"content",
")",
";",
"appendChild",
"(",
"svg",
",",
"annotation",
")",
";",
"}",
")",
";",
"}",
"closeInput",
"(",
")",
";",
"}"
] |
Save a new point annotation from input
|
[
"Save",
"a",
"new",
"point",
"annotation",
"from",
"input"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/point.js#L62-L95
|
11,540
|
instructure/pdf-annotate.js
|
shared/pdf_viewer.js
|
binarySearchFirstItem
|
function binarySearchFirstItem(items, condition) {
var minIndex = 0;
var maxIndex = items.length - 1;
if (items.length === 0 || !condition(items[maxIndex])) {
return items.length;
}
if (condition(items[minIndex])) {
return minIndex;
}
while (minIndex < maxIndex) {
var currentIndex = (minIndex + maxIndex) >> 1;
var currentItem = items[currentIndex];
if (condition(currentItem)) {
maxIndex = currentIndex;
} else {
minIndex = currentIndex + 1;
}
}
return minIndex; /* === maxIndex */
}
|
javascript
|
function binarySearchFirstItem(items, condition) {
var minIndex = 0;
var maxIndex = items.length - 1;
if (items.length === 0 || !condition(items[maxIndex])) {
return items.length;
}
if (condition(items[minIndex])) {
return minIndex;
}
while (minIndex < maxIndex) {
var currentIndex = (minIndex + maxIndex) >> 1;
var currentItem = items[currentIndex];
if (condition(currentItem)) {
maxIndex = currentIndex;
} else {
minIndex = currentIndex + 1;
}
}
return minIndex; /* === maxIndex */
}
|
[
"function",
"binarySearchFirstItem",
"(",
"items",
",",
"condition",
")",
"{",
"var",
"minIndex",
"=",
"0",
";",
"var",
"maxIndex",
"=",
"items",
".",
"length",
"-",
"1",
";",
"if",
"(",
"items",
".",
"length",
"===",
"0",
"||",
"!",
"condition",
"(",
"items",
"[",
"maxIndex",
"]",
")",
")",
"{",
"return",
"items",
".",
"length",
";",
"}",
"if",
"(",
"condition",
"(",
"items",
"[",
"minIndex",
"]",
")",
")",
"{",
"return",
"minIndex",
";",
"}",
"while",
"(",
"minIndex",
"<",
"maxIndex",
")",
"{",
"var",
"currentIndex",
"=",
"(",
"minIndex",
"+",
"maxIndex",
")",
">>",
"1",
";",
"var",
"currentItem",
"=",
"items",
"[",
"currentIndex",
"]",
";",
"if",
"(",
"condition",
"(",
"currentItem",
")",
")",
"{",
"maxIndex",
"=",
"currentIndex",
";",
"}",
"else",
"{",
"minIndex",
"=",
"currentIndex",
"+",
"1",
";",
"}",
"}",
"return",
"minIndex",
";",
"/* === maxIndex */",
"}"
] |
Use binary search to find the index of the first item in a given array which
passes a given condition. The items are expected to be sorted in the sense
that if the condition is true for one item in the array, then it is also true
for all following items.
@returns {Number} Index of the first array element to pass the test,
or |items.length| if no such element exists.
|
[
"Use",
"binary",
"search",
"to",
"find",
"the",
"index",
"of",
"the",
"first",
"item",
"in",
"a",
"given",
"array",
"which",
"passes",
"a",
"given",
"condition",
".",
"The",
"items",
"are",
"expected",
"to",
"be",
"sorted",
"in",
"the",
"sense",
"that",
"if",
"the",
"condition",
"is",
"true",
"for",
"one",
"item",
"in",
"the",
"array",
"then",
"it",
"is",
"also",
"true",
"for",
"all",
"following",
"items",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/shared/pdf_viewer.js#L161-L182
|
11,541
|
instructure/pdf-annotate.js
|
shared/pdf_viewer.js
|
PDFRenderingQueue_renderView
|
function PDFRenderingQueue_renderView(view) {
var state = view.renderingState;
switch (state) {
case RenderingStates.FINISHED:
return false;
case RenderingStates.PAUSED:
this.highestPriorityPage = view.renderingId;
view.resume();
break;
case RenderingStates.RUNNING:
this.highestPriorityPage = view.renderingId;
break;
case RenderingStates.INITIAL:
this.highestPriorityPage = view.renderingId;
var continueRendering = function () {
this.renderHighestPriority();
}.bind(this);
view.draw().then(continueRendering, continueRendering);
break;
}
return true;
}
|
javascript
|
function PDFRenderingQueue_renderView(view) {
var state = view.renderingState;
switch (state) {
case RenderingStates.FINISHED:
return false;
case RenderingStates.PAUSED:
this.highestPriorityPage = view.renderingId;
view.resume();
break;
case RenderingStates.RUNNING:
this.highestPriorityPage = view.renderingId;
break;
case RenderingStates.INITIAL:
this.highestPriorityPage = view.renderingId;
var continueRendering = function () {
this.renderHighestPriority();
}.bind(this);
view.draw().then(continueRendering, continueRendering);
break;
}
return true;
}
|
[
"function",
"PDFRenderingQueue_renderView",
"(",
"view",
")",
"{",
"var",
"state",
"=",
"view",
".",
"renderingState",
";",
"switch",
"(",
"state",
")",
"{",
"case",
"RenderingStates",
".",
"FINISHED",
":",
"return",
"false",
";",
"case",
"RenderingStates",
".",
"PAUSED",
":",
"this",
".",
"highestPriorityPage",
"=",
"view",
".",
"renderingId",
";",
"view",
".",
"resume",
"(",
")",
";",
"break",
";",
"case",
"RenderingStates",
".",
"RUNNING",
":",
"this",
".",
"highestPriorityPage",
"=",
"view",
".",
"renderingId",
";",
"break",
";",
"case",
"RenderingStates",
".",
"INITIAL",
":",
"this",
".",
"highestPriorityPage",
"=",
"view",
".",
"renderingId",
";",
"var",
"continueRendering",
"=",
"function",
"(",
")",
"{",
"this",
".",
"renderHighestPriority",
"(",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
";",
"view",
".",
"draw",
"(",
")",
".",
"then",
"(",
"continueRendering",
",",
"continueRendering",
")",
";",
"break",
";",
"}",
"return",
"true",
";",
"}"
] |
Render a page or thumbnail view. This calls the appropriate function
based on the views state. If the view is already rendered it will return
false.
@param {IRenderableView} view
|
[
"Render",
"a",
"page",
"or",
"thumbnail",
"view",
".",
"This",
"calls",
"the",
"appropriate",
"function",
"based",
"on",
"the",
"views",
"state",
".",
"If",
"the",
"view",
"is",
"already",
"rendered",
"it",
"will",
"return",
"false",
"."
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/shared/pdf_viewer.js#L846-L867
|
11,542
|
instructure/pdf-annotate.js
|
src/a11y/initEventHandlers.js
|
reorderAnnotationsByType
|
function reorderAnnotationsByType(documentId, pageNumber, type) {
PDFJSAnnotate.getStoreAdapter().getAnnotations(documentId, pageNumber)
.then((annotations) => {
return annotations.annotations.filter((a) => {
return a.type === type;
});
})
.then((annotations) => {
annotations.forEach((a) => {
removeAnnotation(documentId, a.uuid);
});
return annotations;
})
.then(renderScreenReaderHints);
}
|
javascript
|
function reorderAnnotationsByType(documentId, pageNumber, type) {
PDFJSAnnotate.getStoreAdapter().getAnnotations(documentId, pageNumber)
.then((annotations) => {
return annotations.annotations.filter((a) => {
return a.type === type;
});
})
.then((annotations) => {
annotations.forEach((a) => {
removeAnnotation(documentId, a.uuid);
});
return annotations;
})
.then(renderScreenReaderHints);
}
|
[
"function",
"reorderAnnotationsByType",
"(",
"documentId",
",",
"pageNumber",
",",
"type",
")",
"{",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"getAnnotations",
"(",
"documentId",
",",
"pageNumber",
")",
".",
"then",
"(",
"(",
"annotations",
")",
"=>",
"{",
"return",
"annotations",
".",
"annotations",
".",
"filter",
"(",
"(",
"a",
")",
"=>",
"{",
"return",
"a",
".",
"type",
"===",
"type",
";",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"(",
"annotations",
")",
"=>",
"{",
"annotations",
".",
"forEach",
"(",
"(",
"a",
")",
"=>",
"{",
"removeAnnotation",
"(",
"documentId",
",",
"a",
".",
"uuid",
")",
";",
"}",
")",
";",
"return",
"annotations",
";",
"}",
")",
".",
"then",
"(",
"renderScreenReaderHints",
")",
";",
"}"
] |
Reorder the annotation numbers by annotation type
@param {String} documentId The ID of the document
@param {Number} pageNumber The page number of the annotations
@param {Strig} type The annotation type
|
[
"Reorder",
"the",
"annotation",
"numbers",
"by",
"annotation",
"type"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/a11y/initEventHandlers.js#L30-L45
|
11,543
|
instructure/pdf-annotate.js
|
src/a11y/initEventHandlers.js
|
insertComment
|
function insertComment(documentId, annotationId, comment) {
let list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
let promise;
if (!list) {
promise = renderScreenReaderComments(documentId, annotationId, []).then(() => {
list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
return true;
});
} else {
promise = Promise.resolve(true);
}
promise.then(() => {
insertScreenReaderComment(comment);
});
}
|
javascript
|
function insertComment(documentId, annotationId, comment) {
let list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
let promise;
if (!list) {
promise = renderScreenReaderComments(documentId, annotationId, []).then(() => {
list = document.querySelector(`pdf-annotate-screenreader-comment-list-${annotationId}`);
return true;
});
} else {
promise = Promise.resolve(true);
}
promise.then(() => {
insertScreenReaderComment(comment);
});
}
|
[
"function",
"insertComment",
"(",
"documentId",
",",
"annotationId",
",",
"comment",
")",
"{",
"let",
"list",
"=",
"document",
".",
"querySelector",
"(",
"`",
"${",
"annotationId",
"}",
"`",
")",
";",
"let",
"promise",
";",
"if",
"(",
"!",
"list",
")",
"{",
"promise",
"=",
"renderScreenReaderComments",
"(",
"documentId",
",",
"annotationId",
",",
"[",
"]",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"list",
"=",
"document",
".",
"querySelector",
"(",
"`",
"${",
"annotationId",
"}",
"`",
")",
";",
"return",
"true",
";",
"}",
")",
";",
"}",
"else",
"{",
"promise",
"=",
"Promise",
".",
"resolve",
"(",
"true",
")",
";",
"}",
"promise",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"insertScreenReaderComment",
"(",
"comment",
")",
";",
"}",
")",
";",
"}"
] |
Insert a screen reader hint for a comment
@param {String} documentId The ID of the document
@param {String} annotationId The ID of tha assocated annotation
@param {Object} comment The comment to insert a hint for
|
[
"Insert",
"a",
"screen",
"reader",
"hint",
"for",
"a",
"comment"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/a11y/initEventHandlers.js#L65-L81
|
11,544
|
instructure/pdf-annotate.js
|
src/a11y/initEventHandlers.js
|
removeElementById
|
function removeElementById(elementId) {
let el = document.getElementById(elementId);
if (el) {
el.parentNode.removeChild(el);
}
}
|
javascript
|
function removeElementById(elementId) {
let el = document.getElementById(elementId);
if (el) {
el.parentNode.removeChild(el);
}
}
|
[
"function",
"removeElementById",
"(",
"elementId",
")",
"{",
"let",
"el",
"=",
"document",
".",
"getElementById",
"(",
"elementId",
")",
";",
"if",
"(",
"el",
")",
"{",
"el",
".",
"parentNode",
".",
"removeChild",
"(",
"el",
")",
";",
"}",
"}"
] |
Remove an element from the DOM by it's ID if it exists
@param {String} elementID The ID of the element to be removed
|
[
"Remove",
"an",
"element",
"from",
"the",
"DOM",
"by",
"it",
"s",
"ID",
"if",
"it",
"exists"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/a11y/initEventHandlers.js#L98-L103
|
11,545
|
instructure/pdf-annotate.js
|
src/UI/rect.js
|
getSelectionRects
|
function getSelectionRects() {
try {
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let rects = range.getClientRects();
if (rects.length > 0 &&
rects[0].width > 0 &&
rects[0].height > 0) {
return rects;
}
} catch (e) {}
return null;
}
|
javascript
|
function getSelectionRects() {
try {
let selection = window.getSelection();
let range = selection.getRangeAt(0);
let rects = range.getClientRects();
if (rects.length > 0 &&
rects[0].width > 0 &&
rects[0].height > 0) {
return rects;
}
} catch (e) {}
return null;
}
|
[
"function",
"getSelectionRects",
"(",
")",
"{",
"try",
"{",
"let",
"selection",
"=",
"window",
".",
"getSelection",
"(",
")",
";",
"let",
"range",
"=",
"selection",
".",
"getRangeAt",
"(",
"0",
")",
";",
"let",
"rects",
"=",
"range",
".",
"getClientRects",
"(",
")",
";",
"if",
"(",
"rects",
".",
"length",
">",
"0",
"&&",
"rects",
"[",
"0",
"]",
".",
"width",
">",
"0",
"&&",
"rects",
"[",
"0",
"]",
".",
"height",
">",
"0",
")",
"{",
"return",
"rects",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"return",
"null",
";",
"}"
] |
Get the current window selection as rects
@return {Array} An Array of rects
|
[
"Get",
"the",
"current",
"window",
"selection",
"as",
"rects"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/rect.js#L25-L39
|
11,546
|
instructure/pdf-annotate.js
|
src/UI/rect.js
|
saveRect
|
function saveRect(type, rects, color) {
let svg = findSVGAtPoint(rects[0].left, rects[0].top);
let node;
let annotation;
if (!svg) {
return;
}
let boundingRect = svg.getBoundingClientRect();
if (!color) {
if (type === 'highlight') {
color = 'FFFF00';
} else if (type === 'strikeout') {
color = 'FF0000';
}
}
// Initialize the annotation
annotation = {
type,
color,
rectangles: [...rects].map((r) => {
let offset = 0;
if (type === 'strikeout') {
offset = r.height / 2;
}
return scaleDown(svg, {
y: (r.top + offset) - boundingRect.top,
x: r.left - boundingRect.left,
width: r.width,
height: r.height
});
}).filter((r) => r.width > 0 && r.height > 0 && r.x > -1 && r.y > -1)
};
// Short circuit if no rectangles exist
if (annotation.rectangles.length === 0) {
return;
}
// Special treatment for area as it only supports a single rect
if (type === 'area') {
let rect = annotation.rectangles[0];
delete annotation.rectangles;
annotation.x = rect.x;
annotation.y = rect.y;
annotation.width = rect.width;
annotation.height = rect.height;
}
let { documentId, pageNumber } = getMetadata(svg);
// Add the annotation
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
appendChild(svg, annotation);
});
}
|
javascript
|
function saveRect(type, rects, color) {
let svg = findSVGAtPoint(rects[0].left, rects[0].top);
let node;
let annotation;
if (!svg) {
return;
}
let boundingRect = svg.getBoundingClientRect();
if (!color) {
if (type === 'highlight') {
color = 'FFFF00';
} else if (type === 'strikeout') {
color = 'FF0000';
}
}
// Initialize the annotation
annotation = {
type,
color,
rectangles: [...rects].map((r) => {
let offset = 0;
if (type === 'strikeout') {
offset = r.height / 2;
}
return scaleDown(svg, {
y: (r.top + offset) - boundingRect.top,
x: r.left - boundingRect.left,
width: r.width,
height: r.height
});
}).filter((r) => r.width > 0 && r.height > 0 && r.x > -1 && r.y > -1)
};
// Short circuit if no rectangles exist
if (annotation.rectangles.length === 0) {
return;
}
// Special treatment for area as it only supports a single rect
if (type === 'area') {
let rect = annotation.rectangles[0];
delete annotation.rectangles;
annotation.x = rect.x;
annotation.y = rect.y;
annotation.width = rect.width;
annotation.height = rect.height;
}
let { documentId, pageNumber } = getMetadata(svg);
// Add the annotation
PDFJSAnnotate.getStoreAdapter().addAnnotation(documentId, pageNumber, annotation)
.then((annotation) => {
appendChild(svg, annotation);
});
}
|
[
"function",
"saveRect",
"(",
"type",
",",
"rects",
",",
"color",
")",
"{",
"let",
"svg",
"=",
"findSVGAtPoint",
"(",
"rects",
"[",
"0",
"]",
".",
"left",
",",
"rects",
"[",
"0",
"]",
".",
"top",
")",
";",
"let",
"node",
";",
"let",
"annotation",
";",
"if",
"(",
"!",
"svg",
")",
"{",
"return",
";",
"}",
"let",
"boundingRect",
"=",
"svg",
".",
"getBoundingClientRect",
"(",
")",
";",
"if",
"(",
"!",
"color",
")",
"{",
"if",
"(",
"type",
"===",
"'highlight'",
")",
"{",
"color",
"=",
"'FFFF00'",
";",
"}",
"else",
"if",
"(",
"type",
"===",
"'strikeout'",
")",
"{",
"color",
"=",
"'FF0000'",
";",
"}",
"}",
"// Initialize the annotation",
"annotation",
"=",
"{",
"type",
",",
"color",
",",
"rectangles",
":",
"[",
"...",
"rects",
"]",
".",
"map",
"(",
"(",
"r",
")",
"=>",
"{",
"let",
"offset",
"=",
"0",
";",
"if",
"(",
"type",
"===",
"'strikeout'",
")",
"{",
"offset",
"=",
"r",
".",
"height",
"/",
"2",
";",
"}",
"return",
"scaleDown",
"(",
"svg",
",",
"{",
"y",
":",
"(",
"r",
".",
"top",
"+",
"offset",
")",
"-",
"boundingRect",
".",
"top",
",",
"x",
":",
"r",
".",
"left",
"-",
"boundingRect",
".",
"left",
",",
"width",
":",
"r",
".",
"width",
",",
"height",
":",
"r",
".",
"height",
"}",
")",
";",
"}",
")",
".",
"filter",
"(",
"(",
"r",
")",
"=>",
"r",
".",
"width",
">",
"0",
"&&",
"r",
".",
"height",
">",
"0",
"&&",
"r",
".",
"x",
">",
"-",
"1",
"&&",
"r",
".",
"y",
">",
"-",
"1",
")",
"}",
";",
"// Short circuit if no rectangles exist",
"if",
"(",
"annotation",
".",
"rectangles",
".",
"length",
"===",
"0",
")",
"{",
"return",
";",
"}",
"// Special treatment for area as it only supports a single rect",
"if",
"(",
"type",
"===",
"'area'",
")",
"{",
"let",
"rect",
"=",
"annotation",
".",
"rectangles",
"[",
"0",
"]",
";",
"delete",
"annotation",
".",
"rectangles",
";",
"annotation",
".",
"x",
"=",
"rect",
".",
"x",
";",
"annotation",
".",
"y",
"=",
"rect",
".",
"y",
";",
"annotation",
".",
"width",
"=",
"rect",
".",
"width",
";",
"annotation",
".",
"height",
"=",
"rect",
".",
"height",
";",
"}",
"let",
"{",
"documentId",
",",
"pageNumber",
"}",
"=",
"getMetadata",
"(",
"svg",
")",
";",
"// Add the annotation",
"PDFJSAnnotate",
".",
"getStoreAdapter",
"(",
")",
".",
"addAnnotation",
"(",
"documentId",
",",
"pageNumber",
",",
"annotation",
")",
".",
"then",
"(",
"(",
"annotation",
")",
"=>",
"{",
"appendChild",
"(",
"svg",
",",
"annotation",
")",
";",
"}",
")",
";",
"}"
] |
Save a rect annotation
@param {String} type The type of rect (area, highlight, strikeout)
@param {Array} rects The rects to use for annotation
@param {String} color The color of the rects
|
[
"Save",
"a",
"rect",
"annotation"
] |
f56e8aa2027326894861ef6b060824137e79a1be
|
https://github.com/instructure/pdf-annotate.js/blob/f56e8aa2027326894861ef6b060824137e79a1be/src/UI/rect.js#L146-L207
|
11,547
|
rikschennink/fitty
|
dist/fitty.module.js
|
redraw
|
function redraw(fitties) {
// getting info from the DOM at this point should not trigger a reflow, let's gather as much intel as possible before triggering a reflow
// check if styles of all fitties have been computed
fitties.filter(function (f) {
return !f.styleComputed;
}).forEach(function (f) {
f.styleComputed = computeStyle(f);
});
// restyle elements that require pre-styling, this triggers a reflow, please try to prevent by adding CSS rules (see docs)
fitties.filter(shouldPreStyle).forEach(applyStyle);
// we now determine which fitties should be redrawn
var fittiesToRedraw = fitties.filter(shouldRedraw);
// we calculate final styles for these fitties
fittiesToRedraw.forEach(calculateStyles);
// now we apply the calculated styles from our previous loop
fittiesToRedraw.forEach(function (f) {
applyStyle(f);
markAsClean(f);
});
// now we dispatch events for all restyled fitties
fittiesToRedraw.forEach(dispatchFitEvent);
}
|
javascript
|
function redraw(fitties) {
// getting info from the DOM at this point should not trigger a reflow, let's gather as much intel as possible before triggering a reflow
// check if styles of all fitties have been computed
fitties.filter(function (f) {
return !f.styleComputed;
}).forEach(function (f) {
f.styleComputed = computeStyle(f);
});
// restyle elements that require pre-styling, this triggers a reflow, please try to prevent by adding CSS rules (see docs)
fitties.filter(shouldPreStyle).forEach(applyStyle);
// we now determine which fitties should be redrawn
var fittiesToRedraw = fitties.filter(shouldRedraw);
// we calculate final styles for these fitties
fittiesToRedraw.forEach(calculateStyles);
// now we apply the calculated styles from our previous loop
fittiesToRedraw.forEach(function (f) {
applyStyle(f);
markAsClean(f);
});
// now we dispatch events for all restyled fitties
fittiesToRedraw.forEach(dispatchFitEvent);
}
|
[
"function",
"redraw",
"(",
"fitties",
")",
"{",
"// getting info from the DOM at this point should not trigger a reflow, let's gather as much intel as possible before triggering a reflow",
"// check if styles of all fitties have been computed",
"fitties",
".",
"filter",
"(",
"function",
"(",
"f",
")",
"{",
"return",
"!",
"f",
".",
"styleComputed",
";",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"f",
")",
"{",
"f",
".",
"styleComputed",
"=",
"computeStyle",
"(",
"f",
")",
";",
"}",
")",
";",
"// restyle elements that require pre-styling, this triggers a reflow, please try to prevent by adding CSS rules (see docs)",
"fitties",
".",
"filter",
"(",
"shouldPreStyle",
")",
".",
"forEach",
"(",
"applyStyle",
")",
";",
"// we now determine which fitties should be redrawn",
"var",
"fittiesToRedraw",
"=",
"fitties",
".",
"filter",
"(",
"shouldRedraw",
")",
";",
"// we calculate final styles for these fitties",
"fittiesToRedraw",
".",
"forEach",
"(",
"calculateStyles",
")",
";",
"// now we apply the calculated styles from our previous loop",
"fittiesToRedraw",
".",
"forEach",
"(",
"function",
"(",
"f",
")",
"{",
"applyStyle",
"(",
"f",
")",
";",
"markAsClean",
"(",
"f",
")",
";",
"}",
")",
";",
"// now we dispatch events for all restyled fitties",
"fittiesToRedraw",
".",
"forEach",
"(",
"dispatchFitEvent",
")",
";",
"}"
] |
redraws fitties so they nicely fit their parent container
|
[
"redraws",
"fitties",
"so",
"they",
"nicely",
"fit",
"their",
"parent",
"container"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L58-L86
|
11,548
|
rikschennink/fitty
|
dist/fitty.module.js
|
shouldRedraw
|
function shouldRedraw(f) {
return f.dirty !== DrawState.DIRTY_LAYOUT || f.dirty === DrawState.DIRTY_LAYOUT && f.element.parentNode.clientWidth !== f.availableWidth;
}
|
javascript
|
function shouldRedraw(f) {
return f.dirty !== DrawState.DIRTY_LAYOUT || f.dirty === DrawState.DIRTY_LAYOUT && f.element.parentNode.clientWidth !== f.availableWidth;
}
|
[
"function",
"shouldRedraw",
"(",
"f",
")",
"{",
"return",
"f",
".",
"dirty",
"!==",
"DrawState",
".",
"DIRTY_LAYOUT",
"||",
"f",
".",
"dirty",
"===",
"DrawState",
".",
"DIRTY_LAYOUT",
"&&",
"f",
".",
"element",
".",
"parentNode",
".",
"clientWidth",
"!==",
"f",
".",
"availableWidth",
";",
"}"
] |
should always redraw if is not dirty layout, if is dirty layout, only redraw if size has changed
|
[
"should",
"always",
"redraw",
"if",
"is",
"not",
"dirty",
"layout",
"if",
"is",
"dirty",
"layout",
"only",
"redraw",
"if",
"size",
"has",
"changed"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L111-L113
|
11,549
|
rikschennink/fitty
|
dist/fitty.module.js
|
computeStyle
|
function computeStyle(f) {
// get style properties
var style = w.getComputedStyle(f.element, null);
// get current font size in pixels (if we already calculated it, use the calculated version)
f.currentFontSize = parseInt(style.getPropertyValue('font-size'), 10);
// get display type and wrap mode
f.display = style.getPropertyValue('display');
f.whiteSpace = style.getPropertyValue('white-space');
}
|
javascript
|
function computeStyle(f) {
// get style properties
var style = w.getComputedStyle(f.element, null);
// get current font size in pixels (if we already calculated it, use the calculated version)
f.currentFontSize = parseInt(style.getPropertyValue('font-size'), 10);
// get display type and wrap mode
f.display = style.getPropertyValue('display');
f.whiteSpace = style.getPropertyValue('white-space');
}
|
[
"function",
"computeStyle",
"(",
"f",
")",
"{",
"// get style properties",
"var",
"style",
"=",
"w",
".",
"getComputedStyle",
"(",
"f",
".",
"element",
",",
"null",
")",
";",
"// get current font size in pixels (if we already calculated it, use the calculated version)",
"f",
".",
"currentFontSize",
"=",
"parseInt",
"(",
"style",
".",
"getPropertyValue",
"(",
"'font-size'",
")",
",",
"10",
")",
";",
"// get display type and wrap mode",
"f",
".",
"display",
"=",
"style",
".",
"getPropertyValue",
"(",
"'display'",
")",
";",
"f",
".",
"whiteSpace",
"=",
"style",
".",
"getPropertyValue",
"(",
"'white-space'",
")",
";",
"}"
] |
every fitty element is tested for invalid styles
|
[
"every",
"fitty",
"element",
"is",
"tested",
"for",
"invalid",
"styles"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L116-L127
|
11,550
|
rikschennink/fitty
|
dist/fitty.module.js
|
shouldPreStyle
|
function shouldPreStyle(f) {
var preStyle = false;
// if we already tested for prestyling we don't have to do it again
if (f.preStyleTestCompleted) {
return false;
}
// should have an inline style, if not, apply
if (!/inline-/.test(f.display)) {
preStyle = true;
f.display = 'inline-block';
}
// to correctly calculate dimensions the element should have whiteSpace set to nowrap
if (f.whiteSpace !== 'nowrap') {
preStyle = true;
f.whiteSpace = 'nowrap';
}
// we don't have to do this twice
f.preStyleTestCompleted = true;
return preStyle;
}
|
javascript
|
function shouldPreStyle(f) {
var preStyle = false;
// if we already tested for prestyling we don't have to do it again
if (f.preStyleTestCompleted) {
return false;
}
// should have an inline style, if not, apply
if (!/inline-/.test(f.display)) {
preStyle = true;
f.display = 'inline-block';
}
// to correctly calculate dimensions the element should have whiteSpace set to nowrap
if (f.whiteSpace !== 'nowrap') {
preStyle = true;
f.whiteSpace = 'nowrap';
}
// we don't have to do this twice
f.preStyleTestCompleted = true;
return preStyle;
}
|
[
"function",
"shouldPreStyle",
"(",
"f",
")",
"{",
"var",
"preStyle",
"=",
"false",
";",
"// if we already tested for prestyling we don't have to do it again",
"if",
"(",
"f",
".",
"preStyleTestCompleted",
")",
"{",
"return",
"false",
";",
"}",
"// should have an inline style, if not, apply",
"if",
"(",
"!",
"/",
"inline-",
"/",
".",
"test",
"(",
"f",
".",
"display",
")",
")",
"{",
"preStyle",
"=",
"true",
";",
"f",
".",
"display",
"=",
"'inline-block'",
";",
"}",
"// to correctly calculate dimensions the element should have whiteSpace set to nowrap",
"if",
"(",
"f",
".",
"whiteSpace",
"!==",
"'nowrap'",
")",
"{",
"preStyle",
"=",
"true",
";",
"f",
".",
"whiteSpace",
"=",
"'nowrap'",
";",
"}",
"// we don't have to do this twice",
"f",
".",
"preStyleTestCompleted",
"=",
"true",
";",
"return",
"preStyle",
";",
"}"
] |
determines if this fitty requires initial styling, can be prevented by applying correct styles through CSS
|
[
"determines",
"if",
"this",
"fitty",
"requires",
"initial",
"styling",
"can",
"be",
"prevented",
"by",
"applying",
"correct",
"styles",
"through",
"CSS"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L130-L155
|
11,551
|
rikschennink/fitty
|
dist/fitty.module.js
|
applyStyle
|
function applyStyle(f) {
// remember original style, we need this to restore the fitty style when unsubscribing
if (!f.originalStyle) {
f.originalStyle = f.element.getAttribute('style') || '';
}
// set the new style to the original style plus the fitty styles
f.element.style.cssText = f.originalStyle + ';white-space:' + f.whiteSpace + ';display:' + f.display + ';font-size:' + f.currentFontSize + 'px';
}
|
javascript
|
function applyStyle(f) {
// remember original style, we need this to restore the fitty style when unsubscribing
if (!f.originalStyle) {
f.originalStyle = f.element.getAttribute('style') || '';
}
// set the new style to the original style plus the fitty styles
f.element.style.cssText = f.originalStyle + ';white-space:' + f.whiteSpace + ';display:' + f.display + ';font-size:' + f.currentFontSize + 'px';
}
|
[
"function",
"applyStyle",
"(",
"f",
")",
"{",
"// remember original style, we need this to restore the fitty style when unsubscribing",
"if",
"(",
"!",
"f",
".",
"originalStyle",
")",
"{",
"f",
".",
"originalStyle",
"=",
"f",
".",
"element",
".",
"getAttribute",
"(",
"'style'",
")",
"||",
"''",
";",
"}",
"// set the new style to the original style plus the fitty styles",
"f",
".",
"element",
".",
"style",
".",
"cssText",
"=",
"f",
".",
"originalStyle",
"+",
"';white-space:'",
"+",
"f",
".",
"whiteSpace",
"+",
"';display:'",
"+",
"f",
".",
"display",
"+",
"';font-size:'",
"+",
"f",
".",
"currentFontSize",
"+",
"'px'",
";",
"}"
] |
apply styles to single fitty
|
[
"apply",
"styles",
"to",
"single",
"fitty"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L158-L167
|
11,552
|
rikschennink/fitty
|
dist/fitty.module.js
|
dispatchFitEvent
|
function dispatchFitEvent(f) {
f.element.dispatchEvent(new CustomEvent('fit', {
detail: {
oldValue: f.previousFontSize,
newValue: f.currentFontSize,
scaleFactor: f.currentFontSize / f.previousFontSize
}
}));
}
|
javascript
|
function dispatchFitEvent(f) {
f.element.dispatchEvent(new CustomEvent('fit', {
detail: {
oldValue: f.previousFontSize,
newValue: f.currentFontSize,
scaleFactor: f.currentFontSize / f.previousFontSize
}
}));
}
|
[
"function",
"dispatchFitEvent",
"(",
"f",
")",
"{",
"f",
".",
"element",
".",
"dispatchEvent",
"(",
"new",
"CustomEvent",
"(",
"'fit'",
",",
"{",
"detail",
":",
"{",
"oldValue",
":",
"f",
".",
"previousFontSize",
",",
"newValue",
":",
"f",
".",
"currentFontSize",
",",
"scaleFactor",
":",
"f",
".",
"currentFontSize",
"/",
"f",
".",
"previousFontSize",
"}",
"}",
")",
")",
";",
"}"
] |
dispatch a fit event on a fitty
|
[
"dispatch",
"a",
"fit",
"event",
"on",
"a",
"fitty"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L170-L178
|
11,553
|
rikschennink/fitty
|
dist/fitty.module.js
|
subscribe
|
function subscribe(f) {
// this is a new fitty so we need to validate if it's styles are in order
f.newbie = true;
// because it's a new fitty it should also be dirty, we want it to redraw on the first loop
f.dirty = true;
// we want to be able to update this fitty
fitties.push(f);
}
|
javascript
|
function subscribe(f) {
// this is a new fitty so we need to validate if it's styles are in order
f.newbie = true;
// because it's a new fitty it should also be dirty, we want it to redraw on the first loop
f.dirty = true;
// we want to be able to update this fitty
fitties.push(f);
}
|
[
"function",
"subscribe",
"(",
"f",
")",
"{",
"// this is a new fitty so we need to validate if it's styles are in order",
"f",
".",
"newbie",
"=",
"true",
";",
"// because it's a new fitty it should also be dirty, we want it to redraw on the first loop",
"f",
".",
"dirty",
"=",
"true",
";",
"// we want to be able to update this fitty",
"fitties",
".",
"push",
"(",
"f",
")",
";",
"}"
] |
add a new fitty, does not redraw said fitty
|
[
"add",
"a",
"new",
"fitty",
"does",
"not",
"redraw",
"said",
"fitty"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L189-L199
|
11,554
|
rikschennink/fitty
|
dist/fitty.module.js
|
unsubscribe
|
function unsubscribe(f) {
return function () {
// remove from fitties array
fitties = fitties.filter(function (_) {
return _.element !== f.element;
});
// stop observing DOM
if (f.observeMutations) {
f.observer.disconnect();
}
// reset font size to inherited size
f.element.style.cssText = f.originalStyle;
};
}
|
javascript
|
function unsubscribe(f) {
return function () {
// remove from fitties array
fitties = fitties.filter(function (_) {
return _.element !== f.element;
});
// stop observing DOM
if (f.observeMutations) {
f.observer.disconnect();
}
// reset font size to inherited size
f.element.style.cssText = f.originalStyle;
};
}
|
[
"function",
"unsubscribe",
"(",
"f",
")",
"{",
"return",
"function",
"(",
")",
"{",
"// remove from fitties array",
"fitties",
"=",
"fitties",
".",
"filter",
"(",
"function",
"(",
"_",
")",
"{",
"return",
"_",
".",
"element",
"!==",
"f",
".",
"element",
";",
"}",
")",
";",
"// stop observing DOM",
"if",
"(",
"f",
".",
"observeMutations",
")",
"{",
"f",
".",
"observer",
".",
"disconnect",
"(",
")",
";",
"}",
"// reset font size to inherited size",
"f",
".",
"element",
".",
"style",
".",
"cssText",
"=",
"f",
".",
"originalStyle",
";",
"}",
";",
"}"
] |
remove an existing fitty
|
[
"remove",
"an",
"existing",
"fitty"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L202-L218
|
11,555
|
rikschennink/fitty
|
dist/fitty.module.js
|
fittyCreate
|
function fittyCreate(elements, options) {
// set options object
var fittyOptions = _extends({}, defaultOptions, options);
// create fitties
var publicFitties = elements.map(function (element) {
// create fitty instance
var f = _extends({}, fittyOptions, {
// internal options for this fitty
element: element
});
// register this fitty
subscribe(f);
// should we observe DOM mutations
observeMutations(f);
// expose API
return {
element: element,
fit: fit(f, DrawState.DIRTY),
unsubscribe: unsubscribe(f)
};
});
// call redraw on newly initiated fitties
requestRedraw();
// expose fitties
return publicFitties;
}
|
javascript
|
function fittyCreate(elements, options) {
// set options object
var fittyOptions = _extends({}, defaultOptions, options);
// create fitties
var publicFitties = elements.map(function (element) {
// create fitty instance
var f = _extends({}, fittyOptions, {
// internal options for this fitty
element: element
});
// register this fitty
subscribe(f);
// should we observe DOM mutations
observeMutations(f);
// expose API
return {
element: element,
fit: fit(f, DrawState.DIRTY),
unsubscribe: unsubscribe(f)
};
});
// call redraw on newly initiated fitties
requestRedraw();
// expose fitties
return publicFitties;
}
|
[
"function",
"fittyCreate",
"(",
"elements",
",",
"options",
")",
"{",
"// set options object",
"var",
"fittyOptions",
"=",
"_extends",
"(",
"{",
"}",
",",
"defaultOptions",
",",
"options",
")",
";",
"// create fitties",
"var",
"publicFitties",
"=",
"elements",
".",
"map",
"(",
"function",
"(",
"element",
")",
"{",
"// create fitty instance",
"var",
"f",
"=",
"_extends",
"(",
"{",
"}",
",",
"fittyOptions",
",",
"{",
"// internal options for this fitty",
"element",
":",
"element",
"}",
")",
";",
"// register this fitty",
"subscribe",
"(",
"f",
")",
";",
"// should we observe DOM mutations",
"observeMutations",
"(",
"f",
")",
";",
"// expose API",
"return",
"{",
"element",
":",
"element",
",",
"fit",
":",
"fit",
"(",
"f",
",",
"DrawState",
".",
"DIRTY",
")",
",",
"unsubscribe",
":",
"unsubscribe",
"(",
"f",
")",
"}",
";",
"}",
")",
";",
"// call redraw on newly initiated fitties",
"requestRedraw",
"(",
")",
";",
"// expose fitties",
"return",
"publicFitties",
";",
"}"
] |
array of elements in, fitty instances out
|
[
"array",
"of",
"elements",
"in",
"fitty",
"instances",
"out"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L250-L284
|
11,556
|
rikschennink/fitty
|
dist/fitty.module.js
|
fitty
|
function fitty(target) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// if target is a string
return typeof target === 'string' ?
// treat it as a querySelector
fittyCreate(toArray(document.querySelectorAll(target)), options) :
// create single fitty
fittyCreate([target], options)[0];
}
|
javascript
|
function fitty(target) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// if target is a string
return typeof target === 'string' ?
// treat it as a querySelector
fittyCreate(toArray(document.querySelectorAll(target)), options) :
// create single fitty
fittyCreate([target], options)[0];
}
|
[
"function",
"fitty",
"(",
"target",
")",
"{",
"var",
"options",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"// if target is a string",
"return",
"typeof",
"target",
"===",
"'string'",
"?",
"// treat it as a querySelector",
"fittyCreate",
"(",
"toArray",
"(",
"document",
".",
"querySelectorAll",
"(",
"target",
")",
")",
",",
"options",
")",
":",
"// create single fitty",
"fittyCreate",
"(",
"[",
"target",
"]",
",",
"options",
")",
"[",
"0",
"]",
";",
"}"
] |
fitty creation function
|
[
"fitty",
"creation",
"function"
] |
6c254ac412336a5cb80a5c25adb7779992ce14f8
|
https://github.com/rikschennink/fitty/blob/6c254ac412336a5cb80a5c25adb7779992ce14f8/dist/fitty.module.js#L287-L299
|
11,557
|
htmlhint/HTMLHint
|
bin/formatter.js
|
loadFormatters
|
function loadFormatters(){
var arrFiles = glob.sync('./formatters/*.js', {
'cwd': __dirname,
'dot': false,
'nodir': true,
'strict': false,
'silent': true
});
var mapFormatters = {};
arrFiles.forEach(function(file){
var fileInfo = path.parse(file);
var formatterPath = path.resolve(__dirname, file);
mapFormatters[fileInfo.name] = require(formatterPath);
});
return mapFormatters;
}
|
javascript
|
function loadFormatters(){
var arrFiles = glob.sync('./formatters/*.js', {
'cwd': __dirname,
'dot': false,
'nodir': true,
'strict': false,
'silent': true
});
var mapFormatters = {};
arrFiles.forEach(function(file){
var fileInfo = path.parse(file);
var formatterPath = path.resolve(__dirname, file);
mapFormatters[fileInfo.name] = require(formatterPath);
});
return mapFormatters;
}
|
[
"function",
"loadFormatters",
"(",
")",
"{",
"var",
"arrFiles",
"=",
"glob",
".",
"sync",
"(",
"'./formatters/*.js'",
",",
"{",
"'cwd'",
":",
"__dirname",
",",
"'dot'",
":",
"false",
",",
"'nodir'",
":",
"true",
",",
"'strict'",
":",
"false",
",",
"'silent'",
":",
"true",
"}",
")",
";",
"var",
"mapFormatters",
"=",
"{",
"}",
";",
"arrFiles",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"fileInfo",
"=",
"path",
".",
"parse",
"(",
"file",
")",
";",
"var",
"formatterPath",
"=",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"file",
")",
";",
"mapFormatters",
"[",
"fileInfo",
".",
"name",
"]",
"=",
"require",
"(",
"formatterPath",
")",
";",
"}",
")",
";",
"return",
"mapFormatters",
";",
"}"
] |
load all formatters
|
[
"load",
"all",
"formatters"
] |
bb9a51e407b2ee1cc0173e70326b3ba786cdad69
|
https://github.com/htmlhint/HTMLHint/blob/bb9a51e407b2ee1cc0173e70326b3ba786cdad69/bin/formatter.js#L21-L36
|
11,558
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(constructor, obj, pluginName) {
// if it's not already bridged
if (!obj[pluginName]) {
var fn = function() {};
fn.prototype = constructor;
var pluginInstance = new fn();
// the _init method has to exist in instance constructors but might be missing
// in core constructors
if (pluginInstance.__init) {
pluginInstance.__init(obj);
}
$.each(constructor, function(methodName, fn) {
// don't proxy "private" methods, only "protected" and public ones
if (methodName.indexOf('__') != 0) {
// if the method does not exist yet
if (!obj[methodName]) {
obj[methodName] = function() {
return pluginInstance[methodName].apply(pluginInstance, Array.prototype.slice.apply(arguments));
};
// remember to which plugin this method corresponds (several plugins may
// have methods of the same name, we need to be sure)
obj[methodName].bridged = pluginInstance;
}
else if (defaults.debug) {
console.log('The '+ methodName +' method of the '+ pluginName
+' plugin conflicts with another plugin or native methods');
}
}
});
obj[pluginName] = pluginInstance;
}
return this;
}
|
javascript
|
function(constructor, obj, pluginName) {
// if it's not already bridged
if (!obj[pluginName]) {
var fn = function() {};
fn.prototype = constructor;
var pluginInstance = new fn();
// the _init method has to exist in instance constructors but might be missing
// in core constructors
if (pluginInstance.__init) {
pluginInstance.__init(obj);
}
$.each(constructor, function(methodName, fn) {
// don't proxy "private" methods, only "protected" and public ones
if (methodName.indexOf('__') != 0) {
// if the method does not exist yet
if (!obj[methodName]) {
obj[methodName] = function() {
return pluginInstance[methodName].apply(pluginInstance, Array.prototype.slice.apply(arguments));
};
// remember to which plugin this method corresponds (several plugins may
// have methods of the same name, we need to be sure)
obj[methodName].bridged = pluginInstance;
}
else if (defaults.debug) {
console.log('The '+ methodName +' method of the '+ pluginName
+' plugin conflicts with another plugin or native methods');
}
}
});
obj[pluginName] = pluginInstance;
}
return this;
}
|
[
"function",
"(",
"constructor",
",",
"obj",
",",
"pluginName",
")",
"{",
"// if it's not already bridged",
"if",
"(",
"!",
"obj",
"[",
"pluginName",
"]",
")",
"{",
"var",
"fn",
"=",
"function",
"(",
")",
"{",
"}",
";",
"fn",
".",
"prototype",
"=",
"constructor",
";",
"var",
"pluginInstance",
"=",
"new",
"fn",
"(",
")",
";",
"// the _init method has to exist in instance constructors but might be missing",
"// in core constructors",
"if",
"(",
"pluginInstance",
".",
"__init",
")",
"{",
"pluginInstance",
".",
"__init",
"(",
"obj",
")",
";",
"}",
"$",
".",
"each",
"(",
"constructor",
",",
"function",
"(",
"methodName",
",",
"fn",
")",
"{",
"// don't proxy \"private\" methods, only \"protected\" and public ones",
"if",
"(",
"methodName",
".",
"indexOf",
"(",
"'__'",
")",
"!=",
"0",
")",
"{",
"// if the method does not exist yet",
"if",
"(",
"!",
"obj",
"[",
"methodName",
"]",
")",
"{",
"obj",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"pluginInstance",
"[",
"methodName",
"]",
".",
"apply",
"(",
"pluginInstance",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"}",
";",
"// remember to which plugin this method corresponds (several plugins may",
"// have methods of the same name, we need to be sure)",
"obj",
"[",
"methodName",
"]",
".",
"bridged",
"=",
"pluginInstance",
";",
"}",
"else",
"if",
"(",
"defaults",
".",
"debug",
")",
"{",
"console",
".",
"log",
"(",
"'The '",
"+",
"methodName",
"+",
"' method of the '",
"+",
"pluginName",
"+",
"' plugin conflicts with another plugin or native methods'",
")",
";",
"}",
"}",
"}",
")",
";",
"obj",
"[",
"pluginName",
"]",
"=",
"pluginInstance",
";",
"}",
"return",
"this",
";",
"}"
] |
A function to proxy the public methods of an object onto another
@param {object} constructor The constructor to bridge
@param {object} obj The object that will get new methods (an instance or the core)
@param {string} pluginName A plugin name for the console log message
@return {core}
@private
|
[
"A",
"function",
"to",
"proxy",
"the",
"public",
"methods",
"of",
"an",
"object",
"onto",
"another"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L99-L143
|
|
11,559
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
var args = Array.prototype.slice.apply(arguments);
if (typeof args[0] == 'string') {
args[0] = { type: args[0] };
}
// note: the order of emitters matters
this.__$emitterPrivate.trigger.apply(this.__$emitterPrivate, args);
this.__$emitterPublic.trigger.apply(this.__$emitterPublic, args);
return this;
}
|
javascript
|
function() {
var args = Array.prototype.slice.apply(arguments);
if (typeof args[0] == 'string') {
args[0] = { type: args[0] };
}
// note: the order of emitters matters
this.__$emitterPrivate.trigger.apply(this.__$emitterPrivate, args);
this.__$emitterPublic.trigger.apply(this.__$emitterPublic, args);
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
";",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"==",
"'string'",
")",
"{",
"args",
"[",
"0",
"]",
"=",
"{",
"type",
":",
"args",
"[",
"0",
"]",
"}",
";",
"}",
"// note: the order of emitters matters",
"this",
".",
"__$emitterPrivate",
".",
"trigger",
".",
"apply",
"(",
"this",
".",
"__$emitterPrivate",
",",
"args",
")",
";",
"this",
".",
"__$emitterPublic",
".",
"trigger",
".",
"apply",
"(",
"this",
".",
"__$emitterPublic",
",",
"args",
")",
";",
"return",
"this",
";",
"}"
] |
Trigger events on the core emitters
@returns {core}
@protected
|
[
"Trigger",
"events",
"on",
"the",
"core",
"emitters"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L263-L276
|
|
11,560
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(selector) {
var instances = [],
sel = selector || '.tooltipstered';
$(sel).each(function() {
var $this = $(this),
ns = $this.data('tooltipster-ns');
if (ns) {
$.each(ns, function(i, namespace) {
instances.push($this.data(namespace));
});
}
});
return instances;
}
|
javascript
|
function(selector) {
var instances = [],
sel = selector || '.tooltipstered';
$(sel).each(function() {
var $this = $(this),
ns = $this.data('tooltipster-ns');
if (ns) {
$.each(ns, function(i, namespace) {
instances.push($this.data(namespace));
});
}
});
return instances;
}
|
[
"function",
"(",
"selector",
")",
"{",
"var",
"instances",
"=",
"[",
"]",
",",
"sel",
"=",
"selector",
"||",
"'.tooltipstered'",
";",
"$",
"(",
"sel",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"$this",
"=",
"$",
"(",
"this",
")",
",",
"ns",
"=",
"$this",
".",
"data",
"(",
"'tooltipster-ns'",
")",
";",
"if",
"(",
"ns",
")",
"{",
"$",
".",
"each",
"(",
"ns",
",",
"function",
"(",
"i",
",",
"namespace",
")",
"{",
"instances",
".",
"push",
"(",
"$this",
".",
"data",
"(",
"namespace",
")",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"instances",
";",
"}"
] |
Returns instances of all tooltips in the page or an a given element
@param {string|HTML object collection} selector optional Use this
parameter to restrict the set of objects that will be inspected
for the retrieval of instances. By default, all instances in the
page are returned.
@return {array} An array of instance objects
@public
|
[
"Returns",
"instances",
"of",
"all",
"tooltips",
"in",
"the",
"page",
"or",
"an",
"a",
"given",
"element"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L288-L307
|
|
11,561
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
var self = this,
$el = self._$tooltip.find('.tooltipster-content'),
formattedContent = self.__Content,
format = function(content) {
formattedContent = content;
};
self._trigger({
type: 'format',
content: self.__Content,
format: format
});
if (self.__options.functionFormat) {
formattedContent = self.__options.functionFormat.call(
self,
self,
{ origin: self._$origin[0] },
self.__Content
);
}
if (typeof formattedContent === 'string' && !self.__options.contentAsHTML) {
$el.text(formattedContent);
}
else {
$el
.empty()
.append(formattedContent);
}
return self;
}
|
javascript
|
function() {
var self = this,
$el = self._$tooltip.find('.tooltipster-content'),
formattedContent = self.__Content,
format = function(content) {
formattedContent = content;
};
self._trigger({
type: 'format',
content: self.__Content,
format: format
});
if (self.__options.functionFormat) {
formattedContent = self.__options.functionFormat.call(
self,
self,
{ origin: self._$origin[0] },
self.__Content
);
}
if (typeof formattedContent === 'string' && !self.__options.contentAsHTML) {
$el.text(formattedContent);
}
else {
$el
.empty()
.append(formattedContent);
}
return self;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
",",
"$el",
"=",
"self",
".",
"_$tooltip",
".",
"find",
"(",
"'.tooltipster-content'",
")",
",",
"formattedContent",
"=",
"self",
".",
"__Content",
",",
"format",
"=",
"function",
"(",
"content",
")",
"{",
"formattedContent",
"=",
"content",
";",
"}",
";",
"self",
".",
"_trigger",
"(",
"{",
"type",
":",
"'format'",
",",
"content",
":",
"self",
".",
"__Content",
",",
"format",
":",
"format",
"}",
")",
";",
"if",
"(",
"self",
".",
"__options",
".",
"functionFormat",
")",
"{",
"formattedContent",
"=",
"self",
".",
"__options",
".",
"functionFormat",
".",
"call",
"(",
"self",
",",
"self",
",",
"{",
"origin",
":",
"self",
".",
"_$origin",
"[",
"0",
"]",
"}",
",",
"self",
".",
"__Content",
")",
";",
"}",
"if",
"(",
"typeof",
"formattedContent",
"===",
"'string'",
"&&",
"!",
"self",
".",
"__options",
".",
"contentAsHTML",
")",
"{",
"$el",
".",
"text",
"(",
"formattedContent",
")",
";",
"}",
"else",
"{",
"$el",
".",
"empty",
"(",
")",
".",
"append",
"(",
"formattedContent",
")",
";",
"}",
"return",
"self",
";",
"}"
] |
Insert the content into the appropriate HTML element of the tooltip
@returns {self}
@private
|
[
"Insert",
"the",
"content",
"into",
"the",
"appropriate",
"HTML",
"element",
"of",
"the",
"tooltip"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L575-L610
|
|
11,562
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(content) {
// clone if asked. Cloning the object makes sure that each instance has its
// own version of the content (in case a same object were provided for several
// instances)
// reminder: typeof null === object
if (content instanceof $ && this.__options.contentCloning) {
content = content.clone(true);
}
this.__Content = content;
this._trigger({
type: 'updated',
content: content
});
return this;
}
|
javascript
|
function(content) {
// clone if asked. Cloning the object makes sure that each instance has its
// own version of the content (in case a same object were provided for several
// instances)
// reminder: typeof null === object
if (content instanceof $ && this.__options.contentCloning) {
content = content.clone(true);
}
this.__Content = content;
this._trigger({
type: 'updated',
content: content
});
return this;
}
|
[
"function",
"(",
"content",
")",
"{",
"// clone if asked. Cloning the object makes sure that each instance has its",
"// own version of the content (in case a same object were provided for several",
"// instances)",
"// reminder: typeof null === object",
"if",
"(",
"content",
"instanceof",
"$",
"&&",
"this",
".",
"__options",
".",
"contentCloning",
")",
"{",
"content",
"=",
"content",
".",
"clone",
"(",
"true",
")",
";",
"}",
"this",
".",
"__Content",
"=",
"content",
";",
"this",
".",
"_trigger",
"(",
"{",
"type",
":",
"'updated'",
",",
"content",
":",
"content",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Save the content, cloning it beforehand if need be
@param content
@returns {self}
@private
|
[
"Save",
"the",
"content",
"cloning",
"it",
"beforehand",
"if",
"need",
"be"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L619-L637
|
|
11,563
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(r) {
geo.origin.size.height = r.height,
geo.origin.windowOffset.left = r.left,
geo.origin.windowOffset.top = r.top,
geo.origin.size.width = r.width
}
|
javascript
|
function(r) {
geo.origin.size.height = r.height,
geo.origin.windowOffset.left = r.left,
geo.origin.windowOffset.top = r.top,
geo.origin.size.width = r.width
}
|
[
"function",
"(",
"r",
")",
"{",
"geo",
".",
"origin",
".",
"size",
".",
"height",
"=",
"r",
".",
"height",
",",
"geo",
".",
"origin",
".",
"windowOffset",
".",
"left",
"=",
"r",
".",
"left",
",",
"geo",
".",
"origin",
".",
"windowOffset",
".",
"top",
"=",
"r",
".",
"top",
",",
"geo",
".",
"origin",
".",
"size",
".",
"width",
"=",
"r",
".",
"width",
"}"
] |
user callback through an event
|
[
"user",
"callback",
"through",
"an",
"event"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L832-L837
|
|
11,564
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
if (typeof this.__options.animationDuration == 'number') {
this.__options.animationDuration = [this.__options.animationDuration, this.__options.animationDuration];
}
if (typeof this.__options.delay == 'number') {
this.__options.delay = [this.__options.delay, this.__options.delay];
}
if (typeof this.__options.delayTouch == 'number') {
this.__options.delayTouch = [this.__options.delayTouch, this.__options.delayTouch];
}
if (typeof this.__options.theme == 'string') {
this.__options.theme = [this.__options.theme];
}
// determine the future parent
if (this.__options.parent === null) {
this.__options.parent = $(env.window.document.body);
}
else if (typeof this.__options.parent == 'string') {
this.__options.parent = $(this.__options.parent);
}
if (this.__options.trigger == 'hover') {
this.__options.triggerOpen = {
mouseenter: true,
touchstart: true
};
this.__options.triggerClose = {
mouseleave: true,
originClick: true,
touchleave: true
};
}
else if (this.__options.trigger == 'click') {
this.__options.triggerOpen = {
click: true,
tap: true
};
this.__options.triggerClose = {
click: true,
tap: true
};
}
// for the plugins
this._trigger('options');
return this;
}
|
javascript
|
function() {
if (typeof this.__options.animationDuration == 'number') {
this.__options.animationDuration = [this.__options.animationDuration, this.__options.animationDuration];
}
if (typeof this.__options.delay == 'number') {
this.__options.delay = [this.__options.delay, this.__options.delay];
}
if (typeof this.__options.delayTouch == 'number') {
this.__options.delayTouch = [this.__options.delayTouch, this.__options.delayTouch];
}
if (typeof this.__options.theme == 'string') {
this.__options.theme = [this.__options.theme];
}
// determine the future parent
if (this.__options.parent === null) {
this.__options.parent = $(env.window.document.body);
}
else if (typeof this.__options.parent == 'string') {
this.__options.parent = $(this.__options.parent);
}
if (this.__options.trigger == 'hover') {
this.__options.triggerOpen = {
mouseenter: true,
touchstart: true
};
this.__options.triggerClose = {
mouseleave: true,
originClick: true,
touchleave: true
};
}
else if (this.__options.trigger == 'click') {
this.__options.triggerOpen = {
click: true,
tap: true
};
this.__options.triggerClose = {
click: true,
tap: true
};
}
// for the plugins
this._trigger('options');
return this;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"typeof",
"this",
".",
"__options",
".",
"animationDuration",
"==",
"'number'",
")",
"{",
"this",
".",
"__options",
".",
"animationDuration",
"=",
"[",
"this",
".",
"__options",
".",
"animationDuration",
",",
"this",
".",
"__options",
".",
"animationDuration",
"]",
";",
"}",
"if",
"(",
"typeof",
"this",
".",
"__options",
".",
"delay",
"==",
"'number'",
")",
"{",
"this",
".",
"__options",
".",
"delay",
"=",
"[",
"this",
".",
"__options",
".",
"delay",
",",
"this",
".",
"__options",
".",
"delay",
"]",
";",
"}",
"if",
"(",
"typeof",
"this",
".",
"__options",
".",
"delayTouch",
"==",
"'number'",
")",
"{",
"this",
".",
"__options",
".",
"delayTouch",
"=",
"[",
"this",
".",
"__options",
".",
"delayTouch",
",",
"this",
".",
"__options",
".",
"delayTouch",
"]",
";",
"}",
"if",
"(",
"typeof",
"this",
".",
"__options",
".",
"theme",
"==",
"'string'",
")",
"{",
"this",
".",
"__options",
".",
"theme",
"=",
"[",
"this",
".",
"__options",
".",
"theme",
"]",
";",
"}",
"// determine the future parent",
"if",
"(",
"this",
".",
"__options",
".",
"parent",
"===",
"null",
")",
"{",
"this",
".",
"__options",
".",
"parent",
"=",
"$",
"(",
"env",
".",
"window",
".",
"document",
".",
"body",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"this",
".",
"__options",
".",
"parent",
"==",
"'string'",
")",
"{",
"this",
".",
"__options",
".",
"parent",
"=",
"$",
"(",
"this",
".",
"__options",
".",
"parent",
")",
";",
"}",
"if",
"(",
"this",
".",
"__options",
".",
"trigger",
"==",
"'hover'",
")",
"{",
"this",
".",
"__options",
".",
"triggerOpen",
"=",
"{",
"mouseenter",
":",
"true",
",",
"touchstart",
":",
"true",
"}",
";",
"this",
".",
"__options",
".",
"triggerClose",
"=",
"{",
"mouseleave",
":",
"true",
",",
"originClick",
":",
"true",
",",
"touchleave",
":",
"true",
"}",
";",
"}",
"else",
"if",
"(",
"this",
".",
"__options",
".",
"trigger",
"==",
"'click'",
")",
"{",
"this",
".",
"__options",
".",
"triggerOpen",
"=",
"{",
"click",
":",
"true",
",",
"tap",
":",
"true",
"}",
";",
"this",
".",
"__options",
".",
"triggerClose",
"=",
"{",
"click",
":",
"true",
",",
"tap",
":",
"true",
"}",
";",
"}",
"// for the plugins",
"this",
".",
"_trigger",
"(",
"'options'",
")",
";",
"return",
"this",
";",
"}"
] |
Some options may need to be formated before being used
@returns {self}
@private
|
[
"Some",
"options",
"may",
"need",
"to",
"be",
"formated",
"before",
"being",
"used"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L924-L980
|
|
11,565
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
var self = this;
// in case the selfDestruction option has been changed by a method call
if (self.__options.selfDestruction) {
// the GC task
self.__garbageCollector = setInterval(function() {
var now = new Date().getTime();
// forget the old events
self.__touchEvents = $.grep(self.__touchEvents, function(event, i) {
// 1 minute
return now - event.time > 60000;
});
// auto-destruct if the origin is gone
if (!bodyContains(self._$origin)) {
self.close(function(){
self.destroy();
});
}
}, 20000);
}
else {
clearInterval(self.__garbageCollector);
}
return self;
}
|
javascript
|
function() {
var self = this;
// in case the selfDestruction option has been changed by a method call
if (self.__options.selfDestruction) {
// the GC task
self.__garbageCollector = setInterval(function() {
var now = new Date().getTime();
// forget the old events
self.__touchEvents = $.grep(self.__touchEvents, function(event, i) {
// 1 minute
return now - event.time > 60000;
});
// auto-destruct if the origin is gone
if (!bodyContains(self._$origin)) {
self.close(function(){
self.destroy();
});
}
}, 20000);
}
else {
clearInterval(self.__garbageCollector);
}
return self;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// in case the selfDestruction option has been changed by a method call",
"if",
"(",
"self",
".",
"__options",
".",
"selfDestruction",
")",
"{",
"// the GC task",
"self",
".",
"__garbageCollector",
"=",
"setInterval",
"(",
"function",
"(",
")",
"{",
"var",
"now",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"// forget the old events",
"self",
".",
"__touchEvents",
"=",
"$",
".",
"grep",
"(",
"self",
".",
"__touchEvents",
",",
"function",
"(",
"event",
",",
"i",
")",
"{",
"// 1 minute",
"return",
"now",
"-",
"event",
".",
"time",
">",
"60000",
";",
"}",
")",
";",
"// auto-destruct if the origin is gone",
"if",
"(",
"!",
"bodyContains",
"(",
"self",
".",
"_$origin",
")",
")",
"{",
"self",
".",
"close",
"(",
"function",
"(",
")",
"{",
"self",
".",
"destroy",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
",",
"20000",
")",
";",
"}",
"else",
"{",
"clearInterval",
"(",
"self",
".",
"__garbageCollector",
")",
";",
"}",
"return",
"self",
";",
"}"
] |
Schedules or cancels the garbage collector task
@returns {self}
@private
|
[
"Schedules",
"or",
"cancels",
"the",
"garbage",
"collector",
"task"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L988-L1020
|
|
11,566
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
// there is only one possible open timeout: the delayed opening
// when the mouseenter/touchstart open triggers are used
clearTimeout(this.__timeouts.open);
this.__timeouts.open = null;
// ... but several close timeouts: the delayed closing when the
// mouseleave close trigger is used and the timer option
$.each(this.__timeouts.close, function(i, timeout) {
clearTimeout(timeout);
});
this.__timeouts.close = [];
return this;
}
|
javascript
|
function() {
// there is only one possible open timeout: the delayed opening
// when the mouseenter/touchstart open triggers are used
clearTimeout(this.__timeouts.open);
this.__timeouts.open = null;
// ... but several close timeouts: the delayed closing when the
// mouseleave close trigger is used and the timer option
$.each(this.__timeouts.close, function(i, timeout) {
clearTimeout(timeout);
});
this.__timeouts.close = [];
return this;
}
|
[
"function",
"(",
")",
"{",
"// there is only one possible open timeout: the delayed opening",
"// when the mouseenter/touchstart open triggers are used",
"clearTimeout",
"(",
"this",
".",
"__timeouts",
".",
"open",
")",
";",
"this",
".",
"__timeouts",
".",
"open",
"=",
"null",
";",
"// ... but several close timeouts: the delayed closing when the",
"// mouseleave close trigger is used and the timer option",
"$",
".",
"each",
"(",
"this",
".",
"__timeouts",
".",
"close",
",",
"function",
"(",
"i",
",",
"timeout",
")",
"{",
"clearTimeout",
"(",
"timeout",
")",
";",
"}",
")",
";",
"this",
".",
"__timeouts",
".",
"close",
"=",
"[",
"]",
";",
"return",
"this",
";",
"}"
] |
Clear appearance timeouts
@returns {self}
@private
|
[
"Clear",
"appearance",
"timeouts"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L1320-L1335
|
|
11,567
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(pluginName, defaultOptions) {
var self = this,
options = $.extend(true, {}, defaultOptions);
// if the plugin options were isolated in a property named after the
// plugin, use them (prevents conflicts with other plugins)
var pluginOptions = self.__options[pluginName];
// if not, try to get them as regular options
if (!pluginOptions){
pluginOptions = {};
$.each(defaultOptions, function(optionName, value) {
var o = self.__options[optionName];
if (o !== undefined) {
pluginOptions[optionName] = o;
}
});
}
// let's merge the default options and the ones that were provided. We'd want
// to do a deep copy but not let jQuery merge arrays, so we'll do a shallow
// extend on two levels, that will be enough if options are not more than 1
// level deep
$.each(options, function(optionName, value) {
if (pluginOptions[optionName] !== undefined) {
if (( typeof value == 'object'
&& !(value instanceof Array)
&& value != null
)
&&
( typeof pluginOptions[optionName] == 'object'
&& !(pluginOptions[optionName] instanceof Array)
&& pluginOptions[optionName] != null
)
) {
$.extend(options[optionName], pluginOptions[optionName]);
}
else {
options[optionName] = pluginOptions[optionName];
}
}
});
return options;
}
|
javascript
|
function(pluginName, defaultOptions) {
var self = this,
options = $.extend(true, {}, defaultOptions);
// if the plugin options were isolated in a property named after the
// plugin, use them (prevents conflicts with other plugins)
var pluginOptions = self.__options[pluginName];
// if not, try to get them as regular options
if (!pluginOptions){
pluginOptions = {};
$.each(defaultOptions, function(optionName, value) {
var o = self.__options[optionName];
if (o !== undefined) {
pluginOptions[optionName] = o;
}
});
}
// let's merge the default options and the ones that were provided. We'd want
// to do a deep copy but not let jQuery merge arrays, so we'll do a shallow
// extend on two levels, that will be enough if options are not more than 1
// level deep
$.each(options, function(optionName, value) {
if (pluginOptions[optionName] !== undefined) {
if (( typeof value == 'object'
&& !(value instanceof Array)
&& value != null
)
&&
( typeof pluginOptions[optionName] == 'object'
&& !(pluginOptions[optionName] instanceof Array)
&& pluginOptions[optionName] != null
)
) {
$.extend(options[optionName], pluginOptions[optionName]);
}
else {
options[optionName] = pluginOptions[optionName];
}
}
});
return options;
}
|
[
"function",
"(",
"pluginName",
",",
"defaultOptions",
")",
"{",
"var",
"self",
"=",
"this",
",",
"options",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"defaultOptions",
")",
";",
"// if the plugin options were isolated in a property named after the",
"// plugin, use them (prevents conflicts with other plugins)",
"var",
"pluginOptions",
"=",
"self",
".",
"__options",
"[",
"pluginName",
"]",
";",
"// if not, try to get them as regular options",
"if",
"(",
"!",
"pluginOptions",
")",
"{",
"pluginOptions",
"=",
"{",
"}",
";",
"$",
".",
"each",
"(",
"defaultOptions",
",",
"function",
"(",
"optionName",
",",
"value",
")",
"{",
"var",
"o",
"=",
"self",
".",
"__options",
"[",
"optionName",
"]",
";",
"if",
"(",
"o",
"!==",
"undefined",
")",
"{",
"pluginOptions",
"[",
"optionName",
"]",
"=",
"o",
";",
"}",
"}",
")",
";",
"}",
"// let's merge the default options and the ones that were provided. We'd want",
"// to do a deep copy but not let jQuery merge arrays, so we'll do a shallow",
"// extend on two levels, that will be enough if options are not more than 1",
"// level deep",
"$",
".",
"each",
"(",
"options",
",",
"function",
"(",
"optionName",
",",
"value",
")",
"{",
"if",
"(",
"pluginOptions",
"[",
"optionName",
"]",
"!==",
"undefined",
")",
"{",
"if",
"(",
"(",
"typeof",
"value",
"==",
"'object'",
"&&",
"!",
"(",
"value",
"instanceof",
"Array",
")",
"&&",
"value",
"!=",
"null",
")",
"&&",
"(",
"typeof",
"pluginOptions",
"[",
"optionName",
"]",
"==",
"'object'",
"&&",
"!",
"(",
"pluginOptions",
"[",
"optionName",
"]",
"instanceof",
"Array",
")",
"&&",
"pluginOptions",
"[",
"optionName",
"]",
"!=",
"null",
")",
")",
"{",
"$",
".",
"extend",
"(",
"options",
"[",
"optionName",
"]",
",",
"pluginOptions",
"[",
"optionName",
"]",
")",
";",
"}",
"else",
"{",
"options",
"[",
"optionName",
"]",
"=",
"pluginOptions",
"[",
"optionName",
"]",
";",
"}",
"}",
"}",
")",
";",
"return",
"options",
";",
"}"
] |
Meant for plugins to get their options
@param {string} pluginName The name of the plugin that asks for its options
@param {object} defaultOptions The default options of the plugin
@returns {object} The options
@protected
|
[
"Meant",
"for",
"plugins",
"to",
"get",
"their",
"options"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2117-L2168
|
|
11,568
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(pluginName) {
var plugin = $.tooltipster._plugin(pluginName);
if (plugin) {
// if there is a constructor for instances
if (plugin.instance) {
// proxy non-private methods on the instance to allow new instance methods
$.tooltipster.__bridge(plugin.instance, this, plugin.name);
}
}
else {
throw new Error('The "'+ pluginName +'" plugin is not defined');
}
return this;
}
|
javascript
|
function(pluginName) {
var plugin = $.tooltipster._plugin(pluginName);
if (plugin) {
// if there is a constructor for instances
if (plugin.instance) {
// proxy non-private methods on the instance to allow new instance methods
$.tooltipster.__bridge(plugin.instance, this, plugin.name);
}
}
else {
throw new Error('The "'+ pluginName +'" plugin is not defined');
}
return this;
}
|
[
"function",
"(",
"pluginName",
")",
"{",
"var",
"plugin",
"=",
"$",
".",
"tooltipster",
".",
"_plugin",
"(",
"pluginName",
")",
";",
"if",
"(",
"plugin",
")",
"{",
"// if there is a constructor for instances",
"if",
"(",
"plugin",
".",
"instance",
")",
"{",
"// proxy non-private methods on the instance to allow new instance methods",
"$",
".",
"tooltipster",
".",
"__bridge",
"(",
"plugin",
".",
"instance",
",",
"this",
",",
"plugin",
".",
"name",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'The \"'",
"+",
"pluginName",
"+",
"'\" plugin is not defined'",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Used at instantiation of the plugin, or afterwards by plugins that activate themselves
on existing instances
@param {object} pluginName
@returns {self}
@protected
|
[
"Used",
"at",
"instantiation",
"of",
"the",
"plugin",
"or",
"afterwards",
"by",
"plugins",
"that",
"activate",
"themselves",
"on",
"existing",
"instances"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2178-L2196
|
|
11,569
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(event) {
var isEmulated = false,
now = new Date().getTime();
for (var i = this.__touchEvents.length - 1; i >= 0; i--) {
var e = this.__touchEvents[i];
// delay, in milliseconds. It's supposed to be 300ms in
// most browsers (350ms on iOS) to allow a double tap but
// can be less (check out FastClick for more info)
if (now - e.time < 500) {
if (e.target === event.target) {
isEmulated = true;
}
}
else {
break;
}
}
return isEmulated;
}
|
javascript
|
function(event) {
var isEmulated = false,
now = new Date().getTime();
for (var i = this.__touchEvents.length - 1; i >= 0; i--) {
var e = this.__touchEvents[i];
// delay, in milliseconds. It's supposed to be 300ms in
// most browsers (350ms on iOS) to allow a double tap but
// can be less (check out FastClick for more info)
if (now - e.time < 500) {
if (e.target === event.target) {
isEmulated = true;
}
}
else {
break;
}
}
return isEmulated;
}
|
[
"function",
"(",
"event",
")",
"{",
"var",
"isEmulated",
"=",
"false",
",",
"now",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"__touchEvents",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"e",
"=",
"this",
".",
"__touchEvents",
"[",
"i",
"]",
";",
"// delay, in milliseconds. It's supposed to be 300ms in",
"// most browsers (350ms on iOS) to allow a double tap but",
"// can be less (check out FastClick for more info)",
"if",
"(",
"now",
"-",
"e",
".",
"time",
"<",
"500",
")",
"{",
"if",
"(",
"e",
".",
"target",
"===",
"event",
".",
"target",
")",
"{",
"isEmulated",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"isEmulated",
";",
"}"
] |
This will return true if the event is a mouse event which was
emulated by the browser after a touch event. This allows us to
really dissociate mouse and touch triggers.
There is a margin of error if a real mouse event is fired right
after (within the delay shown below) a touch event on the same
element, but hopefully it should not happen often.
@returns {boolean}
@protected
|
[
"This",
"will",
"return",
"true",
"if",
"the",
"event",
"is",
"a",
"mouse",
"event",
"which",
"was",
"emulated",
"by",
"the",
"browser",
"after",
"a",
"touch",
"event",
".",
"This",
"allows",
"us",
"to",
"really",
"dissociate",
"mouse",
"and",
"touch",
"triggers",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2210-L2234
|
|
11,570
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(event) {
return (
(this._touchIsTouchEvent(event) && !this._touchSwiped(event.target))
|| (!this._touchIsTouchEvent(event) && !this._touchIsEmulatedEvent(event))
);
}
|
javascript
|
function(event) {
return (
(this._touchIsTouchEvent(event) && !this._touchSwiped(event.target))
|| (!this._touchIsTouchEvent(event) && !this._touchIsEmulatedEvent(event))
);
}
|
[
"function",
"(",
"event",
")",
"{",
"return",
"(",
"(",
"this",
".",
"_touchIsTouchEvent",
"(",
"event",
")",
"&&",
"!",
"this",
".",
"_touchSwiped",
"(",
"event",
".",
"target",
")",
")",
"||",
"(",
"!",
"this",
".",
"_touchIsTouchEvent",
"(",
"event",
")",
"&&",
"!",
"this",
".",
"_touchIsEmulatedEvent",
"(",
"event",
")",
")",
")",
";",
"}"
] |
Returns false if the event was an emulated mouse event or
a touch event involved in a swipe gesture.
@param {object} event
@returns {boolean}
@protected
|
[
"Returns",
"false",
"if",
"the",
"event",
"was",
"an",
"emulated",
"mouse",
"event",
"or",
"a",
"touch",
"event",
"involved",
"in",
"a",
"swipe",
"gesture",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2244-L2249
|
|
11,571
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(event) {
if (this._touchIsTouchEvent(event)) {
event.time = new Date().getTime();
this.__touchEvents.push(event);
}
return this;
}
|
javascript
|
function(event) {
if (this._touchIsTouchEvent(event)) {
event.time = new Date().getTime();
this.__touchEvents.push(event);
}
return this;
}
|
[
"function",
"(",
"event",
")",
"{",
"if",
"(",
"this",
".",
"_touchIsTouchEvent",
"(",
"event",
")",
")",
"{",
"event",
".",
"time",
"=",
"new",
"Date",
"(",
")",
".",
"getTime",
"(",
")",
";",
"this",
".",
"__touchEvents",
".",
"push",
"(",
"event",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Store touch events for a while to detect swiping and emulated mouse events
@param {object} event
@returns {self}
@protected
|
[
"Store",
"touch",
"events",
"for",
"a",
"while",
"to",
"detect",
"swiping",
"and",
"emulated",
"mouse",
"events"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2269-L2277
|
|
11,572
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(target) {
var swiped = false;
for (var i = this.__touchEvents.length - 1; i >= 0; i--) {
var e = this.__touchEvents[i];
if (e.type == 'touchmove') {
swiped = true;
break;
}
else if (
e.type == 'touchstart'
&& target === e.target
) {
break;
}
}
return swiped;
}
|
javascript
|
function(target) {
var swiped = false;
for (var i = this.__touchEvents.length - 1; i >= 0; i--) {
var e = this.__touchEvents[i];
if (e.type == 'touchmove') {
swiped = true;
break;
}
else if (
e.type == 'touchstart'
&& target === e.target
) {
break;
}
}
return swiped;
}
|
[
"function",
"(",
"target",
")",
"{",
"var",
"swiped",
"=",
"false",
";",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"__touchEvents",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"e",
"=",
"this",
".",
"__touchEvents",
"[",
"i",
"]",
";",
"if",
"(",
"e",
".",
"type",
"==",
"'touchmove'",
")",
"{",
"swiped",
"=",
"true",
";",
"break",
";",
"}",
"else",
"if",
"(",
"e",
".",
"type",
"==",
"'touchstart'",
"&&",
"target",
"===",
"e",
".",
"target",
")",
"{",
"break",
";",
"}",
"}",
"return",
"swiped",
";",
"}"
] |
Returns true if a swipe happened after the last touchstart event fired on
event.target.
We need to differentiate a swipe from a tap before we let the event open
or close the tooltip. A swipe is when a touchmove (scroll) event happens
on the body between the touchstart and the touchend events of an element.
@param {object} target The HTML element that may have triggered the swipe
@returns {boolean}
@protected
|
[
"Returns",
"true",
"if",
"a",
"swipe",
"happened",
"after",
"the",
"last",
"touchstart",
"event",
"fired",
"on",
"event",
".",
"target",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2291-L2312
|
|
11,573
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
var args = Array.prototype.slice.apply(arguments);
if (typeof args[0] == 'string') {
args[0] = { type: args[0] };
}
// add properties to the event
args[0].instance = this;
args[0].origin = this._$origin ? this._$origin[0] : null;
args[0].tooltip = this._$tooltip ? this._$tooltip[0] : null;
// note: the order of emitters matters
this.__$emitterPrivate.trigger.apply(this.__$emitterPrivate, args);
$.tooltipster._trigger.apply($.tooltipster, args);
this.__$emitterPublic.trigger.apply(this.__$emitterPublic, args);
return this;
}
|
javascript
|
function() {
var args = Array.prototype.slice.apply(arguments);
if (typeof args[0] == 'string') {
args[0] = { type: args[0] };
}
// add properties to the event
args[0].instance = this;
args[0].origin = this._$origin ? this._$origin[0] : null;
args[0].tooltip = this._$tooltip ? this._$tooltip[0] : null;
// note: the order of emitters matters
this.__$emitterPrivate.trigger.apply(this.__$emitterPrivate, args);
$.tooltipster._trigger.apply($.tooltipster, args);
this.__$emitterPublic.trigger.apply(this.__$emitterPublic, args);
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
";",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"==",
"'string'",
")",
"{",
"args",
"[",
"0",
"]",
"=",
"{",
"type",
":",
"args",
"[",
"0",
"]",
"}",
";",
"}",
"// add properties to the event",
"args",
"[",
"0",
"]",
".",
"instance",
"=",
"this",
";",
"args",
"[",
"0",
"]",
".",
"origin",
"=",
"this",
".",
"_$origin",
"?",
"this",
".",
"_$origin",
"[",
"0",
"]",
":",
"null",
";",
"args",
"[",
"0",
"]",
".",
"tooltip",
"=",
"this",
".",
"_$tooltip",
"?",
"this",
".",
"_$tooltip",
"[",
"0",
"]",
":",
"null",
";",
"// note: the order of emitters matters",
"this",
".",
"__$emitterPrivate",
".",
"trigger",
".",
"apply",
"(",
"this",
".",
"__$emitterPrivate",
",",
"args",
")",
";",
"$",
".",
"tooltipster",
".",
"_trigger",
".",
"apply",
"(",
"$",
".",
"tooltipster",
",",
"args",
")",
";",
"this",
".",
"__$emitterPublic",
".",
"trigger",
".",
"apply",
"(",
"this",
".",
"__$emitterPublic",
",",
"args",
")",
";",
"return",
"this",
";",
"}"
] |
Triggers an event on the instance emitters
@returns {self}
@protected
|
[
"Triggers",
"an",
"event",
"on",
"the",
"instance",
"emitters"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2320-L2339
|
|
11,574
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(pluginName) {
var self = this;
// if the plugin has been activated on this instance
if (self[pluginName]) {
var plugin = $.tooltipster._plugin(pluginName);
// if there is a constructor for instances
if (plugin.instance) {
// unbridge
$.each(plugin.instance, function(methodName, fn) {
// if the method exists (privates methods do not) and comes indeed from
// this plugin (may be missing or come from a conflicting plugin).
if ( self[methodName]
&& self[methodName].bridged === self[pluginName]
) {
delete self[methodName];
}
});
}
// destroy the plugin
if (self[pluginName].__destroy) {
self[pluginName].__destroy();
}
// remove the reference to the plugin instance
delete self[pluginName];
}
return self;
}
|
javascript
|
function(pluginName) {
var self = this;
// if the plugin has been activated on this instance
if (self[pluginName]) {
var plugin = $.tooltipster._plugin(pluginName);
// if there is a constructor for instances
if (plugin.instance) {
// unbridge
$.each(plugin.instance, function(methodName, fn) {
// if the method exists (privates methods do not) and comes indeed from
// this plugin (may be missing or come from a conflicting plugin).
if ( self[methodName]
&& self[methodName].bridged === self[pluginName]
) {
delete self[methodName];
}
});
}
// destroy the plugin
if (self[pluginName].__destroy) {
self[pluginName].__destroy();
}
// remove the reference to the plugin instance
delete self[pluginName];
}
return self;
}
|
[
"function",
"(",
"pluginName",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// if the plugin has been activated on this instance",
"if",
"(",
"self",
"[",
"pluginName",
"]",
")",
"{",
"var",
"plugin",
"=",
"$",
".",
"tooltipster",
".",
"_plugin",
"(",
"pluginName",
")",
";",
"// if there is a constructor for instances",
"if",
"(",
"plugin",
".",
"instance",
")",
"{",
"// unbridge",
"$",
".",
"each",
"(",
"plugin",
".",
"instance",
",",
"function",
"(",
"methodName",
",",
"fn",
")",
"{",
"// if the method exists (privates methods do not) and comes indeed from",
"// this plugin (may be missing or come from a conflicting plugin).",
"if",
"(",
"self",
"[",
"methodName",
"]",
"&&",
"self",
"[",
"methodName",
"]",
".",
"bridged",
"===",
"self",
"[",
"pluginName",
"]",
")",
"{",
"delete",
"self",
"[",
"methodName",
"]",
";",
"}",
"}",
")",
";",
"}",
"// destroy the plugin",
"if",
"(",
"self",
"[",
"pluginName",
"]",
".",
"__destroy",
")",
"{",
"self",
"[",
"pluginName",
"]",
".",
"__destroy",
"(",
")",
";",
"}",
"// remove the reference to the plugin instance",
"delete",
"self",
"[",
"pluginName",
"]",
";",
"}",
"return",
"self",
";",
"}"
] |
Deactivate a plugin on this instance
@returns {self}
@protected
|
[
"Deactivate",
"a",
"plugin",
"on",
"this",
"instance"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2347-L2382
|
|
11,575
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(content) {
var self = this;
// getter method
if (content === undefined) {
return self.__Content;
}
// setter method
else {
if (!self.__destroyed) {
// change the content
self.__contentSet(content);
if (self.__Content !== null) {
// update the tooltip if it is open
if (self.__state !== 'closed') {
// reset the content in the tooltip
self.__contentInsert();
// reposition and resize the tooltip
self.reposition();
// if we want to play a little animation showing the content changed
if (self.__options.updateAnimation) {
if (env.hasTransitions) {
// keep the reference in the local scope
var animation = self.__options.updateAnimation;
self._$tooltip.addClass('tooltipster-update-'+ animation);
// remove the class after a while. The actual duration of the
// update animation may be shorter, it's set in the CSS rules
setTimeout(function() {
if (self.__state != 'closed') {
self._$tooltip.removeClass('tooltipster-update-'+ animation);
}
}, 1000);
}
else {
self._$tooltip.fadeTo(200, 0.5, function() {
if (self.__state != 'closed') {
self._$tooltip.fadeTo(200, 1);
}
});
}
}
}
}
else {
self._close();
}
}
else {
self.__destroyError();
}
return self;
}
}
|
javascript
|
function(content) {
var self = this;
// getter method
if (content === undefined) {
return self.__Content;
}
// setter method
else {
if (!self.__destroyed) {
// change the content
self.__contentSet(content);
if (self.__Content !== null) {
// update the tooltip if it is open
if (self.__state !== 'closed') {
// reset the content in the tooltip
self.__contentInsert();
// reposition and resize the tooltip
self.reposition();
// if we want to play a little animation showing the content changed
if (self.__options.updateAnimation) {
if (env.hasTransitions) {
// keep the reference in the local scope
var animation = self.__options.updateAnimation;
self._$tooltip.addClass('tooltipster-update-'+ animation);
// remove the class after a while. The actual duration of the
// update animation may be shorter, it's set in the CSS rules
setTimeout(function() {
if (self.__state != 'closed') {
self._$tooltip.removeClass('tooltipster-update-'+ animation);
}
}, 1000);
}
else {
self._$tooltip.fadeTo(200, 0.5, function() {
if (self.__state != 'closed') {
self._$tooltip.fadeTo(200, 1);
}
});
}
}
}
}
else {
self._close();
}
}
else {
self.__destroyError();
}
return self;
}
}
|
[
"function",
"(",
"content",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// getter method",
"if",
"(",
"content",
"===",
"undefined",
")",
"{",
"return",
"self",
".",
"__Content",
";",
"}",
"// setter method",
"else",
"{",
"if",
"(",
"!",
"self",
".",
"__destroyed",
")",
"{",
"// change the content",
"self",
".",
"__contentSet",
"(",
"content",
")",
";",
"if",
"(",
"self",
".",
"__Content",
"!==",
"null",
")",
"{",
"// update the tooltip if it is open",
"if",
"(",
"self",
".",
"__state",
"!==",
"'closed'",
")",
"{",
"// reset the content in the tooltip",
"self",
".",
"__contentInsert",
"(",
")",
";",
"// reposition and resize the tooltip",
"self",
".",
"reposition",
"(",
")",
";",
"// if we want to play a little animation showing the content changed",
"if",
"(",
"self",
".",
"__options",
".",
"updateAnimation",
")",
"{",
"if",
"(",
"env",
".",
"hasTransitions",
")",
"{",
"// keep the reference in the local scope",
"var",
"animation",
"=",
"self",
".",
"__options",
".",
"updateAnimation",
";",
"self",
".",
"_$tooltip",
".",
"addClass",
"(",
"'tooltipster-update-'",
"+",
"animation",
")",
";",
"// remove the class after a while. The actual duration of the",
"// update animation may be shorter, it's set in the CSS rules",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"__state",
"!=",
"'closed'",
")",
"{",
"self",
".",
"_$tooltip",
".",
"removeClass",
"(",
"'tooltipster-update-'",
"+",
"animation",
")",
";",
"}",
"}",
",",
"1000",
")",
";",
"}",
"else",
"{",
"self",
".",
"_$tooltip",
".",
"fadeTo",
"(",
"200",
",",
"0.5",
",",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"__state",
"!=",
"'closed'",
")",
"{",
"self",
".",
"_$tooltip",
".",
"fadeTo",
"(",
"200",
",",
"1",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"self",
".",
"_close",
"(",
")",
";",
"}",
"}",
"else",
"{",
"self",
".",
"__destroyError",
"(",
")",
";",
"}",
"return",
"self",
";",
"}",
"}"
] |
Sets or gets the content of the tooltip
@returns {mixed|self}
@public
|
[
"Sets",
"or",
"gets",
"the",
"content",
"of",
"the",
"tooltip"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2407-L2474
|
|
11,576
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
var self = this;
if (!self.__destroyed) {
if(self.__state != 'closed'){
// no closing delay
self.option('animationDuration', 0)
// force closing
._close(null, null, true);
}
else {
// there might be an open timeout still running
self.__timeoutsClear();
}
// send event
self._trigger('destroy');
self.__destroyed = true;
self._$origin
.removeData(self.__namespace)
// remove the open trigger listeners
.off('.'+ self.__namespace +'-triggerOpen');
// remove the touch listener
$(env.window.document.body).off('.' + self.__namespace +'-triggerOpen');
var ns = self._$origin.data('tooltipster-ns');
// if the origin has been removed from DOM, its data may
// well have been destroyed in the process and there would
// be nothing to clean up or restore
if (ns) {
// if there are no more tooltips on this element
if (ns.length === 1) {
// optional restoration of a title attribute
var title = null;
if (self.__options.restoration == 'previous') {
title = self._$origin.data('tooltipster-initialTitle');
}
else if (self.__options.restoration == 'current') {
// old school technique to stringify when outerHTML is not supported
title = (typeof self.__Content == 'string') ?
self.__Content :
$('<div></div>').append(self.__Content).html();
}
if (title) {
self._$origin.attr('title', title);
}
// final cleaning
self._$origin.removeClass('tooltipstered');
self._$origin
.removeData('tooltipster-ns')
.removeData('tooltipster-initialTitle');
}
else {
// remove the instance namespace from the list of namespaces of
// tooltips present on the element
ns = $.grep(ns, function(el, i) {
return el !== self.__namespace;
});
self._$origin.data('tooltipster-ns', ns);
}
}
// last event
self._trigger('destroyed');
// unbind private and public event listeners
self._off();
self.off();
// remove external references, just in case
self.__Content = null;
self.__$emitterPrivate = null;
self.__$emitterPublic = null;
self.__options.parent = null;
self._$origin = null;
self._$tooltip = null;
// make sure the object is no longer referenced in there to prevent
// memory leaks
$.tooltipster.__instancesLatestArr = $.grep($.tooltipster.__instancesLatestArr, function(el, i) {
return self !== el;
});
clearInterval(self.__garbageCollector);
}
else {
self.__destroyError();
}
// we return the scope rather than true so that the call to
// .tooltipster('destroy') actually returns the matched elements
// and applies to all of them
return self;
}
|
javascript
|
function() {
var self = this;
if (!self.__destroyed) {
if(self.__state != 'closed'){
// no closing delay
self.option('animationDuration', 0)
// force closing
._close(null, null, true);
}
else {
// there might be an open timeout still running
self.__timeoutsClear();
}
// send event
self._trigger('destroy');
self.__destroyed = true;
self._$origin
.removeData(self.__namespace)
// remove the open trigger listeners
.off('.'+ self.__namespace +'-triggerOpen');
// remove the touch listener
$(env.window.document.body).off('.' + self.__namespace +'-triggerOpen');
var ns = self._$origin.data('tooltipster-ns');
// if the origin has been removed from DOM, its data may
// well have been destroyed in the process and there would
// be nothing to clean up or restore
if (ns) {
// if there are no more tooltips on this element
if (ns.length === 1) {
// optional restoration of a title attribute
var title = null;
if (self.__options.restoration == 'previous') {
title = self._$origin.data('tooltipster-initialTitle');
}
else if (self.__options.restoration == 'current') {
// old school technique to stringify when outerHTML is not supported
title = (typeof self.__Content == 'string') ?
self.__Content :
$('<div></div>').append(self.__Content).html();
}
if (title) {
self._$origin.attr('title', title);
}
// final cleaning
self._$origin.removeClass('tooltipstered');
self._$origin
.removeData('tooltipster-ns')
.removeData('tooltipster-initialTitle');
}
else {
// remove the instance namespace from the list of namespaces of
// tooltips present on the element
ns = $.grep(ns, function(el, i) {
return el !== self.__namespace;
});
self._$origin.data('tooltipster-ns', ns);
}
}
// last event
self._trigger('destroyed');
// unbind private and public event listeners
self._off();
self.off();
// remove external references, just in case
self.__Content = null;
self.__$emitterPrivate = null;
self.__$emitterPublic = null;
self.__options.parent = null;
self._$origin = null;
self._$tooltip = null;
// make sure the object is no longer referenced in there to prevent
// memory leaks
$.tooltipster.__instancesLatestArr = $.grep($.tooltipster.__instancesLatestArr, function(el, i) {
return self !== el;
});
clearInterval(self.__garbageCollector);
}
else {
self.__destroyError();
}
// we return the scope rather than true so that the call to
// .tooltipster('destroy') actually returns the matched elements
// and applies to all of them
return self;
}
|
[
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"self",
".",
"__destroyed",
")",
"{",
"if",
"(",
"self",
".",
"__state",
"!=",
"'closed'",
")",
"{",
"// no closing delay",
"self",
".",
"option",
"(",
"'animationDuration'",
",",
"0",
")",
"// force closing",
".",
"_close",
"(",
"null",
",",
"null",
",",
"true",
")",
";",
"}",
"else",
"{",
"// there might be an open timeout still running",
"self",
".",
"__timeoutsClear",
"(",
")",
";",
"}",
"// send event",
"self",
".",
"_trigger",
"(",
"'destroy'",
")",
";",
"self",
".",
"__destroyed",
"=",
"true",
";",
"self",
".",
"_$origin",
".",
"removeData",
"(",
"self",
".",
"__namespace",
")",
"// remove the open trigger listeners",
".",
"off",
"(",
"'.'",
"+",
"self",
".",
"__namespace",
"+",
"'-triggerOpen'",
")",
";",
"// remove the touch listener",
"$",
"(",
"env",
".",
"window",
".",
"document",
".",
"body",
")",
".",
"off",
"(",
"'.'",
"+",
"self",
".",
"__namespace",
"+",
"'-triggerOpen'",
")",
";",
"var",
"ns",
"=",
"self",
".",
"_$origin",
".",
"data",
"(",
"'tooltipster-ns'",
")",
";",
"// if the origin has been removed from DOM, its data may",
"// well have been destroyed in the process and there would",
"// be nothing to clean up or restore",
"if",
"(",
"ns",
")",
"{",
"// if there are no more tooltips on this element",
"if",
"(",
"ns",
".",
"length",
"===",
"1",
")",
"{",
"// optional restoration of a title attribute",
"var",
"title",
"=",
"null",
";",
"if",
"(",
"self",
".",
"__options",
".",
"restoration",
"==",
"'previous'",
")",
"{",
"title",
"=",
"self",
".",
"_$origin",
".",
"data",
"(",
"'tooltipster-initialTitle'",
")",
";",
"}",
"else",
"if",
"(",
"self",
".",
"__options",
".",
"restoration",
"==",
"'current'",
")",
"{",
"// old school technique to stringify when outerHTML is not supported",
"title",
"=",
"(",
"typeof",
"self",
".",
"__Content",
"==",
"'string'",
")",
"?",
"self",
".",
"__Content",
":",
"$",
"(",
"'<div></div>'",
")",
".",
"append",
"(",
"self",
".",
"__Content",
")",
".",
"html",
"(",
")",
";",
"}",
"if",
"(",
"title",
")",
"{",
"self",
".",
"_$origin",
".",
"attr",
"(",
"'title'",
",",
"title",
")",
";",
"}",
"// final cleaning",
"self",
".",
"_$origin",
".",
"removeClass",
"(",
"'tooltipstered'",
")",
";",
"self",
".",
"_$origin",
".",
"removeData",
"(",
"'tooltipster-ns'",
")",
".",
"removeData",
"(",
"'tooltipster-initialTitle'",
")",
";",
"}",
"else",
"{",
"// remove the instance namespace from the list of namespaces of",
"// tooltips present on the element",
"ns",
"=",
"$",
".",
"grep",
"(",
"ns",
",",
"function",
"(",
"el",
",",
"i",
")",
"{",
"return",
"el",
"!==",
"self",
".",
"__namespace",
";",
"}",
")",
";",
"self",
".",
"_$origin",
".",
"data",
"(",
"'tooltipster-ns'",
",",
"ns",
")",
";",
"}",
"}",
"// last event",
"self",
".",
"_trigger",
"(",
"'destroyed'",
")",
";",
"// unbind private and public event listeners",
"self",
".",
"_off",
"(",
")",
";",
"self",
".",
"off",
"(",
")",
";",
"// remove external references, just in case",
"self",
".",
"__Content",
"=",
"null",
";",
"self",
".",
"__$emitterPrivate",
"=",
"null",
";",
"self",
".",
"__$emitterPublic",
"=",
"null",
";",
"self",
".",
"__options",
".",
"parent",
"=",
"null",
";",
"self",
".",
"_$origin",
"=",
"null",
";",
"self",
".",
"_$tooltip",
"=",
"null",
";",
"// make sure the object is no longer referenced in there to prevent",
"// memory leaks",
"$",
".",
"tooltipster",
".",
"__instancesLatestArr",
"=",
"$",
".",
"grep",
"(",
"$",
".",
"tooltipster",
".",
"__instancesLatestArr",
",",
"function",
"(",
"el",
",",
"i",
")",
"{",
"return",
"self",
"!==",
"el",
";",
"}",
")",
";",
"clearInterval",
"(",
"self",
".",
"__garbageCollector",
")",
";",
"}",
"else",
"{",
"self",
".",
"__destroyError",
"(",
")",
";",
"}",
"// we return the scope rather than true so that the call to",
"// .tooltipster('destroy') actually returns the matched elements",
"// and applies to all of them",
"return",
"self",
";",
"}"
] |
Destroys the tooltip
@returns {self}
@public
|
[
"Destroys",
"the",
"tooltip"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2482-L2589
|
|
11,577
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function(o, val) {
// getter
if (val === undefined) {
return this.__options[o];
}
// setter
else {
if (!this.__destroyed) {
// change value
this.__options[o] = val;
// format
this.__optionsFormat();
// re-prepare the triggers if needed
if ($.inArray(o, ['trigger', 'triggerClose', 'triggerOpen']) >= 0) {
this.__prepareOrigin();
}
if (o === 'selfDestruction') {
this.__prepareGC();
}
}
else {
this.__destroyError();
}
return this;
}
}
|
javascript
|
function(o, val) {
// getter
if (val === undefined) {
return this.__options[o];
}
// setter
else {
if (!this.__destroyed) {
// change value
this.__options[o] = val;
// format
this.__optionsFormat();
// re-prepare the triggers if needed
if ($.inArray(o, ['trigger', 'triggerClose', 'triggerOpen']) >= 0) {
this.__prepareOrigin();
}
if (o === 'selfDestruction') {
this.__prepareGC();
}
}
else {
this.__destroyError();
}
return this;
}
}
|
[
"function",
"(",
"o",
",",
"val",
")",
"{",
"// getter",
"if",
"(",
"val",
"===",
"undefined",
")",
"{",
"return",
"this",
".",
"__options",
"[",
"o",
"]",
";",
"}",
"// setter",
"else",
"{",
"if",
"(",
"!",
"this",
".",
"__destroyed",
")",
"{",
"// change value",
"this",
".",
"__options",
"[",
"o",
"]",
"=",
"val",
";",
"// format",
"this",
".",
"__optionsFormat",
"(",
")",
";",
"// re-prepare the triggers if needed",
"if",
"(",
"$",
".",
"inArray",
"(",
"o",
",",
"[",
"'trigger'",
",",
"'triggerClose'",
",",
"'triggerOpen'",
"]",
")",
">=",
"0",
")",
"{",
"this",
".",
"__prepareOrigin",
"(",
")",
";",
"}",
"if",
"(",
"o",
"===",
"'selfDestruction'",
")",
"{",
"this",
".",
"__prepareGC",
"(",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"__destroyError",
"(",
")",
";",
"}",
"return",
"this",
";",
"}",
"}"
] |
Get or set options. For internal use and advanced users only.
@param {string} o Option name
@param {mixed} val optional A new value for the option
@return {mixed|self} If val is omitted, the value of the option
is returned, otherwise the instance itself is returned
@public
|
[
"Get",
"or",
"set",
"options",
".",
"For",
"internal",
"use",
"and",
"advanced",
"users",
"only",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2750-L2782
|
|
11,578
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
if (!this.__destroyed) {
this.__$emitterPublic.triggerHandler.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
}
else {
this.__destroyError();
}
return this;
}
|
javascript
|
function() {
if (!this.__destroyed) {
this.__$emitterPublic.triggerHandler.apply(this.__$emitterPublic, Array.prototype.slice.apply(arguments));
}
else {
this.__destroyError();
}
return this;
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"__destroyed",
")",
"{",
"this",
".",
"__$emitterPublic",
".",
"triggerHandler",
".",
"apply",
"(",
"this",
".",
"__$emitterPublic",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"}",
"else",
"{",
"this",
".",
"__destroyError",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
For public use only, not to be used by plugins
@returns {self}
@public
|
[
"For",
"public",
"use",
"only",
"not",
"to",
"be",
"used",
"by",
"plugins"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L2871-L2881
|
|
11,579
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
function() {
this.__forceRedraw();
var tooltipBcr = this.__$tooltip[0].getBoundingClientRect(),
result = { size: {
// bcr.width/height are not defined in IE8- but in this
// case, bcr.right/bottom will have the same value
// except in iOS 8+ where tooltipBcr.bottom/right are wrong
// after scrolling for reasons yet to be determined.
// tooltipBcr.top/left might not be 0, see issue #514
height: tooltipBcr.height || (tooltipBcr.bottom - tooltipBcr.top),
width: tooltipBcr.width || (tooltipBcr.right - tooltipBcr.left)
}};
if (this.constraints) {
// note: we used to use offsetWidth instead of boundingRectClient but
// it returned rounded values, causing issues with sub-pixel layouts.
// note2: noticed that the bcrWidth of text content of a div was once
// greater than the bcrWidth of its container by 1px, causing the final
// tooltip box to be too small for its content. However, evaluating
// their widths one against the other (below) surprisingly returned
// equality. Happened only once in Chrome 48, was not able to reproduce
// => just having fun with float position values...
var $content = this.__$tooltip.find('.tooltipster-content'),
height = this.__$tooltip.outerHeight(),
contentBcr = $content[0].getBoundingClientRect(),
fits = {
height: height <= this.constraints.height,
width: (
// this condition accounts for min-width property that
// may apply
tooltipBcr.width <= this.constraints.width
// the -1 is here because scrollWidth actually returns
// a rounded value, and may be greater than bcr.width if
// it was rounded up. This may cause an issue for contents
// which actually really overflow by 1px or so, but that
// should be rare. Not sure how to solve this efficiently.
// See http://blogs.msdn.com/b/ie/archive/2012/02/17/sub-pixel-rendering-and-the-css-object-model.aspx
&& contentBcr.width >= $content[0].scrollWidth - 1
)
};
result.fits = fits.height && fits.width;
}
// old versions of IE get the width wrong for some reason and it causes
// the text to be broken to a new line, so we round it up. If the width
// is the width of the screen though, we can assume it is accurate.
if ( env.IE
&& env.IE <= 11
&& result.size.width !== env.window.document.documentElement.clientWidth
) {
result.size.width = Math.ceil(result.size.width) + 1;
}
return result;
}
|
javascript
|
function() {
this.__forceRedraw();
var tooltipBcr = this.__$tooltip[0].getBoundingClientRect(),
result = { size: {
// bcr.width/height are not defined in IE8- but in this
// case, bcr.right/bottom will have the same value
// except in iOS 8+ where tooltipBcr.bottom/right are wrong
// after scrolling for reasons yet to be determined.
// tooltipBcr.top/left might not be 0, see issue #514
height: tooltipBcr.height || (tooltipBcr.bottom - tooltipBcr.top),
width: tooltipBcr.width || (tooltipBcr.right - tooltipBcr.left)
}};
if (this.constraints) {
// note: we used to use offsetWidth instead of boundingRectClient but
// it returned rounded values, causing issues with sub-pixel layouts.
// note2: noticed that the bcrWidth of text content of a div was once
// greater than the bcrWidth of its container by 1px, causing the final
// tooltip box to be too small for its content. However, evaluating
// their widths one against the other (below) surprisingly returned
// equality. Happened only once in Chrome 48, was not able to reproduce
// => just having fun with float position values...
var $content = this.__$tooltip.find('.tooltipster-content'),
height = this.__$tooltip.outerHeight(),
contentBcr = $content[0].getBoundingClientRect(),
fits = {
height: height <= this.constraints.height,
width: (
// this condition accounts for min-width property that
// may apply
tooltipBcr.width <= this.constraints.width
// the -1 is here because scrollWidth actually returns
// a rounded value, and may be greater than bcr.width if
// it was rounded up. This may cause an issue for contents
// which actually really overflow by 1px or so, but that
// should be rare. Not sure how to solve this efficiently.
// See http://blogs.msdn.com/b/ie/archive/2012/02/17/sub-pixel-rendering-and-the-css-object-model.aspx
&& contentBcr.width >= $content[0].scrollWidth - 1
)
};
result.fits = fits.height && fits.width;
}
// old versions of IE get the width wrong for some reason and it causes
// the text to be broken to a new line, so we round it up. If the width
// is the width of the screen though, we can assume it is accurate.
if ( env.IE
&& env.IE <= 11
&& result.size.width !== env.window.document.documentElement.clientWidth
) {
result.size.width = Math.ceil(result.size.width) + 1;
}
return result;
}
|
[
"function",
"(",
")",
"{",
"this",
".",
"__forceRedraw",
"(",
")",
";",
"var",
"tooltipBcr",
"=",
"this",
".",
"__$tooltip",
"[",
"0",
"]",
".",
"getBoundingClientRect",
"(",
")",
",",
"result",
"=",
"{",
"size",
":",
"{",
"// bcr.width/height are not defined in IE8- but in this",
"// case, bcr.right/bottom will have the same value",
"// except in iOS 8+ where tooltipBcr.bottom/right are wrong",
"// after scrolling for reasons yet to be determined.",
"// tooltipBcr.top/left might not be 0, see issue #514",
"height",
":",
"tooltipBcr",
".",
"height",
"||",
"(",
"tooltipBcr",
".",
"bottom",
"-",
"tooltipBcr",
".",
"top",
")",
",",
"width",
":",
"tooltipBcr",
".",
"width",
"||",
"(",
"tooltipBcr",
".",
"right",
"-",
"tooltipBcr",
".",
"left",
")",
"}",
"}",
";",
"if",
"(",
"this",
".",
"constraints",
")",
"{",
"// note: we used to use offsetWidth instead of boundingRectClient but",
"// it returned rounded values, causing issues with sub-pixel layouts.",
"// note2: noticed that the bcrWidth of text content of a div was once",
"// greater than the bcrWidth of its container by 1px, causing the final",
"// tooltip box to be too small for its content. However, evaluating",
"// their widths one against the other (below) surprisingly returned",
"// equality. Happened only once in Chrome 48, was not able to reproduce",
"// => just having fun with float position values...",
"var",
"$content",
"=",
"this",
".",
"__$tooltip",
".",
"find",
"(",
"'.tooltipster-content'",
")",
",",
"height",
"=",
"this",
".",
"__$tooltip",
".",
"outerHeight",
"(",
")",
",",
"contentBcr",
"=",
"$content",
"[",
"0",
"]",
".",
"getBoundingClientRect",
"(",
")",
",",
"fits",
"=",
"{",
"height",
":",
"height",
"<=",
"this",
".",
"constraints",
".",
"height",
",",
"width",
":",
"(",
"// this condition accounts for min-width property that",
"// may apply",
"tooltipBcr",
".",
"width",
"<=",
"this",
".",
"constraints",
".",
"width",
"// the -1 is here because scrollWidth actually returns",
"// a rounded value, and may be greater than bcr.width if",
"// it was rounded up. This may cause an issue for contents",
"// which actually really overflow by 1px or so, but that",
"// should be rare. Not sure how to solve this efficiently.",
"// See http://blogs.msdn.com/b/ie/archive/2012/02/17/sub-pixel-rendering-and-the-css-object-model.aspx",
"&&",
"contentBcr",
".",
"width",
">=",
"$content",
"[",
"0",
"]",
".",
"scrollWidth",
"-",
"1",
")",
"}",
";",
"result",
".",
"fits",
"=",
"fits",
".",
"height",
"&&",
"fits",
".",
"width",
";",
"}",
"// old versions of IE get the width wrong for some reason and it causes",
"// the text to be broken to a new line, so we round it up. If the width",
"// is the width of the screen though, we can assume it is accurate.",
"if",
"(",
"env",
".",
"IE",
"&&",
"env",
".",
"IE",
"<=",
"11",
"&&",
"result",
".",
"size",
".",
"width",
"!==",
"env",
".",
"window",
".",
"document",
".",
"documentElement",
".",
"clientWidth",
")",
"{",
"result",
".",
"size",
".",
"width",
"=",
"Math",
".",
"ceil",
"(",
"result",
".",
"size",
".",
"width",
")",
"+",
"1",
";",
"}",
"return",
"result",
";",
"}"
] |
Returns the size of the tooltip. When constraints are applied, also returns
whether the tooltip fits in the provided dimensions.
The idea is to see if the new height is small enough and if the content does
not overflow horizontally.
@param {int} width
@param {int} height
@returns {object} An object with a bool `fits` property and a `size` property
@public
|
[
"Returns",
"the",
"size",
"of",
"the",
"tooltip",
".",
"When",
"constraints",
"are",
"applied",
"also",
"returns",
"whether",
"the",
"tooltip",
"fits",
"in",
"the",
"provided",
"dimensions",
".",
"The",
"idea",
"is",
"to",
"see",
"if",
"the",
"new",
"height",
"is",
"small",
"enough",
"and",
"if",
"the",
"content",
"does",
"not",
"overflow",
"horizontally",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L3202-L3262
|
|
11,580
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
areEqual
|
function areEqual(a,b) {
var same = true;
$.each(a, function(i, _) {
if (b[i] === undefined || a[i] !== b[i]) {
same = false;
return false;
}
});
return same;
}
|
javascript
|
function areEqual(a,b) {
var same = true;
$.each(a, function(i, _) {
if (b[i] === undefined || a[i] !== b[i]) {
same = false;
return false;
}
});
return same;
}
|
[
"function",
"areEqual",
"(",
"a",
",",
"b",
")",
"{",
"var",
"same",
"=",
"true",
";",
"$",
".",
"each",
"(",
"a",
",",
"function",
"(",
"i",
",",
"_",
")",
"{",
"if",
"(",
"b",
"[",
"i",
"]",
"===",
"undefined",
"||",
"a",
"[",
"i",
"]",
"!==",
"b",
"[",
"i",
"]",
")",
"{",
"same",
"=",
"false",
";",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"same",
";",
"}"
] |
quick & dirty compare function, not bijective nor multidimensional
|
[
"quick",
"&",
"dirty",
"compare",
"function",
"not",
"bijective",
"nor",
"multidimensional"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L3266-L3275
|
11,581
|
iamceege/tooltipster
|
src/js/tooltipster.js
|
bodyContains
|
function bodyContains($obj) {
var id = $obj.attr('id'),
el = id ? env.window.document.getElementById(id) : null;
// must also check that the element with the id is the one we want
return el ? el === $obj[0] : $.contains(env.window.document.body, $obj[0]);
}
|
javascript
|
function bodyContains($obj) {
var id = $obj.attr('id'),
el = id ? env.window.document.getElementById(id) : null;
// must also check that the element with the id is the one we want
return el ? el === $obj[0] : $.contains(env.window.document.body, $obj[0]);
}
|
[
"function",
"bodyContains",
"(",
"$obj",
")",
"{",
"var",
"id",
"=",
"$obj",
".",
"attr",
"(",
"'id'",
")",
",",
"el",
"=",
"id",
"?",
"env",
".",
"window",
".",
"document",
".",
"getElementById",
"(",
"id",
")",
":",
"null",
";",
"// must also check that the element with the id is the one we want",
"return",
"el",
"?",
"el",
"===",
"$obj",
"[",
"0",
"]",
":",
"$",
".",
"contains",
"(",
"env",
".",
"window",
".",
"document",
".",
"body",
",",
"$obj",
"[",
"0",
"]",
")",
";",
"}"
] |
A fast function to check if an element is still in the DOM. It
tries to use an id as ids are indexed by the browser, or falls
back to jQuery's `contains` method. May fail if two elements
have the same id, but so be it
@param {object} $obj A jQuery-wrapped HTML element
@return {boolean}
|
[
"A",
"fast",
"function",
"to",
"check",
"if",
"an",
"element",
"is",
"still",
"in",
"the",
"DOM",
".",
"It",
"tries",
"to",
"use",
"an",
"id",
"as",
"ids",
"are",
"indexed",
"by",
"the",
"browser",
"or",
"falls",
"back",
"to",
"jQuery",
"s",
"contains",
"method",
".",
"May",
"fail",
"if",
"two",
"elements",
"have",
"the",
"same",
"id",
"but",
"so",
"be",
"it"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/tooltipster.js#L3286-L3291
|
11,582
|
iamceege/tooltipster
|
src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js
|
function() {
return {
// if the tooltip should display an arrow that points to the origin
arrow: true,
// the distance in pixels between the tooltip and the origin
distance: 6,
// allows to easily change the position of the tooltip
functionPosition: null,
maxWidth: null,
// used to accomodate the arrow of tooltip if there is one.
// First to make sure that the arrow target is not too close
// to the edge of the tooltip, so the arrow does not overflow
// the tooltip. Secondly when we reposition the tooltip to
// make sure that it's positioned in such a way that the arrow is
// still pointing at the target (and not a few pixels beyond it).
// It should be equal to or greater than half the width of
// the arrow (by width we mean the size of the side which touches
// the side of the tooltip).
minIntersection: 16,
minWidth: 0,
// deprecated in 4.0.0. Listed for _optionsExtract to pick it up
position: null,
side: 'top',
// set to false to position the tooltip relatively to the document rather
// than the window when we open it
viewportAware: true
};
}
|
javascript
|
function() {
return {
// if the tooltip should display an arrow that points to the origin
arrow: true,
// the distance in pixels between the tooltip and the origin
distance: 6,
// allows to easily change the position of the tooltip
functionPosition: null,
maxWidth: null,
// used to accomodate the arrow of tooltip if there is one.
// First to make sure that the arrow target is not too close
// to the edge of the tooltip, so the arrow does not overflow
// the tooltip. Secondly when we reposition the tooltip to
// make sure that it's positioned in such a way that the arrow is
// still pointing at the target (and not a few pixels beyond it).
// It should be equal to or greater than half the width of
// the arrow (by width we mean the size of the side which touches
// the side of the tooltip).
minIntersection: 16,
minWidth: 0,
// deprecated in 4.0.0. Listed for _optionsExtract to pick it up
position: null,
side: 'top',
// set to false to position the tooltip relatively to the document rather
// than the window when we open it
viewportAware: true
};
}
|
[
"function",
"(",
")",
"{",
"return",
"{",
"// if the tooltip should display an arrow that points to the origin",
"arrow",
":",
"true",
",",
"// the distance in pixels between the tooltip and the origin",
"distance",
":",
"6",
",",
"// allows to easily change the position of the tooltip",
"functionPosition",
":",
"null",
",",
"maxWidth",
":",
"null",
",",
"// used to accomodate the arrow of tooltip if there is one.",
"// First to make sure that the arrow target is not too close",
"// to the edge of the tooltip, so the arrow does not overflow",
"// the tooltip. Secondly when we reposition the tooltip to",
"// make sure that it's positioned in such a way that the arrow is",
"// still pointing at the target (and not a few pixels beyond it).",
"// It should be equal to or greater than half the width of",
"// the arrow (by width we mean the size of the side which touches",
"// the side of the tooltip).",
"minIntersection",
":",
"16",
",",
"minWidth",
":",
"0",
",",
"// deprecated in 4.0.0. Listed for _optionsExtract to pick it up",
"position",
":",
"null",
",",
"side",
":",
"'top'",
",",
"// set to false to position the tooltip relatively to the document rather",
"// than the window when we open it",
"viewportAware",
":",
"true",
"}",
";",
"}"
] |
Defaults are provided as a function for an easy override by inheritance
@return {object} An object with the defaults options
@private
|
[
"Defaults",
"are",
"provided",
"as",
"a",
"function",
"for",
"an",
"easy",
"override",
"by",
"inheritance"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js#L15-L43
|
|
11,583
|
iamceege/tooltipster
|
src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js
|
function() {
// detach our content object first, so the next jQuery's remove()
// call does not unbind its event handlers
if (this.__instance.content() instanceof $) {
this.__instance.content().detach();
}
// remove the tooltip from the DOM
this.__instance._$tooltip.remove();
this.__instance._$tooltip = null;
}
|
javascript
|
function() {
// detach our content object first, so the next jQuery's remove()
// call does not unbind its event handlers
if (this.__instance.content() instanceof $) {
this.__instance.content().detach();
}
// remove the tooltip from the DOM
this.__instance._$tooltip.remove();
this.__instance._$tooltip = null;
}
|
[
"function",
"(",
")",
"{",
"// detach our content object first, so the next jQuery's remove()",
"// call does not unbind its event handlers",
"if",
"(",
"this",
".",
"__instance",
".",
"content",
"(",
")",
"instanceof",
"$",
")",
"{",
"this",
".",
"__instance",
".",
"content",
"(",
")",
".",
"detach",
"(",
")",
";",
"}",
"// remove the tooltip from the DOM",
"this",
".",
"__instance",
".",
"_$tooltip",
".",
"remove",
"(",
")",
";",
"this",
".",
"__instance",
".",
"_$tooltip",
"=",
"null",
";",
"}"
] |
Called when the tooltip has closed
@private
|
[
"Called",
"when",
"the",
"tooltip",
"has",
"closed"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js#L92-L103
|
|
11,584
|
iamceege/tooltipster
|
src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js
|
function() {
// note: we wrap with a .tooltipster-box div to be able to set a margin on it
// (.tooltipster-base must not have one)
var $html = $(
'<div class="tooltipster-base tooltipster-sidetip">' +
'<div class="tooltipster-box">' +
'<div class="tooltipster-content"></div>' +
'</div>' +
'<div class="tooltipster-arrow">' +
'<div class="tooltipster-arrow-uncropped">' +
'<div class="tooltipster-arrow-border"></div>' +
'<div class="tooltipster-arrow-background"></div>' +
'</div>' +
'</div>' +
'</div>'
);
// hide arrow if asked
if (!this.__options.arrow) {
$html
.find('.tooltipster-box')
.css('margin', 0)
.end()
.find('.tooltipster-arrow')
.hide();
}
// apply min/max width if asked
if (this.__options.minWidth) {
$html.css('min-width', this.__options.minWidth + 'px');
}
if (this.__options.maxWidth) {
$html.css('max-width', this.__options.maxWidth + 'px');
}
this.__instance._$tooltip = $html;
// tell the instance that the tooltip element has been created
this.__instance._trigger('created');
}
|
javascript
|
function() {
// note: we wrap with a .tooltipster-box div to be able to set a margin on it
// (.tooltipster-base must not have one)
var $html = $(
'<div class="tooltipster-base tooltipster-sidetip">' +
'<div class="tooltipster-box">' +
'<div class="tooltipster-content"></div>' +
'</div>' +
'<div class="tooltipster-arrow">' +
'<div class="tooltipster-arrow-uncropped">' +
'<div class="tooltipster-arrow-border"></div>' +
'<div class="tooltipster-arrow-background"></div>' +
'</div>' +
'</div>' +
'</div>'
);
// hide arrow if asked
if (!this.__options.arrow) {
$html
.find('.tooltipster-box')
.css('margin', 0)
.end()
.find('.tooltipster-arrow')
.hide();
}
// apply min/max width if asked
if (this.__options.minWidth) {
$html.css('min-width', this.__options.minWidth + 'px');
}
if (this.__options.maxWidth) {
$html.css('max-width', this.__options.maxWidth + 'px');
}
this.__instance._$tooltip = $html;
// tell the instance that the tooltip element has been created
this.__instance._trigger('created');
}
|
[
"function",
"(",
")",
"{",
"// note: we wrap with a .tooltipster-box div to be able to set a margin on it",
"// (.tooltipster-base must not have one)",
"var",
"$html",
"=",
"$",
"(",
"'<div class=\"tooltipster-base tooltipster-sidetip\">'",
"+",
"'<div class=\"tooltipster-box\">'",
"+",
"'<div class=\"tooltipster-content\"></div>'",
"+",
"'</div>'",
"+",
"'<div class=\"tooltipster-arrow\">'",
"+",
"'<div class=\"tooltipster-arrow-uncropped\">'",
"+",
"'<div class=\"tooltipster-arrow-border\"></div>'",
"+",
"'<div class=\"tooltipster-arrow-background\"></div>'",
"+",
"'</div>'",
"+",
"'</div>'",
"+",
"'</div>'",
")",
";",
"// hide arrow if asked",
"if",
"(",
"!",
"this",
".",
"__options",
".",
"arrow",
")",
"{",
"$html",
".",
"find",
"(",
"'.tooltipster-box'",
")",
".",
"css",
"(",
"'margin'",
",",
"0",
")",
".",
"end",
"(",
")",
".",
"find",
"(",
"'.tooltipster-arrow'",
")",
".",
"hide",
"(",
")",
";",
"}",
"// apply min/max width if asked",
"if",
"(",
"this",
".",
"__options",
".",
"minWidth",
")",
"{",
"$html",
".",
"css",
"(",
"'min-width'",
",",
"this",
".",
"__options",
".",
"minWidth",
"+",
"'px'",
")",
";",
"}",
"if",
"(",
"this",
".",
"__options",
".",
"maxWidth",
")",
"{",
"$html",
".",
"css",
"(",
"'max-width'",
",",
"this",
".",
"__options",
".",
"maxWidth",
"+",
"'px'",
")",
";",
"}",
"this",
".",
"__instance",
".",
"_$tooltip",
"=",
"$html",
";",
"// tell the instance that the tooltip element has been created",
"this",
".",
"__instance",
".",
"_trigger",
"(",
"'created'",
")",
";",
"}"
] |
Creates the HTML element of the tooltip.
@private
|
[
"Creates",
"the",
"HTML",
"element",
"of",
"the",
"tooltip",
"."
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/src/js/plugins/tooltipster/sideTip/tooltipster-sideTip.js#L110-L150
|
|
11,585
|
iamceege/tooltipster
|
doc/js/scripts.js
|
function(instance, helper, data){
// this function is pretty dumb and does not check if there is actually
// enough space available around the tooltip to move it, it just makes it
// snap to the grid. You might want to do something smarter in your app!
var gridBcr = $('#demo-position-grid')[0].getBoundingClientRect(),
arrowSize = parseInt($(helper.tooltipClone).find('.tooltipster-box').css('margin-left'));
// override these
data.coord = {
// move the tooltip so the arrow overflows the grid
left: gridBcr.left - arrowSize,
top: gridBcr.top
};
return data;
}
|
javascript
|
function(instance, helper, data){
// this function is pretty dumb and does not check if there is actually
// enough space available around the tooltip to move it, it just makes it
// snap to the grid. You might want to do something smarter in your app!
var gridBcr = $('#demo-position-grid')[0].getBoundingClientRect(),
arrowSize = parseInt($(helper.tooltipClone).find('.tooltipster-box').css('margin-left'));
// override these
data.coord = {
// move the tooltip so the arrow overflows the grid
left: gridBcr.left - arrowSize,
top: gridBcr.top
};
return data;
}
|
[
"function",
"(",
"instance",
",",
"helper",
",",
"data",
")",
"{",
"// this function is pretty dumb and does not check if there is actually\r",
"// enough space available around the tooltip to move it, it just makes it\r",
"// snap to the grid. You might want to do something smarter in your app!\r",
"var",
"gridBcr",
"=",
"$",
"(",
"'#demo-position-grid'",
")",
"[",
"0",
"]",
".",
"getBoundingClientRect",
"(",
")",
",",
"arrowSize",
"=",
"parseInt",
"(",
"$",
"(",
"helper",
".",
"tooltipClone",
")",
".",
"find",
"(",
"'.tooltipster-box'",
")",
".",
"css",
"(",
"'margin-left'",
")",
")",
";",
"// override these\r",
"data",
".",
"coord",
"=",
"{",
"// move the tooltip so the arrow overflows the grid\r",
"left",
":",
"gridBcr",
".",
"left",
"-",
"arrowSize",
",",
"top",
":",
"gridBcr",
".",
"top",
"}",
";",
"return",
"data",
";",
"}"
] |
8 extra pixels for the arrow to overflow the grid
|
[
"8",
"extra",
"pixels",
"for",
"the",
"arrow",
"to",
"overflow",
"the",
"grid"
] |
bb575f0c8d7494b80cca60a235e14b9477bd1ab7
|
https://github.com/iamceege/tooltipster/blob/bb575f0c8d7494b80cca60a235e14b9477bd1ab7/doc/js/scripts.js#L203-L220
|
|
11,586
|
dthree/cash
|
src/commands/rm.js
|
isWriteable
|
function isWriteable(file) {
let writePermission = true;
try {
const __fd = fs.openSync(file, 'a');
fs.closeSync(__fd);
} catch (e) {
/* istanbul ignore next */
writePermission = false;
}
return writePermission;
}
|
javascript
|
function isWriteable(file) {
let writePermission = true;
try {
const __fd = fs.openSync(file, 'a');
fs.closeSync(__fd);
} catch (e) {
/* istanbul ignore next */
writePermission = false;
}
return writePermission;
}
|
[
"function",
"isWriteable",
"(",
"file",
")",
"{",
"let",
"writePermission",
"=",
"true",
";",
"try",
"{",
"const",
"__fd",
"=",
"fs",
".",
"openSync",
"(",
"file",
",",
"'a'",
")",
";",
"fs",
".",
"closeSync",
"(",
"__fd",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"/* istanbul ignore next */",
"writePermission",
"=",
"false",
";",
"}",
"return",
"writePermission",
";",
"}"
] |
Hack to determine if file has write permissions for current user Avoids having to check user, group, etc, but it's probably slow.
|
[
"Hack",
"to",
"determine",
"if",
"file",
"has",
"write",
"permissions",
"for",
"current",
"user",
"Avoids",
"having",
"to",
"check",
"user",
"group",
"etc",
"but",
"it",
"s",
"probably",
"slow",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/src/commands/rm.js#L147-L158
|
11,587
|
dthree/cash
|
dist/windows.js
|
print
|
function print() {
var parts = String(out).split('\n');
/* istanbul ignore next */
if (parts.length > 1) {
out = parts.pop();
var logging = String(parts.join('\n')).replace(/\r\r/g, '\r');
slf.log(logging);
}
/* istanbul ignore next */
if (closed === false) {
setTimeout(function () {
print();
}, 50);
}
}
|
javascript
|
function print() {
var parts = String(out).split('\n');
/* istanbul ignore next */
if (parts.length > 1) {
out = parts.pop();
var logging = String(parts.join('\n')).replace(/\r\r/g, '\r');
slf.log(logging);
}
/* istanbul ignore next */
if (closed === false) {
setTimeout(function () {
print();
}, 50);
}
}
|
[
"function",
"print",
"(",
")",
"{",
"var",
"parts",
"=",
"String",
"(",
"out",
")",
".",
"split",
"(",
"'\\n'",
")",
";",
"/* istanbul ignore next */",
"if",
"(",
"parts",
".",
"length",
">",
"1",
")",
"{",
"out",
"=",
"parts",
".",
"pop",
"(",
")",
";",
"var",
"logging",
"=",
"String",
"(",
"parts",
".",
"join",
"(",
"'\\n'",
")",
")",
".",
"replace",
"(",
"/",
"\\r\\r",
"/",
"g",
",",
"'\\r'",
")",
";",
"slf",
".",
"log",
"(",
"logging",
")",
";",
"}",
"/* istanbul ignore next */",
"if",
"(",
"closed",
"===",
"false",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"print",
"(",
")",
";",
"}",
",",
"50",
")",
";",
"}",
"}"
] |
Properly print stdout as it's fed, waiting for line breaks before sending it to Vorpal.
|
[
"Properly",
"print",
"stdout",
"as",
"it",
"s",
"fed",
"waiting",
"for",
"line",
"breaks",
"before",
"sending",
"it",
"to",
"Vorpal",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/dist/windows.js#L84-L98
|
11,588
|
dthree/cash
|
packages/touch/dist/commands/touch.js
|
file
|
function file(path, options) {
try {
try {
fs.lstatSync(path);
} catch (e) {
// If the file doesn't exist and
// the user doesn't want to create it,
// we have no purpose in life. Goodbye.
if (options.create === false) {
throw new Error(e);
} else {
fs.closeSync(fs.openSync(path, 'wx'));
}
}
var stat = fs.statSync(path);
var dateToSet = options.date ? Date.create(options.date) : new Date();
if (String(dateToSet) === 'Invalid Date') {
throw new Error('touch: invalid date format ' + options.date);
}
// If -m, keep access time current.
var atime = options.m === true ? new Date(stat.atime) : dateToSet;
// If -a, keep mod time to current.
var mtime = options.a === true ? new Date(stat.mtime) : dateToSet;
if (options.reference !== undefined) {
var reference = void 0;
try {
reference = fs.statSync(options.reference);
} catch (e) {
throw new Error('touch: failed to get attributes of ' + options.reference + ': No such file or directory');
}
atime = options.m === true ? atime : reference.atime;
mtime = options.a === true ? mtime : reference.mtime;
}
fs.utimesSync(path, atime, mtime);
fs.utimesSync(path, atime, mtime);
} catch (e) {
throw new Error(e);
}
}
|
javascript
|
function file(path, options) {
try {
try {
fs.lstatSync(path);
} catch (e) {
// If the file doesn't exist and
// the user doesn't want to create it,
// we have no purpose in life. Goodbye.
if (options.create === false) {
throw new Error(e);
} else {
fs.closeSync(fs.openSync(path, 'wx'));
}
}
var stat = fs.statSync(path);
var dateToSet = options.date ? Date.create(options.date) : new Date();
if (String(dateToSet) === 'Invalid Date') {
throw new Error('touch: invalid date format ' + options.date);
}
// If -m, keep access time current.
var atime = options.m === true ? new Date(stat.atime) : dateToSet;
// If -a, keep mod time to current.
var mtime = options.a === true ? new Date(stat.mtime) : dateToSet;
if (options.reference !== undefined) {
var reference = void 0;
try {
reference = fs.statSync(options.reference);
} catch (e) {
throw new Error('touch: failed to get attributes of ' + options.reference + ': No such file or directory');
}
atime = options.m === true ? atime : reference.atime;
mtime = options.a === true ? mtime : reference.mtime;
}
fs.utimesSync(path, atime, mtime);
fs.utimesSync(path, atime, mtime);
} catch (e) {
throw new Error(e);
}
}
|
[
"function",
"file",
"(",
"path",
",",
"options",
")",
"{",
"try",
"{",
"try",
"{",
"fs",
".",
"lstatSync",
"(",
"path",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// If the file doesn't exist and",
"// the user doesn't want to create it,",
"// we have no purpose in life. Goodbye.",
"if",
"(",
"options",
".",
"create",
"===",
"false",
")",
"{",
"throw",
"new",
"Error",
"(",
"e",
")",
";",
"}",
"else",
"{",
"fs",
".",
"closeSync",
"(",
"fs",
".",
"openSync",
"(",
"path",
",",
"'wx'",
")",
")",
";",
"}",
"}",
"var",
"stat",
"=",
"fs",
".",
"statSync",
"(",
"path",
")",
";",
"var",
"dateToSet",
"=",
"options",
".",
"date",
"?",
"Date",
".",
"create",
"(",
"options",
".",
"date",
")",
":",
"new",
"Date",
"(",
")",
";",
"if",
"(",
"String",
"(",
"dateToSet",
")",
"===",
"'Invalid Date'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'touch: invalid date format '",
"+",
"options",
".",
"date",
")",
";",
"}",
"// If -m, keep access time current.",
"var",
"atime",
"=",
"options",
".",
"m",
"===",
"true",
"?",
"new",
"Date",
"(",
"stat",
".",
"atime",
")",
":",
"dateToSet",
";",
"// If -a, keep mod time to current.",
"var",
"mtime",
"=",
"options",
".",
"a",
"===",
"true",
"?",
"new",
"Date",
"(",
"stat",
".",
"mtime",
")",
":",
"dateToSet",
";",
"if",
"(",
"options",
".",
"reference",
"!==",
"undefined",
")",
"{",
"var",
"reference",
"=",
"void",
"0",
";",
"try",
"{",
"reference",
"=",
"fs",
".",
"statSync",
"(",
"options",
".",
"reference",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"'touch: failed to get attributes of '",
"+",
"options",
".",
"reference",
"+",
"': No such file or directory'",
")",
";",
"}",
"atime",
"=",
"options",
".",
"m",
"===",
"true",
"?",
"atime",
":",
"reference",
".",
"atime",
";",
"mtime",
"=",
"options",
".",
"a",
"===",
"true",
"?",
"mtime",
":",
"reference",
".",
"mtime",
";",
"}",
"fs",
".",
"utimesSync",
"(",
"path",
",",
"atime",
",",
"mtime",
")",
";",
"fs",
".",
"utimesSync",
"(",
"path",
",",
"atime",
",",
"mtime",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"Error",
"(",
"e",
")",
";",
"}",
"}"
] |
Handler for a single file using touch.
@param {String} path
@param {Object} options
@api private
|
[
"Handler",
"for",
"a",
"single",
"file",
"using",
"touch",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/packages/touch/dist/commands/touch.js#L93-L137
|
11,589
|
dthree/cash
|
packages/ls/dist/commands/ls.js
|
error
|
function error(path, e) {
var status = void 0;
var stdout = void 0;
if (e.code === 'ENOENT' && e.syscall === 'scandir') {
status = 1;
stdout = 'ls: cannot access ' + path + ': No such file or directory';
} else {
status = 2;
stdout = e.stack;
}
ls.self.log(stdout);
return { status: status, stdout: stdout };
}
|
javascript
|
function error(path, e) {
var status = void 0;
var stdout = void 0;
if (e.code === 'ENOENT' && e.syscall === 'scandir') {
status = 1;
stdout = 'ls: cannot access ' + path + ': No such file or directory';
} else {
status = 2;
stdout = e.stack;
}
ls.self.log(stdout);
return { status: status, stdout: stdout };
}
|
[
"function",
"error",
"(",
"path",
",",
"e",
")",
"{",
"var",
"status",
"=",
"void",
"0",
";",
"var",
"stdout",
"=",
"void",
"0",
";",
"if",
"(",
"e",
".",
"code",
"===",
"'ENOENT'",
"&&",
"e",
".",
"syscall",
"===",
"'scandir'",
")",
"{",
"status",
"=",
"1",
";",
"stdout",
"=",
"'ls: cannot access '",
"+",
"path",
"+",
"': No such file or directory'",
";",
"}",
"else",
"{",
"status",
"=",
"2",
";",
"stdout",
"=",
"e",
".",
"stack",
";",
"}",
"ls",
".",
"self",
".",
"log",
"(",
"stdout",
")",
";",
"return",
"{",
"status",
":",
"status",
",",
"stdout",
":",
"stdout",
"}",
";",
"}"
] |
Returns ls stderr and response codes
for errors.
@param {String} path
@param {Error} e
@param {String} e.code
@param {String} e.syscall
@param {String} e.stack
@api private
|
[
"Returns",
"ls",
"stderr",
"and",
"response",
"codes",
"for",
"errors",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/packages/ls/dist/commands/ls.js#L112-L126
|
11,590
|
dthree/cash
|
packages/ls/dist/commands/ls.js
|
execDirRecursive
|
function execDirRecursive(path, options) {
var self = this;
var results = [];
walkDirRecursive(path, function (pth) {
var result = self.execDir(pth, options);
results.push(result);
});
return results;
}
|
javascript
|
function execDirRecursive(path, options) {
var self = this;
var results = [];
walkDirRecursive(path, function (pth) {
var result = self.execDir(pth, options);
results.push(result);
});
return results;
}
|
[
"function",
"execDirRecursive",
"(",
"path",
",",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"results",
"=",
"[",
"]",
";",
"walkDirRecursive",
"(",
"path",
",",
"function",
"(",
"pth",
")",
"{",
"var",
"result",
"=",
"self",
".",
"execDir",
"(",
"pth",
",",
"options",
")",
";",
"results",
".",
"push",
"(",
"result",
")",
";",
"}",
")",
";",
"return",
"results",
";",
"}"
] |
Recursively executes `execDir`.
For use with `ls -R`.
@param {String} path
@param {Object} options
@return {Array} results
@api private
|
[
"Recursively",
"executes",
"execDir",
".",
"For",
"use",
"with",
"ls",
"-",
"R",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/packages/ls/dist/commands/ls.js#L139-L148
|
11,591
|
dthree/cash
|
packages/ls/dist/commands/ls.js
|
execDir
|
function execDir(path, options) {
var rawFiles = [];
function pushFile(file, data) {
rawFiles.push({
file: file,
data: data
});
}
// Add in implied current and parent dirs.
pushFile('.', fs.statSync('.'));
pushFile('..', fs.statSync('..'));
// Walk the passed in directory,
// pushing the results into `rawFiles`.
walkDir(path, pushFile, ls.error);
var o = ls.execLsOnFiles(path, rawFiles, options);
o.path = path;
return o;
}
|
javascript
|
function execDir(path, options) {
var rawFiles = [];
function pushFile(file, data) {
rawFiles.push({
file: file,
data: data
});
}
// Add in implied current and parent dirs.
pushFile('.', fs.statSync('.'));
pushFile('..', fs.statSync('..'));
// Walk the passed in directory,
// pushing the results into `rawFiles`.
walkDir(path, pushFile, ls.error);
var o = ls.execLsOnFiles(path, rawFiles, options);
o.path = path;
return o;
}
|
[
"function",
"execDir",
"(",
"path",
",",
"options",
")",
"{",
"var",
"rawFiles",
"=",
"[",
"]",
";",
"function",
"pushFile",
"(",
"file",
",",
"data",
")",
"{",
"rawFiles",
".",
"push",
"(",
"{",
"file",
":",
"file",
",",
"data",
":",
"data",
"}",
")",
";",
"}",
"// Add in implied current and parent dirs.",
"pushFile",
"(",
"'.'",
",",
"fs",
".",
"statSync",
"(",
"'.'",
")",
")",
";",
"pushFile",
"(",
"'..'",
",",
"fs",
".",
"statSync",
"(",
"'..'",
")",
")",
";",
"// Walk the passed in directory,",
"// pushing the results into `rawFiles`.",
"walkDir",
"(",
"path",
",",
"pushFile",
",",
"ls",
".",
"error",
")",
";",
"var",
"o",
"=",
"ls",
".",
"execLsOnFiles",
"(",
"path",
",",
"rawFiles",
",",
"options",
")",
";",
"o",
".",
"path",
"=",
"path",
";",
"return",
"o",
";",
"}"
] |
Executes `ls` functionality
for a given directory.
@param {String} path
@param {Object} options
@return {{path: String, size: *, results: *}} results
@api private
|
[
"Executes",
"ls",
"functionality",
"for",
"a",
"given",
"directory",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/packages/ls/dist/commands/ls.js#L160-L181
|
11,592
|
dthree/cash
|
packages/ls/dist/commands/ls.js
|
formatAll
|
function formatAll(results, options, showName) {
var stdout = '';
if (showName) {
for (var i = 0; i < results.length; ++i) {
stdout += results[i].path + ':\n';
if (options.l) {
stdout += 'total ' + results[i].size + '\n';
}
stdout += results[i].results;
if (i !== results.length - 1) {
stdout += '\n\n';
}
}
} else if (results.length === 1) {
if (options.l && !options.x) {
stdout += 'total ' + results[0].size + '\n';
}
stdout += results[0].results;
}
return stdout;
}
|
javascript
|
function formatAll(results, options, showName) {
var stdout = '';
if (showName) {
for (var i = 0; i < results.length; ++i) {
stdout += results[i].path + ':\n';
if (options.l) {
stdout += 'total ' + results[i].size + '\n';
}
stdout += results[i].results;
if (i !== results.length - 1) {
stdout += '\n\n';
}
}
} else if (results.length === 1) {
if (options.l && !options.x) {
stdout += 'total ' + results[0].size + '\n';
}
stdout += results[0].results;
}
return stdout;
}
|
[
"function",
"formatAll",
"(",
"results",
",",
"options",
",",
"showName",
")",
"{",
"var",
"stdout",
"=",
"''",
";",
"if",
"(",
"showName",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"results",
".",
"length",
";",
"++",
"i",
")",
"{",
"stdout",
"+=",
"results",
"[",
"i",
"]",
".",
"path",
"+",
"':\\n'",
";",
"if",
"(",
"options",
".",
"l",
")",
"{",
"stdout",
"+=",
"'total '",
"+",
"results",
"[",
"i",
"]",
".",
"size",
"+",
"'\\n'",
";",
"}",
"stdout",
"+=",
"results",
"[",
"i",
"]",
".",
"results",
";",
"if",
"(",
"i",
"!==",
"results",
".",
"length",
"-",
"1",
")",
"{",
"stdout",
"+=",
"'\\n\\n'",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"results",
".",
"length",
"===",
"1",
")",
"{",
"if",
"(",
"options",
".",
"l",
"&&",
"!",
"options",
".",
"x",
")",
"{",
"stdout",
"+=",
"'total '",
"+",
"results",
"[",
"0",
"]",
".",
"size",
"+",
"'\\n'",
";",
"}",
"stdout",
"+=",
"results",
"[",
"0",
"]",
".",
"results",
";",
"}",
"return",
"stdout",
";",
"}"
] |
Concatenates the results of multiple
`execDir` functions into their proper
form based on options provided.
@param {Array} results
@param {Object} options
@param {boolean} showName
@return {String} stdout
@api private
|
[
"Concatenates",
"the",
"results",
"of",
"multiple",
"execDir",
"functions",
"into",
"their",
"proper",
"form",
"based",
"on",
"options",
"provided",
"."
] |
3e28dae8bdb71215d5034df9003f3ef2804c2754
|
https://github.com/dthree/cash/blob/3e28dae8bdb71215d5034df9003f3ef2804c2754/packages/ls/dist/commands/ls.js#L358-L378
|
11,593
|
jackspirou/clientjs
|
src/client.js
|
function() {
var parser = new(window.UAParser || exports.UAParser);
browserData = parser.getResult();
fontDetective = new Detector();
return this;
}
|
javascript
|
function() {
var parser = new(window.UAParser || exports.UAParser);
browserData = parser.getResult();
fontDetective = new Detector();
return this;
}
|
[
"function",
"(",
")",
"{",
"var",
"parser",
"=",
"new",
"(",
"window",
".",
"UAParser",
"||",
"exports",
".",
"UAParser",
")",
";",
"browserData",
"=",
"parser",
".",
"getResult",
"(",
")",
";",
"fontDetective",
"=",
"new",
"Detector",
"(",
")",
";",
"return",
"this",
";",
"}"
] |
Global font detective object. ClientJS constructor which sets the browserData object and returs the client object.
|
[
"Global",
"font",
"detective",
"object",
".",
"ClientJS",
"constructor",
"which",
"sets",
"the",
"browserData",
"object",
"and",
"returs",
"the",
"client",
"object",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L137-L142
|
|
11,594
|
jackspirou/clientjs
|
src/client.js
|
function() {
var bar = '|';
var userAgent = browserData.ua;
var screenPrint = this.getScreenPrint();
var pluginList = this.getPlugins();
var fontList = this.getFonts();
var localStorage = this.isLocalStorage();
var sessionStorage = this.isSessionStorage();
var timeZone = this.getTimeZone();
var language = this.getLanguage();
var systemLanguage = this.getSystemLanguage();
var cookies = this.isCookie();
var canvasPrint = this.getCanvasPrint();
var key = userAgent + bar + screenPrint + bar + pluginList + bar + fontList + bar + localStorage + bar + sessionStorage + bar + timeZone + bar + language + bar + systemLanguage + bar + cookies + bar + canvasPrint;
var seed = 256;
return murmurhash3_32_gc(key, seed);
}
|
javascript
|
function() {
var bar = '|';
var userAgent = browserData.ua;
var screenPrint = this.getScreenPrint();
var pluginList = this.getPlugins();
var fontList = this.getFonts();
var localStorage = this.isLocalStorage();
var sessionStorage = this.isSessionStorage();
var timeZone = this.getTimeZone();
var language = this.getLanguage();
var systemLanguage = this.getSystemLanguage();
var cookies = this.isCookie();
var canvasPrint = this.getCanvasPrint();
var key = userAgent + bar + screenPrint + bar + pluginList + bar + fontList + bar + localStorage + bar + sessionStorage + bar + timeZone + bar + language + bar + systemLanguage + bar + cookies + bar + canvasPrint;
var seed = 256;
return murmurhash3_32_gc(key, seed);
}
|
[
"function",
"(",
")",
"{",
"var",
"bar",
"=",
"'|'",
";",
"var",
"userAgent",
"=",
"browserData",
".",
"ua",
";",
"var",
"screenPrint",
"=",
"this",
".",
"getScreenPrint",
"(",
")",
";",
"var",
"pluginList",
"=",
"this",
".",
"getPlugins",
"(",
")",
";",
"var",
"fontList",
"=",
"this",
".",
"getFonts",
"(",
")",
";",
"var",
"localStorage",
"=",
"this",
".",
"isLocalStorage",
"(",
")",
";",
"var",
"sessionStorage",
"=",
"this",
".",
"isSessionStorage",
"(",
")",
";",
"var",
"timeZone",
"=",
"this",
".",
"getTimeZone",
"(",
")",
";",
"var",
"language",
"=",
"this",
".",
"getLanguage",
"(",
")",
";",
"var",
"systemLanguage",
"=",
"this",
".",
"getSystemLanguage",
"(",
")",
";",
"var",
"cookies",
"=",
"this",
".",
"isCookie",
"(",
")",
";",
"var",
"canvasPrint",
"=",
"this",
".",
"getCanvasPrint",
"(",
")",
";",
"var",
"key",
"=",
"userAgent",
"+",
"bar",
"+",
"screenPrint",
"+",
"bar",
"+",
"pluginList",
"+",
"bar",
"+",
"fontList",
"+",
"bar",
"+",
"localStorage",
"+",
"bar",
"+",
"sessionStorage",
"+",
"bar",
"+",
"timeZone",
"+",
"bar",
"+",
"language",
"+",
"bar",
"+",
"systemLanguage",
"+",
"bar",
"+",
"cookies",
"+",
"bar",
"+",
"canvasPrint",
";",
"var",
"seed",
"=",
"256",
";",
"return",
"murmurhash3_32_gc",
"(",
"key",
",",
"seed",
")",
";",
"}"
] |
Get Fingerprint. Return a 32-bit integer representing the browsers fingerprint.
|
[
"Get",
"Fingerprint",
".",
"Return",
"a",
"32",
"-",
"bit",
"integer",
"representing",
"the",
"browsers",
"fingerprint",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L163-L182
|
|
11,595
|
jackspirou/clientjs
|
src/client.js
|
function() {
var bar = '|';
var key = "";
for (var i = 0; i < arguments.length; i++) {
key += arguments[i] + bar;
}
return murmurhash3_32_gc(key, 256);
}
|
javascript
|
function() {
var bar = '|';
var key = "";
for (var i = 0; i < arguments.length; i++) {
key += arguments[i] + bar;
}
return murmurhash3_32_gc(key, 256);
}
|
[
"function",
"(",
")",
"{",
"var",
"bar",
"=",
"'|'",
";",
"var",
"key",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"arguments",
".",
"length",
";",
"i",
"++",
")",
"{",
"key",
"+=",
"arguments",
"[",
"i",
"]",
"+",
"bar",
";",
"}",
"return",
"murmurhash3_32_gc",
"(",
"key",
",",
"256",
")",
";",
"}"
] |
Get Custom Fingerprint. Take a string of datapoints and eturn a 32-bit integer representing the browsers fingerprint.
|
[
"Get",
"Custom",
"Fingerprint",
".",
"Take",
"a",
"string",
"of",
"datapoints",
"and",
"eturn",
"a",
"32",
"-",
"bit",
"integer",
"representing",
"the",
"browsers",
"fingerprint",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L185-L192
|
|
11,596
|
jackspirou/clientjs
|
src/client.js
|
function() {
// detectmobilebrowsers.com JavaScript Mobile Detection Script
var dataString = browserData.ua || navigator.vendor || window.opera;
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(dataString) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(dataString.substr(0, 4)));
}
|
javascript
|
function() {
// detectmobilebrowsers.com JavaScript Mobile Detection Script
var dataString = browserData.ua || navigator.vendor || window.opera;
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(dataString) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(dataString.substr(0, 4)));
}
|
[
"function",
"(",
")",
"{",
"// detectmobilebrowsers.com JavaScript Mobile Detection Script",
"var",
"dataString",
"=",
"browserData",
".",
"ua",
"||",
"navigator",
".",
"vendor",
"||",
"window",
".",
"opera",
";",
"return",
"(",
"/",
"(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"/",
"i",
".",
"test",
"(",
"dataString",
")",
"||",
"/",
"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-",
"/",
"i",
".",
"test",
"(",
"dataString",
".",
"substr",
"(",
"0",
",",
"4",
")",
")",
")",
";",
"}"
] |
MOBILE METHODS Is Mobile. Check if the browser is on a mobile device.
|
[
"MOBILE",
"METHODS",
"Is",
"Mobile",
".",
"Check",
"if",
"the",
"browser",
"is",
"on",
"a",
"mobile",
"device",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L343-L347
|
|
11,597
|
jackspirou/clientjs
|
src/client.js
|
function() {
var pluginsList = "";
for (var i = 0; i < navigator.plugins.length; i++) {
if (i == navigator.plugins.length - 1) {
pluginsList += navigator.plugins[i].name;
} else {
pluginsList += navigator.plugins[i].name + ", ";
}
}
return pluginsList;
}
|
javascript
|
function() {
var pluginsList = "";
for (var i = 0; i < navigator.plugins.length; i++) {
if (i == navigator.plugins.length - 1) {
pluginsList += navigator.plugins[i].name;
} else {
pluginsList += navigator.plugins[i].name + ", ";
}
}
return pluginsList;
}
|
[
"function",
"(",
")",
"{",
"var",
"pluginsList",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"navigator",
".",
"plugins",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"==",
"navigator",
".",
"plugins",
".",
"length",
"-",
"1",
")",
"{",
"pluginsList",
"+=",
"navigator",
".",
"plugins",
"[",
"i",
"]",
".",
"name",
";",
"}",
"else",
"{",
"pluginsList",
"+=",
"navigator",
".",
"plugins",
"[",
"i",
"]",
".",
"name",
"+",
"\", \"",
";",
"}",
"}",
"return",
"pluginsList",
";",
"}"
] |
PLUGIN METHODS Get Plugins. Return a string containing a list of installed plugins.
|
[
"PLUGIN",
"METHODS",
"Get",
"Plugins",
".",
"Return",
"a",
"string",
"containing",
"a",
"list",
"of",
"installed",
"plugins",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L461-L472
|
|
11,598
|
jackspirou/clientjs
|
src/client.js
|
function() {
var mimeTypeList = "";
for (var i = 0; i < navigator.mimeTypes.length; i++) {
if (i == navigator.mimeTypes.length - 1) {
mimeTypeList += navigator.mimeTypes[i].description;
} else {
mimeTypeList += navigator.mimeTypes[i].description + ", ";
}
}
return mimeTypeList;
}
|
javascript
|
function() {
var mimeTypeList = "";
for (var i = 0; i < navigator.mimeTypes.length; i++) {
if (i == navigator.mimeTypes.length - 1) {
mimeTypeList += navigator.mimeTypes[i].description;
} else {
mimeTypeList += navigator.mimeTypes[i].description + ", ";
}
}
return mimeTypeList;
}
|
[
"function",
"(",
")",
"{",
"var",
"mimeTypeList",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"navigator",
".",
"mimeTypes",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"==",
"navigator",
".",
"mimeTypes",
".",
"length",
"-",
"1",
")",
"{",
"mimeTypeList",
"+=",
"navigator",
".",
"mimeTypes",
"[",
"i",
"]",
".",
"description",
";",
"}",
"else",
"{",
"mimeTypeList",
"+=",
"navigator",
".",
"mimeTypes",
"[",
"i",
"]",
".",
"description",
"+",
"\", \"",
";",
"}",
"}",
"return",
"mimeTypeList",
";",
"}"
] |
Get Mime Types. Return a string containing a list of installed mime types.
|
[
"Get",
"Mime",
"Types",
".",
"Return",
"a",
"string",
"containing",
"a",
"list",
"of",
"installed",
"mime",
"types",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L533-L544
|
|
11,599
|
jackspirou/clientjs
|
src/client.js
|
function() {
// create a canvas element
var canvas = document.createElement('canvas');
// define a context var that will be used for browsers with canvas support
var ctx;
// try/catch for older browsers that don't support the canvas element
try {
// attempt to give ctx a 2d canvas context value
ctx = canvas.getContext('2d');
} catch (e) {
// return empty string if canvas element not supported
return "";
}
// https://www.browserleaks.com/canvas#how-does-it-work
// Text with lowercase/uppercase/punctuation symbols
var txt = 'ClientJS,org <canvas> 1.0';
ctx.textBaseline = "top";
// The most common type
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f60";
ctx.fillRect(125, 1, 62, 20);
// Some tricks for color mixing to increase the difference in rendering
ctx.fillStyle = "#069";
ctx.fillText(txt, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
ctx.fillText(txt, 4, 17);
return canvas.toDataURL();
}
|
javascript
|
function() {
// create a canvas element
var canvas = document.createElement('canvas');
// define a context var that will be used for browsers with canvas support
var ctx;
// try/catch for older browsers that don't support the canvas element
try {
// attempt to give ctx a 2d canvas context value
ctx = canvas.getContext('2d');
} catch (e) {
// return empty string if canvas element not supported
return "";
}
// https://www.browserleaks.com/canvas#how-does-it-work
// Text with lowercase/uppercase/punctuation symbols
var txt = 'ClientJS,org <canvas> 1.0';
ctx.textBaseline = "top";
// The most common type
ctx.font = "14px 'Arial'";
ctx.textBaseline = "alphabetic";
ctx.fillStyle = "#f60";
ctx.fillRect(125, 1, 62, 20);
// Some tricks for color mixing to increase the difference in rendering
ctx.fillStyle = "#069";
ctx.fillText(txt, 2, 15);
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
ctx.fillText(txt, 4, 17);
return canvas.toDataURL();
}
|
[
"function",
"(",
")",
"{",
"// create a canvas element",
"var",
"canvas",
"=",
"document",
".",
"createElement",
"(",
"'canvas'",
")",
";",
"// define a context var that will be used for browsers with canvas support",
"var",
"ctx",
";",
"// try/catch for older browsers that don't support the canvas element",
"try",
"{",
"// attempt to give ctx a 2d canvas context value",
"ctx",
"=",
"canvas",
".",
"getContext",
"(",
"'2d'",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// return empty string if canvas element not supported",
"return",
"\"\"",
";",
"}",
"// https://www.browserleaks.com/canvas#how-does-it-work",
"// Text with lowercase/uppercase/punctuation symbols",
"var",
"txt",
"=",
"'ClientJS,org <canvas> 1.0'",
";",
"ctx",
".",
"textBaseline",
"=",
"\"top\"",
";",
"// The most common type",
"ctx",
".",
"font",
"=",
"\"14px 'Arial'\"",
";",
"ctx",
".",
"textBaseline",
"=",
"\"alphabetic\"",
";",
"ctx",
".",
"fillStyle",
"=",
"\"#f60\"",
";",
"ctx",
".",
"fillRect",
"(",
"125",
",",
"1",
",",
"62",
",",
"20",
")",
";",
"// Some tricks for color mixing to increase the difference in rendering",
"ctx",
".",
"fillStyle",
"=",
"\"#069\"",
";",
"ctx",
".",
"fillText",
"(",
"txt",
",",
"2",
",",
"15",
")",
";",
"ctx",
".",
"fillStyle",
"=",
"\"rgba(102, 204, 0, 0.7)\"",
";",
"ctx",
".",
"fillText",
"(",
"txt",
",",
"4",
",",
"17",
")",
";",
"return",
"canvas",
".",
"toDataURL",
"(",
")",
";",
"}"
] |
Get Canvas Print. Return a string containing the canvas URI data.
|
[
"Get",
"Canvas",
"Print",
".",
"Return",
"a",
"string",
"containing",
"the",
"canvas",
"URI",
"data",
"."
] |
6674bdd56680e8c8130260634a4086d469d8c7f2
|
https://github.com/jackspirou/clientjs/blob/6674bdd56680e8c8130260634a4086d469d8c7f2/src/client.js#L648-L683
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.