Partage
  • Partager sur Facebook
  • Partager sur Twitter

UI Droppable. Démonstration "photo-manager", effacement d'un

Sujet résolu
    29 octobre 2010 à 9:24:13

    Bonjour a tous, j'ai repris l'exemple de jquery photo manager, pour deplacer des images d'un endroit a un autres.

    Mon souci c'est que quand je drag and drop un élément ou que je click sur ma balise a pour déplacer mon élément celui ci fais bien l'action voulu, mais il s'efface de son endroit d'origine, alors que j'aimerai que oui il soit déplacer mais qu'il ne s'efface pas.

    <lien url="http://jqueryui.com/demos/droppable/#photo-manager"]http://jqueryui.com/demos/droppable/#photo-manager">Photo Manager exemple</lien>

    Voici l'exemple sur leur site vous verrez que si vous déplacer l'image elle s'efface de l'endroit initiale.

    Je ne trouve pas l'endroit a effacer pour que ceci ne s'effectue plus, malgré mes recherche sur la doc jquery....


    Mon jquery:
    $(function() {
     
    	
        	// there's the gallery and the check
        	var $gallery = $( "#gallery" ),
            $check = $( "#contentRightMenuFormResult" );
    
    
    		// let the gallery items be draggable
        	$( "li", $gallery ).draggable({
           		helper: "clone",
    		});
    
    
        	// let the check be droppable, accepting the gallery items
        	$check.droppable({
            	accept: "#gallery > li",
            	activeClass: "ui-state-highlight",
            	drop: function( event, ui ) {
                	deleteImage( ui.draggable );
                   
            });
    
                            // resolve the icons behavior with event delegation
                        	$( "ul.gallery2 > li" ).click(function( event ) {
                        		var $item = $( this ),
                        		$target = $( event.target );
    
                        		if ( $target.is( "a.ui-icon-check" ) ) {
                            		deleteImage( $item );
                        		} else if ( $target.is( "a.ui-icon-zoomin" ) ) {
                            		viewLargerImage( $target );
                        		} else if ( $target.is( "a.ui-icon-closethick" ) ) {
                            		recycleImage( $item );
                        		}
    
                        		return false;
                        	});
                		}
            		);  
        		});
        
        
        	// image deletion function
        	var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Supprimer de l&rsquo;album' class='ui-icon ui-icon-closethick'>Recycle image</a>";
        	function deleteImage( $item ) {
        		$item.fadeOut(function() {
                	var $list = $( "ul", $check ).length ?
                    $( "ul", $check ) :
                    $( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $check );
    
                	$item.find( "a.ui-icon-check" ).remove();
                	$item.append( recycle_icon ).appendTo( $list ).fadeIn(function() {
                    	$item
                        	/*.animate({ width: "48px" })*/
                        	.find( "img" )
                            	.animate({ height: "72px" });
                	});
            	});
        	}
    
        	
    		// image recycle function
        	var check_icon = "<a href='link/to/check/script/when/we/have/js/off' title='Ajouter a l&apos;album' class='ui-icon ui-icon-check'>Delete image</a>";
        	function recycleImage( $item ) {
            	$item.fadeOut(function() {
                	$item
                    	.find( "a.ui-icon-closethick" )
                            .remove()
                    	.end()
                    	.css( "width", "96px")
                    	.append( check_icon )
                    	/*.find( "img" )
                        .css( "height", "72px" )*/
                    	.end()
                    	.appendTo( $gallery )
                    	.fadeIn();
            	});
        	}
        
    
        	// image preview function, demonstrating the ui.dialog used as a modal window
        	function viewLargerImage( $link ) {
            	var src = $link.attr( "href" ),
                	title = $link.siblings( "img" ).attr( "alt" ),
                	$modal = $( "img[src$='" + src + "']" );
    
            		if ( $modal.length ) {
               			$modal.dialog( "open" );
            		} else {
                		var img = $( "<img alt='" + title + "' width='384' height='288' style='display: none; padding: 8px;' />" )
                    		.attr( "src", src ).appendTo( "body" );
                		setTimeout(function() {
                    		img.dialog({
                        		title: title,
                        		width: 400,
                        		modal: true,
                        		resizable: false,
                    		});
                		}, 1 );
            		}
        		}
    
    
        	// resolve the icons behavior with event delegation
            $( "ul.gallery > li" ).click(function( event ) {
                var $item = $( this ),
                    $target = $( event.target );
    
                if ( $target.is( "a.ui-icon-check" ) ) {
                    deleteImage( $item );
                } else if ( $target.is( "a.ui-icon-zoomin" ) ) {
                    viewLargerImage( $target );
                } else if ( $target.is( "a.ui-icon-closethick" ) ) {
                    recycleImage( $item );
                }
    
                return false;
        	});
        
    	
        	// resolve the icons behavior with event delegation
            $( "ul.gallery2 > li" ).click(function( event ) {
                var $item = $( this ),
                    $target = $( event.target );
    
                if ( $target.is( "a.ui-icon-check" ) ) {
                    deleteImage( $item );
                } else if ( $target.is( "a.ui-icon-zoomin" ) ) {
                    viewLargerImage( $target );
                } else if ( $target.is( "a.ui-icon-closethick" ) ) {
                    recycleImage( $item );
                }
    
                return false;
        	});
    	});
    



    Mon HTML :


    <div id="contentBlock">
                    	<ul id="gallery" class="gallery ui-helper-reset ui-helper-clearfix">
                        	{% for affiche in  attribu_image %}
                            <li class="ui-widget-content ui-corner-tr">
                            	<h6 class="ui-widget-header">{{ affiche.name|slice:":16" }}</h6>
                                <img src="{% ids_images_prefix %}{% for thumb in  affiche.element_thumb %}{{thumb}}{% endfor %}" alt="{{ affiche.name }}" height="72" />
                                <a href="{% ids_images_prefix %}{% for low in  affiche.element_low %}{{low}}{% endfor %}" title="{{ affiche.price }} {{ affiche.description }} {% for tags in affiche.tags  %} {{ tags }}, {% endfor %}" class="ui-icon ui-icon-zoomin">View larger</a>
                                        
                                <form class="item-forms" action="{% url libertyproject.imagin.ajax.add_image %}" method="get">
                                	{% csrf_token %}
                                    <input type="hidden" name="item_id" value="{{affiche.id}}" />
                                    {% if selected_album %}
                                    	<input type="hidden" name="selected_album_id" value="{{selected_album.id}}" />
                                    {% else %}
                                        <input type="hidden" name="selected_album_id" value="{{selected_album}}" />
                                    {% endif %}
                                    <!--<input class="ui-icon ui-icon-check item-send" type="submit" value="send in album" />-->
                                    <a href="link/to/check/script/when/we/have/js/off" title="Ajouter a l&apos;album" class="ui-icon ui-icon-check">Ajouter a l&apos;album</a>
                             	</form>
                         	</li>
                            {% endfor %}
                    	</ul>
                    <br class="spacer" />
                    </div>
    



    <div id="contentRightMenuFormResult">
                                <ul id="gallery2" class="gallery2 ui-helper-reset ui-helper-clearfix">
                                {% for affiche in  album0_items %}
                                    <li class="ui-widget-content ui-corner-tr">
                                        <h6 class="ui-widget-header">{{ affiche.name|slice:":16" }}</h6>
                                        <img src="{% ids_images_prefix %}{% for thumb in  affiche.element_thumb %}{{thumb}}{% endfor %}" alt="{{ affiche.name }}" height="72" />
                                        <a href="{% ids_images_prefix %}{% for low in  affiche.element_low %}{{low}}{% endfor %}" title="{{ affiche.price }} {{ affiche.description }} {% for tags in affiche.tags  %} {{ tags }}, {% endfor %}" class="ui-icon ui-icon-zoomin">View larger</a>
                                        <form class="item-forms-remove" action="{% url libertyproject.imagin.ajax.remove_image %}" method="get">
                                            {% csrf_token %}
                                            <input type="hidden" name="item_id" value="{{affiche.id}}" />
                                            {% if selected_album %}
                                            <input type="hidden" name="selected_album_id" value="{{selected_album.id}}" />
                                            {% else %}
                                            <input type="hidden" name="selected_album_id" value="{{selected_album}}" />
                                            {% endif %}
                                            <!--<input class="ui-icon ui-icon-check item-send" type="submit" value="send in album" />-->
                                            <a href='link/to/recycle/script/when/we/have/js/off' title='Supprimer de l&rsquo;album' class='ui-icon ui-icon-closethick'>Recycle image</a>
                                        </form>
                                    </li>
                                    {% endfor %}
                                </ul>
                                
                            </div>
    



    Merci d'avance !!! ;)

    • Partager sur Facebook
    • Partager sur Twitter
      29 octobre 2010 à 10:52:26

      Salut,

      Tu dois te servir du clonage de draggable. Ca devrait donner quelque chose du genre :

      $(".draggable").draggable({
        helper: 'clone',
        revert: 'invalid',
      });
      
      $("#droppable").droppable({
        drop : function(event, ui){
          $(this).append(ui.helper.clone().removeClass("ui-draggable-dragging").draggable({helper:'original'}));
        }
      });
      
      • Partager sur Facebook
      • Partager sur Twitter
      Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
        29 octobre 2010 à 15:23:23

        Merci, oui sa ressemble a ce que je veux faire.

        J'ai fais comme ceci :

        // let the gallery items be draggable
            	$( "li", $gallery ).draggable({
               		helper: "clone",
        			revert: 'invalid',
        
        		});
        		
        
        
        
        
            	// let the check be droppable, accepting the gallery items
            	$check.droppable({
                	accept: "#gallery > li",
                	activeClass: "ui-state-highlight",
                	drop: function( event, ui ) {
                    	$(this).append(ui.helper.clone().removeClass("ui-draggable-dragging").draggable({helper:'original'}));
                    
            		});
        


        Donc il ne me supprime pas mon image de l'endroit d'où je le déplacé(gallery), par contre la où est déposé(gallery2) il ne prend pas les attributs comme il le devrai de la gallery2.

        J'pense que je devrai lui mettre ce qu'il y a dans cette partie de code:

        // image deletion function
            	var recycle_icon = "<a href='link/to/recycle/script/when/we/have/js/off' title='Supprimer de l&rsquo;album' class='ui-icon ui-icon-closethick'>Recycle image</a>";
            	function deleteImage( $item ) {
            		$item.fadeOut(function() {
                    	var $list = $( "ul", $check ).length ?
                        $( "ul", $check ) :
                        $( "<ul class='gallery ui-helper-reset'/>" ).appendTo( $check );
        
                    	$item.find( "a.ui-icon-check" ).remove();
                    	$item.append( recycle_icon ).appendTo( $list ).fadeIn(function() {
                        	$item
                            	/*.animate({ width: "48px" })*/
                            	.find( "img" )
                                	.animate({ height: "72px" });
                    	});
                	});
            	}
        


        Si vous pouviez me donner un coup de main, c'est mes début en Jquey / javascript et après mainte essaie je n'arrive pas a mes fin...

        Merci d'avace !!! ;)

        • Partager sur Facebook
        • Partager sur Twitter
          2 novembre 2010 à 10:56:37

          J'ai toujours pas réussi a a faire qu'a l'endoit ou est cloner mon drag il prennes les attributs CSS.

          J'ai lu que si on utilise removeClass, il faut utiliser addClass pour lui réattribuer une class.

          J'ai essayer de cette manière :

          $(this).append(ui.helper.clone().removeClass("ui-draggable-dragging").addClass("gallery2 ui-helper-reset ui-helper-clearfix").draggable({helper:'original'}));
          


          Mais rien ne se passe.... :euh:


          Mon CSS si sa peux aider:

          #gallery { float: left; width: 100%; min-height: 12em; padding-left: 0px; } * html #gallery { height: 12em; } /* IE6 */
              .gallery.custom-state-active { background: #eee; }
              .gallery li { float: left; 
                          width: 96px;
                          height: 120px; 
                          padding: 0.4em; 
                          margin: 0 12px 15px 0; 
                          text-align: center; }
              .gallery li h6 { margin: 0 0 0.4em; cursor: move; }
              .gallery li a { float: right; }
              .gallery li a.ui-icon-zoomin { float: left; }
              .gallery li img { width: 100%; cursor: pointer; }
              
              
              #check { float: right; width: 32%; min-height: 18em; padding: 1%;} * html #check { height: 18em; } /* IE6 */
              #check h4 { line-height: 16px; margin: 0 0 0.4em; }
              #check h4 .ui-icon { float: left; }
              #check .gallery h6 { display: none; }
              input.item-send { background-color: transparent; border: none; cursor: pointer; float: right;}
              
                  
              
              #gallery2 { float: left; width: 100%; min-height: 12em; padding-left: 0px; } * html #gallery { height: 12em; } /* IE6 */
              .gallery2.custom-state-active { background: #eee; }
              .gallery2 li { float: left; 
                          width: 96px;
                          height: 120px; 
                          padding: 0.4em; 
                          margin: 0 8px 15px 0; 
                          text-align: center; }
              .gallery2 li h6 { margin: 0 0 0.4em; cursor: move; }
              .gallery2 li a { float: right; }
              .gallery2 li a.ui-icon-zoomin { float: left; }
              .gallery2 li img { width: 100%; cursor: pointer; }
              
              
              #check { float: right; width: 32%; min-height: 18em; padding: 1%;} * html #check { height: 18em; } /* IE6 */
              #check h4 { line-height: 16px; margin: 0 0 0.4em; }
              #check h4 .ui-icon { float: left; }
              #check .gallery2 h6 { display: none; }
              input.item-send { background-color: transparent; border: none; cursor: pointer; float: right;}
          


          Merci d'avance !!! ;)
          • Partager sur Facebook
          • Partager sur Twitter

          UI Droppable. Démonstration "photo-manager", effacement d'un

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown