apps/default/helpers/micromenus.rb in adhearsion-0.7.6 vs apps/default/helpers/micromenus.rb in adhearsion-0.7.7
- old
+ new
@@ -49,26 +49,27 @@
def process request
route = request.dup
if route.empty?
start "Error" do
- build_text "Bad URL!"
- build_text "Must point to a micromenu!"
+ build_text "Whoops!"
+ build_text "You forgot to include the target Micromenu in the URL path!"
end
return
end
title = " Adhearsion Micromenus"
filename = route.shift
load_menu filename
until route.empty?
segment = route.shift
- broken = segment.match(/^([\w_.]+);?(\d*)$/)
- segment, id = broken[1], broken[2]
- id = nil if id.empty?
+ broken = segment.match(/^([\w_.]+)(;(\d*))?$/)
+ segment, id = broken[1], broken[3]
+ id = nil if id && id.empty?
+
matches = @config.select do |x|
x[:type] == :menu && x[:text].nameify == segment
end
dest = matches[(id.simplify || 1) - 1]
@@ -109,17 +110,16 @@
build_call item[:number], item[:text]
end
end
end
end
-
def load_menu filename
@config.clear
file = File.join('config','helpers', 'micromenus', filename + '.rb')
unless File.readable? file
- item "Bad URL!"
- item "File inexistent!"
+ item "Target Micromenu doesn't exist!"
+ item "Did you input the URL correctly?"
else
eval File.read(File.join('config','helpers', 'micromenus', filename + '.rb'))
end
@config
end
@@ -129,12 +129,53 @@
pages * '/'
else
((url[-1] == ?/) ? url : url + "/") + pages * '/'
end
end
-
def get_refresh() @refresh end
+
+
+ module AjaxResponse
+
+ def content_type() "application/xml" end
+
+ def start name='', &block
+ @xml.ul do
+ yield
+ end
+ end
+
+ def build_menu str, uri, request
+ #build_menu item[:text], item[:uri], request
+ #request.flatten! if request.is_a? Array
+ @xml.li do
+ @xml.a str, :href => join_url('ajax', request, uri), :rel => 'ajax'
+ end
+ end
+
+ def build_text str
+ @xml.li { @xml.span str }
+ end
+
+ def build_prompt
+
+ end
+
+ def build_image filename, hash=nil
+ @xml.img :src => "/images/#{filename}"
+ end
+
+ def build_header str
+ @xml.li { @xml.h1 str }
+ end
+
+ def build_call number, name=number
+ @xml.a name, :href => "javascript:dial(#{number})"
+ @xml.br
+ end
+ end
+
module PolycomPhone
def content_type() "text/html" end
@@ -174,11 +215,11 @@
def build_call number, name=number
@xml.a name, :href => "tel://#{number}"
@xml.br
end
end
-
+
module XulUi
include PolycomPhone
def content_type() "application/vnd.mozilla.xul+xml" end
@@ -218,48 +259,139 @@
def build_header str
@xml.label str, :class => 'header'
end
end
-
-
- module FirefoxUi
+ module ModernUi
- include PolycomPhone
-
+ CSSs = %w"carousel columnav microbrowsers"
+ JAVASCRIPTS = %w"yahoo event dom animation connection container dragdrop carousel columnav"
+ INIT = %{
+ try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
+ function init() {
+ var cn_cfg = { prevElement: 'columnav-prev', source: document.getElementById('main') };
+ var cn = new YAHOO.extension.ColumNav('columnav', cn_cfg);
+
+ YAHOO.namespace("example.container");
+
+ YAHOO.example.container.panel1 = new YAHOO.widget.Panel("unique", { width:"350px", visible:true, draggable:true, close:true } );
+ YAHOO.example.container.panel1.render();
+
+ /*
+ YAHOO.example.container.panel2 = new YAHOO.widget.Panel("panel2", { width:"300px", visible:true, draggable:true, close:true } );
+ YAHOO.example.container.panel2.setHeader("Panel #2 from Script");
+ YAHOO.example.container.panel2.setBody("This is a dynamically generated Panel.");
+ YAHOO.example.container.panel2.setFooter("End of Panel #2");
+ YAHOO.example.container.panel2.render(document.body);
+ */
+
+ YAHOO.util.Event.addListener("show1", "click", YAHOO.example.container.panel1.show, YAHOO.example.container.panel1, true);
+ YAHOO.util.Event.addListener("hide1", "click", YAHOO.example.container.panel1.hide, YAHOO.example.container.panel1, true);
+
+ /*
+ YAHOO.util.Event.addListener("show2", "click", YAHOO.example.container.panel2.show, YAHOO.example.container.panel2, true);
+ YAHOO.util.Event.addListener("hide2", "click", YAHOO.example.container.panel2.hide, YAHOO.example.container.panel2, true);
+ */
+ }
+ YAHOO.util.Event.addListener(window, 'load', init);
+
+ }
+
+ def content_type() "text/html" end
+
def start name='', &block
@xml.html do
@xml.head do
@xml.title name
- @xml.link :rel => 'stylesheet', :media => 'all', :href => '/stylesheets/firefox.css'
+ CSSs.each { |css| @xml.link :rel => 'stylesheet', :type => 'text/css', :href => "/stylesheets/#{css}.css"}
+
+ JAVASCRIPTS.each { |script| @xml.script :type => 'text/javascript', :src => "/javascripts/#{script}.js" do end }
+ @xml.script INIT, :type => 'text/javascript'
end
@xml.body do
- yield
+
+ @xml.div :id => "unique", :class => 'microbrowser' do
+
+ @xml.div :class => "hd" do
+ @xml.div :class => "tl" do
+ @xml.div :class => 'prevButton' do
+ @xml.a "Back", :href => "javascript:void(0)", :id => "columnav-prev"
+ end
+ end
+ @xml.h1 name
+ @xml.div :class => 'tr' do
+ @xml.span "Close", :class => "container-close"
+ end
+ end
+
+ @xml.div :class => 'bd' do
+ @xml.div :id => 'columnav', :class => "carousel-component" do
+ @xml.div :class => "carousel-clip-region" do
+ @xml.ul :class => "carousel-list" do end
+ end
+ end
+
+ @xml.ul :id => 'main', :style => 'display:none' do
+ yield
+ # @xml << %{
+ # <li><a href="/viewaddressbook">View Address book again</a>
+ # <ul><li>
+ # <a href="http://google.com">Jicksta.com</a>
+ # </li></ul></li>
+ # <li><a href='#'>Linking to Somewhere</a></li>
+ # <li><strong>Not</strong> linking to somewhere</li>
+ # }
+ end
+ end
+
+ @xml.div :class => "ft" do
+ @xml.hr
+ end
+
+ end
end
end
end
+
+ def build_menu str, uri, request
+ #build_menu item[:text], item[:uri], request
+ #request.flatten! if request.is_a? Array
+ @xml.li { @xml.a str, :rel => 'ajax', :href => join_url('ajax', request, uri) }
+ end
+
+ def build_text str
+ @xml.li { @xml.span str }
+ end
+
+ def build_prompt
+
+ end
+
+ def build_image filename, hash=nil
+ @xml.li { @xml.img :src => "/images/#{filename}" }
+ end
+
+ def build_header str
+ @xml.li { @xml.h1 str }
+ end
+
def build_call number, name=number
- # The tel:// UI doesn't do Firefox much good. Mexuar, maybe?
- @xml.a name, :href => "tel://#{number}"
- @xml.br
+ @xml.li { @xml.a name, :href => "javascript:call(#{number})" }
end
-
end
private
def image name
name += '.bmp' unless name.index ?.
@config << {:type => :image, :text => name}
end
-
- def refresh_every time
+ def refresh_every time
@refresh = time
end
-
def heading str
@config << {:type => :heading, :text => str}
end
alias header heading
@@ -300,52 +432,62 @@
# Useful for performing an action and refreshing.
end
end
USER_AGENT_MAP = {
- "Polycom" => MicromenuGenerator::PolycomPhone,
- "Firefox" => MicromenuGenerator::XulUi#FirefoxUi
+ "Polycom" => MicromenuGenerator::PolycomPhone
}
def do_GET(request, response)
response.status = 200
log "Request from: " + request['User-Agent']
route = request.path[1..-1].split '/'
+ handler = nil
+
+ if route.first == 'ajax'
+ handler = MicromenuGenerator::AjaxResponse
+ route.shift
+ end
+
if route.first == 'images'
file = File.join(%w(config helpers micromenus images), route[1..-1])
# TODO: Handle missing files
response.content_type = WEBrick::HTTPUtils::mime_type file, WEBrick::HTTPUtils::DefaultMimeTypes
response.body = File.read file
elsif route.first == 'stylesheets'
file = File.join %w(config helpers micromenus stylesheets), route[1..-1]
response.content_type = 'text/css'
response.body = File.read file
+ elsif route.first == 'javascripts'
+ file = File.join %w(config helpers micromenus javascripts), route[1..-1]
+ response.content_type = 'text/javascript'
+ response.body = File.read file
else
- mg = MicromenuGenerator.new request, resolve_brand(request['User-Agent']), StringIO.new
+ mg = MicromenuGenerator.new request, handler || resolve_brand(request['User-Agent']), StringIO.new
response.content_type = mg.content_type
response['Expires'] = 2
mg.process route
refresh = mg.get_refresh
- response['Refresh'] = refresh if refresh
+ response['Refresh'] = refresh if refresh
- response.body = mg.io.string
+ response.body = mg.io.string
end
end
def resolve_brand useragent
USER_AGENT_MAP.each do |k,v|
return v if useragent.index k
end
- MicromenuGenerator::PolycomPhone # Polycom's the default since it's XHTML
+ MicromenuGenerator::ModernUi # Default to Class A browser
end
end
$MICROMENUS_SERVER = Thread.new do
- micromenu_server = WEBrick::HTTPServer.new :Port => ($HELPERS.micromenus.port || 1337)
+ micromenu_server = WEBrick::HTTPServer.new :Port => ($HELPERS['micromenus']['port'] || 1337)
micromenu_server.mount '/', MicromenusServlet
$HUTDOWN.hook {
micromenu_server.stop
}