Вход Регистрация
Файл: templates/backend/default/assets/plugins/jquery-craftmap/js/craftmap.js
Строк: 374
<?php
/* 
 * CraftMap
 * author: Marcin Dziewulski
 * web: http://www.jscraft.net
 * email: info@jscraft.net
 * license: http://www.jscraft.net/licensing.html
 */

(function($){
    $.
fn.craftmap = function(options) {
        var 
= {
            
cookiesfalse,
            
fullscreenfalse,
            
container: {
                
name'imgContent'
            
},
            
image: {
                
width1475,
                
height1200,
                
name'imgMap'
            
},
            
map: {
                
position'center'
            
},
            
marker: {
                
name'marker',
                
centertrue,
                
popuptrue,
                
popup_name'popup',
                
onClick: function(markerpopup){},
                
onClose: function(markerpopup){}
            },
            
controls: {
                
inittrue,
                
name'controls',
                
onClick: function(marker){}
            },
            
preloader: {
                
inittrue,
                
name'preloader',
                
onLoad: function(imgdimensions){}
            }
        }; 
// default settings
        
        
var = $.extend(trueDoptions); 
        
        return 
this.each(function(){
            var 
= $(this),
                
IMG M.find('.'+S.image.name),
                
= {
                    
init: function(){
                        
this._container.init();
                        if (
S.fullscreen) {
                            
this.fullscreen.init();
                            
this.fullscreen.resize();
                        }
                        
this._globals.init();
                        if (
S.preloader.initthis.preloader.init();
                        
this.map.init();
                        
this.marker.init();
                        if (
S.controls.initthis.controls.init();
                    },
                    
_container: {
                        
init: function(){
                            
P._container.css();
                            
P._container.wrap();
                        },
                        
css: function(){
                            var    
max = {
                                    
width'100%',
                                    
height'100%'
                                
};
                            
IMG.css(max);
                            var 
css = {
                                
position'relative'
                                
overflow'hidden'
                                
cursor'move'
                            
}
                            
M.css(css);
                        },
                        
wrap: function(){
                            var 
css = {
                                
zIndex'1'
                                
position'absolute',
                                
widthS.image.width,
                                
heightS.image.height
                            
}
                            
M.wrapInner($('<div />').addClass(S.container.name).css(css));
                        }
                    },
                    
_globals: {
                        
init: function(){
                            
M.find('.'+S.container.name),
                            
MARKER C.find('.'+S.marker.name),
                            
md falsemx 0my 0ex 0ey 0delta 0mv = [], interval 0,
                            
= {
                                
wM.width(),
                                
hM.height()
                            },
                            
= {
                                
wC.width(),
                                
hC.height()
                            }
                            if (
S.controls.init){
                                
CONTROLS = $('.'+S.controls.name).find('a');
                            }
                        }
                    },
                    
_mouse: {
                        
get: function(e){
                            var 
e.pageX,
                                
e.pageY
                            return {
'x'x'y'y}
                        },
                        
update: function(e){
                            var 
mouse P._mouse.get(e),
                                
mouse.x,
                                
mouse.y,
                                
movex x-mx,
                                
movey y-my,
                                
top ey+movey,
                                
left ex+movex,
                                
check P.map.position.check(lefttop),
                                
css = {
                                    
topcheck.y,
                                    
leftcheck.x
                                
}
                            
C.css(css);
                            if (
S.cookies){
                                
P.cookies.create('position'check.',' check.y7);
                            }
                        },
                        
decelerate: function(e){
                            var 
mv.lengthtimer 0;
                            if (
l){
                                var 
tc 20;
                                
interval setInterval(function(){
                                    var    
position C.position(), left position.lefttop position.top,
                                        
remain = (tc-timer)/tc,
                                        
last l-1,
                                        
xd = (mv[last].x-mv[0].x)/l,
                                        
yd = (mv[last].y-mv[0].y)/l,
                                        
vx xd*remain,
                                        
vy yd*remain,
                                        
coords P.map.position.check(vx+leftvy+top),
                                        
css = {
                                            
leftcoords.x,
                                            
topcoords.y
                                        
};
                                    
C.css(css);    
                                    ++
timer;
                                    if (
timer == tc){
                                        
clearInterval(interval);
                                        
timer 0;
                                    }
                                }, 
40);    
                            }
                        },
                        
wheel: {
                            
init: function(e){
                                
M.handle = function(e){
                                    
e.preventDefault();
                                    if (!
e) {
                                        
window.event;
                                    }
                                    if (
e.wheelDelta) {
                                        
delta e.wheelDelta/120;
                                        if (
window.opera) {
                                            
delta = -delta;
                                        }
                                    } else if (
e.detail) {
                                        
delta = -e.detail/3;
                                    }
                                }
                                if (
window.addEventListener){
                                    
window.addEventListener('DOMMouseScroll'M.handlefalse);
                                }    
                                
window.onmousewheel document.onmousewheel M.handle;
                            },
                            
remove: function(){
                                if (
window.removeEventListener){
                                    
window.removeEventListener('DOMMouseScroll'M.handlefalse);
                                }
                                
window.onmousewheel document.onmousewheel null;
                            }
                        }
                    },
                    
fullscreen: {
                        
init: function(){
                            var 
win = $(window), win.width(), win.height(),
                                
css = {
                                    
widthw,
                                    
heighth
                                
}
                            
M.css(css);
                        },
                        
resize: function(){
                            $(
window).resize(function(){
                                
P.fullscreen.init();
                                
= {
                                    
wM.width(),
                                    
hM.height()
                                }
                            });
                        }
                    },
                    
cookies: {
                        
create: function(namevaluedays) {
                            if (
days) {
                                var 
date = new Date(), set date.getTime() + (days 24 60 60 1000);
                                
date.setTime(set);
                                var 
expires '; expires=' date.toGMTString();
                            } else {
                                var 
expires '';
                            }
                            
document.cookie name+'='+value+expires+'; path=/';
                        },
                        
erase: function(name) {
                            
cookies.create(name'', -1);
                        },
                        
read: function(name) {
                            var 
name '=',
                                
ca document.cookie.split(';');
                            for(var 
i=0;ca.length;i++) {
                                var 
ca[i];
                                while (
c.charAt(0) == ' '){
                                    
c.substring(1c.length);
                                }
                                if (
c.indexOf(e) == 0){
                                    return 
c.substring(e.length,c.length);
                                }
                            }
                            return 
null;
                        }
                    },
                    
preloader: {
                        
init: function(){
                            var 
img = new Image(),
                                
src IMG.attr('src');
                            
P.preloader.create();
                            $(
img).addClass(S.image.name).attr('src'src).load(function(){
                                var 
= $(this),
                                    
css = {
                                        
widththis.width,
                                        
heightthis.height
                                    
}
                                
t.css(css);
                                
IMG.remove();
                                
P.preloader.remove();
                                
S.preloader.onLoad.call(thistcss);
                            }).
appendTo(C);
                        },
                        
create: function(){
                            var 
css = {
                                
position'absolute'
                                
zIndex'10'
                                
top'0'
                                
left'0'
                                
width'100%'
                                
height'100%'
                            
}
                            
M.append($('<div />').addClass(S.preloader.name).css(css));
                        },
                        
remove: function(){
                            
M.find('.'+S.preloader.name).fadeOut(400, function(){
                                var 
= $(this);
                                
t.remove();
                            });
                        }
                    },
                    
map: {
                        
init: function(){
                            
P.map.position.set();
                            
P.map.move();
                        },
                        
position: {
                            
set: function(){
                                if (
S.cookies){
                                    if (
typeof P.cookies.read('position') != 'null') {
                                        var 
position P.cookies.read('position').split(','), 
                                            
position[0], 
                                            
position[1];
                                    } else {
                                        var 
= (D.w-I.w)/2
                                            
= (D.h-I.h)/2;
                                    }
                                } else {
                                    var 
position S.map.position;
                                    switch (
position){
                                        case 
'center':
                                            var 
= (D.w-I.w)/2,
                                                
= (D.h-I.h)/2;
                                            break;
                                        case 
'top_left':
                                            var 
0,
                                                
0;
                                            break;
                                        case 
'top_right':
                                            var 
D.w-I.w,
                                                
0;
                                            break;
                                        case 
'bottom_left':
                                            var 
0,
                                                
D.h-I.h;
                                            break;
                                        case 
'bottom_right':
                                            var 
D.w-I.w,
                                                
D.h-I.h;
                                            break;
                                        default:
                                            var 
coords position.split(' '),
                                                
= -(coords[0]),
                                                
= -(coords[1]),
                                                
coords P.map.position.check(xy),
                                                
coords.x,
                                                
coords.y;
                                    }    
                                }
                                var 
css = { topyleft}
                                
C.css(css);
                            },
                            
check: function(xy){
                                if (
< (D.h-I.h)){
                                    
D.h-I.h;
                                } else if (
0){
                                    
0;
                                }
                                
                                if (
< (D.w-I.w)){
                                    
D.w-I.w;
                                } else if (
x>0){
                                    
0;
                                }
                                return {
'x'x'y'y}
                            }
                        },
                        
move: function(){
                            
C.bind({
                                
mousedown: function(e){
                                    
md true;
                                    var 
mouse P._mouse.get(e);
                                        
mx mouse.x,
                                        
my mouse.y;
                                    var 
el C.position();
                                        
ex el.left,
                                        
ey el.top;
                                        
mv = [];
                                        
clearInterval(interval);
                                    
P._mouse.update(e);
                                    return 
false;
                                },
                                
mousemove: function(e){
                                    if (
md) {
                                        
P._mouse.update(e);
                                        var 
mouse =  P._mouse.get(e),
                                            
coords = {
                                                
xmouse.x,
                                                
ymouse.y
                                            
}
                                        
mv.push(coords);
                                        if (
mv.length 15){
                                            
mv.pop();
                                        }    
                                    }
                                    return 
false;
                                },
                                
mouseup: function(e){
                                    if (
md)    md false;
                                    
P._mouse.decelerate(e);
                                    return 
false;
                                },
                                
mouseout: function(){
                                    if (
md)    md false;
                                    
P._mouse.wheel.remove();
                                    return 
false;
                                },
                                
mouseover: function(e){
                                    
P._mouse.wheel.init(e);
                                    return 
false;
                                },
                                
mousewheel: function(e){
                                    
P._zoom.init(e);
                                }
                            });
                        }
                    },
                    
_zoom: {
                        
init: function(e){}
                    },
                    
marker: {
                        
init: function(){
                            
P.marker.set();
                            
P.marker.open();
                            
P.marker.close();
                        },
                        
set: function(){
                            
MARKER.each(function(){
                                var 
= $(this), position t.attr('data-coords').split(',');
                                    
parseInt(position[0]), parseInt(position[1]),
                                    
css = {
                                        
position'absolute',
                                        
zIndex'2',
                                        
topy,
                                        
leftx
                                    
}
                                
t.css(css);
                            }).
wrapInner($('<div />').addClass(S.marker.name+'Content').hide());
                        },
                        
open: function(){
                            
MARKER.live('click', function(){
                                var 
= $(this), id t.attr('id'), marker S.markert.width(), t.height(),
                                    
position t.position(), position.leftposition.topid t.attr('id'),
                                    
html t.find('.'+marker.name+'Content').html();
                                    
                                if (
marker.center){
                                    var 
cy = -y+D.h/2-h/2,
                                        
cx = -x+D.w/2-w/2,
                                        
P.map.position.check(cxcy),
                                        
animate = {
                                            
topc.y,
                                            
leftc.x
                                        
};
                                    
C.animate(animate);
                                }
                                
                                if (
marker.popup){
                                    $(
'.'+marker.popup_name).remove();
                                    var 
css = {
                                        
position:'absolute'
                                        
zIndex:'3'
                                    
}
                                    
t.after(
                                        $(
'<div />').addClass(marker.popup_name+' '+id).css(css).html(html).append(
                                            $(
'<a />').addClass('close')
                                        )
                                    );
                                    var 
POPUP t.next('.'+marker.popup_name), 
                                        
pw POPUP.innerWidth(), 
                                        
ph POPUP.innerHeight(),
                                        
x0 0y0 0;
                                    
                                    if (
x-pw 0){
                                        
x0 x;
                                    } else if (
x+pw/I.w){
                                        
x0 x-pw+w;
                                    } else {
                                        
x0 x-(pw/2-w/2);
                                    }
                                    
                                    if (
y-ph 0){
                                        
y0 y+h+h/1.5;
                                    } else {
                                        
y0 y-ph-h/1.5;
                                    }
                                    
                                    if (
x-pw && y-ph 0){
                                        
x0 x+w*2;
                                        
y0 y-h/2;
                                    } else if (
y-ph && x+pw/I.w){
                                        
x0 x-pw-w/2;
                                        
y0 y-h/2;
                                    } else if (
y+ph I.&& x+pw/I.w){
                                        
x0 x-pw+w;
                                        
y0 y-ph-h/2;
                                    } else if (
y+ph I.&& x-pw 0){
                                        
x0 x;
                                        
y0 y-ph-h/2;
                                    }
                                    
                                    var    
css = {
                                            
leftx0,
                                            
topy0
                                        
}
                                    
POPUP.css(css);
                                }
                                
P.controls.active.set(id);
                                
marker.onClick.call(thistPOPUP); 
                                return 
false;
                            });
                        },
                        
close: function(){
                            
C.find('.close').live('click', function(){
                                var 
= $(this), popup t.parents('.'+S.marker.popup_name), marker popup.prev('.'+S.marker.name);
                                
popup.remove();
                                
P.controls.active.remove();
                                
S.marker.onClose.call(thismarkerpopup);
                                return 
false;
                            });
                        }
                    },
                    
controls: {
                        
init: function(){
                            
P.controls.set();
                        },
                        
set: function(){
                            
CONTROLS.click(function(){
                                var 
= $(this), rel t.attr('rel');
                                
div C.find('.'S.marker.name).filter('#'+rel);
                                
div.trigger('click');
                                
S.controls.onClick.call(thisdiv);
                                return 
false;
                            });
                        },
                        
active: {
                            
set: function(id){
                                if (
S.controls.init){
                                    
CONTROLS.removeClass('active').filter(function(){
                                        return 
this.rel == id;
                                    }).
addClass('active');
                                }
                            },
                            
remove: function(){
                                if (
S.controls.init) {
                                    
CONTROLS.removeClass('active');
                                }
                            }
                        }
                    }
                }
            
P.init();
        });
    };
}(
jQuery));
?>
Онлайн: 1
Реклама