۷٬۳۴۸
ویرایش
| بدون خلاصۀ ویرایش | جز (۱ نسخه واردشده) | ||
| (۷ نسخهٔ میانی ویرایش شده توسط ۳ کاربر نشان داده نشد) | |||
| خط ۵: | خط ۵: | ||
| local p = {} | local p = {} | ||
| local navbar = require(' | local navbar = require('پودمان:Navbar')._navbar | ||
| local getArgs -- lazily initialized | local getArgs -- lazily initialized | ||
| local args | local args | ||
| local border | local border | ||
| local listnums  | local listnums | ||
| local ODD_EVEN_MARKER = '\127_ODDEVEN_\127' | local ODD_EVEN_MARKER = '\127_ODDEVEN_\127' | ||
| local RESTART_MARKER = '\127_ODDEVEN0_\127' | local RESTART_MARKER = '\127_ODDEVEN0_\127' | ||
| خط ۲۰: | خط ۲۰: | ||
| 	-- by parent navboxes. The result is that the category shows all pages | 	-- by parent navboxes. The result is that the category shows all pages | ||
| 	-- where a child navbox is not contained in a parent navbox. | 	-- where a child navbox is not contained in a parent navbox. | ||
| 	local orphanCat = '[[رده:ناوبری یتیم]]' | 	local orphanCat = '[[رده:جعبههای ناوبری یتیم]]' | ||
| 	if border == 'subgroup' and args.orphan ~= 'yes' then | 	if border == 'subgroup' and args.orphan ~= 'yes' then | ||
| 		-- No change; striping occurs in outermost navbox. | 		-- No change; striping occurs in outermost navbox. | ||
| خط ۸۱: | خط ۸۱: | ||
| local function renderNavBar(titleCell) | local function renderNavBar(titleCell) | ||
| 	if args.navbar ~= 'off' and args.navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/ | 	if args.navbar ~= 'off' and args.navbar ~= 'plain' and not (not args.name and mw.getCurrentFrame():getParent():getTitle():gsub('/تمرین$', '') == 'الگو:Navbox') then | ||
| 		titleCell:wikitext(navbar{ | 		titleCell:wikitext(navbar{ | ||
| 			args.name, | 			args.name, | ||
| 			mini = 1, | 			mini = 1, | ||
| 			fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none;' | 			fontstyle = (args.basestyle or '') .. ';' .. (args.titlestyle or '') .. ';background:none transparent;border:none;-moz-box-shadow:none;-webkit-box-shadow:none;box-shadow:none; padding:0;' | ||
| 		}) | 		}) | ||
| 	end | 	end | ||
| خط ۱۱۵: | خط ۱۱۵: | ||
| 	if args.titlegroup then | 	if args.titlegroup then | ||
| 		titleCell | 		titleCell | ||
| 			:css('border- | 			:css('border-left', '2px solid #fdfdfd') | ||
| 			:css('width', '100%') | 			:css('width', '100%') | ||
| 	end | 	end | ||
| 	local titleColspan = 2 | 	local titleColspan = 2 | ||
| 	if args.imageleft then titleColspan = titleColspan + 1 end | |||
| 	if args.imageright then titleColspan = titleColspan + 1 end | 	if args.imageright then titleColspan = titleColspan + 1 end | ||
| 	if args.image then titleColspan = titleColspan + 1 end | 	if args.image then titleColspan = titleColspan + 1 end | ||
| خط ۱۳۴: | خط ۱۳۵: | ||
| 	titleCell | 	titleCell | ||
| 		:tag('div') | 		:tag('div') | ||
| 			-- id for aria-labelledby attribute | |||
| 			:attr('id', mw.uri.anchorEncode(args.title)) | 			:attr('id', mw.uri.anchorEncode(args.title)) | ||
| 			:addClass(args.titleclass) | 			:addClass(args.titleclass) | ||
| خط ۱۴۷: | خط ۱۴۹: | ||
| local function getAboveBelowColspan() | local function getAboveBelowColspan() | ||
| 	local ret = 2 | 	local ret = 2 | ||
| 	if args.imageleft then ret = ret + 1 end | |||
| 	if args.imageright then ret = ret + 1 end | 	if args.imageright then ret = ret + 1 end | ||
| 	if args.image then ret = ret + 1 end | 	if args.image then ret = ret + 1 end | ||
| خط ۱۶۳: | خط ۱۶۶: | ||
| 			:attr('colspan', getAboveBelowColspan()) | 			:attr('colspan', getAboveBelowColspan()) | ||
| 			:tag('div') | 			:tag('div') | ||
| 				-- id for aria-labelledby attribute, if no title | |||
| 				:attr('id', args.title and nil or mw.uri.anchorEncode(args.above)) | |||
| 				:wikitext(processItem(args.above, args.nowrapitems)) | 				:wikitext(processItem(args.above, args.nowrapitems)) | ||
| end | end | ||
| خط ۱۸۵: | خط ۱۹۰: | ||
| local function renderListRow(tbl, index, listnum) | local function renderListRow(tbl, index, listnum) | ||
| 	local row = tbl:tag('tr') | 	local row = tbl:tag('tr') | ||
| 	if index == 1 and args.imageleft then | |||
| 		row | |||
| 			:tag('td') | |||
| 				:addClass('navbox-image') | |||
| 				:addClass(args.imageclass) | |||
| 				:css('width', '1px')               -- Minimize width | |||
| 				:css('padding', '0px 2px 0px 0px') | |||
| 				:cssText(args.imageleftstyle) | |||
| 				:attr('rowspan', #listnums) | |||
| 				:tag('div') | |||
| 					:wikitext(processItem(args.imageleft)) | |||
| 	end | |||
| 	if index == 1 and args.imageright then | 	if index == 1 and args.imageright then | ||
| خط ۱۹۲: | خط ۲۱۰: | ||
| 				:addClass(args.imageclass) | 				:addClass(args.imageclass) | ||
| 				:css('width', '1px')               -- Minimize width | 				:css('width', '1px')               -- Minimize width | ||
| 				:css('padding', '0px  | 				:css('padding', '0px 0px 0px 2px') | ||
| 				:cssText(args.imagerightstyle) | 				:cssText(args.imagerightstyle) | ||
| 				:attr('rowspan', #listnums) | 				:attr('rowspan', #listnums) | ||
| خط ۲۰۱: | خط ۲۱۹: | ||
| 	if args['group' .. listnum] then | 	if args['group' .. listnum] then | ||
| 		local groupCell = row:tag('th') | 		local groupCell = row:tag('th') | ||
| 		-- id for aria-labelledby attribute, if lone group with no title or above | |||
| 		if listnum == 1 and not (args.title or args.above or args.group2) then | |||
| 			groupCell | |||
| 				:attr('id', mw.uri.anchorEncode(args.group1)) | |||
| 		end | |||
| 		groupCell | 		groupCell | ||
| خط ۲۰۷: | خط ۲۳۱: | ||
| 			:addClass(args.groupclass) | 			:addClass(args.groupclass) | ||
| 			:cssText(args.basestyle) | 			:cssText(args.basestyle) | ||
| 			:css('width', args.groupwidth or '1%') -- If groupwidth not specified, minimize width | |||
| 		groupCell | 		groupCell | ||
| خط ۲۵۱: | خط ۲۷۵: | ||
| 		:addClass('navbox-' .. oddEven) | 		:addClass('navbox-' .. oddEven) | ||
| 		:addClass(args.listclass) | 		:addClass(args.listclass) | ||
| 		:addClass(args['list' .. listnum .. 'class']) | |||
| 		:tag('div') | 		:tag('div') | ||
| 			:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | 			:css('padding', (index == 1 and args.list1padding) or args.listpadding or '0em 0.25em') | ||
| خط ۲۸۷: | خط ۳۱۲: | ||
| local function hasBackgroundColors() | local function hasBackgroundColors() | ||
| 	for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle'}) do | 	for _, key in ipairs({'titlestyle', 'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do | ||
| 		if tostring(args[key]):find('background', 1, true) then | 		if tostring(args[key]):find('background', 1, true) then | ||
| 			return true | |||
| 		end | |||
| 	end | |||
| end | |||
| local function hasBorders() | |||
| 	for _, key in ipairs({'groupstyle', 'basestyle', 'abovestyle', 'belowstyle'}) do | |||
| 		if tostring(args[key]):find('border', 1, true) then | |||
| 			return true | 			return true | ||
| 		end | 		end | ||
| خط ۲۹۵: | خط ۳۲۸: | ||
| local function isIllegible() | local function isIllegible() | ||
| 	local styleratio = require(' | 	local styleratio = require('پودمان:Color contrast')._styleratio | ||
| 	for key, style in pairs(args) do | 	for key, style in pairs(args) do | ||
| خط ۳۱۲: | خط ۳۴۵: | ||
| 	if hasBackgroundColors() then table.insert(cats, 'جعبههای ناوبری با استفاده از رنگهای پسزمینه') end | 	if hasBackgroundColors() then table.insert(cats, 'جعبههای ناوبری با استفاده از رنگهای پسزمینه') end | ||
| 	if isIllegible() then table.insert(cats, 'ناوبری ناخوانا') end | 	if isIllegible() then table.insert(cats, 'ناوبری ناخوانا') end | ||
| 	if hasBorders() then table.insert(cats, 'جعبههای ناوبری با استفاده از حاشیه') end | |||
| 	return cats | 	return cats | ||
| end | end | ||
| خط ۳۳۵: | خط ۳۶۹: | ||
| 	if args.title and (args.state ~= 'plain' and args.state ~= 'off') then | 	if args.title and (args.state ~= 'plain' and args.state ~= 'off') then | ||
| 		if args.state == 'collapsed' then args.state = 'mw-collapsed' end | |||
| 		tbl | 		tbl | ||
| 			:addClass('collapsible') | 			:addClass('mw-collapsible') | ||
| 			:addClass(args.state or 'autocollapse') | 			:addClass(args.state or 'autocollapse') | ||
| 	end | 	end | ||
| خط ۳۶۶: | خط ۴۰۱: | ||
| function p._navbox(navboxArgs) | function p._navbox(navboxArgs) | ||
| 	args = navboxArgs | 	args = navboxArgs | ||
| 	listnums = {} | |||
| 	for k, _ in pairs(args) do | 	for k, _ in pairs(args) do | ||
| خط ۳۸۹: | خط ۴۲۵: | ||
| 			:attr('role', 'navigation') | 			:attr('role', 'navigation') | ||
| 			:node(tbl) | 			:node(tbl) | ||
| 		if args.title then | 		-- aria-labelledby title, otherwise above, otherwise lone group | ||
| 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title)) | 		if args.title or args.above or (args.group1 and not args.group2) then | ||
| 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1)) | |||
| 		else | 		else | ||
| 			nav:attr('aria-label', 'Navbox') | 			nav:attr('aria-label', 'Navbox') | ||
| خط ۴۰۶: | خط ۴۴۳: | ||
| 			:attr('role', 'navigation') | 			:attr('role', 'navigation') | ||
| 			:addClass('navbox') | 			:addClass('navbox') | ||
| 			:addClass(args.navboxclass) | |||
| 			:cssText(args.bodystyle) | 			:cssText(args.bodystyle) | ||
| 			:cssText(args.style) | 			:cssText(args.style) | ||
| 			:css('padding', '3px') | 			:css('padding', '3px') | ||
| 			:node(tbl) | 			:node(tbl) | ||
| 		if args.title then | 		-- aria-labelledby title, otherwise above, otherwise lone group | ||
| 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title)) | 		if args.title or args.above or (args.group1 and not args.group2) then | ||
| 			nav:attr('aria-labelledby', mw.uri.anchorEncode(args.title or args.above or args.group1)) | |||
| 		else | 		else | ||
| 			nav:attr('aria-label', 'Navbox') | 			nav:attr('aria-label', 'Navbox') | ||
| خط ۴۱۷: | خط ۴۵۶: | ||
| 	end | 	end | ||
| 	renderTrackingCategories(res) | 	if (args.nocat or 'false'):lower() == 'false' then | ||
| 		renderTrackingCategories(res) | |||
| 	end | |||
| 	return striped(tostring(res)) | 	return striped(tostring(res)) | ||
| end | end | ||
| خط ۴۲۴: | خط ۴۶۴: | ||
| function p.navbox(frame) | function p.navbox(frame) | ||
| 	if not getArgs then | 	if not getArgs then | ||
| 		getArgs = require(' | 		getArgs = require('پودمان:Arguments').getArgs | ||
| 	end | |||
| 	args = getArgs(frame, {wrappers = {'الگو:Navbox', 'الگو:Navbox subgroup'}}) | |||
| 	if frame.args.border then | |||
| 		-- This allows الگو:Navbox_subgroup to use {{#invoke:Navbox|navbox|border=...}}. | |||
| 		args.border = frame.args.border | |||
| 	end | 	end | ||
| 	-- Read the arguments in the order they'll be output in, to make references number in the right order. | 	-- Read the arguments in the order they'll be output in, to make references number in the right order. | ||