Objective: use jQuery to create a shopping cart and wish list with draggable, droppable and sortable functionality

Objective: use jQuery to create a shopping cart and wish list with draggable, droppable and sortable functionality

Objective: use jQuery to create a shopping cart and wish list with draggable, droppable and sortable functionality.Requirements:Download the jQuery ui files using a theme of your choice.
Download and extract the shop.html file and associated image and css files to use for this lab.
Open up the shop.html file and add the following functionality:
The page already has a link to the jQuery libraries on a CDN. Add links to the jQuery-ui minified .js file and links to the 2 jQuery-ui stylesheets (jquery css file and theme css file)
Draggable images
At the top of the page, there are a series of images (roses, mums and pansies) in a div with an id of gallery.
Select all of the images in the #gallery div and add the draggable widget
Test to see if you can now drag the images around the page.
Droppable cart and wishlist
At the bottom of the page, there are 2 divs with ids of cart and wishlist. These have a heading and a list element (ul for cart, ol for wishlist). They have been styled already with a minimum height attribute to allow room to drag in the images.
Apply the droppable method to the #cart div and to the #wishlist div.
For this application, we do not want to leave the images in the shopping cart and wishlist. Instead, we want to add a list item with the alt attribute to the list element in the div where the image is dropped.
Inside the parentheses for the draggable widget for the cart, add a drop function:
drop: function(e,ui) {
// add code here
}); // end cart droppable
Inside this anonymous function, add the code to append a list item to the #cartlist ul using the ‘alt’ attribute from the image as the text for the list item. Use ui.draggable to get the image. (ui.draggable.attr(‘alt’))
Repeat for the droppable widget for the wishlist, adding the list item to the #wishes ol.
We want the image to return to it’s old position after adding the item to the cart or wishlist. We can do this by adding revert: true to the draggable widget options for the images.
Test your code. When you drag one of the images over the cart or wishlist div and drop it, it should add the item to the list and then return the image to its original position.
Sortable cart and wishlist
Add the sortable widget to the #cartlist and #wishes divs
We want the user to be able to drag items between the #cartlist and #wishes divs, so add the connectWith: option to wishes with a value of ‘#cartlist’ and to cartlist with a value of ‘#wishes’.
Test your code. It should sort the items properly and move them from cart to wishlist or wishlist to cart, but you will see that it also creates an ‘undefined’ item in the list each time. This is caused by our droppable function that tries to add the

  • when we drop an item in the drop zone.
    To fix this problem, we need to make changes to our drop functions in the droppable widget as follows:
    Add an if statement above the append statement to test if the draggable item has an ‘alt’ attribute. If so, then append the list item using the code we created previously.
    // test to see if the draggable item has an alt attribute
    if (ui.draggable.attr(‘alt’)) {
    // if it has an alt attribute, append the alt text inside of an li tag as before (move the previously created line into the if brackets)
  • “+ui.draggable.attr(‘alt’)+””);
    Now add an else statement to append a list item to the list with the html of the draggable item as the text instead of the alt attribute:
    else {
    // if no alt attribute, add a list item using the html from the draggable item as the list item text
  • “+ui.draggable.html()+” li>”);
    Test again and you will see that you no longer get the undefined lines. However, it is keeping both the original list item and the dropped list item. So we need to add a second line in our else clause to remove the original item: ui.draggable.remove();
    Test on more time and it should work as expected.
    Add an effect to an element of your choice on the page
  • Oder Solution Now

    Why Use Our Services

    1. Professional & Expert Writers: AResearchers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

    2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

    3. Plagiarism-Free Papers: All papers provided by AResearchers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

    4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. AResearchers is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

    5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses. First time customer will receive three free pages on their first order. 

    6. 24/7 Customer Support: At AResearchers, we have put in place a team of experts who answer to all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.