Solved

Help Get Rid of jQuery Pluggin!

Posted on 2015-01-09
5
106 Views
Last Modified: 2015-01-15
I'm using this pluggin:  imgAreaSelect

The plugin works fine.  However, I can't get the selection to go away when the plugin is removed from the page.  It is put in the page via ajax, and the page content is updated via ajax too.  But when the ajax fires and changes the content, the image area selection still shows on the page!

I tried using remove() to totally remove the div with the javascript code and all the related stuff, but that doesn't work.

Want to see what I mean?  It will probably help to see whats up.
Go to this page:  profile page
Hover your mouse over the profile picture and click the change profile pic button.
Upload a picture
Now you'll be on the screen with the plugin.  Now to see the error click the "status" tab which is above the image you uploaded.

So you see my problem.  Any clever ideas to help?

Thanks experts!
0
Comment
Question by:Elxn
  • 4
5 Comments
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Here's an example of how to capture the coordinates of the selection into html inputs and then remove the plugin afterward.
<script type="text/javascript">
$(document).ready(function () {
	var ias = $('#ias').imgAreaSelect({ instance: true });
	ias.setOptions({ x1: 60, y1: 14, x2: 240, y2: 194, aspectRatio: '1:1', handles: true, 
                 onSelectEnd: function (img, selection) {
			$('input[name="x1"]').val(selection.x1);
			$('input[name="y1"]').val(selection.y1);
			$('input[name="x2"]').val(selection.x2);
			$('input[name="y2"]').val(selection.y2); 
			ias.remove();
		} 
	});
});
</script>

Open in new window

0
 
LVL 2

Author Comment

by:Elxn
Comment Utility
Hmm..  I'll give it a shot.  But I thought of this already and didn't do it cause i figured the plugin would go away after the user moved the selection area once.  So they'd then only get one modification of the crop area; that won't do.  

But maybe this means it will be removed when they click the button to save their cropped picture.

Thanks, I'll try it out and see what happens!
0
 
LVL 2

Author Comment

by:Elxn
Comment Utility
Okay I tried it.

It still persisted even doing it that way so it didn't solve the problem.  Also the plugin didn't work anymore when i did it this way; it just showed the initial selection area but you couldn't move it around or change the dimensions of the selection.

Oh, i should say, if i put it in a document dot ready function it doesn't work at all; so i had to take out that encapsulating function to even get the selection area to show.

Any other ideas?
0
 
LVL 2

Accepted Solution

by:
Elxn earned 0 total points
Comment Utility
Okay I got it figured out.

I just had to use the hide setting as said by the documentation.

Just used this code:

$('#ias').imgAreaSelect({hide:true});

Should have seen this earlier!!!
0
 
LVL 2

Author Closing Comment

by:Elxn
Comment Utility
I figured it out myself.  Should have seen this earlier.  If i could reduce the points to 0 I would but I don't know if you can even do that.

So I'll let you moderators see what you think the points should be!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now