code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function normalize(name, baseName) {
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
foundI, foundStarMap, starI, i, j, part, normalizedBaseParts,
baseParts = baseName && baseName.split("/"),
map = config.map,
starMap = (map && map['*']) || {};
//Adjust any relative paths.
if (name) {
name = name.split('/');
lastIndex = name.length - 1;
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//Convert baseName to array, and lop off the last part,
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
name = normalizedBaseParts.concat(name);
}
//start trimDots
for (i = 0; i < name.length; i++) {
part = name[i];
if (part === '.') {
name.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') {
continue;
} else if (i > 0) {
name.splice(i - 1, 2);
i -= 2;
}
}
}
//end trimDots
name = name.join('/');
}
//Apply map config if available.
if ((baseParts || starMap) && map) {
nameParts = name.split('/');
for (i = nameParts.length; i > 0; i -= 1) {
nameSegment = nameParts.slice(0, i).join("/");
if (baseParts) {
//Find the longest baseName segment match in the config.
//So, do joins on the biggest to smallest lengths of baseParts.
for (j = baseParts.length; j > 0; j -= 1) {
mapValue = map[baseParts.slice(0, j).join('/')];
//baseName segment has config, find if it has one for
//this name.
if (mapValue) {
mapValue = mapValue[nameSegment];
if (mapValue) {
//Match, update name to the new value.
foundMap = mapValue;
foundI = i;
break;
}
}
}
}
if (foundMap) {
break;
}
//Check for a star map match, but just hold on to it,
//if there is a shorter segment match later in a matching
//config, then favor over this star map.
if (!foundStarMap && starMap && starMap[nameSegment]) {
foundStarMap = starMap[nameSegment];
starI = i;
}
}
if (!foundMap && foundStarMap) {
foundMap = foundStarMap;
foundI = starI;
}
if (foundMap) {
nameParts.splice(0, foundI, foundMap);
name = nameParts.join('/');
}
}
return name;
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
normalize
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function makeRequire(relName, forceSync) {
return function () {
//A version of a require function that passes a moduleName
//value for items that may need to
//look up paths relative to the moduleName
var args = aps.call(arguments, 0);
//If first arg is not require('string'), and there is only
//one arg, it is the array form without a callback. Insert
//a null so that the following concat is correct.
if (typeof args[0] !== 'string' && args.length === 1) {
args.push(null);
}
return req.apply(undef, args.concat([relName, forceSync]));
};
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
makeRequire
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function makeNormalize(relName) {
return function (name) {
return normalize(name, relName);
};
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
makeNormalize
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function makeLoad(depName) {
return function (value) {
defined[depName] = value;
};
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
makeLoad
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function callDep(name) {
if (hasProp(waiting, name)) {
var args = waiting[name];
delete waiting[name];
defining[name] = true;
main.apply(undef, args);
}
if (!hasProp(defined, name) && !hasProp(defining, name)) {
throw new Error('No ' + name);
}
return defined[name];
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
callDep
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function splitPrefix(name) {
var prefix,
index = name ? name.indexOf('!') : -1;
if (index > -1) {
prefix = name.substring(0, index);
name = name.substring(index + 1, name.length);
}
return [prefix, name];
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
splitPrefix
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function makeRelParts(relName) {
return relName ? splitPrefix(relName) : [];
}
|
Given a relative module name, like ./something, normalize it to
a real name that can be mapped to a path.
@param {String} name the relative name
@param {String} baseName a real name that the name arg is relative
to.
@returns {String} normalized name
|
makeRelParts
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function makeConfig(name) {
return function () {
return (config && config.config && config.config[name]) || {};
};
}
|
Makes a name map, normalizing the name, and using a plugin
for normalization if necessary. Grabs a ref to plugin
too, as an optimization.
|
makeConfig
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function BaseConstructor () {
this.constructor = ChildClass;
}
|
Expose module registry for debugging and tooling
|
BaseConstructor
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function getMethods (theClass) {
var proto = theClass.prototype;
var methods = [];
for (var methodName in proto) {
var m = proto[methodName];
if (typeof m !== 'function') {
continue;
}
if (methodName === 'constructor') {
continue;
}
methods.push(methodName);
}
return methods;
}
|
Expose module registry for debugging and tooling
|
getMethods
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function DecoratedClass () {
var unshift = Array.prototype.unshift;
var argCount = DecoratorClass.prototype.constructor.length;
var calledConstructor = SuperClass.prototype.constructor;
if (argCount > 0) {
unshift.call(arguments, SuperClass.prototype.constructor);
calledConstructor = DecoratorClass.prototype.constructor;
}
calledConstructor.apply(this, arguments);
}
|
Expose module registry for debugging and tooling
|
DecoratedClass
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function ctr () {
this.constructor = DecoratedClass;
}
|
Expose module registry for debugging and tooling
|
ctr
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
calledMethod = function (methodName) {
// Stub out the original method if it's not decorating an actual method
var originalMethod = function () {};
if (methodName in DecoratedClass.prototype) {
originalMethod = DecoratedClass.prototype[methodName];
}
var decoratedMethod = DecoratorClass.prototype[methodName];
return function () {
var unshift = Array.prototype.unshift;
unshift.call(arguments, originalMethod);
return decoratedMethod.apply(this, arguments);
};
}
|
Expose module registry for debugging and tooling
|
calledMethod
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
Observable = function () {
this.listeners = {};
}
|
Expose module registry for debugging and tooling
|
Observable
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Results ($element, options, dataAdapter) {
this.$element = $element;
this.data = dataAdapter;
this.options = options;
Results.__super__.constructor.call(this);
}
|
Expose module registry for debugging and tooling
|
Results
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function BaseSelection ($element, options) {
this.$element = $element;
this.options = options;
BaseSelection.__super__.constructor.call(this);
}
|
Expose module registry for debugging and tooling
|
BaseSelection
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function SingleSelection () {
SingleSelection.__super__.constructor.apply(this, arguments);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
SingleSelection
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function MultipleSelection ($element, options) {
MultipleSelection.__super__.constructor.apply(this, arguments);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
MultipleSelection
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Placeholder (decorated, $element, options) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
Placeholder
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Search (decorated, $element, options) {
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
Search
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Translation (dict) {
this.dict = dict || {};
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Translation
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function SelectAdapter ($element, options) {
this.$element = $element;
this.options = options;
SelectAdapter.__super__.constructor.call(this);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
SelectAdapter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function ArrayAdapter ($element, options) {
this._dataToConvert = options.get('data') || [];
ArrayAdapter.__super__.constructor.call(this, $element, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
ArrayAdapter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function onlyItem (item) {
return function () {
return $(this).val() == item.id;
};
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
onlyItem
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function AjaxAdapter ($element, options) {
this.ajaxOptions = this._applyDefaults(options.get('ajax'));
if (this.ajaxOptions.processResults != null) {
this.processResults = this.ajaxOptions.processResults;
}
AjaxAdapter.__super__.constructor.call(this, $element, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
AjaxAdapter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function request () {
var $request = options.transport(options, function (data) {
var results = self.processResults(data, params);
if (self.options.get('debug') && window.console && console.error) {
// Check to make sure that the response included a `results` key.
if (!results || !results.results || !$.isArray(results.results)) {
console.error(
'Select2: The AJAX results did not return an array in the ' +
'`results` key of the response.'
);
}
}
callback(results);
}, function () {
// Attempt to detect if a request was aborted
// Only works if the transport exposes a status property
if ('status' in $request &&
($request.status === 0 || $request.status === '0')) {
return;
}
self.trigger('results:message', {
message: 'errorLoading'
});
});
self._request = $request;
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
request
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Tags (decorated, $element, options) {
var tags = options.get('tags');
var createTag = options.get('createTag');
if (createTag !== undefined) {
this.createTag = createTag;
}
var insertTag = options.get('insertTag');
if (insertTag !== undefined) {
this.insertTag = insertTag;
}
decorated.call(this, $element, options);
if ($.isArray(tags)) {
for (var t = 0; t < tags.length; t++) {
var tag = tags[t];
var item = this._normalizeItem(tag);
var $option = this.option(item);
this.$element.append($option);
}
}
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Tags
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function wrapper (obj, child) {
var data = obj.results;
for (var i = 0; i < data.length; i++) {
var option = data[i];
var checkChildren = (
option.children != null &&
!wrapper({
results: option.children
}, true)
);
var optionText = (option.text || '').toUpperCase();
var paramsTerm = (params.term || '').toUpperCase();
var checkText = optionText === paramsTerm;
if (checkText || checkChildren) {
if (child) {
return false;
}
obj.data = data;
callback(obj);
return;
}
}
if (child) {
return true;
}
var tag = self.createTag(params);
if (tag != null) {
var $option = self.option(tag);
$option.attr('data-select2-tag', true);
self.addOptions([$option]);
self.insertTag(data, tag);
}
obj.results = data;
callback(obj);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
wrapper
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Tokenizer (decorated, $element, options) {
var tokenizer = options.get('tokenizer');
if (tokenizer !== undefined) {
this.tokenizer = tokenizer;
}
decorated.call(this, $element, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Tokenizer
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function createAndSelect (data) {
// Normalize the data object so we can use it for checks
var item = self._normalizeItem(data);
// Check if the data object already exists as a tag
// Select it if it doesn't
var $existingOptions = self.$element.find('option').filter(function () {
return $(this).val() === item.id;
});
// If an existing option wasn't found for it, create the option
if (!$existingOptions.length) {
var $option = self.option(item);
$option.attr('data-select2-tag', true);
self._removeOldTags();
self.addOptions([$option]);
}
// Select the item, now that we know there is an option for it
select(item);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
createAndSelect
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function select (data) {
self.trigger('select', {
data: data
});
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
select
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function MinimumInputLength (decorated, $e, options) {
this.minimumInputLength = options.get('minimumInputLength');
decorated.call(this, $e, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
MinimumInputLength
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function MaximumInputLength (decorated, $e, options) {
this.maximumInputLength = options.get('maximumInputLength');
decorated.call(this, $e, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
MaximumInputLength
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
MaximumSelectionLength
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Dropdown ($element, options) {
this.$element = $element;
this.options = options;
Dropdown.__super__.constructor.call(this);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Dropdown
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function HidePlaceholder (decorated, $element, options, dataAdapter) {
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
decorated.call(this, $element, options, dataAdapter);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
HidePlaceholder
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function InfiniteScroll (decorated, $element, options, dataAdapter) {
this.lastParams = {};
decorated.call(this, $element, options, dataAdapter);
this.$loadingMore = this.createLoadingMore();
this.loading = false;
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
InfiniteScroll
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function AttachBody (decorated, $element, options) {
this.$dropdownParent = $(options.get('dropdownParent') || document.body);
decorated.call(this, $element, options);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
AttachBody
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function countResults (data) {
var count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
countResults
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
if (this.minimumResultsForSearch < 0) {
this.minimumResultsForSearch = Infinity;
}
decorated.call(this, $element, options, dataAdapter);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
MinimumResultsForSearch
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function stripDiacritics (text) {
// Used 'uni range + named function' from http://jsperf.com/diacritics/18
function match(a) {
return DIACRITICS[a] || a;
}
return text.replace(/[^\u0000-\u007E]/g, match);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
stripDiacritics
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function match(a) {
return DIACRITICS[a] || a;
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
match
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function matcher (params, data) {
// Always return the object if there is nothing to compare
if ($.trim(params.term) === '') {
return data;
}
// Do a recursive check for options with children
if (data.children && data.children.length > 0) {
// Clone the data object if there are children
// This is required as we modify the object to remove any non-matches
var match = $.extend(true, {}, data);
// Check each child of the option
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
var matches = matcher(params, child);
// If there wasn't a match, remove the object in the array
if (matches == null) {
match.children.splice(c, 1);
}
}
// If any children matched, return the new object
if (match.children.length > 0) {
return match;
}
// If there were no matching children, check just the plain object
return matcher(params, match);
}
var original = stripDiacritics(data.text).toUpperCase();
var term = stripDiacritics(params.term).toUpperCase();
// Check if the text contains the term
if (original.indexOf(term) > -1) {
return data;
}
// If it doesn't contain the term, don't return anything
return null;
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
matcher
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Options (options, $element) {
this.options = options;
if ($element != null) {
this.fromElement($element);
}
if ($element != null) {
this.options = Defaults.applyFromElement(this.options, $element);
}
this.options = Defaults.apply(this.options);
if ($element && $element.is('input')) {
var InputCompat = require(this.get('amdBase') + 'compat/inputData');
this.options.dataAdapter = Utils.Decorate(
this.options.dataAdapter,
InputCompat
);
}
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Options
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function upperCaseLetter(_, letter) {
return letter.toUpperCase();
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
upperCaseLetter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
Select2 = function ($element, options) {
if (Utils.GetData($element[0], 'select2') != null) {
Utils.GetData($element[0], 'select2').destroy();
}
this.$element = $element;
this.id = this._generateId($element);
options = options || {};
this.options = new Options(options, $element);
Select2.__super__.constructor.call(this);
// Set up the tabindex
var tabindex = $element.attr('tabindex') || 0;
Utils.StoreData($element[0], 'old-tabindex', tabindex);
$element.attr('tabindex', '-1');
// Set up containers and adapters
var DataAdapter = this.options.get('dataAdapter');
this.dataAdapter = new DataAdapter($element, this.options);
var $container = this.render();
this._placeContainer($container);
var SelectionAdapter = this.options.get('selectionAdapter');
this.selection = new SelectionAdapter($element, this.options);
this.$selection = this.selection.render();
this.selection.position(this.$selection, $container);
var DropdownAdapter = this.options.get('dropdownAdapter');
this.dropdown = new DropdownAdapter($element, this.options);
this.$dropdown = this.dropdown.render();
this.dropdown.position(this.$dropdown, $container);
var ResultsAdapter = this.options.get('resultsAdapter');
this.results = new ResultsAdapter($element, this.options, this.dataAdapter);
this.$results = this.results.render();
this.results.position(this.$results, this.$dropdown);
// Bind events
var self = this;
// Bind the container to all of the adapters
this._bindAdapters();
// Register any DOM event handlers
this._registerDomEvents();
// Register any internal event handlers
this._registerDataEvents();
this._registerSelectionEvents();
this._registerDropdownEvents();
this._registerResultsEvents();
this._registerEvents();
// Set the initial state
this.dataAdapter.current(function (initialData) {
self.trigger('selection:update', {
data: initialData
});
});
// Hide the original select
$element.addClass('select2-hidden-accessible');
$element.attr('aria-hidden', 'true');
// Synchronize any monitored attributes
this._syncAttributes();
Utils.StoreData($element[0], 'select2', this);
// Ensure backwards compatibility with $element.data('select2').
$element.data('select2', this);
}
|
This method will transfer the tabindex attribute from the rendered
selection to the search box. This allows for the search box to be used as
the primary focus instead of the selection container.
@private
|
Select2
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function syncCssClasses ($dest, $src, adapter) {
var classes, replacements = [], adapted;
classes = $.trim($dest.attr('class'));
if (classes) {
classes = '' + classes; // for IE which returns object
$(classes.split(/\s+/)).each(function () {
// Save all Select2 classes
if (this.indexOf('select2-') === 0) {
replacements.push(this);
}
});
}
classes = $.trim($src.attr('class'));
if (classes) {
classes = '' + classes; // for IE which returns object
$(classes.split(/\s+/)).each(function () {
// Only adapt non-Select2 classes
if (this.indexOf('select2-') !== 0) {
adapted = adapter(this);
if (adapted != null) {
replacements.push(adapted);
}
}
});
}
$dest.attr('class', replacements.join(' '));
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
syncCssClasses
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function _containerAdapter (clazz) {
return null;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
_containerAdapter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function _dropdownAdapter (clazz) {
return null;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
_dropdownAdapter
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function InitSelection (decorated, $element, options) {
if (options.get('debug') && window.console && console.warn) {
console.warn(
'Select2: The `initSelection` option has been deprecated in favor' +
' of a custom data adapter that overrides the `current` method. ' +
'This method is now called multiple times instead of a single ' +
'time when the instance is initialized. Support will be removed ' +
'for the `initSelection` option in future versions of Select2'
);
}
this.initSelection = options.get('initSelection');
this._isInitialized = false;
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
InitSelection
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function InputData (decorated, $element, options) {
this._currentData = [];
this._valueSeparator = options.get('valueSeparator') || ',';
if ($element.prop('type') === 'hidden') {
if (options.get('debug') && console && console.warn) {
console.warn(
'Select2: Using a hidden input with Select2 is no longer ' +
'supported and may stop working in the future. It is recommended ' +
'to use a `<select>` element instead.'
);
}
}
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
InputData
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function getSelected (data, selectedIds) {
var selected = [];
if (data.selected || $.inArray(data.id, selectedIds) !== -1) {
data.selected = true;
selected.push(data);
} else {
data.selected = false;
}
if (data.children) {
selected.push.apply(selected, getSelected(data.children, selectedIds));
}
return selected;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
getSelected
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function oldMatcher (matcher) {
function wrappedMatcher (params, data) {
var match = $.extend(true, {}, data);
if (params.term == null || $.trim(params.term) === '') {
return match;
}
if (data.children) {
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
// Check if the child object matches
// The old matcher returned a boolean true or false
var doesMatch = matcher(params.term, child.text, child);
// If the child didn't match, pop it off
if (!doesMatch) {
match.children.splice(c, 1);
}
}
if (match.children.length > 0) {
return match;
}
}
if (matcher(params.term, data.text, data)) {
return match;
}
return null;
}
return wrappedMatcher;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
oldMatcher
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function wrappedMatcher (params, data) {
var match = $.extend(true, {}, data);
if (params.term == null || $.trim(params.term) === '') {
return match;
}
if (data.children) {
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
// Check if the child object matches
// The old matcher returned a boolean true or false
var doesMatch = matcher(params.term, child.text, child);
// If the child didn't match, pop it off
if (!doesMatch) {
match.children.splice(c, 1);
}
}
if (match.children.length > 0) {
return match;
}
}
if (matcher(params.term, data.text, data)) {
return match;
}
return null;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
wrappedMatcher
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function Query (decorated, $element, options) {
if (options.get('debug') && window.console && console.warn) {
console.warn(
'Select2: The `query` option has been deprecated in favor of a ' +
'custom data adapter that overrides the `query` method. Support ' +
'will be removed for the `query` option in future versions of ' +
'Select2.'
);
}
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
Query
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function AttachContainer (decorated, $element, options) {
decorated.call(this, $element, options);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
AttachContainer
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function handler(event) {
var orgEvent = event || window.event,
args = slice.call(arguments, 1),
delta = 0,
deltaX = 0,
deltaY = 0,
absDelta = 0,
offsetX = 0,
offsetY = 0;
event = $.event.fix(orgEvent);
event.type = 'mousewheel';
// Old school scrollwheel delta
if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }
if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }
if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }
if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }
// Firefox < 17 horizontal scrolling related to DOMMouseScroll event
if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
deltaX = deltaY * -1;
deltaY = 0;
}
// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy
delta = deltaY === 0 ? deltaX : deltaY;
// New school wheel delta (wheel event)
if ( 'deltaY' in orgEvent ) {
deltaY = orgEvent.deltaY * -1;
delta = deltaY;
}
if ( 'deltaX' in orgEvent ) {
deltaX = orgEvent.deltaX;
if ( deltaY === 0 ) { delta = deltaX * -1; }
}
// No change actually happened, no reason to go any further
if ( deltaY === 0 && deltaX === 0 ) { return; }
// Need to convert lines and pages to pixels if we aren't already in pixels
// There are three delta modes:
// * deltaMode 0 is by pixels, nothing to do
// * deltaMode 1 is by lines
// * deltaMode 2 is by pages
if ( orgEvent.deltaMode === 1 ) {
var lineHeight = $.data(this, 'mousewheel-line-height');
delta *= lineHeight;
deltaY *= lineHeight;
deltaX *= lineHeight;
} else if ( orgEvent.deltaMode === 2 ) {
var pageHeight = $.data(this, 'mousewheel-page-height');
delta *= pageHeight;
deltaY *= pageHeight;
deltaX *= pageHeight;
}
// Store lowest absolute delta to normalize the delta values
absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );
if ( !lowestDelta || absDelta < lowestDelta ) {
lowestDelta = absDelta;
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
lowestDelta /= 40;
}
}
// Adjust older deltas if necessary
if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {
// Divide all the things by 40!
delta /= 40;
deltaX /= 40;
deltaY /= 40;
}
// Get a whole, normalized value for the deltas
delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);
deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);
deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);
// Normalise offsetX and offsetY properties
if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {
var boundingRect = this.getBoundingClientRect();
offsetX = event.clientX - boundingRect.left;
offsetY = event.clientY - boundingRect.top;
}
// Add information to the event object
event.deltaX = deltaX;
event.deltaY = deltaY;
event.deltaFactor = lowestDelta;
event.offsetX = offsetX;
event.offsetY = offsetY;
// Go ahead and set deltaMode to 0 since we converted to pixels
// Although this is a little odd since we overwrite the deltaX/Y
// properties with normalized deltas.
event.deltaMode = 0;
// Add event and delta to the front of the arguments
args.unshift(event, delta, deltaX, deltaY);
// Clearout lowestDelta after sometime to better
// handle multiple device types that give different
// a different lowestDelta
// Ex: trackpad = 3 and mouse wheel = 120
if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }
nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);
return ($.event.dispatch || $.event.handle).apply(this, args);
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
handler
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function nullLowestDelta() {
lowestDelta = null;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
nullLowestDelta
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function shouldAdjustOldDeltas(orgEvent, absDelta) {
// If this is an older event and the delta is divisable by 120,
// then we are assuming that the browser is treating this as an
// older mouse wheel event and that we should divide the deltas
// by 40 to try and get a more usable deltaFactor.
// Side note, this actually impacts the reported scroll distance
// in older browsers and can cause scrolling to be slower than native.
// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.
return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;
}
|
Helper method to abstract the "disabled" state of this object.
@return {true} if the disabled option is true.
@return {false} if the disabled option is false.
|
shouldAdjustOldDeltas
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/select2/select2.full.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/select2/select2.full.js
|
Apache-2.0
|
function deanchor(pattern) {
// Allow any number of empty noncapturing groups before/after anchors, because regexes
// built/generated by XRegExp sometimes include them
var leadingAnchor = /^(?:\(\?:\))*\^/;
var trailingAnchor = /\$(?:\(\?:\))*$/;
if (
leadingAnchor.test(pattern) &&
trailingAnchor.test(pattern) &&
// Ensure that the trailing `$` isn't escaped
trailingAnchor.test(pattern.replace(/\\[\s\S]/g, ''))
) {
return pattern.replace(leadingAnchor, '').replace(trailingAnchor, '');
}
return pattern;
}
|
Strips a leading `^` and trailing unescaped `$`, if both are present.
@private
@param {String} pattern Pattern to process.
@returns {String} Pattern with edge anchors removed.
|
deanchor
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function asXRegExp(value, addFlagX) {
var flags = addFlagX ? 'x' : '';
return XRegExp.isRegExp(value) ?
(value[REGEX_DATA] && value[REGEX_DATA].captureNames ?
// Don't recompile, to preserve capture names
value :
// Recompile as XRegExp
XRegExp(value.source, flags)
) :
// Compile string as XRegExp
XRegExp(value, flags);
}
|
Converts the provided value to an XRegExp. Native RegExp flags are not preserved.
@private
@param {String|RegExp} value Value to convert.
@param {Boolean} [addFlagX] Whether to apply the `x` flag in cases when `value` is not
already a regex generated by XRegExp
@returns {RegExp} XRegExp object with XRegExp syntax applied.
|
asXRegExp
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function row(name, value, start, end) {
return {
name: name,
value: value,
start: start,
end: end
};
}
|
Returns a match detail object composed of the provided values.
@private
|
row
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function hasNativeFlag(flag) {
// Can't check based on the presence of properties/getters since browsers might support such
// properties even when they don't support the corresponding flag in regex construction (tested
// in Chrome 48, where `'unicode' in /x/` is true but trying to construct a regex with flag `u`
// throws an error)
var isSupported = true;
try {
// Can't use regex literals for testing even in a `try` because regex literals with
// unsupported flags cause a compilation error in IE
new RegExp('', flag);
} catch (exception) {
isSupported = false;
}
return isSupported;
}
|
XRegExp provides augmented, extensible regular expressions. You get additional regex syntax and
flags, beyond what browsers support natively. XRegExp is also a regex utility belt with tools to
make your client-side grepping simpler and more powerful, while freeing you from related
cross-browser inconsistencies.
|
hasNativeFlag
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function augment(regex, captureNames, xSource, xFlags, isInternalOnly) {
var p;
regex[REGEX_DATA] = {
captureNames: captureNames
};
if (isInternalOnly) {
return regex;
}
// Can't auto-inherit these since the XRegExp constructor returns a nonprimitive value
if (regex.__proto__) {
regex.__proto__ = XRegExp.prototype;
} else {
for (p in XRegExp.prototype) {
// An `XRegExp.prototype.hasOwnProperty(p)` check wouldn't be worth it here, since this
// is performance sensitive, and enumerable `Object.prototype` or `RegExp.prototype`
// extensions exist on `regex.prototype` anyway
regex[p] = XRegExp.prototype[p];
}
}
regex[REGEX_DATA].source = xSource;
// Emulate the ES6 `flags` prop by ensuring flags are in alphabetical order
regex[REGEX_DATA].flags = xFlags ? xFlags.split('').sort().join('') : xFlags;
return regex;
}
|
Attaches extended data and `XRegExp.prototype` properties to a regex object.
@private
@param {RegExp} regex Regex to augment.
@param {Array} captureNames Array with capture names, or `null`.
@param {String} xSource XRegExp pattern used to generate `regex`, or `null` if N/A.
@param {String} xFlags XRegExp flags used to generate `regex`, or `null` if N/A.
@param {Boolean} [isInternalOnly=false] Whether the regex will be used only for internal
operations, and never exposed to users. For internal-only regexes, we can improve perf by
skipping some operations like attaching `XRegExp.prototype` properties.
@returns {RegExp} Augmented regex.
|
augment
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function clipDuplicates(str) {
return nativ.replace.call(str, /([\s\S])(?=[\s\S]*\1)/g, '');
}
|
Removes any duplicate characters from the provided string.
@private
@param {String} str String to remove duplicate characters from.
@returns {String} String with any duplicate characters removed.
|
clipDuplicates
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function copyRegex(regex, options) {
if (!XRegExp.isRegExp(regex)) {
throw new TypeError('Type RegExp expected');
}
var xData = regex[REGEX_DATA] || {};
var flags = getNativeFlags(regex);
var flagsToAdd = '';
var flagsToRemove = '';
var xregexpSource = null;
var xregexpFlags = null;
options = options || {};
if (options.removeG) {flagsToRemove += 'g';}
if (options.removeY) {flagsToRemove += 'y';}
if (flagsToRemove) {
flags = nativ.replace.call(flags, new RegExp('[' + flagsToRemove + ']+', 'g'), '');
}
if (options.addG) {flagsToAdd += 'g';}
if (options.addY) {flagsToAdd += 'y';}
if (flagsToAdd) {
flags = clipDuplicates(flags + flagsToAdd);
}
if (!options.isInternalOnly) {
if (xData.source !== undefined) {
xregexpSource = xData.source;
}
// null or undefined; don't want to add to `flags` if the previous value was null, since
// that indicates we're not tracking original precompilation flags
if (xData.flags != null) {
// Flags are only added for non-internal regexes by `XRegExp.globalize`. Flags are never
// removed for non-internal regexes, so don't need to handle it
xregexpFlags = flagsToAdd ? clipDuplicates(xData.flags + flagsToAdd) : xData.flags;
}
}
// Augment with `XRegExp.prototype` properties, but use the native `RegExp` constructor to avoid
// searching for special tokens. That would be wrong for regexes constructed by `RegExp`, and
// unnecessary for regexes constructed by `XRegExp` because the regex has already undergone the
// translation to native regex syntax
regex = augment(
new RegExp(options.source || regex.source, flags),
hasNamedCapture(regex) ? xData.captureNames.slice(0) : null,
xregexpSource,
xregexpFlags,
options.isInternalOnly
);
return regex;
}
|
Copies a regex object while preserving extended data and augmenting with `XRegExp.prototype`
properties. The copy has a fresh `lastIndex` property (set to zero). Allows adding and removing
flags g and y while copying the regex.
@private
@param {RegExp} regex Regex to copy.
@param {Object} [options] Options object with optional properties:
- `addG` {Boolean} Add flag g while copying the regex.
- `addY` {Boolean} Add flag y while copying the regex.
- `removeG` {Boolean} Remove flag g while copying the regex.
- `removeY` {Boolean} Remove flag y while copying the regex.
- `isInternalOnly` {Boolean} Whether the copied regex will be used only for internal
operations, and never exposed to users. For internal-only regexes, we can improve perf by
skipping some operations like attaching `XRegExp.prototype` properties.
- `source` {String} Overrides `<regex>.source`, for special cases.
@returns {RegExp} Copy of the provided regex, possibly with modified flags.
|
copyRegex
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function dec(hex) {
return parseInt(hex, 16);
}
|
Converts hexadecimal to decimal.
@private
@param {String} hex
@returns {Number}
|
dec
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function getContextualTokenSeparator(match, scope, flags) {
if (
// No need to separate tokens if at the beginning or end of a group
match.input.charAt(match.index - 1) === '(' ||
match.input.charAt(match.index + match[0].length) === ')' ||
// Avoid separating tokens when the following token is a quantifier
isPatternNext(match.input, match.index + match[0].length, flags, '[?*+]|{\\d+(?:,\\d*)?}')
) {
return '';
}
// Keep tokens separated. This avoids e.g. inadvertedly changing `\1 1` or `\1(?#)1` to `\11`.
// This also ensures all tokens remain as discrete atoms, e.g. it avoids converting the syntax
// error `(? :` into `(?:`.
return '(?:)';
}
|
Returns a pattern that can be used in a native RegExp in place of an ignorable token such as an
inline comment or whitespace with flag x. This is used directly as a token handler function
passed to `XRegExp.addToken`.
@private
@param {String} match Match arg of `XRegExp.addToken` handler
@param {String} scope Scope arg of `XRegExp.addToken` handler
@param {String} flags Flags arg of `XRegExp.addToken` handler
@returns {String} Either '' or '(?:)', depending on which is needed in the context of the match.
|
getContextualTokenSeparator
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function getNativeFlags(regex) {
return hasFlagsProp ?
regex.flags :
// Explicitly using `RegExp.prototype.toString` (rather than e.g. `String` or concatenation
// with an empty string) allows this to continue working predictably when
// `XRegExp.proptotype.toString` is overridden
nativ.exec.call(/\/([a-z]*)$/i, RegExp.prototype.toString.call(regex))[1];
}
|
Returns native `RegExp` flags used by a regex object.
@private
@param {RegExp} regex Regex to check.
@returns {String} Native flags in use.
|
getNativeFlags
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function hasNamedCapture(regex) {
return !!(regex[REGEX_DATA] && regex[REGEX_DATA].captureNames);
}
|
Determines whether a regex has extended instance data used to track capture names.
@private
@param {RegExp} regex Regex to check.
@returns {Boolean} Whether the regex uses named capture.
|
hasNamedCapture
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function hex(dec) {
return parseInt(dec, 10).toString(16);
}
|
Converts decimal to hexadecimal.
@private
@param {Number|String} dec
@returns {String}
|
hex
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function indexOf(array, value) {
var len = array.length;
var i;
for (i = 0; i < len; ++i) {
if (array[i] === value) {
return i;
}
}
return -1;
}
|
Returns the first index at which a given value can be found in an array.
@private
@param {Array} array Array to search.
@param {*} value Value to locate in the array.
@returns {Number} Zero-based index at which the item is found, or -1.
|
indexOf
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function isPatternNext(pattern, pos, flags, needlePattern) {
var inlineCommentPattern = '\\(\\?#[^)]*\\)';
var lineCommentPattern = '#[^#\\n]*';
var patternsToIgnore = flags.indexOf('x') > -1 ?
// Ignore any leading whitespace, line comments, and inline comments
['\\s', lineCommentPattern, inlineCommentPattern] :
// Ignore any leading inline comments
[inlineCommentPattern];
return nativ.test.call(
new RegExp('^(?:' + patternsToIgnore.join('|') + ')*(?:' + needlePattern + ')'),
pattern.slice(pos)
);
}
|
Checks whether the next nonignorable token after the specified position matches the
`needlePattern`
@private
@param {String} pattern Pattern to search within.
@param {Number} pos Index in `pattern` to search at.
@param {String} flags Flags used by the pattern.
@param {String} needlePattern Pattern to match the next token against.
@returns {Boolean} Whether the next nonignorable token matches `needlePattern`
|
isPatternNext
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function isType(value, type) {
return toString.call(value) === '[object ' + type + ']';
}
|
Determines whether a value is of the specified type, by resolving its internal [[Class]].
@private
@param {*} value Object to check.
@param {String} type Type to check for, in TitleCase.
@returns {Boolean} Whether the object matches the type.
|
isType
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function pad4(str) {
while (str.length < 4) {
str = '0' + str;
}
return str;
}
|
Adds leading zeros if shorter than four characters. Used for fixed-length hexadecimal values.
@private
@param {String} str
@returns {String}
|
pad4
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function prepareFlags(pattern, flags) {
var i;
// Recent browsers throw on duplicate flags, so copy this behavior for nonnative flags
if (clipDuplicates(flags) !== flags) {
throw new SyntaxError('Invalid duplicate regex flag ' + flags);
}
// Strip and apply a leading mode modifier with any combination of flags except g or y
pattern = nativ.replace.call(pattern, /^\(\?([\w$]+)\)/, function($0, $1) {
if (nativ.test.call(/[gy]/, $1)) {
throw new SyntaxError('Cannot use flag g or y in mode modifier ' + $0);
}
// Allow duplicate flags within the mode modifier
flags = clipDuplicates(flags + $1);
return '';
});
// Throw on unknown native or nonnative flags
for (i = 0; i < flags.length; ++i) {
if (!registeredFlags[flags.charAt(i)]) {
throw new SyntaxError('Unknown regex flag ' + flags.charAt(i));
}
}
return {
pattern: pattern,
flags: flags
};
}
|
Checks for flag-related errors, and strips/applies flags in a leading mode modifier. Offloads
the flag preparation logic from the `XRegExp` constructor.
@private
@param {String} pattern Regex pattern, possibly with a leading mode modifier.
@param {String} flags Any combination of flags.
@returns {Object} Object with properties `pattern` and `flags`.
|
prepareFlags
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function prepareOptions(value) {
var options = {};
if (isType(value, 'String')) {
XRegExp.forEach(value, /[^\s,]+/, function(match) {
options[match] = true;
});
return options;
}
return value;
}
|
Prepares an options object from the given value.
@private
@param {String|Object} value Value to convert to an options object.
@returns {Object} Options object.
|
prepareOptions
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function registerFlag(flag) {
if (!/^[\w$]$/.test(flag)) {
throw new Error('Flag must be a single character A-Za-z0-9_$');
}
registeredFlags[flag] = true;
}
|
Registers a flag so it doesn't throw an 'unknown flag' error.
@private
@param {String} flag Single-character flag to register.
|
registerFlag
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function runTokens(pattern, flags, pos, scope, context) {
var i = tokens.length;
var leadChar = pattern.charAt(pos);
var result = null;
var match;
var t;
// Run in reverse insertion order
while (i--) {
t = tokens[i];
if (
(t.leadChar && t.leadChar !== leadChar) ||
(t.scope !== scope && t.scope !== 'all') ||
(t.flag && flags.indexOf(t.flag) === -1)
) {
continue;
}
match = XRegExp.exec(pattern, t.regex, pos, 'sticky');
if (match) {
result = {
matchLength: match[0].length,
output: t.handler.call(context, match, scope, flags),
reparse: t.reparse
};
// Finished with token tests
break;
}
}
return result;
}
|
Runs built-in and custom regex syntax tokens in reverse insertion order at the specified
position, until a match is found.
@private
@param {String} pattern Original pattern from which an XRegExp object is being built.
@param {String} flags Flags being used to construct the regex.
@param {Number} pos Position to search for tokens within `pattern`.
@param {Number} scope Regex scope to apply: 'default' or 'class'.
@param {Object} context Context object to use for token handler functions.
@returns {Object} Object with properties `matchLength`, `output`, and `reparse`; or `null`.
|
runTokens
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function setAstral(on) {
features.astral = on;
}
|
Enables or disables implicit astral mode opt-in. When enabled, flag A is automatically added to
all new regexes created by XRegExp. This causes an error to be thrown when creating regexes if
the Unicode Base addon is not available, since flag A is registered by that addon.
@private
@param {Boolean} on `true` to enable; `false` to disable.
|
setAstral
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function setNatives(on) {
RegExp.prototype.exec = (on ? fixed : nativ).exec;
RegExp.prototype.test = (on ? fixed : nativ).test;
String.prototype.match = (on ? fixed : nativ).match;
String.prototype.replace = (on ? fixed : nativ).replace;
String.prototype.split = (on ? fixed : nativ).split;
features.natives = on;
}
|
Enables or disables native method overrides.
@private
@param {Boolean} on `true` to enable; `false` to disable.
|
setNatives
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function toObject(value) {
// null or undefined
if (value == null) {
throw new TypeError('Cannot convert null or undefined to object');
}
return value;
}
|
Returns the object, or throws an error if it is `null` or `undefined`. This is used to follow
the ES5 abstract operation `ToObject`.
@private
@param {*} value Object to check and return.
@returns {*} The provided object.
|
toObject
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function XRegExp(pattern, flags) {
if (XRegExp.isRegExp(pattern)) {
if (flags !== undefined) {
throw new TypeError('Cannot supply flags when copying a RegExp');
}
return copyRegex(pattern);
}
// Copy the argument behavior of `RegExp`
pattern = pattern === undefined ? '' : String(pattern);
flags = flags === undefined ? '' : String(flags);
if (XRegExp.isInstalled('astral') && flags.indexOf('A') === -1) {
// This causes an error to be thrown if the Unicode Base addon is not available
flags += 'A';
}
if (!patternCache[pattern]) {
patternCache[pattern] = {};
}
if (!patternCache[pattern][flags]) {
var context = {
hasNamedCapture: false,
captureNames: []
};
var scope = defaultScope;
var output = '';
var pos = 0;
var result;
// Check for flag-related errors, and strip/apply flags in a leading mode modifier
var applied = prepareFlags(pattern, flags);
var appliedPattern = applied.pattern;
var appliedFlags = applied.flags;
// Use XRegExp's tokens to translate the pattern to a native regex pattern.
// `appliedPattern.length` may change on each iteration if tokens use `reparse`
while (pos < appliedPattern.length) {
do {
// Check for custom tokens at the current position
result = runTokens(appliedPattern, appliedFlags, pos, scope, context);
// If the matched token used the `reparse` option, splice its output into the
// pattern before running tokens again at the same position
if (result && result.reparse) {
appliedPattern = appliedPattern.slice(0, pos) +
result.output +
appliedPattern.slice(pos + result.matchLength);
}
} while (result && result.reparse);
if (result) {
output += result.output;
pos += (result.matchLength || 1);
} else {
// Get the native token at the current position
var token = XRegExp.exec(appliedPattern, nativeTokens[scope], pos, 'sticky')[0];
output += token;
pos += token.length;
if (token === '[' && scope === defaultScope) {
scope = classScope;
} else if (token === ']' && scope === classScope) {
scope = defaultScope;
}
}
}
patternCache[pattern][flags] = {
// Use basic cleanup to collapse repeated empty groups like `(?:)(?:)` to `(?:)`. Empty
// groups are sometimes inserted during regex transpilation in order to keep tokens
// separated. However, more than one empty group in a row is never needed.
pattern: nativ.replace.call(output, /(?:\(\?:\))+/g, '(?:)'),
// Strip all but native flags
flags: nativ.replace.call(appliedFlags, /[^gimuy]+/g, ''),
// `context.captureNames` has an item for each capturing group, even if unnamed
captures: context.hasNamedCapture ? context.captureNames : null
};
}
var generated = patternCache[pattern][flags];
return augment(
new RegExp(generated.pattern, generated.flags),
generated.captures,
pattern,
flags
);
}
|
Creates an extended regular expression object for matching text with a pattern. Differs from a
native regular expression in that additional syntax and flags are supported. The returned object
is in fact a native `RegExp` and works with all native methods.
@class XRegExp
@constructor
@param {String|RegExp} pattern Regex pattern string, or an existing regex object to copy.
@param {String} [flags] Any combination of flags.
Native flags:
- `g` - global
- `i` - ignore case
- `m` - multiline anchors
- `u` - unicode (ES6)
- `y` - sticky (Firefox 3+, ES6)
Additional XRegExp flags:
- `n` - explicit capture
- `s` - dot matches all (aka singleline)
- `x` - free-spacing and line comments (aka extended)
- `A` - astral (requires the Unicode Base addon)
Flags cannot be provided when constructing one `RegExp` from another.
@returns {RegExp} Extended regular expression object.
@example
// With named capture and flag x
XRegExp('(?<year> [0-9]{4} ) -? # year \n\
(?<month> [0-9]{2} ) -? # month \n\
(?<day> [0-9]{2} ) # day ', 'x');
// Providing a regex object copies it. Native regexes are recompiled using native (not XRegExp)
// syntax. Copies maintain extended data, are augmented with `XRegExp.prototype` properties, and
// have fresh `lastIndex` properties (set to zero).
XRegExp(/regex/);
|
XRegExp
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function addMatch(match) {
if (item.backref) {
// Safari 4.0.5 (but not 5.0.5+) inappropriately uses sparse arrays to hold the
// `undefined`s for backreferences to nonparticipating capturing groups. In such
// cases, a `hasOwnProperty` or `in` check on its own would inappropriately throw
// the exception, so also check if the backreference is a number that is within the
// bounds of the array.
if (!(match.hasOwnProperty(item.backref) || +item.backref < match.length)) {
throw new ReferenceError('Backreference to undefined group: ' + item.backref);
}
matches.push(match[item.backref] || '');
} else {
matches.push(match[0]);
}
}
|
Retrieves the matches from searching a string using a chain of regexes that successively search
within previous matches. The provided `chain` array can contain regexes and or objects with
`regex` and `backref` properties. When a backreference is specified, the named or numbered
backreference is passed forward to the next regex or returned.
@memberOf XRegExp
@param {String} str String to search.
@param {Array} chain Regexes that each search for matches within preceding results.
@returns {Array} Matches by the last regex in the chain, or an empty array.
@example
// Basic usage; matches numbers within <b> tags
XRegExp.matchChain('1 <b>2</b> 3 <b>4 a 56</b>', [
XRegExp('(?is)<b>.*?</b>'),
/\d+/
]);
// -> ['2', '4', '56']
// Passing forward and returning specific backreferences
html = '<a href="http://xregexp.com/api/">XRegExp</a>\
<a href="http://www.google.com/">Google</a>';
XRegExp.matchChain(html, [
{regex: /<a href="([^"]+)">/i, backref: 1},
{regex: XRegExp('(?i)^https?://(?<domain>[^/?#]+)'), backref: 'domain'}
]);
// -> ['xregexp.com', 'www.google.com']
|
addMatch
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
function rewrite(match, paren, backref) {
var name = captureNames[numCaptures - numPriorCaptures];
// Capturing group
if (paren) {
++numCaptures;
// If the current capture has a name, preserve the name
if (name) {
return '(?<' + name + '>';
}
// Backreference
} else if (backref) {
// Rewrite the backreference
return '\\' + (+backref + numPriorCaptures);
}
return match;
}
|
Returns an XRegExp object that is the union of the given patterns. Patterns can be provided as
regex objects or strings. Metacharacters are escaped in patterns provided as strings.
Backreferences in provided regex objects are automatically renumbered to work correctly within
the larger combined pattern. Native flags used by provided regexes are ignored in favor of the
`flags` argument.
@memberOf XRegExp
@param {Array} patterns Regexes and strings to combine.
@param {String} [flags] Any combination of XRegExp flags.
@param {Object} [options] Options object with optional properties:
- `conjunction` {String} Type of conjunction to use: 'or' (default) or 'none'.
@returns {RegExp} Union of the provided regexes and strings.
@example
XRegExp.union(['a+b*c', /(dogs)\1/, /(cats)\1/], 'i');
// -> /a\+b\*c|(dogs)\1|(cats)\2/i
XRegExp.union([/man/, /bear/, /pig/], 'i', {conjunction: 'none'});
// -> /manbearpig/i
|
rewrite
|
javascript
|
johanmodin/clifs
|
www/assets/admin/js/vendor/xregexp/xregexp.js
|
https://github.com/johanmodin/clifs/blob/master/www/assets/admin/js/vendor/xregexp/xregexp.js
|
Apache-2.0
|
check = function () {
var now = that.getTime();
if (now - start >= timeoutValue) {
reject(new Error('' + timeoutValue + 'ms timeout exceeded'));
} else {
that['context'].document.fonts.load(that.getStyle('"' + that['family'] + '"'), testString).then(function (fonts) {
if (fonts.length >= 1) {
resolve();
} else {
setTimeout(check, 25);
}
}, reject);
}
}
|
@param {string=} text Optional test string to use for detecting if a font is available.
@param {number=} timeout Optional timeout for giving up on font load detection and rejecting the promise (defaults to 3 seconds).
@return {Promise.<fontface.Observer>}
|
check
|
javascript
|
bramstein/fontfaceobserver
|
src/observer.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/src/observer.js
|
BSD-2-Clause
|
function check() {
if ((widthA != -1 && widthB != -1) || (widthA != -1 && widthC != -1) || (widthB != -1 && widthC != -1)) {
if (widthA == widthB || widthA == widthC || widthB == widthC) {
// All values are the same, so the browser has most likely loaded the web font
if (Observer.hasWebKitFallbackBug()) {
// Except if the browser has the WebKit fallback bug, in which case we check to see if all
// values are set to one of the last resort fonts.
if (((widthA == fallbackWidthA && widthB == fallbackWidthA && widthC == fallbackWidthA) ||
(widthA == fallbackWidthB && widthB == fallbackWidthB && widthC == fallbackWidthB) ||
(widthA == fallbackWidthC && widthB == fallbackWidthC && widthC == fallbackWidthC))) {
// The width we got matches some of the known last resort fonts, so let's assume we're dealing with the last resort font.
return;
}
}
removeContainer();
clearTimeout(timeoutId);
resolve(that);
}
}
}
|
@private
If metric compatible fonts are detected, one of the widths will be -1. This is
because a metric compatible font won't trigger a scroll event. We work around
this by considering a font loaded if at least two of the widths are the same.
Because we have three widths, this still prevents false positives.
Cases:
1) Font loads: both a, b and c are called and have the same value.
2) Font fails to load: resize callback is never called and timeout happens.
3) WebKit bug: both a, b and c are called and have the same value, but the
values are equal to one of the last resort fonts, we ignore this and
continue waiting until we get new values (or a timeout).
|
check
|
javascript
|
bramstein/fontfaceobserver
|
src/observer.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/src/observer.js
|
BSD-2-Clause
|
function checkForTimeout() {
var now = that.getTime();
if (now - start >= timeoutValue) {
removeContainer();
reject(new Error('' + timeoutValue + 'ms timeout exceeded'));
} else {
var hidden = that['context'].document['hidden'];
if (hidden === true || hidden === undefined) {
widthA = rulerA.getWidth();
widthB = rulerB.getWidth();
widthC = rulerC.getWidth();
check();
}
timeoutId = setTimeout(checkForTimeout, 50);
}
}
|
@private
If metric compatible fonts are detected, one of the widths will be -1. This is
because a metric compatible font won't trigger a scroll event. We work around
this by considering a font loaded if at least two of the widths are the same.
Because we have three widths, this still prevents false positives.
Cases:
1) Font loads: both a, b and c are called and have the same value.
2) Font fails to load: resize callback is never called and timeout happens.
3) WebKit bug: both a, b and c are called and have the same value, but the
values are equal to one of the last resort fonts, we ignore this and
continue waiting until we get new values (or a timeout).
|
checkForTimeout
|
javascript
|
bramstein/fontfaceobserver
|
src/observer.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/src/observer.js
|
BSD-2-Clause
|
function visitNode(path) {
if (path in deps.written) {
return;
}
// we have already visited this one. We can get here if we have cyclic
// dependencies
if (path in deps.visited) {
if (!(path in seenScript)) {
seenScript[path] = true;
scripts.push(path);
}
return;
}
deps.visited[path] = true;
if (path in deps.requires) {
for (var requireName in deps.requires[path]) {
// If the required name is defined, we assume that it was already
// bootstrapped by other means.
if (!goog.isProvided_(requireName)) {
if (requireName in deps.nameToPath) {
visitNode(deps.nameToPath[requireName]);
} else {
throw Error('Undefined nameToPath for ' + requireName);
}
}
}
}
if (!(path in seenScript)) {
seenScript[path] = true;
scripts.push(path);
}
}
|
Resolves dependencies based on the dependencies added using addDependency
and calls importScript_ in the correct order.
@private
|
visitNode
|
javascript
|
bramstein/fontfaceobserver
|
vendor/google/base.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/vendor/google/base.js
|
BSD-2-Clause
|
getMapping = function(cssName) {
return goog.cssNameMapping_[cssName] || cssName;
}
|
Handles strings that are intended to be used as CSS class names.
This function works in tandem with @see goog.setCssNameMapping.
Without any mapping set, the arguments are simple joined with a
hyphen and passed through unaltered.
When there is a mapping, there are two possible styles in which
these mappings are used. In the BY_PART style, each part (i.e. in
between hyphens) of the passed in css name is rewritten according
to the map. In the BY_WHOLE style, the full css name is looked up in
the map directly. If a rewrite is not specified by the map, the
compiler will output a warning.
When the mapping is passed to the compiler, it will replace calls
to goog.getCssName with the strings from the mapping, e.g.
var x = goog.getCssName('foo');
var y = goog.getCssName(this.baseClass, 'active');
becomes:
var x= 'foo';
var y = this.baseClass + '-active';
If one argument is passed it will be processed, if two are passed
only the modifier will be processed, as it is assumed the first
argument was generated as a result of calling goog.getCssName.
@param {string} className The class name.
@param {string=} opt_modifier A modifier to be appended to the class name.
@return {string} The class name or the concatenation of the class name and
the modifier.
|
getMapping
|
javascript
|
bramstein/fontfaceobserver
|
vendor/google/base.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/vendor/google/base.js
|
BSD-2-Clause
|
renameByParts = function(cssName) {
// Remap all the parts individually.
var parts = cssName.split('-');
var mapped = [];
for (var i = 0; i < parts.length; i++) {
mapped.push(getMapping(parts[i]));
}
return mapped.join('-');
}
|
Handles strings that are intended to be used as CSS class names.
This function works in tandem with @see goog.setCssNameMapping.
Without any mapping set, the arguments are simple joined with a
hyphen and passed through unaltered.
When there is a mapping, there are two possible styles in which
these mappings are used. In the BY_PART style, each part (i.e. in
between hyphens) of the passed in css name is rewritten according
to the map. In the BY_WHOLE style, the full css name is looked up in
the map directly. If a rewrite is not specified by the map, the
compiler will output a warning.
When the mapping is passed to the compiler, it will replace calls
to goog.getCssName with the strings from the mapping, e.g.
var x = goog.getCssName('foo');
var y = goog.getCssName(this.baseClass, 'active');
becomes:
var x= 'foo';
var y = this.baseClass + '-active';
If one argument is passed it will be processed, if two are passed
only the modifier will be processed, as it is assumed the first
argument was generated as a result of calling goog.getCssName.
@param {string} className The class name.
@param {string=} opt_modifier A modifier to be appended to the class name.
@return {string} The class name or the concatenation of the class name and
the modifier.
|
renameByParts
|
javascript
|
bramstein/fontfaceobserver
|
vendor/google/base.js
|
https://github.com/bramstein/fontfaceobserver/blob/master/vendor/google/base.js
|
BSD-2-Clause
|
getTime = function () {
var date, format;
var time = Math.max(_start, _end);
var diff = _start - _end;
var offset_GMT = new Date().getTimezoneOffset();
var diff_format;
if (isTime) {
date = new Date(time);
format = timeFormat(options.format, time);
diff_format = timeFormat(options.format, diff + offset_GMT * 60 * 1000);
} else {
date = new Date();
format = time / 1e3;
diff_format = diff / 1e3;
}
return {
'year': date.getFullYear(),
'month': date.getMonth() + 1,
'day': date.getDate(),
'hour': date.getHours(),
'minute': date.getMinutes(),
'second': date.getSeconds(),
'quarter': Math.floor((date.getMonth() + 3) / 3),
'microsecond': date.getMilliseconds(),
'format': format,
'distance': diff_format,
'timestamp': diff
};
}
|
jquery.countdown.js 1.0
http://jquerywidget.com
|
getTime
|
javascript
|
mumuy/widget
|
code/jquery.countdown.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.countdown.js
|
MIT
|
count = function () {
if (_hander) {
clearInterval(_hander);
}
options.countEach(getTime());
$this.addClass(options.disabledCls);
var isReverse = _start > _end ? true : false;
_hander = setInterval(function () {
if (isReverse) {
_start -= options.interval;
options.countEach(getTime());
if (_start <= _end) {
clearInterval(_hander);
$this.removeClass(options.disabledCls);
options.countEnd(getTime());
}
} else {
_start += options.interval;
options.countEach(getTime());
if (_start >= _end) {
clearInterval(_hander);
$this.removeClass(options.disabledCls);
options.countEnd(getTime());
}
}
}, options.interval);
}
|
jquery.countdown.js 1.0
http://jquerywidget.com
|
count
|
javascript
|
mumuy/widget
|
code/jquery.countdown.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.countdown.js
|
MIT
|
function getTimestamp(str) {
str = str.replace(/\-/g, '/');
return +new Date(str) || +new Date('1970/1/1 ' + str);
}
|
jquery.countdown.js 1.0
http://jquerywidget.com
|
getTimestamp
|
javascript
|
mumuy/widget
|
code/jquery.countdown.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.countdown.js
|
MIT
|
closeLayer = function(){
if($trigger){
$trigger.removeClass(options.activeCls);
}
$layer.hide();
$trigger = null;
$textarea = null;
options.onHide();
}
|
jquery.emoticons.js 1.0
http://jquerywidget.com
|
closeLayer
|
javascript
|
mumuy/widget
|
code/jquery.emoticons.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.emoticons.js
|
MIT
|
getCursortPosition = function (textDom) {
var cursorPos = 0;
if (document.selection) { // IE Support
textDom.focus ();
var selectRange = document.selection.createRange();
selectRange.moveStart ('character', -textDom.value.length);
cursorPos = selectRange.text.length;
}else if (textDom.selectionStart || textDom.selectionStart == '0') { // Firefox support
cursorPos = textDom.selectionStart;
}
return cursorPos;
}
|
jquery.emoticons.js 1.0
http://jquerywidget.com
|
getCursortPosition
|
javascript
|
mumuy/widget
|
code/jquery.emoticons.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.emoticons.js
|
MIT
|
function insertText(obj,str) {
if(document.all && obj.createTextRange && obj.caretPos){
var caretPos=obj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length-1) == '' ?
str+'' : str;
}else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
cursorPos = startPos,
tmpStr = obj.value;
obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
cursorPos += str.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
obj.focus();
} else {
obj.value += str;
}
}
|
jquery.emoticons.js 1.0
http://jquerywidget.com
|
insertText
|
javascript
|
mumuy/widget
|
code/jquery.emoticons.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.emoticons.js
|
MIT
|
resize = function(){
options.onResize(_api);
_window_width = $document.width();
$outer.attr('style','');
_width = $outer.width();
$fixed.css({
'width':_window_width==_width?'100%':_width
});
if(options.autoFixed){
var heightAuto = function(){
_height = $this.outerHeight();
$outer.css({
'height':_height
});
};
heightAuto();
setTimeout(heightAuto,500);
}
}
|
jquery.headroom.js 1.0
http://jquerywidget.com
|
resize
|
javascript
|
mumuy/widget
|
code/jquery.headroom.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.headroom.js
|
MIT
|
heightAuto = function(){
_height = $this.outerHeight();
$outer.css({
'height':_height
});
}
|
jquery.headroom.js 1.0
http://jquerywidget.com
|
heightAuto
|
javascript
|
mumuy/widget
|
code/jquery.headroom.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.headroom.js
|
MIT
|
imageDownLoad = function(url,callback){
callback = callback || function(){};
var image = new Image();
image.src = url;
image.onload = callback(image);
}
|
jquery.magiczoom.js 1.0
http://jquerywidget.com
|
imageDownLoad
|
javascript
|
mumuy/widget
|
code/jquery.magiczoom.js
|
https://github.com/mumuy/widget/blob/master/code/jquery.magiczoom.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.