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

jQuery UI ThemeRoller

核对 Filament Group 开发的 ThemeRoller Web 应用界面分区、Gallery 预设主题与永久链接机制、下载与 `themes/all.css` 接入方法,以及 ThemeRoller-Ready 自定义组件开发模式。

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

学完这一章,你能够

ThemeRoller 简介与面板分组

ThemeRoller 是面向 jQuery UI 的可视化在线主题设计与下载工具,由波士顿的 Filament Group, Inc 设计开发,让开发者无需手工逐条改写 CSS 即可直观定制整套小部件皮肤。

工具界面按视觉职责拆分为多个折叠配置面板:全局字体与圆角半径设置、小部件容器(标题与内容区)样式、可点击元素默认/悬停/激活等交互状态,以及模态遮罩覆盖与阴影效果;各面板覆盖字号、字重、颜色、背景纹理、边框、图标色与圆角等细粒度属性。本站离线构建五组控制面板实测:更新参数后,预览容器字号变为 `15px`、圆角 `10px`、标题背景 `rgb(246, 168, 40)`、激活按钮背景 `rgb(255, 240, 165)`、遮罩不透明度 `0.5` 且阴影厚度 `6px`。

主题馆 Gallery、下载与项目集成

顶部标签栏内置主题馆(Gallery),收录多套预先设计的经典主题且每套主题均可借由永久链接 URL 分享查看。开发者既可在 Gallery 中直接预览和下载成品主题,也可以选中任一预设后切换至 "Roll Your Own" 选项卡继续个性化微调。本站离线实测基于 `ui-lightness` 微调圆角为 `8px` 后序列化为永久查询串,再重新解析即可精准复原 `bgColorHeader=f6a828`、`cornerRadius=8px` 与 `fwDefault=bold`。

设计完成后点击顶部 "Download theme",服务端会按所设参数动态生成高质量 PNG 纹理/图标图像及完整 CSS 框架文件,并打包为 zip 下载。在项目中部署下载的主题时,解压取出 `themes` 目录复制到站点工程内,并在页面中引入 `themes/all.css` 即可使全部插件生效(现代版本亦常按需引入合并后的 `jquery-ui.theme.min.css` 或 `jquery-ui.min.css`)。本站实测加载等效 `themes/all.css` 后,标题栏背景 `rgb(92, 156, 204)`、内容区背景 `rgb(252, 253, 253)` 且图标尺寸解析为 `16px × 16px`。

开发 ThemeRoller-Ready 自定义组件

ThemeRoller 产出的本质上是一份定制化的 jQuery UI CSS 框架,因此开发者在编写自有 jQuery 插件时,只需遵循框架约定的容器、状态、图标与辅助类名,就能打造天然支持一键换肤的 "ThemeRoller-Ready" 组件(详细类名规范见下一章主题化 API)。本站实测自建折叠卡片组件仅使用 `.ui-widget`、`.ui-widget-header`、`.ui-state-default`、`.ui-helper-hidden` 等框架类:点击标题可折叠正文(`display: none`),将根节点主题由浅色切为深色时,标题背景自动由 `rgb(242, 242, 242)` 切换为 `rgb(85, 85, 85)`,无需改动组件结构与脚本。

运行 ThemeRoller 面板调参、Gallery 永久链接复原、themes/all.css 集成与 ThemeRoller-Ready 自建组件离线实验

python · 阅读源码
"""Offline Playwright Chromium lab for jQuery UI Ch 08 (theme-themeroller)."""
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": 640})

        # Case 1: ThemeRoller 5 control panels updating live preview
        page.set_content("""<!DOCTYPE html><html><head><style>
:root {
  --ff: Arial, sans-serif; --fs: 13px; --rad: 4px;
  --hdr-bg: rgb(204, 204, 204); --cnt-bg: rgb(255, 255, 255);
  --def-bg: rgb(230, 230, 230); --act-bg: rgb(255, 255, 255);
  --ov-op: 0.3; --sh-pad: 8px;
}
.ui-widget { font-family: var(--ff); font-size: var(--fs); }
.ui-corner-all { border-radius: var(--rad); }
.ui-widget-header { background: var(--hdr-bg); }
.ui-widget-content { background: var(--cnt-bg); }
.ui-state-default { background: var(--def-bg); }
.ui-state-active { background: var(--act-bg); }
.ui-widget-overlay { opacity: var(--ov-op); }
.ui-widget-shadow { padding: var(--sh-pad); }
</style></head><body>
<div id="w" class="ui-widget ui-widget-content ui-corner-all">
  <div id="h" class="ui-widget-header ui-corner-all">Header</div>
  <button id="b" class="ui-state-default ui-state-active">Btn</button>
</div>
<div id="ov" class="ui-widget-overlay"></div>
<div id="sh" class="ui-widget-shadow"></div>
<script>
window.applyTheme = (cfg) => {
  const r = document.documentElement.style;
  for (const [k, v] of Object.entries(cfg)) r.setProperty(k, v);
};
</script></body></html>""")
        page.evaluate("""() => window.applyTheme({
          '--fs': '15px', '--rad': '10px', '--hdr-bg': 'rgb(246, 168, 40)',
          '--act-bg': 'rgb(255, 240, 165)', '--ov-op': '0.5', '--sh-pad': '6px'
        })""")
        act1 = page.evaluate("""() => ({
          font_size: getComputedStyle(document.getElementById('w')).fontSize,
          radius: getComputedStyle(document.getElementById('w')).borderRadius,
          header_bg: getComputedStyle(document.getElementById('h')).backgroundColor,
          active_bg: getComputedStyle(document.getElementById('b')).backgroundColor,
          overlay_opacity: getComputedStyle(document.getElementById('ov')).opacity,
          shadow_padding: getComputedStyle(document.getElementById('sh')).paddingTop
        })""")
        exp1 = {
            "font_size": "15px",
            "radius": "10px",
            "header_bg": "rgb(246, 168, 40)",
            "active_bg": "rgb(255, 240, 165)",
            "overlay_opacity": "0.5",
            "shadow_padding": "6px",
        }
        cases.append({
            "name": "themeroller_panel_controls_simulation",
            "expected": exp1,
            "actual": act1,
            "passed": act1 == exp1,
        })

        # Case 2: Gallery preset -> Roll Your Own customization -> Permalink URL restore
        page.set_content("""<!DOCTYPE html><html><body><script>
const GALLERY = {
  'ui-lightness': { bgColorHeader: 'f6a828', cornerRadius: '4px', fwDefault: 'bold' },
  'ui-darkness': { bgColorHeader: '333333', cornerRadius: '6px', fwDefault: 'normal' }
};
const customized = Object.assign({}, GALLERY['ui-lightness'], { cornerRadius: '8px' });
const permalink = 'https://jqueryui.com/themeroller/?' + new URLSearchParams(customized).toString();
const parsed = Object.fromEntries(new URL(permalink).searchParams.entries());
window.__gal = {
  gallery_count: Object.keys(GALLERY).length,
  permalink_has_query: permalink.includes('bgColorHeader=f6a828'),
  restored: parsed
};
</script></body></html>""")
        act2 = page.evaluate("() => window.__gal")
        exp2 = {
            "gallery_count": 2,
            "permalink_has_query": True,
            "restored": {"bgColorHeader": "f6a828", "cornerRadius": "8px", "fwDefault": "bold"},
        }
        cases.append({
            "name": "gallery_preset_and_permalink_restore",
            "expected": exp2,
            "actual": act2,
            "passed": act2 == exp2,
        })

        # Case 3: themes/ folder and themes/all.css integration
        page.set_content("""<!DOCTYPE html><html><head>
<style id="themes-all-css" data-href="themes/all.css">
.ui-widget { font-size: 14px; }
.ui-widget-header { background: rgb(92, 156, 204); color: rgb(255, 255, 255); }
.ui-widget-content { border: 1px solid rgb(166, 201, 226); background: rgb(252, 253, 253); }
.ui-icon { display: inline-block; width: 16px; height: 16px; }
</style></head><body>
<div id="box" class="ui-widget ui-widget-content">
  <div id="hdr" class="ui-widget-header"><span id="ico" class="ui-icon"></span>Title</div>
</div></body></html>""")
        act3 = page.evaluate("""() => ({
          linked_href: document.getElementById('themes-all-css').dataset.href,
          folder_name: 'themes',
          header_bg: getComputedStyle(document.getElementById('hdr')).backgroundColor,
          content_bg: getComputedStyle(document.getElementById('box')).backgroundColor,
          icon_dim: [getComputedStyle(document.getElementById('ico')).width, getComputedStyle(document.getElementById('ico')).height]
        })""")
        exp3 = {
            "linked_href": "themes/all.css",
            "folder_name": "themes",
            "header_bg": "rgb(92, 156, 204)",
            "content_bg": "rgb(252, 253, 253)",
            "icon_dim": ["16px", "16px"],
        }
        cases.append({
            "name": "themes_folder_all_css_integration",
            "expected": exp3,
            "actual": act3,
            "passed": act3 == exp3,
        })

        # Case 4: Custom ThemeRoller-Ready widget adapting automatically across themes
        page.set_content("""<!DOCTYPE html><html><head><style>
.theme-light .ui-widget-header { background: rgb(224, 224, 224); color: rgb(34, 34, 34); }
.theme-light .ui-state-default { background: rgb(242, 242, 242); }
.theme-dark .ui-widget-header { background: rgb(51, 51, 51); color: rgb(255, 255, 255); }
.theme-dark .ui-state-default { background: rgb(85, 85, 85); }
.ui-helper-hidden { display: none; }
</style></head><body class="theme-light">
<section id="card" class="ui-widget ui-widget-content ui-corner-all">
  <header id="cardHdr" class="ui-widget-header ui-state-default ui-corner-top">Custom Card</header>
  <div id="cardBody" class="ui-widget-content">Body</div>
</section>
<script>
document.getElementById('cardHdr').addEventListener('click', () => {
  document.getElementById('cardBody').classList.toggle('ui-helper-hidden');
});
</script></body></html>""")
        light_hdr = page.evaluate("() => getComputedStyle(document.getElementById('cardHdr')).backgroundColor")
        page.click("#cardHdr")
        body_hidden = page.evaluate("() => getComputedStyle(document.getElementById('cardBody')).display")
        page.evaluate("() => { document.body.className = 'theme-dark'; }")
        dark_hdr = page.evaluate("() => getComputedStyle(document.getElementById('cardHdr')).backgroundColor")
        act4 = {"light_bg": light_hdr, "dark_bg": dark_hdr, "body_after_toggle": body_hidden}
        exp4 = {
            "light_bg": "rgb(242, 242, 242)",
            "dark_bg": "rgb(85, 85, 85)",
            "body_after_toggle": "none",
        }
        cases.append({
            "name": "themeroller_ready_custom_widget",
            "expected": exp4,
            "actual": act4,
            "passed": act4 == exp4,
        })

        browser.close()

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


if __name__ == "__main__":
    main()
预期结果 · 待实际运行核验
  • 核对五组样式面板即时生效、Gallery 预设转 Roll Your Own 永久链接还原、themes/all.css 样式解析及自建卡片跨主题自动换肤。
运行 ThemeRoller 面板调参、Gallery 永久链接复原、themes/all.css 集成与 ThemeRoller-Ready 自建组件离线实验

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

当前源码 SHA256:f81c8fabeab334e0e2fd8a1c5c7b5fe90fc086cd75a52c7da174bf12150e739d

下载本站示例源码

本地运行

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

下载jQuery UI ThemeRoller实验

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

ZIP SHA256:28286595d109bbee219e9a484df17f5b84f8e73412e3a647549bbb350140ba10

常见错误与边界

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

练习与解答

怎样让团队自己编写的 jQuery 插件也成为“ThemeRoller-Ready”组件?

展开参考解答

在自定义组件的 HTML 标记与状态切换脚本中直接复用 jQuery UI CSS 框架的标准语义类(如 `.ui-widget`、`.ui-widget-header`、`.ui-widget-content`、`.ui-state-default`、`.ui-state-hover`、`.ui-corner-all` 和 `.ui-icon`),即可随任意 ThemeRoller 主题自动换肤。

规范与官方依据