From 65448a312af017d1f86d16ed51449bdc06686dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82e=CC=A8biowski-Owczarek?= Date: Tue, 30 Jul 2024 00:03:29 +0200 Subject: [PATCH] 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 use `require`, falling back to relying on the `jQuery` global in the other case. Ref gh-2187 Ref jquery/jqueryui.com#216 --- demos/search.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/demos/search.js b/demos/search.js index 448071cc9f..c6dddb80ef 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",