Skip to content

Commit 0d5d93b

Browse files
committed
Allow choices.js to be imported on server. As windows.document is by default not defined, default template rendering will not function, the callbackOnCreateTemplates callback must be used. Choices-js#861
1 parent 8f57a83 commit 0d5d93b

22 files changed

Lines changed: 84 additions & 39 deletions

public/assets/scripts/choices.cjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,9 @@ var setIsLoading = function (isLoading) { return ({
17541754
}); };
17551755

17561756
/* eslint-disable @typescript-eslint/no-explicit-any */
1757+
var canUseDom = !!(typeof window !== 'undefined' &&
1758+
window.document &&
1759+
window.document.createElement);
17571760
var getRandomNumber = function (min, max) {
17581761
return Math.floor(Math.random() * (max - min) + min);
17591762
};
@@ -1982,7 +1985,7 @@ var Container = /** @class */ (function () {
19821985
// If flip is enabled and the dropdown bottom position is
19831986
// greater than the window height flip the dropdown.
19841987
var shouldFlip = false;
1985-
if (this.position === 'auto') {
1988+
if (canUseDom && this.position === 'auto') {
19861989
shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)"))
19871990
.matches;
19881991
}
@@ -3620,7 +3623,8 @@ var templates = {
36203623
};
36213624

36223625
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
3623-
var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style &&
3626+
var IS_IE11 = canUseDom &&
3627+
'-ms-scroll-limit' in document.documentElement.style &&
36243628
'-ms-ime-align' in document.documentElement.style;
36253629
var USER_DEFAULTS = {};
36263630
var parseDataSetId = function (element) {
@@ -3744,7 +3748,7 @@ var Choices = /** @class */ (function () {
37443748
* or when calculated direction is different from the document
37453749
*/
37463750
this._direction = this.passedElement.dir;
3747-
if (!this._direction) {
3751+
if (!this._direction && canUseDom) {
37483752
var elementDirection = window.getComputedStyle(this.passedElement.element).direction;
37493753
var documentDirection = window.getComputedStyle(document.documentElement).direction;
37503754
if (elementDirection !== documentDirection) {

public/assets/scripts/choices.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,9 @@
17581758
}); };
17591759

17601760
/* eslint-disable @typescript-eslint/no-explicit-any */
1761+
var canUseDom = !!(typeof window !== 'undefined' &&
1762+
window.document &&
1763+
window.document.createElement);
17611764
var getRandomNumber = function (min, max) {
17621765
return Math.floor(Math.random() * (max - min) + min);
17631766
};
@@ -1986,7 +1989,7 @@
19861989
// If flip is enabled and the dropdown bottom position is
19871990
// greater than the window height flip the dropdown.
19881991
var shouldFlip = false;
1989-
if (this.position === 'auto') {
1992+
if (canUseDom && this.position === 'auto') {
19901993
shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)"))
19911994
.matches;
19921995
}
@@ -3624,7 +3627,8 @@
36243627
};
36253628

36263629
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
3627-
var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style &&
3630+
var IS_IE11 = canUseDom &&
3631+
'-ms-scroll-limit' in document.documentElement.style &&
36283632
'-ms-ime-align' in document.documentElement.style;
36293633
var USER_DEFAULTS = {};
36303634
var parseDataSetId = function (element) {
@@ -3748,7 +3752,7 @@
37483752
* or when calculated direction is different from the document
37493753
*/
37503754
this._direction = this.passedElement.dir;
3751-
if (!this._direction) {
3755+
if (!this._direction && canUseDom) {
37523756
var elementDirection = window.getComputedStyle(this.passedElement.element).direction;
37533757
var documentDirection = window.getComputedStyle(document.documentElement).direction;
37543758
if (elementDirection !== documentDirection) {

public/assets/scripts/choices.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/assets/scripts/choices.min.js

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

public/assets/scripts/choices.min.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/assets/scripts/choices.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,9 @@ var setIsLoading = function (isLoading) { return ({
17521752
}); };
17531753

17541754
/* eslint-disable @typescript-eslint/no-explicit-any */
1755+
var canUseDom = !!(typeof window !== 'undefined' &&
1756+
window.document &&
1757+
window.document.createElement);
17551758
var getRandomNumber = function (min, max) {
17561759
return Math.floor(Math.random() * (max - min) + min);
17571760
};
@@ -1980,7 +1983,7 @@ var Container = /** @class */ (function () {
19801983
// If flip is enabled and the dropdown bottom position is
19811984
// greater than the window height flip the dropdown.
19821985
var shouldFlip = false;
1983-
if (this.position === 'auto') {
1986+
if (canUseDom && this.position === 'auto') {
19841987
shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)"))
19851988
.matches;
19861989
}
@@ -3618,7 +3621,8 @@ var templates = {
36183621
};
36193622

36203623
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
3621-
var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style &&
3624+
var IS_IE11 = canUseDom &&
3625+
'-ms-scroll-limit' in document.documentElement.style &&
36223626
'-ms-ime-align' in document.documentElement.style;
36233627
var USER_DEFAULTS = {};
36243628
var parseDataSetId = function (element) {
@@ -3742,7 +3746,7 @@ var Choices = /** @class */ (function () {
37423746
* or when calculated direction is different from the document
37433747
*/
37443748
this._direction = this.passedElement.dir;
3745-
if (!this._direction) {
3749+
if (!this._direction && canUseDom) {
37463750
var elementDirection = window.getComputedStyle(this.passedElement.element).direction;
37473751
var documentDirection = window.getComputedStyle(document.documentElement).direction;
37483752
if (elementDirection !== documentDirection) {

public/assets/scripts/choices.search-basic.cjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,9 @@ var setIsLoading = function (isLoading) { return ({
12721272
}); };
12731273

12741274
/* eslint-disable @typescript-eslint/no-explicit-any */
1275+
var canUseDom = !!(typeof window !== 'undefined' &&
1276+
window.document &&
1277+
window.document.createElement);
12751278
var getRandomNumber = function (min, max) {
12761279
return Math.floor(Math.random() * (max - min) + min);
12771280
};
@@ -1500,7 +1503,7 @@ var Container = /** @class */ (function () {
15001503
// If flip is enabled and the dropdown bottom position is
15011504
// greater than the window height flip the dropdown.
15021505
var shouldFlip = false;
1503-
if (this.position === 'auto') {
1506+
if (canUseDom && this.position === 'auto') {
15041507
shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)"))
15051508
.matches;
15061509
}
@@ -3138,7 +3141,8 @@ var templates = {
31383141
};
31393142

31403143
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
3141-
var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style &&
3144+
var IS_IE11 = canUseDom &&
3145+
'-ms-scroll-limit' in document.documentElement.style &&
31423146
'-ms-ime-align' in document.documentElement.style;
31433147
var USER_DEFAULTS = {};
31443148
var parseDataSetId = function (element) {
@@ -3262,7 +3266,7 @@ var Choices = /** @class */ (function () {
32623266
* or when calculated direction is different from the document
32633267
*/
32643268
this._direction = this.passedElement.dir;
3265-
if (!this._direction) {
3269+
if (!this._direction && canUseDom) {
32663270
var elementDirection = window.getComputedStyle(this.passedElement.element).direction;
32673271
var documentDirection = window.getComputedStyle(document.documentElement).direction;
32683272
if (elementDirection !== documentDirection) {

public/assets/scripts/choices.search-basic.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,9 @@
12761276
}); };
12771277

12781278
/* eslint-disable @typescript-eslint/no-explicit-any */
1279+
var canUseDom = !!(typeof window !== 'undefined' &&
1280+
window.document &&
1281+
window.document.createElement);
12791282
var getRandomNumber = function (min, max) {
12801283
return Math.floor(Math.random() * (max - min) + min);
12811284
};
@@ -1504,7 +1507,7 @@
15041507
// If flip is enabled and the dropdown bottom position is
15051508
// greater than the window height flip the dropdown.
15061509
var shouldFlip = false;
1507-
if (this.position === 'auto') {
1510+
if (canUseDom && this.position === 'auto') {
15081511
shouldFlip = !window.matchMedia("(min-height: ".concat(dropdownPos + 1, "px)"))
15091512
.matches;
15101513
}
@@ -3142,7 +3145,8 @@
31423145
};
31433146

31443147
/** @see {@link http://browserhacks.com/#hack-acea075d0ac6954f275a70023906050c} */
3145-
var IS_IE11 = '-ms-scroll-limit' in document.documentElement.style &&
3148+
var IS_IE11 = canUseDom &&
3149+
'-ms-scroll-limit' in document.documentElement.style &&
31463150
'-ms-ime-align' in document.documentElement.style;
31473151
var USER_DEFAULTS = {};
31483152
var parseDataSetId = function (element) {
@@ -3266,7 +3270,7 @@
32663270
* or when calculated direction is different from the document
32673271
*/
32683272
this._direction = this.passedElement.dir;
3269-
if (!this._direction) {
3273+
if (!this._direction && canUseDom) {
32703274
var elementDirection = window.getComputedStyle(this.passedElement.element).direction;
32713275
var documentDirection = window.getComputedStyle(document.documentElement).direction;
32723276
if (elementDirection !== documentDirection) {

public/assets/scripts/choices.search-basic.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/assets/scripts/choices.search-basic.min.js

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

0 commit comments

Comments
 (0)