메뉴 여닫기
개인 메뉴 토글
로그인하지 않음
만약 지금 편집한다면 당신의 IP 주소가 공개될 수 있습니다.

모듈:FloatingUI

이터널리턴 이스포츠 위키
Mongsil (토론 | 기여)님의 2024년 12월 2일 (월) 22:16 판 (새 문서: --- Lua functions for Extension:FloatingUI --- --- WARNING --- ------- --- THIS IS AN EXPERIMENTAL MODULE MADE FOR AN EXPERIMENTAL EXTENSION --- THIS IS NOT READY FOR PRODUCTION AND SUBJECT TO CHANGE --- ------- local FloatingUI = {} --- Return the HTML of the FloatingUI section component as string --- --- @param data table {label, data, desc, col, inline) --- @return string html function FloatingUI.renderSection( data ) if data == nil or type( data ) ~= 'table' or next( d...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
Message_documentation_title[view][edit][history][purge]
message_transclude_desc
de:모듈:FloatingUIen:모듈:FloatingUI
Function list
L 15 — FloatingUI.renderSection
L 42 — FloatingUI.load
L 57 — FloatingUI.render

--- Lua functions for Extension:FloatingUI
---
--- WARNING
--- -------
--- THIS IS AN EXPERIMENTAL MODULE MADE FOR AN EXPERIMENTAL EXTENSION
--- THIS IS NOT READY FOR PRODUCTION AND SUBJECT TO CHANGE
--- -------
local FloatingUI = {}


--- Return the HTML of the FloatingUI section component as string
---
--- @param data table {label, data, desc, col, inline)
--- @return string html
function FloatingUI.renderSection( data )
    if data == nil or type( data ) ~= 'table' or next( data ) == nil then return '' end

    local htmlTag = 'div'
    if data[ 'inline' ] == true then
        htmlTag = 'span'
    end

    local html = mw.html.create( htmlTag )
        :addClass( 't-floatingui-section' )

    if data[ 'col' ] then html:addClass( 't-floatingui-section--cols-' .. data[ 'col' ] ) end

    local dataOrder = { 'label', 'data', 'desc' }
    for _, key in ipairs( dataOrder ) do
        if data[ key ] then
            html:tag( htmlTag )
                :addClass( 't-floatingui-' .. key )
                :wikitext( data[ key ] )
        end
    end
    return tostring( html )
end

--- Load FloatingUI library only
---
--- @return string wikitext Wikitext to load the FloatingUI library only
function FloatingUI.load()
    local frame = mw.getCurrentFrame()
    return frame:extensionTag {
        name = 'templatestyles', args = { src = 'Module:FloatingUI/styles.css' }
    } .. frame:callParserFunction {
        name = '#floatingui', args = { '' }
    }
end

--- Render the HTML for FloatingUI
---
--- @param reference string Reference wikitext to trigger the floating element
--- @param content string Content wikitext in the floating element
--- @param inline boolean Whether to render inline
--- @return string wikitext Wikitext for the HTML required to use FloatingUI
function FloatingUI.render( reference, content, inline )
    if not reference or not content then
        return ''
    end

    local htmlTag = 'div'
    if inline == true then
        htmlTag = 'span'
    end

    local html = mw.html.create()
        :tag( htmlTag )
        :addClass( 'ext-floatingui-reference' )
        :wikitext( reference )
        :done()
        :tag( htmlTag )
        :addClass( 'ext-floatingui-content' )
        :tag( htmlTag )
        :addClass( 'mw-parser-output' )
        :tag( htmlTag )
        :addClass( 't-floatingui' )
        :wikitext( content )
        :allDone()

    return tostring( html )
end

return FloatingUI