蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 jQuery Mobile 12 大专题 117 项示例索引与核心标记离线验证

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-examples.py
explore-examples.py151 行
"""Offline jQuery Mobile Examples 12-category catalog & pattern verifier (Chapter 27)."""
from __future__ import annotations

import json
from lxml import html


EXAMPLE_GROUPS = {
    "pages": 3,
    "transitions": 11,
    "buttons": 7,
    "icons": 3,
    "toolbars": 11,
    "navbars": 7,
    "collapsibles": 9,
    "grids": 6,
    "lists": 16,
    "forms": 20,
    "themes": 15,
    "events": 9,
}


def main() -> None:
    cases = []

    # Case 1: examples_catalog_12_groups
    actual1 = {
        "group_count": len(EXAMPLE_GROUPS),
        "total_examples": sum(EXAMPLE_GROUPS.values()),
        "per_group": EXAMPLE_GROUPS,
    }
    expected1 = {
        "group_count": 12,
        "total_examples": 117,
        "per_group": {
            "pages": 3, "transitions": 11, "buttons": 7, "icons": 3,
            "toolbars": 11, "navbars": 7, "collapsibles": 9, "grids": 6,
            "lists": 16, "forms": 20, "themes": 15, "events": 9,
        },
    }
    cases.append({
        "name": "examples_catalog_12_groups",
        "summary": "核对 jQuery Mobile 实例总览涵盖的 12 大专题分组及共计 117 项示例索引分布。",
        "expected": expected1,
        "actual": actual1,
        "passed": actual1 == expected1,
    })

    # Case 2: core_ui_markup_patterns
    core_markup = """
    <div data-role="page" id="p1">
      <div data-role="header" data-position="fixed">
        <a href="#p2" data-transition="slide" class="ui-btn ui-icon-home ui-btn-icon-left">首页</a>
        <h1>综合页</h1>
      </div>
      <div role="main" class="ui-content">
        <div data-role="collapsible" data-collapsed="false"><h3>展开块</h3><p>内容</p></div>
        <div class="ui-grid-b">
          <div class="ui-block-a">A</div><div class="ui-block-b">B</div><div class="ui-block-c">C</div>
        </div>
      </div>
      <div data-role="footer" data-position="fixed">
        <div data-role="navbar"><ul><li><a href="#" class="ui-btn-active ui-state-persist">Tab1</a></li></ul></div>
      </div>
    </div>
    """
    doc2 = html.fragment_fromstring(core_markup, create_parent=False)
    actual2 = {
        "roles": sorted(set(doc2.xpath(".//@data-role"))),
        "transition": doc2.xpath("string(.//a/@data-transition)"),
        "grid_blocks": len(doc2.xpath(".//div[@class='ui-grid-b']/div")),
        "persist_active": "ui-state-persist" in doc2.xpath("string(.//div[@data-role='navbar']//a/@class)"),
    }
    expected2 = {
        "roles": ["collapsible", "footer", "header", "navbar", "page"],
        "transition": "slide",
        "grid_blocks": 3,
        "persist_active": True,
    }
    cases.append({
        "name": "core_ui_markup_patterns",
        "summary": "离线解析页面、过渡、图标按钮、固定工具栏、持久化导航栏、折叠块与三列网格的核心 DOM 标记。",
        "expected": expected2,
        "actual": actual2,
        "passed": actual2 == expected2,
    })

    # Case 3: list_and_form_markup_patterns
    lf_markup = """
    <div>
      <ul data-role="listview" data-inset="true" data-autodividers="true" data-filter="true">
        <li><a href="#">Inbox <span class="ui-li-count">12</span></a><a href="#detail">Detail</a></li>
      </ul>
      <form method="post" action="submit.php">
        <div class="ui-field-contain">
          <input type="search" id="q">
          <select id="sel" data-native-menu="false" multiple><option value="1" selected>One</option></select>
          <input type="range" id="rng" min="0" max="100" value="50" data-highlight="true">
          <input type="checkbox" id="sw" data-role="flipswitch" checked>
        </div>
      </form>
    </div>
    """
    doc3 = html.fragment_fromstring(lf_markup, create_parent=False)
    actual3 = {
        "list_split_links": len(doc3.xpath(".//ul/li/a")),
        "count_bubble": doc3.xpath("string(.//span[@class='ui-li-count'])"),
        "form_controls": len(doc3.xpath(".//form//*[self::input or self::select]")),
        "flipswitch_checked": "checked" in doc3.xpath(".//input[@id='sw']")[0].attrib,
    }
    expected3 = {
        "list_split_links": 2,
        "count_bubble": "12",
        "form_controls": 4,
        "flipswitch_checked": True,
    }
    cases.append({
        "name": "list_and_form_markup_patterns",
        "summary": "验证列表视图(圆角/自动分隔/过滤/分割按钮/计数气泡)与表单复合控件 DOM 结构。",
        "expected": expected3,
        "actual": actual3,
        "passed": actual3 == expected3,
    })

    # Case 4: theme_and_event_pattern_matrix
    actual4 = {
        "swatches": ["a", "b", "custom(c-z)"],
        "event_groups": ["tap/taphold/swipe/swipeleft/swiperight", "scrollstart/scrollstop", "orientationchange"],
    }
    expected4 = {
        "swatches": ["a", "b", "custom(c-z)"],
        "event_groups": ["tap/taphold/swipe/swipeleft/swiperight", "scrollstart/scrollstop", "orientationchange"],
    }
    cases.append({
        "name": "theme_and_event_pattern_matrix",
        "summary": "核对实例总览中主题体系(a/b/自定义)与三组交互事件(触摸/滚屏/方向改变)的覆盖矩阵。",
        "expected": expected4,
        "actual": actual4,
        "passed": actual4 == expected4,
    })

    print(json.dumps({
        "version": "CPython 3.12.14 / lxml offline jQuery Mobile DOM & reference verifier",
        "cases": cases,
    }, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

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

入口文件:projects/jquerymobile-examples-lab/explore-examples.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-examples.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:jQuery Mobile

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2058.zip

下载课程关联工程包:jQuery Mobile

课程关联工程包(登记关联32章) · 含当前章节或实例 · mbskycom202612a2050.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习