蓝色天空网mbsky.com · 知识 · 实践 · 创造jQuery UI · 本地阅读预览
教程 / 前端开发 / jQuery UI

jQuery UI 下载

核对 jQuery UI Download Builder 的三步自定义构建流程:组件依赖自动勾选、预设/作用域主题配置、版本与 jQuery 依赖核对及 zip 产物清单。

本站独立整理的内容草稿。实例显示的是预期结果;浏览器、服务端运行与技术内容验收尚待完成,本页只用于阅读和图文核对。

学完这一章,你能够

通过 Download Builder 定制下载包

了解基础概念后,可通过 jQuery UI 官方 Download Builder(下载生成器)按需组装仅包含项目所需模块的自定义发行包。整个定制流程依次分为选择组件、配置主题与选定版本三个步骤,最后一键生成压缩包。

三步配置与版本依赖核对

步骤 1 为选择 JavaScript 组件:生成器将全部模块划分为核心(UI Core)、交互部件(Interactions)、小部件(Widgets)和效果库(Effects)四大分组。若选中存在前置依赖的组件,系统会自动连带勾选其全部依赖并合并输出为单个 JS 文件。本站离线模拟 4 组构建面板实测:勾选 `droppable` 自动补全 5 项依赖(`core`、`draggable`、`droppable`、`mouse`、`widget`);继续勾选 `dialog` 自动扩展至 8 项(补入 `dialog`、`position`、`resizable`)。

步骤 2 为选择或自定义主题:可在下拉列表中挑选官方预设主题,或通过 ThemeRoller 定制视觉方案。对于单主题页面,直接忽略主题面板中的“高级主题设置”即可;若需在同一页面混用多套主题,则可填写 CSS 作用域前缀(CSS Scope)防止样式串扰。本站实测 `.theme-a` 与 `.theme-b` 双作用域共存时,两个 `.ui-widget-header` 计算背景色分别独立呈现为 `rgb(33, 145, 192)` 与 `rgb(246, 168, 40)`。

步骤 3 为选择版本号并点击 Download 下载自定义 zip 文件。版本选择直接关系到与宿主 jQuery 的兼容性:历史上 jQuery UI 1.10.2 与 1.9.2 均要求 jQuery 1.6 及以上版本(现代 1.13+ 分支已升级对应更高 jQuery 版本)。本站离线版本校验实测:jQuery `1.5.2` 对 jQuery UI `1.10.2` 判定不兼容(`ok=false`),而 `1.6.4` 与 `1.10.2` 分别匹配 `1.10.2` 与 `1.9.2`(`ok=true`);点击下载生成的清单包含 `css/smoothness/jquery-ui.custom.css`、`development-bundle/`、`js/jquery.min.js`、`js/jquery-ui.custom.min.js` 与 `index.html`。

运行 Download Builder 依赖自动勾选、多主题 CSS 作用域隔离与版本兼容校验离线实验

python · 阅读源码
"""Offline Playwright Chromium lab for jQuery UI Ch 03 (download)."""
import json
from playwright.sync_api import sync_playwright


def launch_browser(p):
    try:
        return p.chromium.launch(headless=True)
    except Exception:
        return p.chromium.launch(headless=True, channel="chrome")


def main():
    cases = []
    with sync_playwright() as p:
        browser = launch_browser(p)
        page = browser.new_page(viewport={"width": 960, "height": 700})

        # Case 1: Download Builder component dependency auto-selection
        page.set_content("""<!DOCTYPE html><html><body>
<form id="builder">
  <fieldset data-group="ui-core">
    <input type="checkbox" value="core" />
    <input type="checkbox" value="widget" />
    <input type="checkbox" value="mouse" />
    <input type="checkbox" value="position" />
  </fieldset>
  <fieldset data-group="interactions">
    <input type="checkbox" value="draggable" />
    <input type="checkbox" value="droppable" />
    <input type="checkbox" value="resizable" />
    <input type="checkbox" value="selectable" />
    <input type="checkbox" value="sortable" />
  </fieldset>
  <fieldset data-group="widgets">
    <input type="checkbox" value="accordion" />
    <input type="checkbox" value="datepicker" />
    <input type="checkbox" value="dialog" />
    <input type="checkbox" value="slider" />
  </fieldset>
  <fieldset data-group="effects">
    <input type="checkbox" value="effects-core" />
    <input type="checkbox" value="fade" />
  </fieldset>
</form>
<script>
const DEPS = {
  mouse: ['core', 'widget'],
  draggable: ['core', 'widget', 'mouse'],
  droppable: ['draggable'],
  resizable: ['core', 'widget', 'mouse'],
  accordion: ['core', 'widget'],
  datepicker: ['core'],
  dialog: ['core', 'widget', 'position', 'draggable', 'resizable'],
  fade: ['effects-core']
};
function selectWithDeps(name) {
  const cb = document.querySelector(`input[value="${name}"]`);
  if (!cb) return;
  cb.checked = true;
  (DEPS[name] || []).forEach(selectWithDeps);
}
document.querySelectorAll('#builder input[type="checkbox"]').forEach(cb => {
  cb.addEventListener('change', () => { if (cb.checked) selectWithDeps(cb.value); });
});
</script></body></html>""")
        page.check('input[value="droppable"]')
        after_drop = page.evaluate("""() => [...document.querySelectorAll('#builder input:checked')].map(i => i.value).sort()""")
        page.check('input[value="dialog"]')
        after_dialog = page.evaluate("""() => [...document.querySelectorAll('#builder input:checked')].map(i => i.value).sort()""")
        act1 = {"after_droppable": after_drop, "after_dialog": after_dialog, "group_count": page.locator("fieldset").count()}
        exp1 = {
            "after_droppable": ["core", "draggable", "droppable", "mouse", "widget"],
            "after_dialog": ["core", "dialog", "draggable", "droppable", "mouse", "position", "resizable", "widget"],
            "group_count": 4,
        }
        cases.append({
            "name": "component_dependency_auto_select",
            "expected": exp1,
            "actual": act1,
            "passed": act1 == exp1,
        })

        # Case 2: Advanced Theme Settings - CSS Scope multi-theme isolation
        page.set_content("""<!DOCTYPE html><html><head><style>
.theme-a .ui-widget-header { background: rgb(33, 145, 192); color: rgb(255, 255, 255); }
.theme-b .ui-widget-header { background: rgb(246, 168, 40); color: rgb(34, 34, 34); }
</style></head><body>
<div class="theme-a"><div id="h1" class="ui-widget-header">Scope A</div></div>
<div class="theme-b"><div id="h2" class="ui-widget-header">Scope B</div></div>
</body></html>""")
        act2 = page.evaluate("""() => ({
          scope_a_bg: getComputedStyle(document.getElementById('h1')).backgroundColor,
          scope_a_color: getComputedStyle(document.getElementById('h1')).color,
          scope_b_bg: getComputedStyle(document.getElementById('h2')).backgroundColor,
          scope_b_color: getComputedStyle(document.getElementById('h2')).color
        })""")
        exp2 = {
            "scope_a_bg": "rgb(33, 145, 192)",
            "scope_a_color": "rgb(255, 255, 255)",
            "scope_b_bg": "rgb(246, 168, 40)",
            "scope_b_color": "rgb(34, 34, 34)",
        }
        cases.append({
            "name": "scoped_multi_theme_css_isolation",
            "expected": exp2,
            "actual": act2,
            "passed": act2 == exp2,
        })

        # Case 3: Version selector & jQuery minimum requirement check
        page.set_content("""<!DOCTYPE html><html><body>
<input type="radio" name="ver" value="1.10.2" data-min-jq="1.6" checked />
<input type="radio" name="ver" value="1.9.2" data-min-jq="1.6" />
<script>
function verGte(a, b) {
  const pa = a.split('.').map(Number), pb = b.split('.').map(Number);
  for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
    const da = pa[i] || 0, db = pb[i] || 0;
    if (da !== db) return da > db;
  }
  return true;
}
window.checkCompat = (jqVer) => {
  const sel = document.querySelector('input[name="ver"]:checked');
  return { ui: sel.value, min_jq: sel.dataset.minJq, ok: verGte(jqVer, sel.dataset.minJq) };
};
</script></body></html>""")
        c152 = page.evaluate("() => window.checkCompat('1.5.2')")
        c164 = page.evaluate("() => window.checkCompat('1.6.4')")
        page.check('input[value="1.9.2"]')
        c192 = page.evaluate("() => window.checkCompat('1.10.2')")
        act3 = {"jq_1_5_2": c152, "jq_1_6_4": c164, "ui_1_9_2_with_jq_1_10_2": c192}
        exp3 = {
            "jq_1_5_2": {"ui": "1.10.2", "min_jq": "1.6", "ok": False},
            "jq_1_6_4": {"ui": "1.10.2", "min_jq": "1.6", "ok": True},
            "ui_1_9_2_with_jq_1_10_2": {"ui": "1.9.2", "min_jq": "1.6", "ok": True},
        }
        cases.append({
            "name": "version_jquery_compatibility_matrix",
            "expected": exp3,
            "actual": act3,
            "passed": act3 == exp3,
        })

        # Case 4: Custom zip package manifest verification
        page.set_content("""<!DOCTYPE html><html><body>
<button id="dlBtn">Download</button><pre id="manifest"></pre>
<script>
document.getElementById('dlBtn').addEventListener('click', () => {
  const theme = 'smoothness';
  const manifest = [
    `css/${theme}/jquery-ui.custom.css`,
    'development-bundle/',
    'js/jquery.min.js',
    'js/jquery-ui.custom.min.js',
    'index.html'
  ];
  document.getElementById('manifest').textContent = JSON.stringify(manifest);
});
</script></body></html>""")
        page.click("#dlBtn")
        act4 = json.loads(page.locator("#manifest").inner_text())
        exp4 = [
            "css/smoothness/jquery-ui.custom.css",
            "development-bundle/",
            "js/jquery.min.js",
            "js/jquery-ui.custom.min.js",
            "index.html",
        ]
        cases.append({
            "name": "custom_bundle_manifest_generation",
            "expected": exp4,
            "actual": act4,
            "passed": act4 == exp4,
        })

        browser.close()

    print(json.dumps({"cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
预期结果 · 待实际运行核验
  • 核对 droppable/dialog 传递依赖自动选中、.theme-a/.theme-b 背景隔离、jQuery 1.5.2 vs 1.6.4 兼容判定及自定义 zip 文件清单。
运行 Download Builder 依赖自动勾选、多主题 CSS 作用域隔离与版本兼容校验离线实验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

当前源码 SHA256:1be35b7f6f76eb7d2008f62488f1d64446f9f33391a36a2dd23e05b3f00cfe70

下载本站示例源码

本地运行

解压后按 README 说明在对应本地环境运行脚本。

下载jQuery UI 下载实验

所需环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

ZIP SHA256:c841e2d18d8aad73662e4d49249436a8fef84a6cfbb4160e59e4e5a903230478

常见错误与边界

  • 实际端口、文档资源与应用配置都应和测试条件一致。

练习与解答

在 Download Builder 中什么场景下才需要填写“高级主题设置”中的 CSS Scope?

展开参考解答

只有当同一个 HTML 页面需要同时加载并局部应用多套不同 jQuery UI 主题时才需要配置 CSS 作用域;仅使用单一主题的页面直接跳过该项即可。

规范与官方依据