跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
学习园地
新人须知
教程整合
NEW!!!
主题编号使用指导
论坛百科
SS分区介绍
论坛设定
论坛文化
传奇殿堂
SS大事年表
SS大学图书馆
维基事务
基本规则
新手指南——技术
新手指南——内容
wiki语法手册
规范全集
搜索
搜索
外观
登录
个人工具
登录
查看“︁模块:切换显示”︁的源代码
模块
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
特殊页面
页面信息
外观
移至侧栏
隐藏
←
模块:切换显示
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
local module = {} local getArgs = require('Module:Arguments').getArgs local initSpan = function(className, templateName, frame) mw.log.warn("Module:切换显示 called") mw.log.warn(className) local args = getArgs(frame, { wrappers = 'Template:' .. templateName }) local parent_args = frame:getParent().args; local span = mw.html.create('span') span:attr('class', className) if className == 'textToggleDisplayButtons' then -- 自Template:切换显示调用。 local operators = {} -- 操作参数。 local contentlist = {} --[[内容表列。结构为: { strcode = 字符串代号, on = @on后缀的内容, off = @off后缀的内容, default = 没有@on或@off后缀的内容, } ]] for k, v in pairs(args) do mw.log(k, v) if mw.ustring.sub(k, 1, 1) == '@' then operators[k] = v else local strcode local onoff = nil -- 获取字符串代号和开关类型。 if mw.ustring.sub(k, -3) == '@on' then strcode = mw.ustring.sub(k, 1, mw.ustring.len(k) - 3) onoff = 'on' elseif mw.ustring.sub(k, -4) == '@off' then strcode = mw.ustring.sub(k, 1, mw.ustring.len(k) - 4) onoff = 'off' else strcode = k end onoff = onoff or 'default' -- 没有开关类型就是默认值。 if not contentlist[strcode] then table.insert(contentlist, {strcode = strcode}) -- 增加空的内容表。 contentlist[strcode] = #contentlist -- 定位新增加的索引,绑定到参数k。 end contentlist[contentlist[strcode]][onoff] = v -- 替换内容。 end end local counter = 0 -- 计数器。 for k_operators, v_operators in pairs(operators) do span:attr('data-key-' .. counter, k_operators):attr('data-value-' .. counter, v_operators) counter = counter + 1 end for index, content in ipairs(contentlist) do span:tag('span'):attr('data-order', index - 1):attr('data-key', content.strcode):tag('span'):addClass( 'textToggleDisplayButtonLabelText on' ):wikitext(frame:preprocess(content.on or content.default)):done():tag('span'):addClass( 'textToggleDisplayButtonLabelText off' ):wikitext(frame:preprocess(content.off or content.default)) end else local counter = 0 -- 计数器 for k, v in pairs(args) do if v ~= nil then span:attr('data-key-' .. counter, k):attr('data-value-' .. counter, v) counter = counter + 1 end end end return tostring(span) end function module.template(frame) local args = getArgs(frame, { wrappers = 'Template:切换显示/模板' }) local tTitle = args['@'] or '' if tTitle == '' then return nil end local tag = args['@tag'] local branches = {} local params = {} for k, v in args do if not mw.ustring.match(k, '^@[^@]') then local i = 1 while true do local _, j, flag = mw.ustring.find(k, '@(.)', i) if j == nil then i = mw.ustring.len(k) break elseif flag == '@' then i = j + 1 else i = j - 2 break end end local param = mw.text.trim(mw.ustring.gsub(mw.ustring.sub(k, 1, i), '@@', '@')) local branch = mw.ustring.sub(k, i + 2) if mw.text.trim(param) ~= '' then if params[param] == nil then params[param] = {} end if branch ~= '' and branches[branch] == nil then branches[branch] = #branches + 1 table.insert(branches, branch) end if branch == '' then params[param][0] = v else params[param][branch] = v end end end end local result = {} for _, branch in ipairs(branches) do if type(branch) == 'string' then local tArgs = {} for param, bValue in pairs(params) do tArgs[param] = bValue[branch] or bValue[0] end table.insert( result, frame:expandTemplate { title = '切换显示', args = { [1] = branch, [2] = frame:expandTemplate {title = tTitle, args = tArgs}, [3] = tag } } ) end end return table.concat(result) end function module.button(frame) return initSpan('textToggleDisplayButtons', '切换显示按钮', frame) end function module.style(frame) return initSpan('textToggleDisplayStyle', '切换显示样式', frame) end function module.buttonStyle(frame) return initSpan('textToggleDisplayButtonsStyle', '切换显示按钮样式', frame) end return module
该页面使用的模板:
模块:切换显示/doc
(
查看源代码
)
返回
模块:切换显示
。