Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing jquery imgareaselect plugin from element

So im using this neat jquery plugin http://odyniec.net/projects/imgareaselect/ It works fine, but i'm firing it with jquery ui callback function (dialog), and i need to remove the selection after dialog closes.

function initialize_selection() {
$('#image_area').imgAreaSelect({ x1: 10, y1: 10, x2: $('#image_area').width()-10, y2: $('#image_area').height()-10 , fadeSpeed: 400, handles: true});
}

$(function() {
$('#image_edit').click(function(){
    $('#edit_image_dialog').load('actions.php?action=edit_temp_image', function(){
            $('#edit_image_dialog').dialog({
                modal: true,
                resizable: false,
                width: 480,
                    buttons: {
            Ok: function() {
                        //foo_bar                                                                        
            },
                        Cancel: function() {
                        //foo_bar
            }
                    },
                    beforeclose: function(){
                    //What should i put here ???
                    ;}
            });
    initialize_selection();
        });
    });
});

I would really appreciate some tips, because i'm new to jquery and I can't work this out by myself.

Thank you

like image 909
votnii Avatar asked Mar 05 '10 13:03

votnii


4 Answers

The only way I've found to get the selection treatment areas removed was the following:

"Close": function() { 
  $(".imgareaselect-selection").parent().remove();
  $(".imgareaselect-outer").remove();
  $(this).dialog("close"); 
},

The following did not work for me (in the jquery and jqueryui elements in Wordpress 3.0.5)

$(selector).imgAreaSelect( {remove: true} );
like image 27
Michael Reed Avatar answered Nov 08 '22 21:11

Michael Reed


http://odyniec.net/projects/imgareaselect/usage.html

$('#image_area').imgAreaSelect({remove:true});

should work, but not sure

like image 71
Daniele Cruciani Avatar answered Nov 08 '22 21:11

Daniele Cruciani


This worked for me:

var $ias = $('#imageArea').imgAreaSelect({
    instance: true
});

$('#clearBtn2').click(function() {
    $ias.cancelSelection();
});
like image 5
jrt Avatar answered Nov 08 '22 22:11

jrt


According to the documentation for the options at HomeimgAreaSelect Documentation

$('#image_area').imgAreaSelect( {remove: true} );

will do the trick

like image 3
Gabriele Petrioli Avatar answered Nov 08 '22 21:11

Gabriele Petrioli