Listen

可在模組:Listen/doc建立此模組的說明文件

--本模塊嵌入{{listen}}  local mFileLink = require('Module:File link') local mTableTools = require('Module:TableTools') local mSideBox = require('Module:Side box')  local p = {} local hasMissing -- For the tracking category  function p.main(frame) local origArgs = frame:getParent().args local args = {} for k, v in pairs(origArgs) do v = v:match('^%s*(.-)%s*$') if v ~= '' then args[k] = v end end return p._main(args) end  function p._main(args) -- Find whether we are outputting a plain or an embedded box. local isPlain = args.plain == 'yes' local isEmbedded = args.embed and true  -- Organise the arguments by number. local numArgs = {} do local origNumArgs = mTableTools.numData(args) origNumArgs[1] = origNumArgs.other -- Overwrite args.filename1 etc. with args.filename etc. origNumArgs = mTableTools.compressSparseArray(origNumArgs) for i, t in ipairs(origNumArgs) do -- Check if the files exist. local obj = t.filename and mw.title.new('Media:' .. t.filename) if obj and obj.exists then numArgs[#numArgs + 1] = t else hasMissing = true end end -- Exit early if none exist. if #numArgs == 0 then return p.renderTrackingCategories(isPlain, true) end end  -- Build the arguments for {{side box}} local sbargs = {} sbargs.class = 'noprint' sbargs.metadata = 'no' sbargs.position = args.pos  -- Style arguments do local style = {} if isPlain then style[#style + 1] = 'border:none' style[#style + 1] = 'background:transparent' style[#style + 1] = 'float:none' end if isEmbedded then style[#style + 1] = 'border-collapse:collapse' style[#style + 1] = 'border-width:1px 0 0 0' style[#style + 1] = 'background:transparent' style[#style + 1] = 'float:none' style[#style + 1] = 'margin:0 -5px' end if args.pos == 'left' then style[#style + 1] = 'float:left' elseif args.pos == 'center' then style[#style + 1] = 'float:none' style[#style + 1] = 'margin-left:auto' style[#style + 1] = 'margin-right:auto' end  style[#style + 1] = args.style sbargs.style = table.concat(style, '; ') end sbargs.textstyle = 'line-height:1.1em'  -- Image if not isPlain and not isEmbedded then if args.image then sbargs.image = args.image else local images = { speech = 'Audio-input-microphone.svg', music = 'Gnome-mime-audio-openclipart.svg' } local image = args.type and images[args.type] or 'Gnome-mime-sound-openclipart.svg' sbargs.image = mFileLink._main{ file = image, size = '65x50px', location = 'center', link = '', alt = '' } end end  -- Text do local header if args.header then header = mw.html.create('div') header:css{ background = 'transparent', ['text-align'] = 'left', padding = args.embed and '2px 0' or '2px' } :wikitext(args.header) header = tostring(header) header = header .. '\n' else header = '' end local text = {} for i, t in ipairs(numArgs) do text[#text + 1] = p.renderRow( t.filename, t.title, t.play, t.alt, t.description, t.start ) if numArgs[i + 1] then text[#text + 1] = '
'
end end sbargs.text = header .. table.concat(text) end -- Below if not isPlain and not isEmbedded and args.help ~= 'no' then sbargs.below = string.format( '
播放%s檔案有問題?請看[[維基大典:媒體幫助|媒體幫助]]。'
, #numArgs == 1 and '此' or '此等' ) end -- Render the side box. local sideBox = mw.getCurrentFrame():extensionTag{name = 'templatestyles', args = {src = 'Sidebox/styles.css'}} .. mSideBox._main(sbargs) -- Render the tracking categories. local trackingCategories = p.renderTrackingCategories(isPlain) return sideBox .. trackingCategories end function p.renderRow(filename, title, play, alt, description, start) -- Renders the HTML for one file description row. if not filename then return nil end local root = mw.html.create('') root:tag('div') :addClass('haudio') :newline() :tag('div') :css('padding', '4px 0') :wikitext(string.format('[[:File:%s|%s]]', filename, title or '')) :done() :newline() :tag('div') :wikitext( play ~= 'no' and mFileLink._main{ file = filename, size = '300px', alt = alt, start = start } or nil ) :done() :newline() :tag('div') :css('padding', '2px 0 0 0') :addClass('description') :wikitext(description) :done() :done() return tostring(root) end function p.renderTrackingCategories(isPlain, isEmpty, titleObj) -- Renders all tracking categories produced by the template. -- isPlain and isEmpty are passed through from p._main, -- and the titleObj is only used for testing purposes. local cats = {} local currentTitle = titleObj or mw.title.getCurrentTitle() if currentTitle.namespace == 0 then -- We are in mainspace. if not isEmpty then cats[#cats + 1] = '嵌入hAudio微格式的條目' end if hasMissing then cats[#cats + 1] = '嵌入空的聽模板條目' end end if isPlain then cats[#cats + 1] = '使用plain參數的聽模板' end for i, cat in ipairs(cats) do cats[i] = string.format('[[Category:%s]]', cat) end return table.concat(cats) end return p

Tags:

🔥 Trending searches on Wiki 古文 / 文言文:

香港浸會大學近視菲律賓二千年南昌市斯里蘭卡前二〇八年冥王星伊拉克清聖祖格致劉表共產主義孫紹彰化縣明晉恭王唐寅伊莉莎白二世青蒿素蘇聯飛機司馬遷帕斯卡蕭伯納優伶臨高啟明織田信長吉隆坡葡萄牙羅莎盧森堡王昭君長春市漢孝獻皇帝爪哇語四呼仁川國際空港玻利維亞地中海氣候中國朝代三維印製拉丁語賈誼杜甫黃金分割遼義宗網絡逾垣術彭德懷董賢六尺巷說文解字文化大革命語法道德經福克蘭群島首爾特別市大英百科列奧尼達一世網際協定位址百科全書帝摯廩給公曆十一月三日花千骨俄語巴勒斯坦🡆 More