diff options
author | Michał Gołębiowski-Owczarek <m.goleb@gmail.com> | 2024-07-30 08:31:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-30 08:31:10 +0200 |
commit | 600057f59c57fb428c0a453147476092741842c6 (patch) | |
tree | 77cf6b359747a888e3c5da42dfd518486aa8eca9 | |
parent | 5665215a8560832193735d9507a90d10e03b90c8 (diff) | |
download | jquery-ui-600057f59c57fb428c0a453147476092741842c6.tar.gz jquery-ui-600057f59c57fb428c0a453147476092741842c6.zip |
Demos: Make autocomplete demos work on jqueryui.com
The `jqueryui.com` demos build process deAMDifies HTML files, replacing required
JS files with direct script tags. On the other hand, when running demos locally
from the jQuery UI repository, RequireJS is used.
This used to work fine until we got a new `search.js` file introduced in
gh-2187. The deAMDifying process doesn't touch non-HTML files which made loading
autocomplete demos crash on "require is not a function"
To resolve the issues without a major rearchitecture of the build process,
the `search.js` file now detects AMD and uses `require`, falling back to relying
on the `jQuery` global in the other case.
Closes gh-2274
Ref gh-2187
Ref jquery/jqueryui.com#216
-rw-r--r-- | demos/search.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/demos/search.js b/demos/search.js index 448071cc9..c6dddb80e 100644 --- a/demos/search.js +++ b/demos/search.js @@ -1,5 +1,18 @@ -require( [ "jquery", ], function( $ ) { +( function( factory ) { "use strict"; + + if ( typeof define === "function" && define.amd ) { + + // Fetch jQuery as an AMD dependency + require( [ "jquery" ], factory ); + } else { + + // Use the jQuery browser global + factory( jQuery ); + } +} )( function( $ ) { + "use strict"; + var database = { "Great Bittern" : "Botaurus stellaris", "Little Grebe" : "Tachybaptus ruficollis", |