Class: ODDB::Html::View::SearchBar

Inherits:
HtmlGrid::InputText
  • Object
show all
Defined in:
lib/oddb/html/view/search.rb

Instance Method Summary collapse

Instance Method Details

#initObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/oddb/html/view/search.rb', line 20

def init
  super
  self.onload = "document.getElementById('searchbar').focus();"
  val = @lookandfeel.lookup(:query_info)
  txt_val = @session.persistent_user_input(@name) || val
  @attributes.store('value', txt_val)
  @attributes.update({
    'onFocus'  =>  "if (value=='#{val}') { value='' };",
    'onBlur'  =>  "if (value=='') { value='#{val}' };",
    'id'      =>  "searchbar",
  })
  args = [@name, '']
  submit = @lookandfeel._event_url(@container.event, args)
  script = "if(#{@name}.value!='#{val}'){"
  script << "var href = '#{submit}'"
  script << "+encodeURIComponent(#{@name}.value.replace(/\\//, '%2F'));"
  script << "if(this.dstype)"
  script << "href += '/dstype/' + this.dstype.value;"
  #script << "href += '#best_result';"
  script << "document.location.href=href; } return false"
  self.onsubmit = script
end