[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 /** 2 * reflection.js v1.5 3 * 4 * Contributors: Cow http://cow.neondragon.net 5 * Gfx http://www.jroller.com/page/gfx/ 6 * Sitharus http://www.sitharus.com 7 * Andreas Linde http://www.andreaslinde.de 8 * Tralala, coder @ http://www.vbulletin.org 9 * 10 * Freely distributable under MIT-style license. 11 */ 12 13 /* From prototype.js */ 14 document.getElementsByClassName = function(className) { 15 var children = document.getElementsByTagName('*') || document.all; 16 var elements = new Array(); 17 18 for (var i = 0; i < children.length; i++) { 19 var child = children[i]; 20 var classNames = child.className.split(' '); 21 for (var j = 0; j < classNames.length; j++) { 22 if (classNames[j] == className) { 23 elements.push(child); 24 break; 25 } 26 } 27 } 28 return elements; 29 } 30 31 var Reflection = { 32 defaultHeight : 0.5, 33 defaultOpacity: 0.5, 34 35 add: function(image, options) { 36 Reflection.remove(image); 37 38 doptions = { "height" : Reflection.defaultHeight, "opacity" : Reflection.defaultOpacity } 39 if (options) { 40 for (var i in doptions) { 41 if (!options[i]) { 42 options[i] = doptions[i]; 43 } 44 } 45 } else { 46 options = doptions; 47 } 48 49 try { 50 var d = document.createElement('div'); 51 var p = image; 52 53 var classes = p.className.split(' '); 54 var newClasses = ''; 55 for (j=0;j<classes.length;j++) { 56 if (classes[j] != "reflect") { 57 if (newClasses) { 58 newClasses += ' ' 59 } 60 61 newClasses += classes[j]; 62 } 63 } 64 65 var reflectionHeight = Math.floor(p.height*options['height']); 66 var divHeight = Math.floor(p.height*(1+options['height'])); 67 68 var reflectionWidth = p.width; 69 70 /* Copy original image's classes & styles to div */ 71 d.className = newClasses; 72 p.className = 'reflected'; 73 74 d.style.cssText = p.style.cssText; 75 p.style.cssText = ' '; 76 77 if (document.all && !window.opera) { 78 var reflection = document.createElement('img'); 79 reflection.src = p.src; 80 reflection.style.width = reflectionWidth+'px'; 81 82 reflection.style.marginBottom = "-"+(p.height-reflectionHeight)+'px'; 83 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)+')'; 84 85 d.style.width = reflectionWidth+'px'; 86 d.style.height = divHeight+'px'; 87 p.parentNode.replaceChild(d, p); 88 89 d.appendChild(p); 90 d.appendChild(reflection); 91 } else { 92 var canvas = document.createElement('canvas'); 93 var context = canvas.getContext("2d"); 94 95 canvas.style.height = reflectionHeight+'px'; 96 canvas.style.width = reflectionWidth+'px'; 97 canvas.height = reflectionHeight; 98 canvas.width = reflectionWidth; 99 100 d.style.width = reflectionWidth+'px'; 101 d.style.height = divHeight+'px'; 102 p.parentNode.replaceChild(d, p); 103 104 d.appendChild(p); 105 d.appendChild(canvas); 106 107 context.save(); 108 109 context.translate(0,image.height-1); 110 context.scale(1,-1); 111 112 context.drawImage(image, 0, 0, reflectionWidth, image.height); 113 114 context.restore(); 115 116 context.globalCompositeOperation = "destination-out"; 117 var gradient = context.createLinearGradient(0, 0, 0, reflectionHeight); 118 119 gradient.addColorStop(1, "rgba(255, 255, 255, 1.0)"); 120 gradient.addColorStop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")"); 121 122 context.fillStyle = gradient; 123 if (navigator.appVersion.indexOf('WebKit') != -1) { 124 context.fill(); 125 } else { 126 context.fillRect(0, 0, reflectionWidth, reflectionHeight*2); 127 } 128 } 129 } catch (e) { 130 } 131 }, 132 133 remove : function(image) { 134 if (image.className == "reflected") { 135 image.className = image.parentNode.className; 136 image.parentNode.parentNode.replaceChild(image, image.parentNode); 137 } 138 } 139 } 140 141 function addReflections() { 142 var rimages = document.getElementsByClassName('reflect'); 143 for (i=0;i<rimages.length;i++) { 144 var rheight = null; 145 var ropacity = null; 146 147 var classes = rimages[i].className.split(' '); 148 for (j=0;j<classes.length;j++) { 149 if (classes[j].indexOf("rheight") == 0) { 150 var rheight = classes[j].substring(7)/100; 151 } else if (classes[j].indexOf("ropacity") == 0) { 152 var ropacity = classes[j].substring(8)/100; 153 } 154 } 155 156 Reflection.add(rimages[i], { height: rheight, opacity : ropacity}); 157 } 158 } 159 160 var previousOnload = window.onload; 161 window.onload = function () { if(previousOnload) previousOnload(); addReflections(); }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |