Posted By

nerdfiles on 09/02/10


Tagged

javascript jquery


Versions (?)

Managing Popups through Anchor @rel and jquery


 / Published in: JavaScript
 

  1. /* For popups:
  2.   <a href="http://google.com"
  3.   title=""
  4.   rel='popup:{"width":"200","height":"200","title":""}'>
  5.   augue ut enim
  6.   </a>
  7.   */
  8. $("a[rel^='popup']").bind("click", function(e) {
  9. var url = $(this).attr("href"),
  10. rel = $(this).attr("rel"),
  11. windowSettings = JSON.parse(rel.match(/{(.*)}/)[0]) ||
  12. $.parseJSON(rel.match(/{(.*)}/)[0]) ||
  13. {
  14. status: 1,
  15. toolbar: 1,
  16. location: 1,
  17. menubar: 1,
  18. directories: 1,
  19. resizable: 1,
  20. scrollbars: 1,
  21. height: 400,
  22. width: 400,
  23. title: ""
  24. },
  25. windowSettingsStr = [],
  26. counter = 0;
  27.  
  28. for (var i in windowSettings) {
  29. windowSettingsStr[counter] = i+"="+windowSettings[i];
  30. counter += 1;
  31. }
  32.  
  33. var n = window.open(url, windowSettings.title, windowSettingsStr.join(","));
  34.  
  35. if (window.focus) {
  36. n.focus();
  37. }
  38.  
  39. e.preventDefault();
  40. });

Report this snippet  

You need to login to post a comment.