Changeset 486830
- Timestamp:
- 01/09/2012 12:25:31 PM (14 years ago)
- File:
-
- 1 edited
-
glass/trunk/glass.js (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
glass/trunk/glass.js
r481324 r486830 1 // 2 // // Try to find the margins on all parent of the image. 3 // o = obj; 4 // do { 5 // o = o.parentNode; 6 // 7 // // Get the marginLeft, marginTop. 8 // // 9 // if (o.currentStyle) { // CSS style for IE & Opera 10 // mleft = o.currentStyle['margin-left']; 11 // mtop = o.currentStyle['margin-top']; 12 // } 13 // else if (window.getComputedStyle) { // CSS style for Firefox 14 // style = document.defaultView.getComputedStyle(o, null); 15 // mleft = style.getPropertyValue('margin-left'); 16 // mtop = style.getPropertyValue('margin-top'); 17 // } 18 // 19 // if (mleft != '0px' || mtop != '0px') { 20 // // Use dummyImg to convert the strings to pixel counts. 21 // // 22 // with(document.body.glass.my.dummyImg) { 23 // style.width = mleft; 24 // style.height = mtop; 25 // o.absoluteX += width; 26 // o.absoluteY += height; 27 // 28 // alert("t,l " + mleft + "," + mtop + " = " + width + "," + height); 29 // } 30 // } 31 // 32 // } while (o && o.tagName.toLowerCase() != 'body'); 33 // 34 // 35 36 1 37 ///////////////////////////////////////////////////////////////////////////// 2 38 // … … 169 205 } 170 206 207 208 171 209 // AddAbsoluteXY: Add absoluteX and Y to properties of object. 172 210 // … … 180 218 obj.absoluteY = 0; 181 219 182 while (o && o.offsetParent) {220 while (o) { // && o.offsetParent) { 183 221 obj.absoluteX += o.offsetLeft; 184 222 obj.absoluteY += o.offsetTop; … … 265 303 borderTop = borderBottom = '0'; 266 304 267 // Get the Left, T ip, Right, and Bottom widths from the style.305 // Get the Left, Top, Right, and Bottom widths from the style. 268 306 // 269 307 if (obj.currentStyle) { // CSS style for IE & Opera … … 510 548 style.maxHeight = 'none'; 511 549 } 512 document.body. appendChild(dummyImg);550 document.body.glass.my.parent.appendChild(dummyImg); 513 551 return dummyImg; 514 552 } … … 655 693 node = null; 656 694 657 if (event.touches.length == 2) {695 if (touches.length == 2) { 658 696 // Find the lowres image. 659 697 if (touches[0].target) … … 666 704 glassTouchSetSize(event); 667 705 myevent = new Object(); 668 myevent.pageX = ( event.touches[0].pageX + event.touches[1].pageX) / 2;669 myevent.pageY = ( event.touches[0].pageY + event.touches[1].pageY) / 2;706 myevent.pageX = (touches[0].pageX + touches[1].pageX) / 2; 707 myevent.pageY = (touches[0].pageY + touches[1].pageY) / 2; 670 708 glassStart(node, myevent); 671 709 } … … 677 715 function glassTouchEnd(event) 678 716 { 679 if (event.touches.length < 2)717 if (event.touches.length < 2) 680 718 document.body.glass.style.display = "none"; 681 719 } … … 684 722 // <img> and a text <p> inside. 685 723 // 686 function glassSetup( )724 function glassSetup(parent) 687 725 { 688 726 // Create the glass as a div object. 689 727 glass = document.body.glass = document.createElement("div"); 690 728 document.body.glass.my = new Object(); 729 document.body.glass.my.parent = parent; 691 730 692 731 // Since a double click also causes at least one (single) click … … 814 853 815 854 // Add the glass to the document. 816 document.body.appendChild(glass);855 parent.appendChild(glass); 817 856 818 857 // Add some functionality to the glass here. … … 974 1013 function glassCreate(size) 975 1014 { 976 glassSetup(); // Note a Resize is needed after this.977 glassResize(size); // Resize can be called again and again.978 if (gGlassRimPath == '') {979 glassSetRGB(document.myrtheGlassRimRGB || 'FF3300');980 }981 1015 } 982 1016 … … 1009 1043 // none, so this probably won't break anything. 1010 1044 // 1011 function glassInit() 1045 1046 1047 1048 1049 function insertGlass(parent) 1012 1050 { 1013 1051 // Set the path to the rim images. 1014 1052 gGlassRimPath = (document.myrtheGlassRimPath || ''); 1015 1053 1016 // Actually create the glass. 1017 glassCreate(document.myrtheGlassDefaultSize || 5); 1018 1054 // Create the glass a resize is needed to complete the setup. 1055 glassSetup(parent || document.body); 1056 glassResize(document.myrtheGlassDefaultSize || 5); 1057 1058 // If a user selectable color is used, set it. 1059 if (gGlassRimPath == '') { 1060 glassSetRGB(document.myrtheGlassRimRGB || 'FF3300'); 1061 } 1062 } 1063 1064 1065 1066 // ActivateImage: make the image react to a touchstart or mouseover 1067 // and start loading the hires image. 1068 // 1069 function activateImage(img) 1070 { 1071 if ('ontouchstart' in img) 1072 img.ontouchstart = glassTouchStart; // iOS/Safari hook. 1073 else 1074 img.onmouseover = glassMouseStart; // Turn on the glass. 1075 1076 cc = 0; 1077 if (!document.body.glass) { 1078 parent = img; 1079 while(parent.tagName.toLowerCase() !='body') { 1080 parent = parent.parentNode; 1081 cc += 1; 1082 } 1083 parent = document.body; 1084 insertGlass(parent); 1085 alert("Took " + cc + " parents."); 1086 } 1087 1088 img.hires.preload = createDummyImage(img.hires.URL); // Preload. 1089 img.hires.preload.onload = glassRefresh; // Hide "Loading." layer. 1090 } 1091 1092 1093 function glassInit() 1094 { 1019 1095 // Loop through all the images on the page. 1020 1096 a_img = document.getElementsByTagName("img"); … … 1035 1111 img.hires = new Object(); 1036 1112 img.hires.URL = img.parentNode.href; 1037 img.hires.preload = createDummyImage(img.hires.URL); // Preload. 1038 img.hires.preload.onload = glassRefresh; // Hide "Loading." layer. 1039 if ('ontouchstart' in img) 1040 img.ontouchstart = glassTouchStart; // iOS/Safari hook. 1041 else 1042 img.onmouseover = glassMouseStart; // Turn on the glass. 1113 1114 activateImage(img); 1043 1115 } 1044 1116 else if (document.myrtheGlassDx && document.myrtheGlassDy) { … … 1065 1137 img.hires.URL = am[1] + '-'+dx+'x'+dy + am[3]; 1066 1138 } 1067 img.hires.preload = createDummyImage(img.hires.URL); // Preload. 1068 img.hires.preload.onload = glassRefresh; // Hide "Loading." layer. 1069 if ('ontouchstart' in img) 1070 img.ontouchstart = glassTouchStart; // iOS/Safari hook. 1071 else 1072 img.onmouseover = glassMouseStart; // Turn on the glass. 1139 1140 activateImage(img); 1073 1141 1074 1142 // Since an image can be either dx,dy or dy,dx sized,
Note: See TracChangeset
for help on using the changeset viewer.