I am not new to jQuery, however this UI plugin makes me feel like so.
I have a div which has a list. This list is sortable. I also have a remove button and edit button as well as a handler image.
Anytime you click a draggable object for the first time, it sets it's position to absolute (0,0) to the screen and not the container itself. Furthermore, I am using the remove() on the element when clicking remove on the draggable element.
I am at a complete loss. Please see my code below:
jQuery:
- $(document).ready(function(){
- $('.sortable').sortable({
- revert:true
- });
- $('.draggable').draggable({
- //handle: '.dragger',
- connectToSortable: '.sortable',
- cancel:'.remove',
- revert: true,
- containment: 'parent',
- axis: 'y'
- });
- //$('.draggable').disableSelection();
- $('.input').each(function(){
- var default_value = this.value;
- $(this).focus(function() {
- if(this.value == default_value) {
- this.value = '';
- }
- });
- $(this).blur(function() {
- if(this.value == '') {
- this.value = default_value;
- }
- });
- });
- $(".toggle img").click(function(event) {
- event.preventDefault();
- $('img', $(this).parent()).toggle();
- });
- $('.collapse').click(function(event){
- $(this).parent().parent().parent().children('.sortable').slideUp('slow');
-
- })
- $('.expand').click(function(event){
- $(this).parent().parent().parent().children('.sortable').slideDown('slow');
- })
- $('.edit').click(function(){
- alert('I will not be censored');
- })
- //
- $('.remove').click(function(){
- var answer = confirm('Are you sure you want to delete this testimonial?');
- if(answer){
- //will do a removal query here of the selected testimonial
- $(this).parent().remove();
- }
- })
HTML:
- <!-- form Should $_POST the ordered results to the DB for order position on the live site. -->
- <form id="testimonial-order" method="post" action="#">
- <ul class="sortable">
- <li class="ui-state-default">
- <div class="draggable corner-8 blue ui-draggable">
- <img class="dragger left ui-widget-header" height="22" width="10" alt="Dragger" src="<!--{$rewriteBase}-->image/pixel/btn_drag_handle.png"/>
- <div class="pixel-name left">elanio 1</div>
- <img class="edit right" height="13" width="13" alt="edit icon" src="<!--{$rewriteBase}-->images/pixel/btn_edit.png"/>
- <img class="remove right" height="13" width="13" alt="remove icon" src="<!--{$rewriteBase}-->images/pixel/btn_remove.png"/>
- <label class="right">published<input type="checkbox"/></label>
- </div>
- </li>
- <li class="ui-state-default">
- <div class="draggable corner-8 blue ui-draggable">
- <img class="dragger left ui-widget-header" height="" width="" alt="Dragger" src="<!--{$rewriteBase}-->image/pixel/btn_drag_handle.png"/>
- <div class="pixel-name left">elanio 12</div>
- <img class="edit right" height="13" width="13" alt="edit icon" src="<!--{$rewriteBase}-->images/pixel/btn_edit.png"/>
- <img class="remove right" height="13" width="13" alt="remove icon" src="<!--{$rewriteBase}-->images/pixel/btn_remove.png"/>
- <label class="right">published<input type="checkbox" checked="checked"/></label>
- </div>
- </li>
- <li class="ui-state-default">
- <div class="draggable corner-8 blue ui-draggable">
- <img class="dragger left ui-widget-header" height="" width="" alt="Dragger" src="<!--{$rewriteBase}-->image/pixel/btn_drag_handle.png"/>
- <div class="pixel-name left">elanio 13</div>
- <img class="edit right" height="13" width="13" alt="edit icon" src="<!--{$rewriteBase}-->images/pixel/btn_edit.png"/>
- <img class="remove right" height="13" width="13" alt="remove icon" src="<!--{$rewriteBase}-->images/pixel/btn_remove.png"/>
- <label class="right">published<input type="checkbox"/></label>
- </div>
- </li>
- <li class="ui-state-default">
- <div class="draggable corner-8 blue ui-draggable">
- <img class="dragger left ui-widget-header" height="" width="" alt="Dragger" src="<!--{$rewriteBase}-->image/pixel/btn_drag_handle.png"/>
- <div class="pixel-name left">elanio 14</div>
- <img class="edit right" height="13" width="13" alt="edit icon" src="<!--{$rewriteBase}-->images/pixel/btn_edit.png"/>
- <img class="remove right" height="13" width="13" alt="remove icon" src="<!--{$rewriteBase}-->images/pixel/btn_remove.png"/>
- <label class="right">published<input type="checkbox"/></label>
- </div>
- </li>
- <li class="ui-state-default">
- <div class="draggable corner-8 blue ui-draggable">
- <img class="dragger left ui-widget-header" height="22" width="10" alt="Dragger" src="<!--{$rewriteBase}-->image/pixel/btn_drag_handle.png"/>
- <div class="pixel-name left">Jelanio 15</div>
- <img class="edit right" height="13" width="13" alt="edit icon" src="<!--{$rewriteBase}-->images/pixel/btn_edit.png"/>
- <img class="remove right" height="13" width="13" alt="remove icon" src="<!--{$rewriteBase}-->images/pixel/btn_remove.png"/>
- <label class="right">published<input type="checkbox"/></label>
- </div>
- </li>
- </div>
- </li>
- </ul><!-- end .sortable -->