Модуль:Navbar: различия между версиями

Материал из ultracity
Перейти к навигации Перейти к поиску
(Новая страница: «local p = {} local hlist = 'Template:Flatlist/styles.css' 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) end local whiteColorDefs = { ['#fff'] = true, ['#ffffff'] = true, ['white'] = true,...»)
Метка: отменено
Нет описания правки
Метка: ручная отмена
 
Строка 1: Строка 1:
local p = {}
local p = {}


local hlist = 'Template:Flatlist/styles.css'
local templatestyles = 'Module:Navbar/styles.css'
local getArgs
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)
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|link=%s|%s]]',
isWhite and ' white' or '',
tostring( title ),
altText
)
end
function p.ruwikiNavbar(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
return p._ruwikiNavbar(getArgs(frame))
end


function p._navbar(args)
function p._navbar(args)
Строка 77: Строка 29:


local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
local tag
if args.nodiv then
if args.nodiv then
tag = 'span'
tag = 'span'
Строка 86: Строка 38:
local div = mw.html.create():tag(tag)
local div = mw.html.create():tag(tag)
div
div
:addClass('navbar hlist plainlinks noprint')
:addClass('plainlinks')
:attr('data-navboxnavigation-link', '0')
:addClass('noprint')
:cssText(args.style)
:addClass('navbar')
:cssText(args.style or 'text-align:left; white-space:nowrap;')


if args.mini then div:addClass('navbar-mini') end
if args.mini then div:addClass('mini') end


if not (args.mini or args.plain) then
if not (args.mini or args.plain) then
div
div
:tag('span')
:tag('span')
:addClass('navbar-boxtext')
:css('word-spacing', 0)
:cssText(args.fontstyle)
:cssText(args.fontstyle)
:wikitext(args.text or 'Шаблон:')
:wikitext(args.text or 'Шаблон:')
:wikitext(' ')
:wikitext(' ')
end
end
 
local ul = div:tag('ul');
if args.brackets then
if args.brackets then
ul:addClass('navbar-brackets')
div
:tag('span')
:css('margin-right', '-0.125em')
:cssText(args.fontstyle)
:wikitext('&#91;')
--:newline();
end
end
local ul = div:tag('span');


ul
ul
:tag('li')
:tag('span')
:addClass('nv-view')
:addClass('nv-view')
:wikitext('[[' .. title.fullText .. '|')
:wikitext('[[' .. title.fullText .. '|')
Строка 119: Строка 78:
:done()
:done()
:tag('li')
:tag('span')
:addClass('nv-talk')
:addClass('nv-talk')
:wikitext(' &#8226; ')
:wikitext('[[' .. talkpage .. '|')
:wikitext('[[' .. talkpage .. '|')
:tag(args.mini and 'abbr' or 'span')
:tag(args.mini and 'abbr' or 'span')
Строка 131: Строка 91:
if not args.noedit then
if not args.noedit then
ul
ul
:tag('li')
:tag('span')
:addClass('nv-edit')
:addClass('nv-edit')
:wikitext('[[Special:EditPage/' .. title.fullText .. '|')
:wikitext(' &#8226; ')
:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
:tag(args.mini and 'abbr' or 'span')
:tag(args.mini and 'abbr' or 'span')
:attr('title', 'Править этот шаблон')
:attr('title', 'Править этот шаблон')
Строка 139: Строка 101:
:wikitext(args.mini and 'р' or 'править')
:wikitext(args.mini and 'р' or 'править')
:done()
:done()
:wikitext(']]');
:wikitext(']');
end
 
if args.brackets then
div
:tag('span')
:css('margin-left', '-0.125em')
:cssText(args.fontstyle)
:wikitext('&#93;')
--:newline();
end
end


if args.collapsible then
if args.collapsible then
div:done()
div
:done()
:tag('span')
:tag('span')
:addClass( args.mini and 'navbar-ct-mini' or 'navbar-ct-full' )
:css('font-size', '110%')
:cssText(args.fontstyle)
:cssText(args.fontstyle)
:wikitext(args[1])
:wikitext(args[1])
end
end


local frame = mw.getCurrentFrame()
return tostring(div:done())
return frame:extensionTag{
name = 'templatestyles', args = { src = hlist }
} .. frame:extensionTag{
name = 'templatestyles', args = { src = templatestyles }
} .. tostring(div:done())
end
end



Текущая версия от 21:40, 14 июня 2024

Для документации этого модуля может быть создана страница Модуль:Navbar/doc

local p = {}

local getArgs

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

	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

	local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or '';
	
	if args.nodiv then
		tag = 'span'
	else
		tag = 'div'
	end
	
	local div = mw.html.create():tag(tag)
	div
		:addClass('plainlinks')
		:addClass('noprint')
		:addClass('navbar')
		:cssText(args.style or 'text-align:left; white-space:nowrap;')

	if args.mini then div:addClass('mini') end

	if not (args.mini or args.plain) then
		div
			:tag('span')
				:css('word-spacing', 0)
				:cssText(args.fontstyle)
				:wikitext(args.text or 'Шаблон:')
				:wikitext(' ')
	end

	if args.brackets then
		div
			:tag('span')
				:css('margin-right', '-0.125em')
				:cssText(args.fontstyle)
				:wikitext('&#91;')
				--:newline();
	end

	local ul = div:tag('span');

	ul
		:tag('span')
			: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('span')
			:addClass('nv-talk')
			:wikitext(' &#8226; ')
			: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('span')
				:addClass('nv-edit')
				:wikitext(' &#8226; ')
				:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
				:tag(args.mini and 'abbr' or 'span')
					:attr('title', 'Править этот шаблон')
					:cssText(args.fontstyle)
					:wikitext(args.mini and 'р' or 'править')
					:done()
				:wikitext(']');
	end

	if args.brackets then
		div
			:tag('span')
				:css('margin-left', '-0.125em')
				:cssText(args.fontstyle)
				:wikitext('&#93;')
				--:newline();
	end

	if args.collapsible then
		div
			:done()
		:tag('span')
			:css('font-size', '110%')
			:cssText(args.fontstyle)
			:wikitext(args[1])
	end

	return tostring(div:done())
end

function p.navbar(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	return p._navbar(getArgs(frame))
end

return p