Changeset 1126

Show
Ignore:
Timestamp:
2008-07-26 13:43:45 (6 months ago)
Author:
gaspard
Message:

Changed zena.css to use 'shading.png' for drag_handle.
Set default to 'live' in [filter] when using parameter 'update'.
Added new test condition: <r:if node='start'> to test wether the current node is the same as the start node (browser url's node).

Cleanup of drag&drop code. Fixed a bug where drag_handle was not inserted in saved template generated by [each].

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/parser/lib/rules/zena.rb

    r1125 r1126  
    530530      end 
    531531      out "</div></form>" 
    532       if @params[:live] 
     532      if @params[:live] || @params[:updatea] 
    533533        out "<%= observe_form( \"#{dom_id}_f\" , :method => :get, :frequency  =>  1, :submit =>\"#{dom_id}_f\", :url => zafu_node_path(#{node_id})) %>" 
    534534      end 
     
    693693        else 
    694694          @html_tag_params[:class] = ["'s<%= #{node}.version.status %>'"] 
     695          @html_tag ||= 'span' 
    695696          res 
    696697        end 
     
    12161217     
    12171218    def r_drop 
    1218       @html_tag_params[:class] ||= 'drop' 
     1219      if parent.method == 'each' && @method == parent.single_child_method 
     1220        parent.add_html_class('drop') 
     1221      else 
     1222        @html_tag_params[:class] ||= 'drop' 
     1223      end 
    12191224      r_block 
    12201225    end 
     
    12521257      new_dom_scope 
    12531258      @html_tag ||= 'div' 
    1254       @html_tag_params ||= {} 
    1255       dom_id = unique_name 
    1256       @html_tag_params[:id] = erb_dom_id 
    12571259      case @params[:revert] 
    12581260      when 'move' 
     
    12631265        revert_effect = 'Element.move' 
    12641266      end 
    1265       res = expand_with 
    1266       if @params[:drag_handle] 
    1267         drag_handle = @params[:drag_handle] == 'true' ? 'drag_hand' : @params[:drag_handle] 
    1268         if res =~ /class\s*=\s*['"]#{drag_handle}/ 
    1269           # nothing to do 
    1270           insert = '' 
    1271         else 
    1272           insert = "<span class='#{drag_handle}'>&nbsp;</span>" 
    1273         end 
    1274       else 
    1275         insert = '' 
    1276       end 
    1277       out render_html_tag(insert + res) 
    1278        
    1279       out "<script type='text/javascript'> 
    1280       //<![CDATA[" 
     1267       
     1268      res, drag_handle = set_drag_handle_and_id(expand_with, @params, :id => erb_dom_id) 
     1269       
     1270      out render_html_tag(res) 
     1271       
    12811272      if drag_handle 
    12821273        out "<script type='text/javascript'>\n//<![CDATA[\n 
    1283           new Draggable('#{@html_tag_params[:id]}', {ghosting:true, revert:true, revertEffect:#{revertEffect}, handle:$(dom_id).select('.#{drag_handle}')[0]}); 
    1284         });\n//]]>\n</script>" 
    1285       else 
    1286         out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{@html_tag_params[:id]}',0,true,true,#{revert_effect})\n//]]>\n</script>" 
     1274          new Draggable('#{erb_dom_id}', {ghosting:true, revert:true, revertEffect:#{revert_effect}, handle:$('#{erb_dom_id}').select('.#{drag_handle}')[0]});\n//]]>\n</script>" 
     1275      else 
     1276        out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{erb_dom_id}',0,true,true,#{revert_effect})\n//]]>\n</script>" 
    12871277      end 
    12881278    end 
     
    14191409     
    14201410    def r_each 
    1421       if descendant('edit') || descendant('unlink') || ['block', 'drop'].include?(single_child_method) || @params[:draggable] == 'true' 
     1411      is_draggable = @params[:draggable] == 'true' || @params[:drag_handle] 
     1412       
     1413      if descendant('edit') || descendant('unlink') || ['block', 'drop'].include?(single_child_method) || is_draggable 
    14221414        id_hash = {:id => erb_dom_id} 
    14231415      else 
    14241416        id_hash = nil 
    14251417      end 
     1418       
    14261419       
    14271420      if @context[:make_form] 
     
    14301423      elsif @context[:list] 
    14311424        # normal rendering: not the start of a saved template 
    1432         if @params[:draggable] == 'true' || descendant('unlink') 
     1425        if is_draggable || descendant('unlink') 
    14331426          @html_tag ||= 'div' 
    14341427          out "<% #{var}_dom_ids = [] -%>" 
     
    14571450        end 
    14581451         
    1459         if @params[:draggable] == 'true' 
     1452        if is_draggable 
    14601453          out "<% #{var}_dom_ids << \"#{dom_id}\" -%>" 
    14611454        end 
     
    14651458        @anchor_param = nil 
    14661459         
    1467         res = expand_with(:node => var, :scope_node => var) 
    1468          
    1469         if @params[:drag_handle] && @params[:draggable] == 'true' 
    1470           drag_handle = @params[:drag_handle] == 'true' ? 'drag_handle' : @params[:drag_handle] 
    1471           if res =~ /class\s*=\s*['"]#{drag_handle}/ 
    1472             # nothing to do 
    1473             insert = '' 
    1474           else 
    1475             insert = "<span class='#{drag_handle}'>&nbsp;</span>" 
    1476           end 
    1477         else 
    1478           insert = '' 
    1479         end 
    1480          
    1481         if id_hash 
    1482           if @html_tag 
    1483             @html_tag_params.merge!(id_hash) 
    1484             res = insert + res 
    1485           else 
    1486             res = add_params(res, id_hash, insert) 
    1487           end 
    1488         end 
    1489          
     1460        res, drag_handle = set_drag_handle_and_id(expand_with(:node => var, :scope_node => var), @params, id_hash) 
    14901461         
    14911462        out render_html_tag(res, html_append) 
     
    14931464        out "<% end -%>" 
    14941465         
    1495         if @params[:draggable] == 'true' 
     1466        if is_draggable 
    14961467          if drag_handle 
    14971468            out "<script type='text/javascript'>\n//<![CDATA[\n<%= #{var}_dom_ids.inspect %>.each(function(dom_id, index) { 
     
    15051476      elsif @context[:saved_template] 
    15061477        # render to start a saved template 
    1507         res = expand_with(:scope_node => node) 
    1508          
    1509         if id_hash 
    1510           if @html_tag 
    1511             @html_tag_params.merge!(id_hash) 
    1512             res = render_html_tag(res, html_append) 
     1478        res, drag_handle = set_drag_handle_and_id(expand_with(:scope_node => node), @params, id_hash) 
     1479         
     1480        out render_html_tag(res) 
     1481         
     1482        if is_draggable 
     1483          if drag_handle 
     1484            out "<script type='text/javascript'>\n//<![CDATA[\nnew Draggable('#{erb_dom_id}', {ghosting:true, revert:true, handle:$('#{erb_dom_id}').select('.#{drag_handle}')[0]});\n//]]>\n</script>" 
    15131485          else 
    1514             res = add_params(res, id_hash) 
    1515           end 
    1516         end 
    1517          
    1518         out res 
    1519          
    1520         if @params[:draggable] == 'true' 
    1521           out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{erb_dom_id}')\n//]]>\n</script>" 
     1486            out "<script type='text/javascript'>\n//<![CDATA[\nZena.draggable('#{erb_dom_id}')\n//]]>\n</script>" 
     1487          end 
    15221488        end 
    15231489      else 
     
    15271493      end 
    15281494    end 
    1529     
     1495     
    15301496    def r_case 
    15311497      out "<% if false -%>" 
     
    26112577              when 'main' 
    26122578                "#{node}[:id] == #{node_name}[:id]" 
     2579              when 'start' 
     2580                "#{node}[:zip] == (params[:s] || #{node_name}[:zip]).to_i" 
    26132581              when 'parent' 
    26142582                "#{node}[:id] == #{node_name}[:parent_id]" 
     
    31583126    end 
    31593127     
     3128    # Used by [each] and [draggable] to insert 'id' and drag handle span 
     3129    def set_drag_handle_and_id(text, params, id_hash) 
     3130      res, drag_handle = text, nil 
     3131      if params[:drag_handle] 
     3132        drag_handle = params[:drag_handle] == 'true' ? 'drag_handle' : params[:drag_handle] 
     3133        if text =~ /class\s*=\s*['"]#{drag_handle}/ 
     3134          # nothing to do 
     3135          insert = '' 
     3136        else 
     3137          insert = "<span class='#{drag_handle}'>&nbsp;</span>" 
     3138        end 
     3139      else 
     3140        insert = '' 
     3141      end 
     3142       
     3143      if id_hash 
     3144        if @html_tag 
     3145          @html_tag_params.merge!(id_hash) 
     3146          res = insert + text 
     3147        else 
     3148          res = add_params(text, id_hash, insert) 
     3149        end 
     3150      end 
     3151      [res, drag_handle] 
     3152    end 
     3153     
    31603154    def expand_with(acontext={}) 
    31613155      # set variables 
  • trunk/public/stylesheets/zena.css

    r1124 r1126  
    3636 
    3737/* ========================= Ajax css ========================= */ 
    38 .drop_hover { background:#ace; border:2px dashed #99f;} 
     38.drop_hover { background:#ace; border:2px dashed #99f;} 
    3939.drop { min-height:1em;} 
    40 .drag_handle { padding-left:1em; margin:2px; background: #bbf;} 
     40.drag_handle { padding-left:1em; margin:2px; background: url('/images/shading.png');} 
    4141 
    4242/* ========================= Zazen css ======================== */