Geen bewerkingssamenvatting |
Geen bewerkingssamenvatting |
||
| (Een tussenliggende versie door dezelfde gebruiker niet weergegeven) | |||
| Regel 1: | Regel 1: | ||
--[[ | --[[ | ||
Adapted from Template:Wsrating | Adapted from Template:Wsrating | ||
@deprecated - now part of FFInput | |||
]]-- | ]]-- | ||
| Regel 22: | Regel 23: | ||
end | end | ||
--[[ | |||
Depends on CSS in Common.css | |||
]] | |||
p.common = function( frame ) | p.common = function( frame ) | ||
local name = frame.args.name or "rating" | local name = frame.args.name or "rating" | ||
| Regel 30: | Regel 33: | ||
local checked = frame.args.checked or "" | local checked = frame.args.checked or "" | ||
local static = frame.args.static or "false" | local static = frame.args.static or "false" | ||
local cancellable = frame.args.cancellable or "false" | local cancellable = frame.args.cancellable or "false" | ||
local cancelTitle = frame.args.canceltitle or "Annuleren" | local cancelTitle = frame.args.canceltitle or "Annuleren" | ||
-- create radio inputs with labels | |||
local stepSequence = mw.text.split( steps, ";" ) | local stepSequence = mw.text.split( steps, ";" ) | ||
local checkInputs = "" | local checkInputs = "" | ||
for i,step in ipairs(stepSequence) do | for i,step in ipairs(stepSequence) do | ||
| Regel 53: | Regel 54: | ||
end | end | ||
-- optionally add a radio input for cancelling value (= no value) | |||
local cancelInput = "" | local cancelInput = "" | ||
if cancellable == "true" then | if cancellable == "true" then | ||
| Regel 59: | Regel 61: | ||
checkInputs = checkInputs .. p.createRatingCheckInput( "radio", "", "", cancelId, name, "", cancelClass, cancelTitle ) | checkInputs = checkInputs .. p.createRatingCheckInput( "radio", "", "", cancelId, name, "", cancelClass, cancelTitle ) | ||
end | end | ||
-- wrap everything in fieldset and div container | |||
local fieldsetClass = { class = "rate", enabled = "enabled" } | |||
if ( static == "true" ) then fieldsetClass["disabled"] = "disabled" end | |||
local fieldset = mw.text.tag( | local fieldset = mw.text.tag( | ||
"fieldset", | "fieldset", | ||
fieldsetClass, | |||
checkInputs | checkInputs | ||
) | ) | ||
| Regel 86: | Regel 77: | ||
p.createRatingCheckInput = function( checkType, val, isChecked, id, name, labelName, labelClass, title, showOnChecked, showOnUnchecked ) | p.createRatingCheckInput = function( checkType, val, isChecked, id, name, labelName, labelClass, title, showOnChecked, showOnUnchecked ) | ||
-- (1) create input | -- (1) create input | ||
local args = { ["type"] = checkType, name = name, id = id } | |||
local args = { | |||
if val ~= nil then args["value"] = val end | if val ~= nil then args["value"] = val end | ||
if isChecked ~= nil then args.checked = isChecked end | if isChecked ~= nil then args.checked = isChecked end | ||
-- currently unused but may be helpful if additional visuals are needed | |||
local showOnChecked = showOnChecked or nil | local showOnChecked = showOnChecked or nil | ||
if showOnChecked ~= nil then args["show-on-checked"] = showOnChecked end | if showOnChecked ~= nil then args["show-on-checked"] = showOnChecked end | ||
| Regel 101: | Regel 87: | ||
local checkInput = mw.text.tag( '_input', args, "" ) | local checkInput = mw.text.tag( '_input', args, "" ) | ||
-- (2) create label | -- (2) create label | ||
local labelArgs = { class = labelClass, title = title, ["for"] = id } | |||
local labelArgs = { | |||
local labelInput = mw.text.tag( "label", labelArgs, labelName ) | local labelInput = mw.text.tag( "label", labelArgs, labelName ) | ||
Huidige versie van 22 aug 2025 13:49
--[[
Adapted from Template:Wsrating
@deprecated - now part of FFInput
]]--
local p = {}
local mFFInput = require('Module:FFInput')
--[[
{{#invoke:FFRating|input|... }}
]]--
p.input = function(frame)
end
--[[
display version
{{#invoke:FFRating|display|... }}
]]--
p.display = function(frame)
end
--[[
Depends on CSS in Common.css
]]
p.common = function( frame )
local name = frame.args.name or "rating"
local steps = frame.args.steps or "10;9.5;9;8.5;8;7.5;7;6.5;6;5.5;5;4.5;4;3.5;3;2.5;2;1.5;1;0.5"
local star = frame.args.star or "ster"
local stars = frame.args.stars or "sterren"
local checked = frame.args.checked or ""
local static = frame.args.static or "false"
local cancellable = frame.args.cancellable or "false"
local cancelTitle = frame.args.canceltitle or "Annuleren"
-- create radio inputs with labels
local stepSequence = mw.text.split( steps, ";" )
local checkInputs = ""
for i,step in ipairs(stepSequence) do
local id = name .. "-" .. string.gsub(step, "%.", "-") --{{{name|rating}}}-{{#var:@numericid}}
local isChecked = ""
if ( step == checked ) then isChecked = "checked" end
local class = ""
-- eg 9.5 sterren, 1 ster
local title = step .. " "
if ( step == "1" or step == "0.5" ) then title = title .. star else title = title .. stars end
local labelClass = "ws-star half"
if string.find(step, ".5") == nil then
labelClass = "ws-star whole"
end
checkInputs = checkInputs .. p.createRatingCheckInput( "radio", step, isChecked, id, name, "", labelClass, title )
end
-- optionally add a radio input for cancelling value (= no value)
local cancelInput = ""
if cancellable == "true" then
cancelId = name .. "-cancel"
cancelClass = "ws-cancel-stars"
checkInputs = checkInputs .. p.createRatingCheckInput( "radio", "", "", cancelId, name, "", cancelClass, cancelTitle )
end
-- wrap everything in fieldset and div container
local fieldsetClass = { class = "rate", enabled = "enabled" }
if ( static == "true" ) then fieldsetClass["disabled"] = "disabled" end
local fieldset = mw.text.tag(
"fieldset",
fieldsetClass,
checkInputs
)
local res = mw.text.tag( "div", { class = "ws-star-ratings" }, fieldset )
return frame:preprocess(res);
end
p.createRatingCheckInput = function( checkType, val, isChecked, id, name, labelName, labelClass, title, showOnChecked, showOnUnchecked )
-- (1) create input
local args = { ["type"] = checkType, name = name, id = id }
if val ~= nil then args["value"] = val end
if isChecked ~= nil then args.checked = isChecked end
-- currently unused but may be helpful if additional visuals are needed
local showOnChecked = showOnChecked or nil
if showOnChecked ~= nil then args["show-on-checked"] = showOnChecked end
if showOnUnchecked ~= nil then args["show-on-unchecked"] = showOnUnchecked end
local checkInput = mw.text.tag( '_input', args, "" )
-- (2) create label
local labelArgs = { class = labelClass, title = title, ["for"] = id }
local labelInput = mw.text.tag( "label", labelArgs, labelName )
-- (3) Join and return
local res = checkInput .. labelInput
return res
end
return p
