Skip to content

Commit acb2bd5

Browse files
committed
Lock down some publicly accessible structures
1 parent 695e1e8 commit acb2bd5

13 files changed

Lines changed: 444 additions & 464 deletions

File tree

src/Velocity/defaults.ts

Lines changed: 182 additions & 215 deletions
Large diffs are not rendered by default.

src/Velocity/normalizations/style.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,20 @@ function getSetStyle(propertyName: string) {
115115
const rxVendors = /^(webkit|moz|ms|o)[A-Z]/,
116116
prefixElement = State.prefixElement;
117117

118-
for (const propertyName in prefixElement.style) {
119-
if (rxVendors.test(propertyName)) {
120-
const unprefixed = propertyName.replace(/^[a-z]+([A-Z])/, ($, letter: string) => letter.toLowerCase());
118+
if (prefixElement) {
119+
for (const propertyName in prefixElement.style) {
120+
if (rxVendors.test(propertyName)) {
121+
const unprefixed = propertyName.replace(/^[a-z]+([A-Z])/, ($, letter: string) => letter.toLowerCase());
121122

122-
if (ALL_VENDOR_PREFIXES || isString(prefixElement.style[unprefixed])) {
123-
const addUnit = rxAddPx.test(unprefixed) ? "px" : undefined;
123+
if (ALL_VENDOR_PREFIXES || isString(prefixElement.style[unprefixed])) {
124+
const addUnit = rxAddPx.test(unprefixed) ? "px" : undefined;
124125

125-
registerNormalization(["Element", unprefixed, getSetPrefixed(propertyName, unprefixed), addUnit]);
126-
}
127-
} else if (!hasNormalization(["Element", propertyName])) {
128-
const addUnit = rxAddPx.test(propertyName) ? "px" : undefined;
126+
registerNormalization(["Element", unprefixed, getSetPrefixed(propertyName, unprefixed), addUnit]);
127+
}
128+
} else if (!hasNormalization(["Element", propertyName])) {
129+
const addUnit = rxAddPx.test(propertyName) ? "px" : undefined;
129130

130-
registerNormalization(["Element", propertyName, getSetStyle(propertyName), addUnit]);
131+
registerNormalization(["Element", propertyName, getSetStyle(propertyName), addUnit]);
132+
}
131133
}
132134
}

src/Velocity/state.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ const isClient = window && window === window.window,
1616
export const State: VelocityState = {
1717
isClient,
1818
isMobile: isClient && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
19-
isAndroid: isClient && /Android/i.test(navigator.userAgent),
2019
isGingerbread: isClient && /Android 2\.3\.[3-7]/i.test(navigator.userAgent),
21-
isChrome: isClient && (window as any).chrome,
22-
isFirefox: isClient && /Firefox/i.test(navigator.userAgent),
2320
prefixElement: isClient && document.createElement("div"),
2421
windowScrollAnchor,
2522
scrollAnchor: windowScrollAnchor ? window : (!isClient || document.documentElement || document.body.parentNode || document.body),

src/velocity.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace VelocityStatic {
6060
/**
6161
* Velocity option defaults, which can be overriden by the user.
6262
*/
63-
export const defaults: StrictVelocityOptions & {reset?: () => void} = DefaultObject;
63+
export const defaults: StrictVelocityOptions & {reset?: () => void} = DefaultObject as any;
6464

6565
/**
6666
* Used to patch any object to allow Velocity chaining. In order to chain an
@@ -182,4 +182,6 @@ for (const property in VelocityStatic) {
182182
}
183183
}
184184

185+
Object.freeze(Velocity);
186+
185187
export default Velocity; // tslint:disable-line:no-default-export

test/src/utilities.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ declare global {
2525
}
2626
}
2727

28-
export const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
29-
isAndroid = /Android/i.test(navigator.userAgent),
28+
export const $ = ((window as any).jQuery || (window as any).Zepto),
29+
$qunitStage = document.getElementById("qunit-stage"),
3030
defaultStyles = {
3131
opacity: 1,
3232
width: 1,
@@ -51,8 +51,6 @@ export const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Oper
5151
delay: 0,
5252
mobileHA: true,
5353
},
54-
$ = ((window as any).jQuery || (window as any).Zepto),
55-
$qunitStage = document.getElementById("qunit-stage"),
5654
asyncCheckDuration = (defaultOptions.duration as number) / 2,
5755
completeCheckDuration = (defaultOptions.duration as number) * 2,
5856
IE = (() => {

test/test.js

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

velocity.d.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,33 +1312,17 @@ export interface VelocityState {
13121312
*/
13131313
readonly isMobile: boolean;
13141314

1315-
/**
1316-
* The mobileHA option's behavior changes on older Android devices
1317-
* (Gingerbread, versions 2.3.3-2.3.7).
1318-
*/
1319-
readonly isAndroid: boolean;
1320-
13211315
/**
13221316
* The mobileHA option's behavior changes on older Android devices
13231317
* (Gingerbread, versions 2.3.3-2.3.7).
13241318
*/
13251319
readonly isGingerbread: boolean;
13261320

1327-
/**
1328-
* Chrome browser
1329-
*/
1330-
readonly isChrome: boolean;
1331-
1332-
/**
1333-
* Firefox browser
1334-
*/
1335-
readonly isFirefox: boolean;
1336-
13371321
/**
13381322
* Create a cached element for re-use when checking for CSS property
13391323
* prefixes.
13401324
*/
1341-
readonly prefixElement: HTMLDivElement;
1325+
readonly prefixElement?: HTMLDivElement;
13421326

13431327
/**
13441328
* Retrieve the appropriate scroll anchor and property name for the

0 commit comments

Comments
 (0)