Solved

jQuery Dialog - Dialog popup on links click

Posted on 2010-11-18
6
290 Views
Last Modified: 2012-05-10
I am facing the problem of dialog not opening on subsequent click on a same link.  I read about it on different sites however I still dont know how to go about it in my case.  I have the following page http://www.clemexdownload.com/sites/newlook/test5.html
where the behavior and code can be found.  My links look something like this  <a href="images/myImage.jpg" id="imgModalX" title="My title for this image">Click to enlarge</a>
where the image uri and title is pass to the function that open the dialog.

If you have any suggestions please let me know.
Thanks
0
Comment
Question by:clemex
  • 3
  • 3
6 Comments
 
LVL 18

Accepted Solution

by:
Sudaraka Wijesinghe earned 500 total points
ID: 34170933
I only experienced the problem you explained when using Chrome, it work on FF and IE.
I believe it's because after the first time image is loaded (and cached) for the session it won't fire the load() event on the second time you click the link.

Check if the code below works. (I haven't had time to test)

References:
http://api.jquery.com/live/
http://wap.w3schools.com/jsref/prop_img_complete.asp
jQuery(document).ready( function() {
 
	  
	  /* Creer images PopUp sur certain liens */
	  $("a[id^=imgModal]").click(function(event){       
			
		event.preventDefault();
		PreviewImage($(this).attr('href'),$(this).attr('title'));
											
	  });  	  
  
  //When the image has loaded, display the dialog
  $('#image').live('load', function(){
	ShowDialog();
  });

});

PreviewImage = function(uri, mytitle) {

  //Get the HTML Elements
  imageDialog = $("#dialog");
  imageTag = $('#image');
  
  //Split the URI so we can get the file name
  uriParts = uri.split("/");

  //Set the image src
  imageTag.attr('src', uri);

  if(imageTag[0].complete) ShowDialog();
}

ShowDialog = function(){

    $('#dialog').dialog({
		modal: true,
		resizable: false,
		draggable: false,
		width: 'auto',
		title: mytitle
    });
    
}

Open in new window

0
 

Author Comment

by:clemex
ID: 34175947
This is great thanks.
I modified the code slightly and it work great.  Also did not understand what the lines 12-15 were doing so   I removed them and it still work.  Are they really necessary? Maybe for a specific browser?  You can see it in action here:
http://www.clemexdownload.com/sites/newlook/test51.html

Thanks
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34176276
Good to know you got it working.

Lines 12-15 will not come in to play as you are using the same image in the main page and in the dialog box, because the image is already loaded by the browser in the main page before you open the dialog box.
But if you use a different image in the dialog box you will need this part of the code.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:clemex
ID: 34188549
Ok I updated this page with a different image in the dialog window but even with the bit of code it seems not to open on the first click but only on subsequent clicks.

http://www.clemexdownload.com/sites/newlook/products/powderdisperser.html

If possible you can let me know your thought on this at chabot_eric at hotmail.com
Thanks
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34189432
Try changing the
  //When the image has loaded, display the dialog
  $('#image').live('load', function(){
        ShowDialog();
  });

to

  //When the image has loaded, display the dialog
  $('#image').bind('load', function(){
        ShowDialog();
  });

I saw few articles when I was digging this, that live event binding seem to has a problem with load event.
0
 

Author Comment

by:clemex
ID: 34190802
Perfect!
Thanks again.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

706 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

21 Experts available now in Live!

Get 1:1 Help Now