2011-08-05 06:11:15 +02:00
|
|
|
class SelectParser
|
|
|
|
|
|
|
|
constructor: ->
|
|
|
|
@options_index = 0
|
|
|
|
@parsed = []
|
|
|
|
|
|
|
|
add_node: (child) ->
|
2012-11-27 04:28:17 +01:00
|
|
|
if child.nodeName.toUpperCase() is "OPTGROUP"
|
2011-08-05 06:11:15 +02:00
|
|
|
this.add_group child
|
|
|
|
else
|
|
|
|
this.add_option child
|
|
|
|
|
|
|
|
add_group: (group) ->
|
|
|
|
group_position = @parsed.length
|
|
|
|
@parsed.push
|
|
|
|
array_index: group_position
|
|
|
|
group: true
|
|
|
|
label: group.label
|
|
|
|
children: 0
|
|
|
|
disabled: group.disabled
|
|
|
|
this.add_option( option, group_position, group.disabled ) for option in group.childNodes
|
|
|
|
|
|
|
|
add_option: (option, group_position, group_disabled) ->
|
2012-11-27 04:28:17 +01:00
|
|
|
if option.nodeName.toUpperCase() is "OPTION"
|
2011-08-05 06:11:15 +02:00
|
|
|
if option.text != ""
|
|
|
|
if group_position?
|
|
|
|
@parsed[group_position].children += 1
|
|
|
|
@parsed.push
|
|
|
|
array_index: @parsed.length
|
|
|
|
options_index: @options_index
|
|
|
|
value: option.value
|
|
|
|
text: option.text
|
|
|
|
html: option.innerHTML
|
|
|
|
selected: option.selected
|
|
|
|
disabled: if group_disabled is true then group_disabled else option.disabled
|
|
|
|
group_array_index: group_position
|
2012-01-03 12:07:33 +01:00
|
|
|
classes: option.className
|
|
|
|
style: option.style.cssText
|
2011-08-05 06:11:15 +02:00
|
|
|
else
|
|
|
|
@parsed.push
|
|
|
|
array_index: @parsed.length
|
|
|
|
options_index: @options_index
|
|
|
|
empty: true
|
|
|
|
@options_index += 1
|
|
|
|
|
|
|
|
SelectParser.select_to_array = (select) ->
|
|
|
|
parser = new SelectParser()
|
|
|
|
parser.add_node( child ) for child in select.childNodes
|
|
|
|
parser.parsed
|
|
|
|
|
|
|
|
this.SelectParser = SelectParser
|