Improved Navbar, changed attribute handling
This commit is contained in:
@@ -19,11 +19,11 @@ feature
|
|||||||
do
|
do
|
||||||
create container.make_multi_control ("container")
|
create container.make_multi_control ("container")
|
||||||
container.add_class ("container")
|
container.add_class ("container")
|
||||||
create navbar.make_navbar ("Sample Page")
|
create navbar.make_navbar_with_brand ("Example")
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/%"", "Home"))
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/grid%"", "Grid"))
|
||||||
navbar.add_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
navbar.add_list_element (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"/repeater%"", "Repeater"))
|
||||||
navbar.add_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"#%"", "About"))
|
navbar.add_list_element_right (create {WSF_BASIC_CONTROL}.make_with_body ("a", "href=%"#%"", "About"))
|
||||||
container.add_control (navbar)
|
container.add_control (navbar)
|
||||||
control := container
|
control := container
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,62 +10,109 @@ class
|
|||||||
inherit
|
inherit
|
||||||
|
|
||||||
WSF_STATELESS_MULTI_CONTROL
|
WSF_STATELESS_MULTI_CONTROL
|
||||||
|
redefine
|
||||||
|
render
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_navbar
|
make_navbar,
|
||||||
|
make_navbar_with_brand
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_navbar (b: STRING)
|
make_navbar
|
||||||
-- Initialize with specified brand string
|
--Initialize
|
||||||
local
|
|
||||||
container: WSF_STATELESS_MULTI_CONTROL
|
|
||||||
header: WSF_STATELESS_MULTI_CONTROL
|
|
||||||
collapse_button: WSF_STATELESS_MULTI_CONTROL
|
|
||||||
brand: WSF_BASIC_CONTROL
|
|
||||||
icon_bar: WSF_BASIC_CONTROL
|
|
||||||
do
|
do
|
||||||
make_multi_control
|
make_multi_control
|
||||||
add_class ("navbar navbar-inverse navbar-fixed-top")
|
add_class ("navbar navbar-inverse navbar-fixed-top")
|
||||||
create container.make_multi_control
|
|
||||||
create header.make_multi_control
|
|
||||||
create collapse_button.make_with_tag_name ("button")
|
|
||||||
create collapse.make_multi_control
|
|
||||||
create nav.make_with_tag_name ("ul")
|
create nav.make_with_tag_name ("ul")
|
||||||
create nav_right.make_with_tag_name ("ul")
|
|
||||||
create brand.make_control ("a")
|
|
||||||
create icon_bar.make_control ("span")
|
|
||||||
container.add_class ("container")
|
|
||||||
header.add_class ("navbar-header")
|
|
||||||
collapse_button.add_class ("navbar-toggle")
|
|
||||||
icon_bar.add_class ("icon-bar")
|
|
||||||
collapse_button.add_control (icon_bar)
|
|
||||||
collapse_button.add_control (icon_bar)
|
|
||||||
collapse_button.add_control (icon_bar)
|
|
||||||
brand.add_class ("navbar-brand")
|
|
||||||
brand.set_attributes ("href=%"#%"")
|
|
||||||
brand.set_body (b)
|
|
||||||
header.add_control (collapse_button)
|
|
||||||
header.add_control (brand)
|
|
||||||
nav.add_class ("nav navbar-nav")
|
nav.add_class ("nav navbar-nav")
|
||||||
nav_right.add_class ("nav navbar-nav navbar-right")
|
end
|
||||||
collapse.add_class ("navbar-collapse")
|
|
||||||
collapse.add_control (nav)
|
make_navbar_with_brand (b: STRING)
|
||||||
collapse.add_control (nav_right)
|
-- Initialize with specified brand string
|
||||||
container.add_control (header)
|
do
|
||||||
container.add_control (collapse)
|
make_navbar
|
||||||
add_control (container)
|
brand := b
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Rendering
|
||||||
|
|
||||||
|
render: STRING
|
||||||
|
local
|
||||||
|
temp: STRING
|
||||||
|
nav_string: STRING
|
||||||
|
do
|
||||||
|
temp := render_tag_with_tagname ("span", "", "", "icon-bar")
|
||||||
|
temp.append (render_tag_with_tagname ("span", "", "", "icon-bar"))
|
||||||
|
temp.append (render_tag_with_tagname ("span", "", "", "icon-bar"))
|
||||||
|
temp := render_tag_with_tagname ("button", temp, "", "navbar-toggle")
|
||||||
|
if attached brand as b then
|
||||||
|
temp.append (render_tag_with_tagname ("a", b, "href=%"#%"", "navbar-brand"))
|
||||||
|
end
|
||||||
|
temp := render_tag_with_tagname ("div", temp, "", "navbar-header")
|
||||||
|
nav_string := nav.render
|
||||||
|
if attached nav_right as n then
|
||||||
|
nav_string.append (n.render)
|
||||||
|
end
|
||||||
|
temp.append (render_tag_with_tagname ("div", nav_string, "", "navbar-collapse"))
|
||||||
|
Result := render_tag_with_tagname ("div", temp, "", "container")
|
||||||
|
Result := render_tag (Result, "")
|
||||||
|
end
|
||||||
|
|
||||||
|
feature -- Change
|
||||||
|
|
||||||
|
add_list_element_right (c: WSF_STATELESS_CONTROL)
|
||||||
|
-- Add element in li tag to right aligned part of navbar
|
||||||
|
local
|
||||||
|
right: WSF_STATELESS_MULTI_CONTROL
|
||||||
|
li: WSF_STATELESS_MULTI_CONTROL
|
||||||
|
do
|
||||||
|
create li.make_with_tag_name ("li")
|
||||||
|
li.add_control (c)
|
||||||
|
add_element_right (li)
|
||||||
|
end
|
||||||
|
|
||||||
|
add_list_element (c: WSF_STATELESS_CONTROL)
|
||||||
|
-- Add element in li tag to main nav
|
||||||
|
local
|
||||||
|
li: WSF_STATELESS_MULTI_CONTROL
|
||||||
|
do
|
||||||
|
create li.make_with_tag_name ("li")
|
||||||
|
li.add_control (c)
|
||||||
|
add_element (li)
|
||||||
|
end
|
||||||
|
|
||||||
|
add_element_right (c: WSF_STATELESS_CONTROL)
|
||||||
|
-- Add element to right aligned part of navbar
|
||||||
|
local
|
||||||
|
right: WSF_STATELESS_MULTI_CONTROL
|
||||||
|
do
|
||||||
|
if attached nav_right as r then
|
||||||
|
right := r
|
||||||
|
else
|
||||||
|
create right.make_with_tag_name ("ul")
|
||||||
|
right.add_class ("nav navbar-nav navbar-right")
|
||||||
|
nav_right := right
|
||||||
|
end
|
||||||
|
right.add_control (c)
|
||||||
|
end
|
||||||
|
|
||||||
|
add_element (c: WSF_STATELESS_CONTROL)
|
||||||
|
-- Add element to main nav
|
||||||
|
do
|
||||||
|
nav.add_control (c)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Properties
|
feature -- Properties
|
||||||
|
|
||||||
collapse: WSF_STATELESS_MULTI_CONTROL
|
brand: detachable STRING
|
||||||
-- Content of collapsable navbar
|
-- Optional brand of the navbar
|
||||||
|
|
||||||
nav: WSF_STATELESS_MULTI_CONTROL
|
nav: WSF_STATELESS_MULTI_CONTROL
|
||||||
-- Middle nav
|
-- Middle nav
|
||||||
|
|
||||||
nav_right: WSF_STATELESS_MULTI_CONTROL
|
nav_right: detachable WSF_STATELESS_MULTI_CONTROL
|
||||||
-- Right nav
|
-- Right nav
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ class
|
|||||||
inherit
|
inherit
|
||||||
|
|
||||||
WSF_STATELESS_CONTROL
|
WSF_STATELESS_CONTROL
|
||||||
|
redefine
|
||||||
|
attributes
|
||||||
|
end
|
||||||
|
|
||||||
create
|
create
|
||||||
make_control, make_with_body
|
make_control, make_with_body
|
||||||
@@ -30,14 +33,6 @@ feature {NONE} -- Initialization
|
|||||||
body := b
|
body := b
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
|
||||||
|
|
||||||
attributes: STRING
|
|
||||||
-- Attributes string of this control
|
|
||||||
|
|
||||||
body: STRING
|
|
||||||
-- Body of this control
|
|
||||||
|
|
||||||
feature -- Rendering
|
feature -- Rendering
|
||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
@@ -46,7 +41,7 @@ feature -- Rendering
|
|||||||
Result := render_tag (body, attributes)
|
Result := render_tag (body, attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature
|
feature -- Change
|
||||||
|
|
||||||
set_attributes (a: STRING)
|
set_attributes (a: STRING)
|
||||||
-- Set the attributes string of this control
|
-- Set the attributes string of this control
|
||||||
@@ -60,4 +55,12 @@ feature
|
|||||||
body := b
|
body := b
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Access
|
||||||
|
|
||||||
|
attributes: STRING
|
||||||
|
-- Attributes of this control
|
||||||
|
|
||||||
|
body: STRING
|
||||||
|
-- Body of this control
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make_control (n, a_tag_name: STRING)
|
make_control (n, a_tag_name: STRING)
|
||||||
-- Initialize with specified control name and tag
|
-- Initialize with specified control name and tag
|
||||||
|
require
|
||||||
|
not n.is_empty
|
||||||
|
not a_tag_name.is_empty
|
||||||
do
|
do
|
||||||
make (a_tag_name)
|
make (a_tag_name)
|
||||||
control_name := n
|
control_name := n
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ feature {NONE} -- Initialization
|
|||||||
|
|
||||||
make (a_tag_name: STRING)
|
make (a_tag_name: STRING)
|
||||||
-- Initialize with specified tag
|
-- Initialize with specified tag
|
||||||
|
require
|
||||||
|
not a_tag_name.is_empty
|
||||||
do
|
do
|
||||||
tag_name := a_tag_name
|
tag_name := a_tag_name
|
||||||
create css_classes.make (0)
|
create css_classes.make (0)
|
||||||
ensure
|
|
||||||
attached css_classes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
@@ -26,7 +26,8 @@ feature -- Access
|
|||||||
css_classes: ARRAYED_LIST [STRING]
|
css_classes: ARRAYED_LIST [STRING]
|
||||||
-- List of classes (appear in the "class" attribute)
|
-- List of classes (appear in the "class" attribute)
|
||||||
|
|
||||||
-- TODO: Maybe improve
|
attributes: detachable STRING
|
||||||
|
-- Attributes string
|
||||||
|
|
||||||
feature -- Change
|
feature -- Change
|
||||||
|
|
||||||
@@ -71,6 +72,16 @@ feature -- Rendering
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
render_tag_with_body (body: STRING): STRING
|
||||||
|
-- Generate HTML of this control with the specified body
|
||||||
|
do
|
||||||
|
if attached attributes as attrs then
|
||||||
|
Result := render_tag (body, attrs)
|
||||||
|
else
|
||||||
|
Result := render_tag (body, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
render: STRING
|
render: STRING
|
||||||
-- Return html representation of control
|
-- Return html representation of control
|
||||||
deferred
|
deferred
|
||||||
|
|||||||
Reference in New Issue
Block a user