'use strict';
/*
2017:
Abrose Little
8/14/2019: Updated to JQueryUI 1.12
Based on jQuery UI Version 1.11; you may need to update the methods/params to find, if you use a different version.
I break these out into categories to mirror how jQuery UI site breaks them out.
Makes it maybe easier to decide what you care about searching for or not.
I am sure there is a more elegant way, so please fork/show me if so.
You can copy and paste this into, e.g., VS Code's search box. Surprisingly, it can handle this monstrosity pretty well.
*/
let widgets = [
'accordion',
'autocomplete',
'button',
'buttonset',
'checkboxradio', // 1.12
'controlgroup', // 1.12
'datepicker',
'dialog',
'menu',
'progressbar',
'selectmenu',
'slider',
'spinner',
'tabs',
'tooltip'
];
let effectMethods = [
'effect',
'switchClass',
'switchClass'
];
let effectNames = [
'blind',
'bounce',
'clip',
'drop',
'explode',
'fade',
'fold',
'highlight',
'puff',
'scale',
'shake',
'size',
'slide',
'transfer'
];
let easings = [
'easeInQuad',
'easeOutQuad',
'easeInOutQuad',
'easeInCubic',
'easeOutCubic',
'easeInOutCubic',
'easeInQuart',
'easeOutQuart',
'easeInOutQuart',
'easeInQuint',
'easeOutQuint',
'easeInOutQuint',
'easeInExpo',
'easeOutExpo',
'easeInOutExpo',
'easeInSine',
'easeOutSine',
'easeInOutSine',
'easeInCirc',
'easeOutCirc',
'easeInOutCirc',
'easeInElastic',
'easeOutElastic',
'easeInOutElastic',
'easeInBack',
'easeOutBack',
'easeInOutBack',
'easeInBounce',
'easeOutBounce',
'easeInOutBounce'
];
let interactions = [
'draggable',
'droppable',
'mouse',
'resizable',
'selectable',
'sortable'
];
// These are things the docs claim to override/augment in base jQuery.
// I found it to produce too many false positives in my code base to include them.
let jQueryMods = [
'toggle',
'addClass',
'removeClass',
'toggleClass',
// 'focus', // standard DOM method yikes
'position',
'show',
'hide'
];
let additionalMethods = [
'disableSelection',
'enableSelection',
'removeUniqueId',
'scrollParent',
'uniqueId',
'zIndex'
];
let selectors = [
// 'data\\s*\\(', // KG removed since it's in jQuery
'focusable',
'tabbable'
];
let methods = [
widgets,
effectMethods,
interactions,
// jQueryMods, // this catches too many false positives
additionalMethods
];
let params = [
//effectNames,
//easings
];
let keyCode = '|jQuery\\.ui\\.keyCode';
let colorAnimations = '|\\.\\s*animate\\s*\\(\\s*\\{[\\s\\S]*[cC]olor\\s*:';
let widgetFactory = '|\\$\\s*\\.\\s*widget\\s*(\\.\\s*bridge\\s*)?\\(';
let methodMatcher = (expr, matcher, index) => {
if (expr.length) { expr += '|'; }
return expr += `\\.\\s*${matcher}\\s*\\(`;
};
// this is to reduce false positives--the 'any character' matcher [\s\S] is too generous w/o the extra constraint of the object literals
let paramInObjectMatcher = (expr, matcher, index) => {
if (expr.length) { expr += '|'; }
return expr += `\\(\\s*\\{[\\s\\S]*['"]${matcher}['"][\\s\\S]*\\}\\s*\\)`;
};
// contrasted with the above, this matches when the param to be matched is the only param given (as a string)
let singleParamMatcher = (expr, matcher, index) => {
if (expr.length) { expr += '|'; }
return expr += `\\(\\s*['"]${matcher}['"]\\s*\\)`;
};
let selectorMatcher = (expr, matcher, index) => {
if (expr.length) { expr += '|'; }
return expr += `\\([\\s\\S]*:${matcher}[\\s\\S]*\\)`; // not sure this is right for usage, but I think so within the context of jQuery/jQuery UI
};
let matchExpression = methods.reduce((expr, matchers) => matchers.reduce(methodMatcher, expr), '');
matchExpression = params.reduce((expr, matchers) => matchers.reduce(paramInObjectMatcher, expr), matchExpression);
matchExpression = params.reduce((expr, matchers) => matchers.reduce(singleParamMatcher, expr), matchExpression);
matchExpression = selectors.reduce(selectorMatcher, matchExpression);
matchExpression += keyCode + widgetFactory /* + colorAnimations */;
let res = document.getElementById('results');
if (res) res.innerText = matchExpression;