Fixed slider

This commit is contained in:
Severin Münger
2013-09-27 18:13:55 +02:00
parent 113df6efe1
commit c6d59d3366
8 changed files with 91 additions and 55 deletions

View File

@@ -25,6 +25,7 @@ feature {NONE} -- Initialization
make_multi_control (n)
add_class ("navbar navbar-inverse navbar-fixed-top")
create nav.make_with_tag_name (control_name + "_nav", "ul")
create nav_right.make_with_tag_name (control_name + "_nav_right", "ul")
nav.add_class ("nav navbar-nav")
end
@@ -43,16 +44,15 @@ feature -- Rendering
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.multiply (3)
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)
if nav_right.controls.count > 0 then
nav_string.append (nav_right.render)
end
temp.append (render_tag_with_tagname ("div", nav_string, "", "navbar-collapse"))
Result := render_tag_with_tagname ("div", temp, "", "container")
@@ -61,6 +61,17 @@ feature -- Rendering
feature -- Change
set_active (tab: INTEGER)
require
tab >= 0 and tab < nav.controls.count + nav_right.controls.count
do
if tab < nav.controls.count then
nav.controls.i_th (tab).add_class ("active")
else
nav_right.controls.i_th (tab - nav.controls.count).add_class ("active")
end
end
add_list_element_right (c: WSF_STATELESS_CONTROL)
-- Add element in li tag to right aligned part of navbar
local
@@ -68,11 +79,7 @@ feature -- Change
li: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
name := control_name + "_rightlink";
if attached nav_right as right then
name := name + right.controls.count.out
else
name := name + "0"
end
name := name + nav_right.controls.count.out
create li.make_with_tag_name (name, "li")
li.add_control (c)
add_element_right (li)
@@ -117,7 +124,7 @@ feature -- Properties
nav: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Middle nav
nav_right: detachable WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
nav_right: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- Right nav
end

View File

@@ -21,9 +21,9 @@ feature {NONE} -- Initialization
do
make_control (n, "div")
add_class ("carousel slide")
create list.make_with_tag_name (control_name+"_links", "ol")
create list.make_with_tag_name (control_name + "_links", "ol")
list.add_class ("carousel-indicators")
create slide_wrapper.make_multi_control (control_name+"_wrapper")
create slide_wrapper.make_multi_control (control_name + "_wrapper")
slide_wrapper.add_class ("carousel-inner")
end
@@ -53,45 +53,63 @@ feature -- Rendering
do
temp := list.render
temp.append (slide_wrapper.render)
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-prev%"></span>", "href=%"#" + control_name + "%" data-slide=%"next%"", "left carousel-control"))
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-next%"></span>", "href=%"#" + control_name + "%" data-slide=%"prev%"", "right carousel-control"))
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-prev%"></span>", "href=%"#" + control_name + "%" data-slide=%"prev%"", "left carousel-control"))
temp.append (render_tag_with_tagname ("a", "<span class=%"icon-next%"></span>", "href=%"#" + control_name + "%" data-slide=%"next%"", "right carousel-control"))
Result := render_tag (temp, "")
end
feature -- Change
add_image_with_caption (src, alt: STRING; caption: detachable WSF_STATELESS_CONTROL)
add_image_with_caption (src, alt, caption: STRING)
local
caption_control: detachable WSF_STATELESS_CONTROL
do
if attached caption as c then
caption_control := create {WSF_BASIC_CONTROL}.make_with_body ("p", "", c)
end
add_image_with_caption_control (src, alt, caption_control)
end
add_image_with_caption_control (src, alt: STRING; caption: detachable WSF_STATELESS_CONTROL)
-- Add a new image to the slider, with specified url, alternative text and caption element
local
item: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
item: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
do
list.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("li", "data-target=%"#" + control_name + "%" data-slide-to=%"" + list.controls.count.out + "%"", ""));
create item.make_multi_control (control_name+"_item"+slide_wrapper.controls.count.out)
create item.make_multi_control (control_name + "_item" + slide_wrapper.controls.count.out)
item.add_class ("item")
item.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("img", "src=%"" + src + "%" alt=%"" + alt + "%"", ""))
item.add_control (create {WSF_BASIC_CONTROL}.make_with_body_class ("img", "src=%"" + src + "%" alt=%"" + alt + "%"", "", ""))
if attached caption as c then
item.add_control (c)
end
slide_wrapper.add_control (item)
add_control (item)
end
add_image (src, alt: STRING)
-- Add a new image to the slider, with specified url and alternative text
do
add_image_with_caption (src, alt, Void)
add_image_with_caption (src, alt, "")
end
add_control(c:WSF_STATELESS_CONTROL)
do
end
add_control (c: WSF_STATELESS_CONTROL)
-- Add a new control to the slider
local
cl: STRING
do
cl := ""
if slide_wrapper.controls.count = 0 then
cl := "active"
c.add_class (cl)
end
slide_wrapper.add_control (c)
list.add_control (create {WSF_BASIC_CONTROL}.make_with_body_class ("li", "data-target=%"#" + control_name + "%" data-slide-to=%"" + list.controls.count.out + "%"", cl, ""));
end
feature -- Properties
list: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
list: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- List of slider links
slide_wrapper: WSF_MULTI_CONTROL[WSF_STATELESS_CONTROL]
slide_wrapper: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
-- List of the single slides
end

View File

@@ -15,14 +15,14 @@ inherit
end
create
make_control, make_with_body
make_control, make_with_body, make_with_body_class
feature {NONE} -- Initialization
make_control (t: STRING)
-- Initialize
do
make_with_body (t, "", "")
make_with_body_class (t, "", "", "")
end
make_with_body (t, attr, b: STRING)
@@ -33,6 +33,15 @@ feature {NONE} -- Initialization
body := b
end
make_with_body_class (t, attr, c, b: STRING)
-- Initialize with specific attributes and body
do
make_with_body (t, attr, b)
if not c.is_empty then
css_classes.extend (c)
end
end
feature -- Rendering
render: STRING

View File

@@ -14,11 +14,6 @@ inherit
render_tag
end
feature
control_name: STRING
feature {NONE} -- Initialization
make_control (n, a_tag_name: STRING)
@@ -37,30 +32,30 @@ feature {NONE} -- Initialization
feature -- Actions
start_modal(url:STRING; title:STRING)
--Start a modal window containg an other or the same page
start_modal (url: STRING; title: STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
modal: JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("start_modal"), "type")
modal.put (create {JSON_STRING}.make_json(url), "url")
modal.put (create {JSON_STRING}.make_json(title), "title")
modal.put (create {JSON_STRING}.make_json ("start_modal"), "type")
modal.put (create {JSON_STRING}.make_json (url), "url")
modal.put (create {JSON_STRING}.make_json (title), "title")
actions.add (modal)
end
show_alert(mesage:STRING)
--Start a modal window containg an other or the same page
show_alert (mesage: STRING)
--Start a modal window containg an other or the same page
local
modal:JSON_OBJECT
modal: JSON_OBJECT
do
create modal.make
modal.put (create {JSON_STRING}.make_json("show_alert"), "type")
modal.put (create {JSON_STRING}.make_json(mesage), "message")
modal.put (create {JSON_STRING}.make_json ("show_alert"), "type")
modal.put (create {JSON_STRING}.make_json (mesage), "message")
actions.add (modal)
end
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
load_state (new_states: JSON_OBJECT)
-- Select state stored with `control_name` as key
@@ -90,9 +85,9 @@ feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- STATE MANAGEMENT
end
if actions.count > 0 then
if not attached states.item ("actions") then
states.put (create {JSON_ARRAY}.make_array,"actions")
states.put (create {JSON_ARRAY}.make_array, "actions")
end
if attached {JSON_ARRAY}states.item ("actions") as action_list then
if attached {JSON_ARRAY} states.item ("actions") as action_list then
across
actions.array_representation as action
loop
@@ -138,17 +133,18 @@ feature -- Rendering
Result := render_tag_with_tagname (tag_name, body, l_attributes, css_classes_string)
end
feature -- EVENT HANDLING
feature -- Event handling
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
-- Method called if any callback received. In this method you can route the callback to the event handler
deferred
end
feature -- Change
set_isolation (p: BOOLEAN)
do
isolate := true
isolate := p
end
feature -- Properties
@@ -156,4 +152,7 @@ feature -- Properties
isolate: BOOLEAN
actions: JSON_ARRAY
control_name: STRING
end

View File

@@ -27,7 +27,7 @@ feature -- Access
-- List of classes (appear in the "class" attribute)
attributes: detachable STRING
-- Attributes string
-- Attributes string (without classes)
feature -- Change

View File

@@ -10,15 +10,13 @@ deferred class
inherit
WSF_PAGE_CONTROL
redefine
control
redefine
control
end
feature
initialize_controls
local
navbar: WSF_NAVBAR_CONTROL
do
create control.make_multi_control ("container")
control.add_class ("container")
@@ -37,4 +35,6 @@ feature
control: WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
navbar: WSF_NAVBAR_CONTROL
end

View File

@@ -24,6 +24,8 @@ feature -- Implementation
Precursor
create slider.make_slider ("myslider")
slider.add_image ("http://www.placesmustseen.com/wp-content/uploads/2013/01/paris-eiffel-tower.jpg", "Eiffel Tower")
slider.add_image ("http://24.media.tumblr.com/0fcec9a7dde5b405a46b6fcda1ffad0c/tumblr_mtagkyYVIT1st5lhmo1_1280.jpg", "car")
slider.add_image ("http://25.media.tumblr.com/d9e791508eb9a532aa7f258fa4e0fedc/tumblr_mtag5zve3g1st5lhmo1_1280.jpg", "landscape")
control.add_control (create {WSF_BASIC_CONTROL}.make_with_body ("h1", "", " Image Slider Demo"))
control.add_control (slider)
end

View File

@@ -86,6 +86,7 @@ feature
source.set_control (progress)
progress.set_isolation (true)
control.add_control (progress)
navbar.set_active (1)
end
handle_click2