X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=app%2Fassets%2Fjavascripts%2Fpanels.js.coffee;h=fbddfaedd17e37aaa8635d792d1f1bd4e8630843;hb=ee5a37a91fc01e87b5187c9db64a51386fada3fc;hp=472e4382ee0cb863537444592fa75c5435e1ebd5;hpb=eb8b6c622716df82710495a3842738bfb046089b;p=pettanr%2Fpettanr.git diff --git a/app/assets/javascripts/panels.js.coffee b/app/assets/javascripts/panels.js.coffee index 472e4382..fbddfaed 100644 --- a/app/assets/javascripts/panels.js.coffee +++ b/app/assets/javascripts/panels.js.coffee @@ -1,6 +1,11 @@ $ -> confirm_confirm_confirm = () -> confirm( ) + new_element_index = {} + new_element_index[pettanr_current_panel_id] = 0 + + escapeHTML = (t) -> + $("
").text(t).html() set_tree_value = (keys, last_attr, value) -> key = keys.shift() @@ -17,15 +22,37 @@ $ -> return true else return false - is_tree = (o) -> - if o.attr('tree') + is_var = (o) -> + if o.attr('column') if o.attr('column') == '_destroy' and o.val().length < 1 return false else return true + else + return false + is_element = (o) -> + if o.attr('element_type') + return true + else + return false + is_element_part = (o) -> + if o.attr('element_part_type') return true else return false + element_types = {'panel_picture': 'panel_pictures', 'speech_balloon': 'speech_balloons', 'ground_picture': 'ground_pictures', 'ground_color': 'ground_colors'} + element_type_to_table = (element_type) -> + element_types[element_type] + make_tree = (attr, o) -> + if is_var(o) + tree = 'panels-' + o.attr('panel_id') + '-' + if is_element(o) + tree = tree + element_type_to_table(o.attr('element_type')) + '_attributes-' + o.attr('element_id') + '-' + if is_element_part(o) + tree = tree + o.attr('element_part_type') + '_attributes-' + tree = tree + o.attr('column') + keys = tree.split('-') + set_tree_value(keys, attr, o.val()) panel_tag_id = (element) -> '#panel' + element.attr('panel_id') @@ -36,24 +63,47 @@ $ -> refresh_attribute = () -> attr = {} $('input').map -> - if is_tree($(@)) - keys = $(@).attr('tree').split('-') - set_tree_value(keys, attr, $(this).val()) + make_tree(attr, $(@)) $('textarea').map -> - if is_tree($(@)) - keys = $(@).attr('tree').split('-') - set_tree_value(keys, attr, $(this).val()) + make_tree(attr, $(@)) $('select').map -> - if is_tree($(@)) - keys = $(@).attr('tree').split('-') - set_tree_value(keys, attr, $(this).val()) + make_tree(attr, $(@)) $('#pettanr-panel-json').val(JSON.stringify(attr['panels'][pettanr_current_panel_id.toString() ])) $('#tabs').tabs() $('#elements-tabs').tabs() + $('#new-element-tabs').tabs() + $('#new-speech_balloon-tabs').tabs() $('#elements-tabs').addClass( "ui-tabs-vertical ui-helper-clearfix" ) $("#elements-tabs li").removeClass("ui-corner-top") $("#elements-tabs li").addClass("ui-corner-left") + $("#elements-tabs li").map -> + $(@).mouseover -> + switch $(@).attr('element_type') + when 'speech_balloon' + trace = element_tag_id($(@)) + t = $('img', $(trace)) + when 'panel_picture' + trace = element_tag_id($(@)) + 'img' + t = $(trace) + else + t = null + if t + $('.ui-resizable-handle', t.parent()).map -> + $(@).css('display', 'block') + $(@).mouseout -> + switch $(@).attr('element_type') + when 'speech_balloon' + trace = element_tag_id($(@)) + t = $('img', $(trace)) + when 'panel_picture' + trace = element_tag_id($(@)) + 'img' + t = $(trace) + else + t = null + if t + $('.ui-resizable-handle', t.parent()).map -> + $(@).css('display', 'none') #destroy button $('.ui-icon-destroy').map -> @@ -258,7 +308,7 @@ $ -> when 'content' trace = element_tag_id($(@)) speech_trace = '#panel' + $(@).attr('panel_id') + 'speech_balloon' + $(@).attr('element_id') + 'speech' + $(@).attr('element_part_id') - v = $(@).val() + v = escapeHTML($(@).val()) $(speech_trace).html(v) # ground-picture @@ -409,7 +459,7 @@ $ -> d = $(@).parent() trace = element_tag_id(d) f = $(trace + 'width') - w = f.val() / 2 + w = Math.floor(f.val() / 2) f.val(w) $(trace + 'img').width(Math.abs(w)) $(trace + 'img').parent().width(Math.abs(w)) @@ -440,7 +490,7 @@ $ -> d = $(@).parent() trace = element_tag_id(d) f = $(trace + 'height') - h = f.val() / 2 + h = Math.floor(f.val() / 2) f.val(h) $(trace + 'img').height(Math.abs(h)) $(trace + 'img').parent().height(Math.abs(h)) @@ -478,3 +528,11 @@ $ -> $(@).hide() $(@).parent().hide() #label + # add button on new form + $('.submit-new-form').map -> + $(@).html('') + + $('.new-element').map -> + $(@).click -> + false +