Module:Sandbox/Bility/Shortcut

local p = {}

-- shortcut box code generator
function shortcut(sCuts, sType)
    local wikicode = '<div style="position: relative; top: -3em;">'
    local wikilist = '<ul>'
    local shortName = '[[Wikipedia:Shortcut|Shortcut'
    if sType == 3 then shortName = '[[Wikipedia:Policies and guidelines|Policy]] [[Wikipedia:Shortcut|shortcut' end
    local alignStyle = 'float: right; '
    local alignClass = ''
    if sType == 4 then
        alignStyle = 'float: left; '
        alignClass = 'shortcutbox-left '
    end
    local linkcount = 0
    for i in ipairs(sCuts) do
        if sCuts[i] ~= '' and mw.title.new(sCuts[i]).id ~= 0 then
            wikicode = wikicode .. '<span id="{{anchorencode:' .. sCuts[i] .. '}}"></span>'
            wikilist = wikilist .. '<li>[[' .. sCuts[i] .. ']]</li>'
            linkcount = linkcount + 1
        end
    end
    wikilist = wikilist .. '</ul>'
    if linkcount == 0 then
        return nil
    end
    if sType == 2 then wikilist = '<div class="hlist">' .. wikilist .. '</div>' end
    wikicode = wikicode .. '</div>\n'
    wikicode = wikicode .. '<table class="shortcutbox ' .. alignClass .. 'noprint" style="' .. alignStyle .. 'border: 1px solid #aaa; background: #fff; margin: .3em .3em .3em 1em; padding: 3px; text-align: center;"><tr><th style="border: none; background: transparent;" class="plainlist">'
    wikicode = wikicode .. '<small>' .. shortName
    if linkcount > 1 then
        wikicode = wikicode .. 's'
    end
    wikicode = wikicode .. ']]' .. wikilist .. '</small></th></tr></table>'
    
    return wikicode
end

-- normal vertical list of shortcuts
function p.vertical(frame)
    return shortcut(frame.args, 1)-- or '[[Category:Wikipedia shortcut box first parameter needs fixing|{{PAGENAME}}]]'
end

-- horizontal list of shortcuts
function p.horizontal(frame)
    return shortcut(frame.args, 2)-- or '[[Category:Wikipedia shortcut box first parameter needs fixing|{{PAGENAME}}]]'
end

-- list of policy shortcuts
function p.policy(frame)
    return shortcut(frame.args, 3)-- or '[[Category:Wikipedia shortcut box first parameter needs fixing|{{PAGENAME}}]]'
end

-- left-aligned list of shortcuts
function p.left(frame)
    return shortcut(frame.args, 4)-- or '[[Category:Wikipedia shortcut box first parameter needs fixing|{{PAGENAME}}]]'
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.