1/** 2 * reflection.js v2.0 3 * http://cow.neondragon.net/stuff/reflection/ 4 * Freely distributable under MIT-style license. 5 */ 6 7/* From prototype.js */ 8if (!document.myGetElementsByClassName) { 9 document.myGetElementsByClassName = function(className) { 10 var children = document.getElementsByTagName('*') || document.all; 11 var elements = new Array(); 12 13 for (var i = 0; i < children.length; i++) { 14 var child = children[i]; 15 var classNames = child.className.split(' '); 16 for (var j = 0; j < classNames.length; j++) { 17 if (classNames[j] == className) { 18 elements.push(child); 19 break; 20 } 21 } 22 } 23 return elements; 24 } 25} 26 27var Reflection = { 28 defaultHeight : 0.5, 29 defaultOpacity: 0.5, 30 31 add: function(image, options) { 32 Reflection.remove(image); 33 34 doptions = { "height" : Reflection.defaultHeight, "opacity" : Reflection.defaultOpacity } 35 if (options) { 36 for (var i in doptions) { 37 if (!options[i]) { 38 options[i] = doptions[i]; 39 } 40 } 41 } else { 42 options = doptions; 43 } 44 45 try { 46 var d = document.createElement('div'); 47 var p = image; 48 49 var classes = p.className.split(' '); 50 var newClasses = ''; 51 for (j=0;j<classes.length;j++) { 52 if (classes[j] != "reflect") { 53 if (newClasses) { 54 newClasses += ' ' 55 } 56 57 newClasses += classes[j]; 58 } 59 } 60 61 var reflectionHeight = Math.floor(p.height*options['height']); 62 var divHeight = Math.floor(p.height*(1+options['height'])); 63 64 var reflectionWidth = p.width; 65 66 if (document.all && !window.opera) { 67 /* Fix hyperlinks */ 68 if(p.parentElement.tagName == 'A') { 69 var d = document.createElement('a'); 70 d.href = p.parentElement.href; 71 } 72 73 /* Copy original image's classes & styles to div */ 74 d.className = newClasses; 75 p.className = 'reflected'; 76 77 d.style.cssText = p.style.cssText; 78 p.style.cssText = 'vertical-align: bottom'; 79 80 var reflection = document.createElement('img'); 81 reflection.src = p.src; 82 reflection.style.width = reflectionWidth+'px'; 83 reflection.style.display = 'block'; 84 reflection.style.height = p.height+"px"; 85 86 reflection.style.marginBottom = "-"+(p.height-reflectionHeight)+'px'; 87 reflection.style.filter = 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options['opacity']*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')'; 88 89 d.style.width = reflectionWidth+'px'; 90 d.style.height = divHeight+'px'; 91 p.parentNode.replaceChild(d, p); 92 93 d.appendChild(p); 94 d.appendChild(reflection); 95 } else { 96 var canvas = document.createElement('canvas'); 97 if (canvas.getContext) { 98 /* Copy original image's classes & styles to div */ 99 d.className = newClasses; 100 p.className = 'reflected'; 101 102 d.style.cssText = p.style.cssText; 103 p.style.cssText = 'vertical-align: bottom'; 104 105 var context = canvas.getContext("2d"); 106 107 canvas.style.height = reflectionHeight+'px'; 108 canvas.style.width = reflectionWidth+'px'; 109 canvas.height = reflectionHeight; 110 canvas.width = reflectionWidth; 111 112 d.style.width = reflectionWidth+'px'; 113 d.style.height = divHeight+'px'; 114 p.parentNode.replaceChild(d, p); 115 116 d.appendChild(p); 117 d.appendChild(canvas); 118 119 context.save(); 120 121 context.translate(0,image.height-1); 122 context.scale(1,-1); 123 124 context.drawImage(image, 0, 0, reflectionWidth, image.height); 125 126 context.restore(); 127 128 context.globalCompositeOperation = "destination-out"; 129 var gradient = context.createLinearGradient(0, 0, 0, reflectionHeight); 130 131 gradient.addColorStop(1, "rgba(255, 255, 255, 1.0)"); 132 gradient.addColorStop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")"); 133 134 context.fillStyle = gradient; 135 context.rect(0, 0, reflectionWidth, reflectionHeight*2); 136 context.fill(); 137 } 138 } 139 } catch (e) { 140 } 141 }, 142 143 remove : function(image) { 144 if (image.className == "reflected") { 145 image.className = image.parentNode.className; 146 image.parentNode.parentNode.replaceChild(image, image.parentNode); 147 } 148 } 149} 150 151function addReflections() { 152 var rimages = document.myGetElementsByClassName('reflect'); 153 for (i=0;i<rimages.length;i++) { 154 var rheight = null; 155 var ropacity = null; 156 157 var classes = rimages[i].className.split(' '); 158 for (j=0;j<classes.length;j++) { 159 if (classes[j].indexOf("rheight") == 0) { 160 var rheight = classes[j].substring(7)/100; 161 } else if (classes[j].indexOf("ropacity") == 0) { 162 var ropacity = classes[j].substring(8)/100; 163 } 164 } 165 166 Reflection.add(rimages[i], { height: rheight, opacity : ropacity}); 167 } 168} 169 170var previousOnload = window.onload; 171window.onload = function () { if(previousOnload) previousOnload(); addReflections(); }
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.