webmcp
diff framework/env/ui/paginate.lua @ 569:5b19007574de
New argument active_link_attr for env.ui.paginate{...}
author | jbe |
---|---|
date | Wed Oct 13 17:21:44 2021 +0200 (2021-10-13) |
parents | c43f251262d8 |
children |
line diff
1.1 --- a/framework/env/ui/paginate.lua Wed Oct 13 16:48:34 2021 +0200 1.2 +++ b/framework/env/ui/paginate.lua Wed Oct 13 17:21:44 2021 +0200 1.3 @@ -1,14 +1,15 @@ 1.4 --[[-- 1.5 ui.paginate{ 1.6 - selector = selector, -- a selector for items from the database (will be modified) 1.7 - anchor = anchor, -- optional name of anchor in document to jump to 1.8 - per_page = per_page, -- items per page, defaults to 10 1.9 - container_attr = container_attr, -- html attr for the container element 1.10 - link_attr = link_attr, -- html attr for each page link 1.11 - name = name, -- name of the CGI get variable, defaults to "page" 1.12 - position = position, -- position of page links relative to content: "before", "after", or "both" (default) 1.13 - content = function() 1.14 - ... -- code block which should be encapsulated with page selection links 1.15 + selector = selector, -- a selector for items from the database (will be modified) 1.16 + anchor = anchor, -- optional name of anchor in document to jump to 1.17 + per_page = per_page, -- items per page, defaults to 10 1.18 + container_attr = container_attr, -- html attr for the container element 1.19 + link_attr = link_attr, -- html attr for each page link 1.20 + active_link_attr = active_link_attr, -- alternative html attr for the active page link 1.21 + name = name, -- name of the CGI get variable, defaults to "page" 1.22 + position = position, -- position of page links relative to content: "before", "after", or "both" (default) 1.23 + content = function() 1.24 + ... -- code block which should be encapsulated with page selection links 1.25 end 1.26 } 1.27 1.28 @@ -17,14 +18,15 @@ 1.29 --]]-- 1.30 1.31 function ui.paginate(args) 1.32 - local selector = args.selector 1.33 - local anchor = args.anchor 1.34 - local per_page = args.per_page or 10 1.35 - local container_attr = args.container_attr or { class = 'ui_paginate' } 1.36 - local link_attr = args.link_attr or {} 1.37 - local name = args.name or 'page' 1.38 - local position = args.position or 'both' 1.39 - local content = args.content 1.40 + local selector = args.selector 1.41 + local anchor = args.anchor 1.42 + local per_page = args.per_page or 10 1.43 + local container_attr = args.container_attr or { class = 'ui_paginate' } 1.44 + local link_attr = args.link_attr or {} 1.45 + local active_link_attr = args.active_link_attr or link_attr 1.46 + local name = args.name or 'page' 1.47 + local position = args.position or 'both' 1.48 + local content = args.content 1.49 local count_selector = selector:get_db_conn():new_selector() 1.50 count_selector:add_field('count(1)') 1.51 count_selector:add_from(selector) 1.52 @@ -49,13 +51,16 @@ 1.53 slot.put(" ") 1.54 end 1.55 params[name] = page 1.56 - local attr = table.new(link_attr) 1.57 + local attr 1.58 if current_page == page then 1.59 + attr = table.new(active_link_attr) 1.60 if attr.class then 1.61 attr.class = attr.class .. " active" 1.62 else 1.63 attr.class = "active" 1.64 end 1.65 + else 1.66 + attr = table.new(link_attr) 1.67 end 1.68 ui.link{ 1.69 attr = attr,