ထလာ်တိတ်အာနကဵုမာတိကာညိ

မဝ်ဂျူ:Navbar

နူ ဝဳကဳပဳဒဳယာ

Lua error in မဝ်ဂျူ:Lua_banner at line 113: attempt to index field 'edit' (a nil value). Script error: The module returned a nil value. It is supposed to return an export table. This is a Lua implementation of {{Navbar}}. It is used in Module:Navbox.


local p = {}

-- နဲကဲ သွက်ဂွံ ပလေဝ် မလိက်သၠး (Whitespace) ကေုာံ မလိက်အလုံ (Empty string)
local function trimArg(val)
	if type(val) == 'string' then
		val = val:match('^%s*(.-)%s*$')
		if val == '' then
			return nil
		end
	end
	return val
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; width:6em;'
	end

	local titleText = args[titleArg] or (':' .. mw.getCurrentFrame():getParent():getTitle())
	local title = mw.title.new(titleText, 'Template')

	if not title then
		error('ယၟုမုက်လိက် ဗၠေတ်ဒၟံင် ' .. titleText)
	end

	local talkpage = title.talkPageTitle and title.talkPageTitle.fullText or ''

	local div = mw.html.create():tag('div')
	div
		:addClass('plainlinks')
		:addClass('hlist')
		:addClass('navbar')
		:cssText(args.style)

	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('[')
				:newline()
	end

	local ul = div:tag('ul')

	-- လေန် သွက်ဂွံ ဗဵု (View)
	ul
		:tag('li')
			:addClass('nv-view')
			:wikitext('[[' .. title.fullText .. '|')
			:tag('abbr')
				:attr('title', 'ကျောဝ်ဗဵု ထာမ်ပလိက်ဏအ်')
				:css('font-size', '90%')
				:cssText(args.fontstyle)
				:wikitext(args.mini and 'ဗ' or 'ဗဵု')
				:done()
			:wikitext(']]')
			:done()
			
	-- လေန် သွက်ဂွံ ဓရီုကျာ (Talk)
	ul
		:tag('li')
			:addClass('nv-talk')
			:wikitext('[[' .. talkpage .. '|')
			:tag('abbr')
				:attr('title', 'ဓရီုကျာ ပရူ ထာမ်ပလိက်ဏအ်')
				:css('font-size', '90%')
				:cssText(args.fontstyle)
				:wikitext(args.mini and 'ဓ' or 'ဓရီုကျာ')
				:done()
			:wikitext(']]')

	-- လေန် သွက်ဂွံ ပလေဝ်ဒါန် (Edit)
	if not args.noedit then
		ul
			:tag('li')
				:addClass('nv-edit')
				:wikitext('[' .. title:fullUrl('action=edit') .. ' ')
				:tag('abbr')
					:attr('title', 'ပလေဝ်ဒါန် ထာမ်ပလိက်ဏအ်')
					:css('font-size', '90%')
					: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(']')
				: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 မဆက်စၠောအ် ကု Template (ဟွံဒးစကာ Module:Arguments ရ)
function p.navbar(frame)
	local args = {}
	
	-- ကေတ် တင်ဂၞင် နူကဵု Parent frame (Template မကော်စကာလဝ်)
	local parent = frame:getParent()
	if parent then
		for k, v in pairs(parent.args) do
			args[k] = trimArg(v)
		end
	end
	
	-- ကေတ် တင်ဂၞင် နူကဵု Current frame (ယဝ်နွံမ္ဂး ဍေံ ကလေင်ဒၞာဲထောအ် Parent args ရ)
	for k, v in pairs(frame.args) do
		args[k] = trimArg(v)
	end

	return p._navbar(args)
end

return p