Вход Регистрация
Файл: gamele.ru/index/js/iepngfix_tilebg.js
Строк: 122
<?php
// IE5.5+ PNG Alpha Fix v2.0 Alpha: Background Tiling Support
// (c) 2008 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix window.IEPNGFix || {};

IEPNGFix.tileBG = function(elmpngSrcready) {
    
// Params: A reference to a DOM element, the PNG src file pathname, and a
    // hidden "ready-to-run" passed when called back after image preloading.

    
var data this.data[elm.uniqueID],
        
elmW Math.max(elm.clientWidthelm.scrollWidth),
        
elmH Math.max(elm.clientHeightelm.scrollHeight),
        
bgX elm.currentStyle.backgroundPositionX,
        
bgY elm.currentStyle.backgroundPositionY,
        
bgR elm.currentStyle.backgroundRepeat;

    
// Cache of DIVs created per element, and image preloader/data.
    
if (!data.tiles) {
        
data.tiles = {
            
elmelm,
            
src'',
            
cache: [],
            
img: new Image(),
            
old: {}
        };
    }
    var 
tiles data.tiles,
        
pngW tiles.img.width,
        
pngH tiles.img.height;

    if (
pngSrc) {
        if (!
ready && pngSrc != tiles.src) {
            
// New image? Preload it with a callback to detect dimensions.
            
tiles.img.onload = function() {
                
this.onload null;
                
IEPNGFix.tileBG(elmpngSrc1);
            };
            return 
tiles.img.src pngSrc;
        }
    } else {
        
// No image?
        
if (tiles.srcready 1;
        
pngW pngH 0;
    }
    
tiles.src pngSrc;

    if (!
ready && elmW == tiles.old.&& elmH == tiles.old.&&
        
bgX == tiles.old.&& bgY == tiles.old.&& bgR == tiles.old.r) {
        return;
    }

    
// Convert English and percentage positions to pixels.
    
var pos = {
            
top'0%',
            
left'0%',
            
center'50%',
            
bottom'100%',
            
right'100%'
        
},
        
x,
        
y,
        
pc;
    
pos[bgX] || bgX;
    
pos[bgY] || bgY;
    if (
pc x.match(/(d+)%/)) {
        
Math.round((elmW pngW) * (parseInt(pc[1]) / 100));
    }
    if (
pc y.match(/(d+)%/)) {
        
Math.round((elmH pngH) * (parseInt(pc[1]) / 100));
    }
    
parseInt(x);
    
parseInt(y);

    
// Handle backgroundRepeat.
    
var repeatX = { 'repeat'1'repeat-x'}[bgR],
        
repeatY = { 'repeat'1'repeat-y'}[bgR];
    if (
repeatX) {
        
%= pngW;
        if (
0-= pngW;
    }
    if (
repeatY) {
        
%= pngH;
        if (
0-= pngH;
    }

    
// Go!
    
this.hook.enabled 0;
    if (!({ 
relative1absolute}[elm.currentStyle.position])) {
        
elm.style.position 'relative';
    }
    var 
count 0,
        
xPos,
        
maxX repeatX elmW 0.1,
        
yPos,
        
maxY repeatY elmH 0.1,
        
d,
        
s,
        
isNew;
    if (
pngW && pngH) {
        for (
xPos xxPos maxXxPos += pngW) {
            for (
yPos yyPos maxYyPos += pngH) {
                
isNew 0;
                if (!
tiles.cache[count]) {
                    
tiles.cache[count] = document.createElement('div');
                    
isNew 1;
                }
                var 
clipR = (xPos pngW elmW elmW xPos pngW),
                    
clipB = (yPos pngH elmH elmH yPos pngH);
                
tiles.cache[count];
                
d.style;
                
s.behavior 'none';
                
s.left xPos 'px';
                
s.top yPos 'px';
                
s.width clipR 'px';
                
s.height clipB 'px';
                
s.clip 'rect(' +
                    (
yPos yPos 0) + 'px,' +
                    
clipR 'px,' +
                    
clipB 'px,' +
                    (
xPos xPos 0) + 'px)';
                
s.display 'block';
                if (
isNew) {
                    
s.position 'absolute';
                    
s.zIndex = -999;
                    if (
elm.firstChild) {
                        
elm.insertBefore(delm.firstChild);
                    } else {
                        
elm.appendChild(d);
                    }
                }
                
this.fix(dpngSrc0);
                
count++;
            }
        }
    }
    while (
count tiles.cache.length) {
        
this.fix(tiles.cache[count], ''0);
        
tiles.cache[count++].style.display 'none';
    }

    
this.hook.enabled 1;

    
// Cache so updates are infrequent.
    
tiles.old = {
        
welmW,
        
helmH,
        
xbgX,
        
ybgY,
        
rbgR
    
};
};


IEPNGFix.update = function() {
    
// Update all PNG backgrounds.
    
for (var i in IEPNGFix.data) {
        var 
IEPNGFix.data[i].tiles;
        if (
&& t.elm && t.src) {
            
IEPNGFix.tileBG(t.elmt.src);
        }
    }
};
IEPNGFix.update.timer 0;

if (
window.attachEvent && !window.opera) {
    
window.attachEvent('onresize', function() {
        
clearTimeout(IEPNGFix.update.timer);
        
IEPNGFix.update.timer setTimeout(IEPNGFix.update100);
    });
}
?>
Онлайн: 1
Реклама