2970
правок
Neotrit (обсуждение | вклад) м (1 версия импортирована) |
Neotrit (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local function | local hlist = 'Template:Flatlist/styles.css' | ||
local | local templatestyles = 'Module:Navbar/styles.css' | ||
local getArgs | |||
function p._ruwikiNavbar( args ) | |||
local titleText = args[ 1 ] or (':' .. mw.getCurrentFrame():getParent():getTitle()) | |||
local title = mw.title.new(mw.text.trim(titleText), 'Template'); | |||
if not title then | |||
error('Invalid title ' .. titleText) | |||
if | |||
end | end | ||
local whiteColorDefs = { | |||
['#fff'] = true, | |||
['#ffffff'] = true, | |||
['white'] = true, | |||
} | |||
local fontColor = args.fontcolor and args.fontcolor:lower() | |||
local isWhite = fontColor and whiteColorDefs[ fontColor ] == true | |||
local fontStyle = args.fontstyle and mw.text.unstripNoWiki( args.fontstyle:lower() ) | |||
if not isWhite and fontStyle then | |||
local styleratio = require( 'Module:Color contrast' )._styleratio | |||
isWhite = styleratio( { | |||
fontStyle .. '; color:#666;', | |||
'', | |||
'#666' | |||
} ) < 3.66 | |||
end | |||
local isTemplate = title.namespace == 10 | |||
local altText = string.format( | |||
'Перейти %s «%s»', | |||
isTemplate and 'к шаблону' or 'на страницу', | |||
mw.text.split( isTemplate and title.text or title.fullText, '#' )[ 1 ] | |||
) | |||
return string.format( | |||
'[[Файл:Wikipedia interwiki section gear icon%s.svg|14px|class=noprint%s|link=%s|%s]]', | |||
isWhite and ' white' or '', | |||
isWhite and '' or ' skin-invert-image', | |||
tostring( title ), | |||
altText | |||
) | |||
end | end | ||
function p.ruwikiNavbar(frame) | |||
if not getArgs then | |||
if | getArgs = require('Module:Arguments').getArgs | ||
end | end | ||
return p._ruwikiNavbar(getArgs(frame)) | |||
end | end | ||
function p._navbar(args) | |||
local titleArg = 1 | |||
if args.collapsible then | |||
titleArg = 2 | |||
if not args.plain then | |||
args.mini = 1 | |||
end | |||
if args.fontcolor then | |||
args.fontstyle = 'color:' .. args.fontcolor .. ';' | |||
end | |||
args.style = 'float:left; text-align:left; white-space:nowrap;' | |||
end | |||
if args[titleArg] == 'off' then | |||
return | |||
end | end | ||
local | local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle()) | ||
local title = mw.title.new(mw.text.trim(titleText), 'Template'); | |||
if not title then | |||
error('Invalid title ' .. titleText) | |||
end | end | ||
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''; | |||
local tag | |||
if args.nodiv then | |||
local | tag = 'span' | ||
else | |||
tag = 'div' | |||
local | |||
end | end | ||
local div = mw.html.create():tag(tag) | |||
local div = mw.html.create():tag( | |||
div | div | ||
:addClass( | :addClass('navbar hlist plainlinks noprint') | ||
:attr('data-navboxnavigation-link', '0') | |||
: | :cssText(args.style) | ||
:cssText( | |||
if | if args.mini then div:addClass('navbar-mini') end | ||
if not (args.mini or args.plain) then | |||
div | div | ||
:tag('span') | :tag('span') | ||
:addClass( | :addClass('navbar-boxtext') | ||
: | :cssText(args.fontstyle) | ||
:wikitext( | :wikitext(args.text or 'Шаблон:') | ||
:wikitext(' ') | |||
end | end | ||
local | local ul = div:tag('ul'); | ||
if args.brackets then | |||
ul:addClass('navbar-brackets') | |||
end | |||
ul | |||
:tag('li') | |||
if | :addClass('nv-view') | ||
:wikitext('[[' .. title.fullText .. '|') | |||
:tag(args.mini and 'abbr' or 'span') | |||
:addClass(args.mini and 'navbar-mini-abbr') | |||
:attr('title', 'Просмотр этого шаблона') | |||
:cssText(args.fontstyle) | |||
:wikitext(args.mini and 'п' or 'просмотр') | |||
:done() | |||
:wikitext(']]') | |||
:done() | |||
:tag('li') | |||
:addClass('nv-talk') | |||
:wikitext('[[' .. talkpage .. '|') | |||
:tag(args.mini and 'abbr' or 'span') | |||
:attr('title', 'Обсуждение этого шаблона') | |||
:cssText(args.fontstyle) | |||
:wikitext(args.mini and 'о' or 'обсуждение') | |||
:done() | |||
:wikitext(']]'); | |||
if not args.noedit then | |||
ul | |||
:tag('li') | |||
:addClass('nv-edit') | |||
:wikitext('[[Special:EditPage/' .. title.fullText .. '|') | |||
:tag(args.mini and 'abbr' or 'span') | |||
:attr('title', 'Править этот шаблон') | |||
:cssText(args.fontstyle) | |||
:wikitext(args.mini and 'р' or 'править') | |||
:done() | |||
:wikitext(']]'); | |||
end | |||
if args.collapsible then | |||
div:done() | div:done() | ||
:tag('span') | |||
:addClass( | :addClass( args.mini and 'navbar-ct-mini' or 'navbar-ct-full' ) | ||
:cssText( | :cssText(args.fontstyle) | ||
:wikitext(args[1]) | :wikitext(args[1]) | ||
end | end | ||
local frame = mw.getCurrentFrame() | local frame = mw.getCurrentFrame() | ||
return frame:extensionTag{ | return frame:extensionTag{ | ||
name = 'templatestyles', args = { src = | name = 'templatestyles', args = { src = hlist } | ||
} .. frame:extensionTag{ | } .. frame:extensionTag{ | ||
name = 'templatestyles', args = { src = | name = 'templatestyles', args = { src = templatestyles } | ||
} .. tostring(div:done()) | } .. tostring(div:done()) | ||
end | end | ||
function p.navbar(frame) | function p.navbar(frame) | ||
if not getArgs then | |||
getArgs = require('Module:Arguments').getArgs | |||
end | |||
return p._navbar(getArgs(frame)) | |||
end | end | ||
return p | return p | ||