943,616 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Apr 18th, 2008
0

Re: Firefox Compatibility help with script

I want to change Tactics, I want to alter this code

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type='text/javascript'>
  2. <!--
  3. function ResizeThem(){
  4. maxheight=250;
  5. maxwidth= 250;
  6. imgs=document.getElementsByTagName("img");
  7. for (p=0; p<imgs.length; p++) {
  8. if (imgs[p].getAttribute("alt")=="user posted image") {
  9. w=parseInt(imgs[p].width);
  10. h=parseInt(imgs[p].height);
  11. if (parseInt(imgs[p].width)>maxwidth) {
  12. imgs[p].style.cursor="pointer";
  13. imgs[p].setAttribute('title','Reduced Image - Click to see full size');
  14. imgs[p].onclick=new Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
  15. imgs[p].height=(maxwidth/imgs[p].width)*imgs[p].height;
  16. imgs[p].width=maxwidth;}
  17. if (parseInt(imgs[p].height)>maxheight) {
  18. imgs[p].style.cursor="pointer";
  19. imgs[p].onclick=new
  20. Function("iw=window.open(this.src,'ImageViewer','resizable=1,scrollbars=1');iw.focus()");
  21. imgs[p].width=(maxheight/imgs[p].height)*imgs[p].width;
  22. imgs[p].height=maxheight;}}}}
  23. ResizeThem()
  24. //-->
  25. </script>

So that it still reduces the images, but instead of opening them in a new window, they expand (floating) in the same window instead, Using the Code below.
I need to assign the reduced images as "ImageExpander"

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function ImageExpander(oThumb, sImgSrc)
  2. {
  3. // store thumbnail image and overwrite its onclick handler.
  4. this.oThumb = oThumb;
  5. this.oThumb.expander = this;
  6. this.oThumb.onclick = function() { this.expander.expand(); }
  7.  
  8. // record original size
  9. this.smallWidth = oThumb.offsetWidth;
  10. this.smallHeight = oThumb.offsetHeight;
  11.  
  12. this.bExpand = true;
  13. this.bTicks = false;
  14.  
  15. // self organized list
  16. if ( !window.aImageExpanders )
  17. {
  18. window.aImageExpanders = new Array();
  19. }
  20. window.aImageExpanders.push(this);
  21.  
  22. // create the full sized image.
  23. this.oImg = new Image();
  24. this.oImg.expander = this;
  25. this.oImg.onload = function(){this.expander.onload();}
  26. this.oImg.src = sImgSrc;
  27. }
  28.  
  29. ImageExpander.prototype.onload = function()
  30. {
  31. this.oDiv = document.createElement("div");
  32. document.body.appendChild(this.oDiv);
  33. this.oDiv.appendChild(this.oImg);
  34. this.oDiv.style.position = "absolute";
  35. this.oDiv.expander = this;
  36. this.oDiv.onclick = function() {this.expander.toggle();};
  37. this.oImg.title = "Click to reduce.";
  38. this.bigWidth = this.oImg.width;
  39. this.bigHeight = this.oImg.height;
  40.  
  41. if ( this.bExpand )
  42. {
  43. this.expand();
  44. }
  45. else
  46. {
  47. this.oDiv.style.visibility = "hidden";
  48. this.oImg.style.visibility = "hidden";
  49. }
  50. }
  51. ImageExpander.prototype.toggle = function()
  52. {
  53. this.bExpand = !this.bExpand;
  54. if ( this.bExpand )
  55. {
  56. for ( var i in window.aImageExpanders )
  57. if ( window.aImageExpanders[i] !== this )
  58. window.aImageExpanders[i].reduce();
  59. }
  60. }
  61. ImageExpander.prototype.expand = function()
  62. {
  63. // set direction of expansion.
  64. this.bExpand = true;
  65.  
  66. // set all other images to reduce
  67. for ( var i in window.aImageExpanders )
  68. if ( window.aImageExpanders[i] !== this )
  69. window.aImageExpanders[i].reduce();
  70.  
  71. // if not loaded, don't continue just yet
  72. if ( !this.oDiv ) return;
  73.  
  74. // hide the thumbnail
  75. this.oThumb.style.visibility = "hidden";
  76.  
  77. // calculate initial dimensions
  78. this.x = this.oThumb.offsetLeft;
  79. this.y = this.oThumb.offsetTop;
  80. this.w = this.oThumb.clientWidth;
  81. this.h = this.oThumb.clientHeight;
  82.  
  83. this.oDiv.style.left = this.x + "px";
  84. this.oDiv.style.top = this.y + "px";
  85. this.oImg.style.width = this.w + "px";
  86. this.oImg.style.height = this.h + "px";
  87. this.oDiv.style.visibility = "visible";
  88. this.oImg.style.visibility = "visible";
  89.  
  90. // start the animation engine.
  91. if ( !this.bTicks )
  92. {
  93. this.bTicks = true;
  94. var pThis = this;
  95. window.setTimeout(function(){pThis.tick();},25);
  96. }
  97. }
  98. ImageExpander.prototype.reduce = function()
  99. {
  100. // set direction of expansion.
  101. this.bExpand = false;
  102. }
  103. ImageExpander.prototype.tick = function()
  104. {
  105. // calculate screen dimensions
  106. var cw = document.body.clientWidth;
  107. var ch = document.body.clientHeight;
  108. var cx = document.body.scrollLeft + cw / 2;
  109. var cy = document.body.scrollTop + ch / 2;
  110.  
  111. // calculate target
  112. var tw,th,tx,ty;
  113. if ( this.bExpand )
  114. {
  115. tw = this.bigWidth;
  116. th = this.bigHeight;
  117. if ( tw > cw )
  118. {
  119. th *= cw / tw;
  120. tw = cw;
  121. }
  122. if ( th > ch )
  123. {
  124. tw *= ch / th;
  125. th = ch;
  126. }
  127. tx = cx - tw / 2;
  128. ty = cy - th / 2;
  129. }
  130. else
  131. {
  132. tw = this.smallWidth;
  133. th = this.smallHeight;
  134. tx = this.oThumb.offsetLeft;
  135. ty = this.oThumb.offsetTop;
  136. }
  137. // move 5% closer to target
  138. var nHit = 0;
  139. var fMove = function(n,tn)
  140. {
  141. var dn = tn - n;
  142. if ( Math.abs(dn) < 3 )
  143. {
  144. nHit++;
  145. return tn;
  146. }
  147. else
  148. {
  149. return n + dn / 10;
  150. }
  151. }
  152. this.x = fMove(this.x, tx);
  153. this.y = fMove(this.y, ty);
  154. this.w = fMove(this.w, tw);
  155. this.h = fMove(this.h, th);
  156.  
  157. this.oDiv.style.left = this.x + "px";
  158. this.oDiv.style.top = this.y + "px";
  159. this.oImg.style.width = this.w + "px";
  160. this.oImg.style.height = this.h + "px";
  161.  
  162. // if reducing and size/position is a match, stop the tick
  163. if ( !this.bExpand && (nHit == 4) )
  164. {
  165. this.oImg.style.visibility = "hidden";
  166. this.oDiv.style.visibility = "hidden";
  167. this.oThumb.style.visibility = "visible";
  168.  
  169. this.bTicks = false;
  170. }
  171.  
  172. if ( this.bTicks )
  173. {
  174. var pThis = this;
  175. window.setTimeout(function(){pThis.tick();},25);
  176. }
  177. }

normally you would write a thumbnail for this code like so

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
  2. <img src="spike_thumb.jpg" title="click to expand." style="float:right;" onclick="new ImageExpander(this, 'spike.jpg');">
  3. </a>

Example of the code above here

http://www.webreference.com/programm.../ImageView.htm

I know I need to Alter this line in the first code both times

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. imgs[p].onclick=new
  2. Function("iw=window.open(this.src,'ImageViewer','resizable=1 ,scrollbars=1');iw.focus()");

but im not sure how.
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 21st, 2008
0

Re: Firefox Compatibility help with script

How can parse an img url as query string to insert an image into a window on another domain?
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 21st, 2008
0

Re: Firefox Compatibility help with script

If you have the image on a server (whichever), just place the url on the "a" tag...

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="spike.jpg" onclick="this.href = 'javascript:void(0);';">
  2. <img src="http://www.myserver.com/images/spike_thumb.jpg" title="click to expand." style="float:right;" onclick="new ImageExpander(this, 'http://www.myserver2.com/images/spike.jpg');">
  3. </a>
Reputation Points: 10
Solved Threads: 4
Newbie Poster
HenryGR is offline Offline
24 posts
since Mar 2008
Apr 22nd, 2008
0

Re: Firefox Compatibility help with script

Sorry, I have confused this topic by suggesting an entirely different code.
It is the first code i posted that I wish to use, parsing the image url to a custom page on a new server.
please disregard post #11
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 22nd, 2008
0

Re: Firefox Compatibility help with script

The first code opens a new window, I want to use a custom window on another domain.
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 24th, 2008
0

Re: Firefox Compatibility help with script

Bump! does anyone understand me?
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 24th, 2008
0

Re: Firefox Compatibility help with script

can I rework the code to load the full size image in a hidden floating div above the page instead?
just add a close button to the div?
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 25th, 2008
0

Re: Firefox Compatibility help with script

Click to Expand / Collapse  Quote originally posted by Inny ...
How can parse an img url as query string to insert an image into a window on another domain?
You can't access the DOM of a window on another domain opened by your domain. This is a restriction that prevents XSS (cross/same domain policy)

If you own the other domain, then you can have PHP display the image by crafting a URL that tells it the image to display and dimensions.
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Apr 25th, 2008
0

Re: Firefox Compatibility help with script

can I rework the code to load the full size image in a hidden floating div above the page instead?
just add a close button to the div?
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005
Apr 26th, 2008
0

Re: Firefox Compatibility help with script

Bump!
Reputation Points: 11
Solved Threads: 6
Posting Whiz in Training
Inny is offline Offline
293 posts
since Oct 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Writing To div. Why wont this work?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Keep sub-window on top of main window





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC