Skip to content

Instantly share code, notes, and snippets.

@edtoken
Created January 31, 2014 14:30
Show Gist options
  • Save edtoken/8733055 to your computer and use it in GitHub Desktop.
Save edtoken/8733055 to your computer and use it in GitHub Desktop.
//
//
//
//
/**
* Создаю галереи
*/
$.fn.createGallery = function()
{
return this.each(function(num){
var c = document.createElement('div');
c.id = 'car_' + num;
c.className = 'gg_block gg_' + num;
var wr = document.createElement('div');
wr.className = 'gg_wr';
var carousel = document.createDocumentFragment();
var items = $(this).find('dl');
$(wr).css('width', items.length * 160);
for(var i=0; i< items.length;i++)
{
var item = document.createElement('div');
var a = document.createElement('span');
a.setAttribute('href', $(items[i]).find('a').attr('href')) ;
a.setAttribute('data-href', 1) ;
a.setAttribute('data-fancybox-group', 'fg_'+num) ;
a.className = 'fancybox';
$(a).append($(items[i]).find('img')[0]);
item.appendChild(a);
carousel.appendChild(item);
}
wr.appendChild(carousel);
c.appendChild(wr);
$(this).find('.carousel').html(c);
});
}
/**
* Дополняю метод гугл апи для удаления маркеров
*/
google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i < this.markers.length; i++){
this.markers[i].setMap(null);
}
this.markers = new Array();
};
/**
* Определяет высоту и ширину экрана
* @return {array} [array[0] ширина aray[1] высота]
*/
function windoSize() {
var myWidth = 0, myHeight = 0;
var int1=0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
int1=1;
} else if( document.documentElement && ( document.documentElement.clientWidth ||
document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
int1=2;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
int1=3;
}
return [myWidth, myHeight];
}
/**
* data: опции передаваемые движком при загрузке страницы
*
* load: изменяется на true после загрузки
* state: ряд=колонка которые были изменены
*
* nav_speed: скорость навигации,
* что бы при загрузке страницы не было видно прокрутки в начале стоит 0
* при создании базовой вьюхи это значение будет равно c.load_nav_speed
*
* load_nav_speed: скорость навигации после загрузки
*
* debug: показывать ли отладочные комментарии
*
* models: модели
* views: вьюхи
* collections: коллекции
* router: роутер
*
* @type {Object}
*/
var c = {
data:data,
load:false,
state:{},
url:'/wp-content/themes/plax/ajax.php?action=',
getActPageInRow:function(r)
{
var key = _.keys(c.data.pages)[r];
var row = c.data.pages[key];
var col = (typeof(c.state[key]) == 'undefined') ? 0 : c.state[key];
var page = row[col];
return page;
},
nav_speed:0,
load_nav_speed:500,
debug:true,
models:{},
pages:{},
views:{},
collections:{},
router:{},
log:function(obj)
{
if(this.debug !== true) return;
console.log(obj);
}
};
/**
* Роутер.
* Имеет 2 метода
* index и default.Оба создают базовую вьюху с параметрами страницы.
*/
c.router = Backbone.Router.extend({
routes: {
'': 'index',
'*default': 'default_route'
},
index: function(){
if(c.debug == true) console.log('[c.router] : index');
if(typeof(c.views.base) == 'object'){
c.views.base.model.set({page:'', state:'preload', page_sctoll:true});
}else{
c.views.base = new c.views.base({page:'', state:'preload', page_sctoll:true});
}
c.views.base.model.trigger('change:page');
},
default_route:function(query)
{
if(c.debug == true) console.log('[c.router] : default_route');
if(query[query.length-1] == '/') query = query.substr(0, query.length-1);
if(typeof(c.views.base) == 'object'){
c.views.base.model.set({page:query, state:'preload', page_sctoll:true});
}else{
c.views.base = new c.views.base({page:query, state:'preload', page_sctoll:true});
}
}
});
/**
* Базовая модель.
*
* row: текущий ряд (число)
* row_obj: DOM объект текущего ряда
*
* col: текущая колонка (число)
* col_obj: DOM объект текущей колонки (страница, число)
*
* page: урл текущей страницы, который установил роутер
* page_id: id текущей страницы
* title: заголовок текущей страницы
*
* width: щирина экрана
* height: высота экрана
* scroll: текущая прокрутка страницы
* scroll_nav: применяет 2 значение true и false отключает навигацию при прокрутке
* direction: направление прокрутки странницы
*
* base_load: изменяет состояние после установки базовых размеров на true
* state: ряд, в котором произошли последние изменения
*
* @type {[type]}
*/
c.models.base = Backbone.Model.extend({
defaults:{
row:'',
row_obj:'',
col:'',
col_obj:'',
page:'',
page_id:0,
title:'',
width:0,
height:0,
scroll:0,
scroll_nav:false,
page_sctoll:false,
direction:0,
base_load:false,
state:{}
}
});
/**
* Модель карты
*/
c.models.map = Backbone.Model.extend({
defaults:{
map:'',
map_options:'',
},
initialize:function()
{
this.bind('change:map_options', this.ch_moptions, this);
this.bind('change:map', this.ch_map, this);
this.bind('change:rendererOptions', this.ch_rendererOptions, this);
this.bind('change:directionsDisplay', this.ch_directionsDisplay, this);
this.bind('change:panoramaOptions', this.ch_panoramaOptions, this);
this.bind('change:panorama', this.ch_panorama, this);
this.bind('change:marker_start', this.ch_marker_start, this);
this.bind('change:drive_request', this.ch_drive_request, this);
this.bind('change:dir_response', this.ch_dir_response, this);
this.bind('change:markerArray', this.ch_markerArray, this);
},
ch_markerArray:function()
{
var panorama_map = this.get('panorama_map');
for(var i=0;i<panorama_map.markers;i++)
{
panorama_map.markers[i].setMap(null);
}
var markerArray = this.get('markerArray');
for(var n in markerArray)
{
var pos = markerArray[n].getPosition();
var marker = new google.maps.Marker({
position: pos,
map: panorama_map,
title:'Кликните на маркере для просмотра позиции в street view если это возможно'
});
panorama_map.markers.push(marker);
}
},
ch_dir_response:function()
{
var that = this;
var markerArray = this.get('markerArray');
for(var ma in markerArray)
{
markerArray[ma].setMap(null);
}
var map = this.get('map');
var new_markerArray = [];
var dir_response = this.get('dir_response');
var myRoute = dir_response.routes[0].legs[0];
for (var i = 0; i < myRoute.steps.length; i++) {
var marker = new google.maps.Marker({
position: myRoute.steps[i].start_location,
map: map,
title:'Кликните на маркере для просмотра позиции в street view если это возможно'
});
that.attachInstructionText(marker, myRoute.steps[i].instructions);
new_markerArray[i] = marker;
}
this.set({markerArray:new_markerArray});
},
attachInstructionText:function(marker, text)
{
var that = this;
var map = this.get('map');
var sv = this.get('sv');
google.maps.event.addListener(marker, 'click', function(ev) {
sv.getPanoramaByLocation(ev.latLng, 50, that.setPanoPosition);
});
},
ch_drive_request:function()
{
var that = this;
var drive_request = this.get('drive_request');
var directionsService = this.get('directionsService');
directionsService.route(drive_request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
that.get('directionsDisplay').setDirections(response);
that.trigger('change:directionsDisplay');
that.set({dir_response:response});
that.get('marker_start').setMap(null);
that.get('marker_map').setMap(null);
}
});
},
ch_panorama:function()
{
var map = this.get('map');
var panorama = this.get('panorama');
map.setStreetView(panorama);
return this;
},
ch_panoramaOptions:function()
{
var panoramaOptions = this.get('panoramaOptions');
var panorama = this.get('panorama');
if(typeof(panorama) == 'undefined' || panorama == null || panorama == '')
{
var map_options = this.get('map_options');
var map_pano = new google.maps.Map(document.getElementById(this.view.pano.id),map_options);
map_pano.markers = [];
this.set({panorama_map:map_pano});
var panorama = map_pano.getStreetView();
panorama.setVisible(true);
}
panorama.setOptions(panoramaOptions);
this.set({panorama:panorama});
return this;
},
ch_directionsDisplay:function()
{
var directionsDisplay = this.get('directionsDisplay');
var map = this.get('map');
directionsDisplay.setMap(map);
return this;
},
ch_rendererOptions:function()
{
var rendererOptions = this.get('rendererOptions');
var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
this.set({directionsDisplay:directionsDisplay});
return this;
},
ch_map:function()
{
var that = this;
var map = this.get('map');
var marker = new google.maps.Marker({
position: map.center,
draggable:false,
icon:'/wp-content/themes/plax/img/icon_marker.png',
map: map
});
this.set({marker_map:marker});
google.maps.event.addListener(map, 'click', function(event) {
that.set_startDirection(event.latLng);
});
},
ch_moptions:function()
{
var map_options = this.get('map_options');
var map = new google.maps.Map(document.getElementById(this.view.map_block.id),map_options);
var rendererOptions = {
map: map
};
var panoramaOptions = {
position: map_options.center,
addressControlOptions: {
position: google.maps.ControlPosition.BOTTOM_CENTER
},
linksControl: false,
panControl: false,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL
},
enableCloseButton: false
};
this.set({map:map, rendererOptions:rendererOptions, panoramaOptions:panoramaOptions});
return this;
},
setPanoPosition:function(data, status)
{
var that = this.c.views.base.map.model;
if(status !== 'OK'){
that.view.pano.innerHTML = '';
that.set({panorama:null});
return this;
}
var panoramaOptions = that.get('panoramaOptions');
panoramaOptions.position = data.location.latLng;
that.set({panoramaOptions:panoramaOptions});
that.trigger('change:panoramaOptions');
return this;
},
ch_marker_start:function()
{
var start = this.get('marker_start').getPosition();
var end = this.get('marker_map').getPosition();
var request = {
origin:end,
destination:start,
travelMode: google.maps.TravelMode.DRIVING
};
this.set({drive_request:request});
return this;
},
set_startDirection:function(location)
{
var that = this;
var map = this.get('map');
var marker = this.get('marker_start');
var sv = this.get('sv');
if(typeof(marker) == 'undefined')
{
var marker = new google.maps.Marker({
position: location,
draggable:true,
map: map,
});
this.set({marker_start:marker});
sv.getPanoramaByLocation(location, 50, that.setPanoPosition);
return this;
}
marker.setPosition(location);
this.trigger('change:marker_start');
sv.getPanoramaByLocation(location, 50, that.setPanoPosition);
return this;
},
regen_map:function()
{
var that = this;
var map, directionsDisplay, directionsService, stepDisplay, panorama, sv;
var sv = new google.maps.StreetViewService();
var map_center = c.data.map_options.latlng.split(',');
var stepDisplay = new google.maps.InfoWindow();
var directionsService = new google.maps.DirectionsService();
var map_options = {
center:new google.maps.LatLng(map_center[0], map_center[1]),
zoom:c.data.map_options.zoom * 1,
disableDefaultUI: true
};
this.set({sv:sv, map_options:map_options, map_center:map_center, stepDisplay:stepDisplay, directionsService:directionsService});
}
});
/**
* Вьюха карты
*/
c.views.map = Backbone.View.extend({
el:document.getElementById('page_map'),
events:{
'click #closemib':'closemib'
},
initialize:function()
{
this.model = new c.models.map();
this.model.view = this;
this.model.bind('regen_map', this.model.regen_map, this.model);
this.model.bind('change', this.render, this);
this.mib = document.getElementById('mib');
this.stnavigate = document.getElementById('stnavigate');
this.pano = document.getElementById('pano');
this.map_block = document.getElementById('map_block');
this.model.trigger('regen_map');
},
render:function()
{
var data = this.model.toJSON();
if(data.panorama !== null)
{
this.$el.addClass('panorama');
}else{
this.$el.removeClass('panorama');
}
},
closemib:function()
{
$(this.mib).toggleClass('hidden');
}
});
/**
* Вьюха фиксированного горизонтального меню
*/
c.views.fixed_gor = Backbone.View.extend({
el:document.getElementById('site_nav'),
initialize:function()
{
this.model.bind('change:row', this.render, this);
return this;
},
render:function()
{
this.el.className = '';
type = 'other';
if(this.model.get('row') == 0) type = 'base';
this.$el.addClass(type);
return this;
}
});
/**
* Вьюха фиксированного правого меню
*/
c.views.fixed_nav = Backbone.View.extend({
el:document.getElementById('js_fiexed_nav'),
render:function()
{
if(c.debug == true) console.log('[c.views.fixed_nav] : render');
var state = c.state;
this.el.innerHTML = '';
for(var n in c.data.pages)
{
var r = c.data.pages[n];
var s = state[n];
s = 0;
var item = _.template("<li><a href='<%= url %>'><%= title %></a></li>");
this.$el.append(item(r[s]));
}
}
});
c.models.layout = Backbone.Model.extend({
defaults:{
title:'',
name:'',
info:'',
img:'',
swimming:'',
h:0,
t:0
},
url:function(){
return c.url + 'layout';
}
});
c.views.layout = Backbone.View.extend({
el:document.createElement('div'),
initialize:function(){
var that = this;
this.model = new c.models.layout();
this.model.view = this;
// this.model.bind('change', this.render, this);
$('.js_slayout').click(function(){
var h = this.getAttribute('data-house-id');
var t = this.getAttribute('data-type-id');
that.model.set({h:h,t:t}, {silent:true});
var options = {
success:function(){
// alert('success');
that.render();
},
error:function(){
// alert('error');
}
}
var attr = that.model.toJSON();
that.model.save(attr, options);
});
$('.js_aptype').click(function(){
$(this.parentNode.parentNode).find('.js_apblock').removeClass('active');
$(this.parentNode).addClass('active');
});
},
render:function()
{
var data = this.model.toJSON();
console.log(data);
var template = _.template($('#select_swim').html());
$('#f_modals').html(template(data));
$('#f_modals').fadeIn(300);
$('body').css('overflow', 'hidden').addClass('hidden');
// $('body').css('padding-right', '15px');
// $('body').css('width', 'auto');
}
});
/**
* Базовая вьюха
*/
c.views.base = Backbone.View.extend({
el:document.createElement('div'),
initialize:function()
{
if(c.debug == true) console.log('[c.views.base] : initialize');
var that = this;
this.model = new c.models.base();
this.fixed_nav = new c.views.fixed_nav({model:this.model});
this.fixed_gor = new c.views.fixed_gor({model: this.model});
this.layout = new c.views.layout();
this.model.bind('change:page', this.setPageRowCol, this);
this.model.bind('change:row', this.navigateRow, this);
this.model.bind('change:col', this.navigateCol, this);
this.model.bind('change:width', this.changeWidth, this);
this.model.bind('change:height', this.changeHeight, this);
this.model.bind('change:state', this.changeState, this);
this.model.bind('change:direction', this.changedDrection, this);
this.model.bind('change:scroll_nav', this.change_scrollnav, this);
this.model.bind('change:page_sctoll', this.ch_page_sctoll, this);
this.model.bind('nextpage', this.nextpage, this);
this.model.bind('prevpage', this.prevpage, this);
this.model.bind('change:base_load', this.base_generate, this);
var width_height = windoSize();
this.model.set({page:this.options.page, width:width_height[0], height:width_height[1]});
that.setBaseStyle();
c.nav_speed = c.load_nav_speed;
c.load = true;
},
ch_page_sctoll:function()
{
var that = this;
clearTimeout(that.model.get('timeout'));
var timeout = setTimeout(function() {
that.model.set({page_sctoll:false})
}, 600);
this.model.set({timeout:timeout});
},
nextpage:function(){
if(this.model.get('page_sctoll') === true) return;
// console.log(_.values(c.pages));
var key = _.keys(c.data.pages)[this.model.get('row')+1];
var row = _.values(c.data.pages)[this.model.get('row')+1];
var col = (c.state[key] != 'undefined') ? 0 : c.state[key];
if(typeof(key) == 'undefined' || typeof(row) == 'undefined' || typeof(col) == 'undefined') return this;
Backbone.history.navigate(decodeURIComponent(row[col].key), true);
},
prevpage:function(){
if(this.model.get('page_sctoll') === true) return;
var key = _.keys(c.data.pages)[this.model.get('row')-1];
var row = _.values(c.data.pages)[this.model.get('row')-1];
var col = (c.state[key] != 'undefined') ? 0 : c.state[key];
var pagekey = (row[col].key === false) ? '' : row[col].key;
if(typeof(key) == 'undefined' || typeof(row) == 'undefined' || typeof(col) == 'undefined') return this;
Backbone.history.navigate(decodeURIComponent(pagekey), true);
},
change_scrollnav:function()
{
// var sn = this.model.get('scroll_nav');
// if(sn === true) return;
// var that = this;
// clearTimeout(c.tm);
// var tm = setTimeout(function() {
// that.model.set({scroll_nav:true});
// }, c.load_nav_speed+300);
// c.tm = tm;
},
base_generate:function()
{
var that = this;
setTimeout(function() {
that.map = new c.views.map({model_base:that.model});
}, 500);
},
changedDrection:function()
{
if(c.debug == true) console.log('[c.views.base] : changedDrection');
var d = this.model.get('direction');
},
changeState:function()
{
if(c.debug == true) console.log('[c.views.base] : changeState');
this.fixed_nav.render();
},
setBaseStyle:function()
{
if(c.debug == true) console.log('[c.views.base] : setBaseStyle');
var rows = $('.row');
var h = this.model.get('height');
var w = this.model.get('width');
$('#page_body').css('height', Math.floor(h* rows.length));
for(var i=0;i<rows.length;i++)
{
var row = rows[i];
$(row).css('width', $(row).find('.col').length * w);
$(row).css('top', i * h);
row.style.top = i * h;
}
$('.h_10').css('height', Math.floor(h/10));
$('.h_30').css('height', Math.floor(h/3));
$('.h_40').css('height', Math.floor(h/10*4));
$('.h_50').css('height', Math.floor(h/2));
$('.h_70').css('height', Math.floor(h/3*2));
$('.w_10').css('width', Math.floor(w/10));
$('.w_30').css('width', Math.floor(w/3));
$('.w_40').css('width', Math.floor(w/10*4));
$('.w_50').css('width', Math.floor(w/2));
$('.w_70').css('width', Math.floor(w/3*2));
this.model.set({base_load:true});
$('#page_body').addClass('loaded');
},
changeWidth:function()
{
if(c.debug == true) console.log('[c.views.base] : changeWidth');
$('.col').css('width', this.model.get('width'));
return this;
},
changeHeight:function()
{
if(c.debug == true) console.log('[c.views.base] : changeHeight');
$('.col').css('height', this.model.get('height'));
$('.row').css('height', this.model.get('height'));
return this;
},
navigateRow:function()
{
if(c.debug == true) console.log('[c.views.base] : navigateRow');
var that = this;
var row_obj = document.getElementById('js_row_' + this.model.get('row'));
var top = this.model.get('row') * this.model.get('height');
setTimeout(function() {
that.model.set({row_obj:row_obj});
if(that.model.get('col') === 0) that.model.trigger('change:col');
$('.row').removeClass('active');
setTimeout(function() {
$(row_obj).addClass('active');
}, 100);
}, 100);
/**
* ыертикальный скролл страницы
* @type {[type]}
*/
// this.model.trigger('change:col');
jQuery("html,body").animate({scrollTop: row_obj.offsetTop}, 500);
},
navigateCol:function()
{
var that = this;
if(c.debug == true) console.log('[c.views.base] : navigateCol');
var col_obj = document.getElementById('js_c_'+this.model.get('col')+'_r_'+this.model.get('row'));
var row_obj = this.model.get('row_obj');
this.model.set({col_obj:col_obj})
$('.col').removeClass('active');
setTimeout(function() {
$(col_obj).addClass('active');
}, 100);
setTimeout(function() {
$(that.model.get('row_obj')).animate({
left:-col_obj.offsetLeft
}, 500);
var nav = $(row_obj).find('.child_nav a');
$(nav).removeClass('active');
var arritems = $(row_obj).find('article');
for(var ra=0; ra<arritems.length; ra++)
{
var arrnavs = $(arritems[ra]).find('.child_nav a');
var add = false;
for(var ia=0; ia<arrnavs.length; ia++)
{
if(add === true) continue;
var act = arrnavs[ia].href.indexOf(that.model.get('page'));
if(act >= 0) {
$(arrnavs[ia]).addClass('active');
add = true;
}
}
}
}, 100);
},
setPageRowCol:function()
{
if(c.debug == true) console.log('[c.views.base] : setPageRowCol');
var that = this;
var page = this.model.get('page');
var state = _.clone(c.state);
r=0;
top:
for(var n in c.data.pages)
{
col = 0;
for(var b in c.data.pages[n])
{
var pageobj = c.data.pages[n][b];
var key = pageobj.key;
if(key[key.length-1] == '/') key = key.substr(0, key.length-1);
if(key == page)
{
state[n] = col;
c.state = state;
this.model.set({row:r,col:col,page_id:pageobj.object_id,title: pageobj.title, state:state}, {silent:true});
this.model.trigger('change:row');
this.model.trigger('change:col');
this.model.trigger('change:page_id');
this.model.trigger('change:title');
this.model.trigger('change:state');
break top;
}else if(r==_.keys(c.data.pages).length-1 && col == _.keys(c.data.pages[n]).length-1 && key != page){
// alert('Эта страница не найдена');
}
col++;
}
r++;
}
return this;
}
});
(function(){
if(c.debug == true) console.log('[READY] : load');
/**
* галереи карусели
*/
$('.gallery_carousel').createGallery();
$('.fancybox').fancybox();
/**
* #галереи карусели
*/
$.fn.createGalleryH = function()
{
var setAttr = function(node, attrName, attrValue){
switch(attrName)
{
case 'idPrefix':
node.id = attrValue;
break;
case 'className':
node.className = attrValue;
break;
case 'style':
node.setAttribute('style', attrValue);
break;
case 'inner':
node.innerHTML = attrValue;
break;
default:
node.setAttribute(attrName, attrValue);
break;
};
return node;
};
var createNode = function(attrs)
{
var that = this;
if(!attrs.nodeName || attrs.nodeName.length <=0) return;
var node = document.createElement(attrs.nodeName);
delete attrs.nodeName;
// delete attrs.active;
for(var a in attrs){
if(a === 'onclick') continue;
if(typeof(attrs[a]) == 'function') attrs[a] = attrs[a].call(this);
if(attrs[a] === false) continue;
if(typeof(attrs[a]) == 'object'){
val = '';
for(var b in attrs[a]){
if(typeof(attrs[a][b]) == 'function') attrs[a][b] = attrs[a][b].call(this);
if(a === 'style'){
val += b + ':' + attrs[a][b] + ';';
}else{
val = attrs[a][b];
}
node = setAttr(node, a, val);
}
continue;
}
node = setAttr(node, a, attrs[a]);
}
if(typeof(attrs.onclick) != 'undefined') node.onclick = function(){
attrs.onclick.apply(that);
};
return node;
};
var month_i = 0;
var generateMonth = function()
{
var items = $(this).find('a');
var items_block = document.createElement('div');
items_block.id = 'alb_items_' + month_i;
$(items_block).css('display', 'none');
for(var i=0;i<items.length;i++)
{
var item = items[i];
$(item).addClass('fancybox');
item.setAttribute('data-fancybox-group', 'images_'+month_i);
items_block.appendChild(item);
if(i==0)
{
$(this.parentNode).append(item);
}
}
$(this).remove();
$('#albumimages').append(items_block);
month_i++;
}
return this.each(function(){
var month = $(this).find('.onemonth');
$(this).css('width', 980 * month.length);
for(var i=0; i< month.length; i++)
{
var cur_months = $(month[i]).find('.month_images');
for(var mi=0; mi<cur_months.length; mi++)
{
generateMonth.apply(cur_months[mi]);
}
}
});
}
$.fn.gnavigate = function()
{
var al = $(this).find('.albums_list');
var dw = $(this).find('.dateswrap ul');
var moveMonth = function(num)
{
};
var openMonth = function()
{
$('.gnav_item').removeClass('active');
var numbers = this.id.split('_');
var month = $('#mg_'+numbers[1]);
$('#0_'+numbers[1]+'.gnav_item').addClass('active');
$(al).animate({
left:-month[0].offsetLeft
}, 600);
$('.onemonth').removeClass('active');
$(month).addClass('active');
$('.gsp_item').removeClass('active');
$('#gsp_'+numbers[1]).addClass('active');
var items = $('.gnav_item');
$('.gnav_item').removeClass('disable');
for(var i=0; i<items.length;i++)
{
if(i+1 < numbers[1] * 1 - 1)
{
$(items[i]).addClass('disable');
}else if(i >= numbers[1]*1 + 2)
{
$(items[i]).addClass('disable');
}
}
};
$('.gnav_item').click(function(){
openMonth.apply(this);
});
$('.gsp_item').click(function(){
openMonth.apply(this);
});
var item = $('.gnav_item')[0];
$(item).click();
// console.log($($('.gnav_item')[0]));
// openMonth.apply($($('.gnav_item')[0]));
}
$.fn.gHnav = function()
{
itemsPosition = function()
{
var items = this.$el.find('li');
var circl = $('.dateswrap .circl');
var cw = $(circl).width();
var num = 0;
for(var i=0; i< items.length; i++)
{
var newtop = 240 - num * 65;
var newright = 240 - (40 * items.length - 40 * num);
if(i == 4)
{
num = 0;
var newtop = 240 - num * 65;
newright = 240 - (40 * items.length - 40 * num);
}
$(items[i]).css('top', -newtop);
$(items[i]).css('right', newright);
if(i == 0) $(items[i]).addClass('active');
items[i].id = this.num + '_' + (i+1);
items[i].className += ' gnav_item';
// $(items[i]).append('<span style="height:'+newtop+'px;"></span>');
var iw = Math.floor(cw/items.length);
$(circl).append('<span style="width:'+iw+'px;" class="gsp_item" id="gsp_' + (i+1)+'"></span>');
num++;
}
}
return this.each(function(i){
this.$el = $(this);
this.num = i;
itemsPosition.apply(this);
});
}
$('.albums_list').createGalleryH();
$('.dateswrap').gHnav();
$('.phwrap').gnavigate();
/**
* MODAL FORMS
*/
var view_form = function(){
var form_id = this.getAttribute('data-form_id');
var form = document.getElementById(form_id);
if(!form) return;
$('#forms_mask').fadeIn(300);
$(form).fadeIn(300);
$('body').css('overflow', 'hidden');
$('body').css('padding-right', '15px');
$('body').css('width', 'auto');
}
var close_form = function(){
$('.form_bg').fadeOut(300);
$('#forms_mask').fadeOut(300);
// if(document.getElementById('f_modals').innerHTML.length > 0) return;
$('body').css('overflow', '');
$('body').css('padding-right', '0');
$('body').css('width', '100%');
$('body').removeClass('hidden');
// $('body').attr('style', '');
};
$('body').on('click', '.modal', function(){
view_form.apply(this);
return false;
});
$('.closeForm').click(function(){
close_form();
});
$('#forms_mask').click(function(e){
if(e.target.id !== 'forms_mask') return;
close_form();
});
/**
* #MODAL FORMS
*/
var viewRomm = function()
{
var node = document.createElement('div');
node.setAttribute('data-form_id', 'form_1');
var r_id = this.getAttribute('data-room_id');
view_form.apply(node);
$('#form_1').find('#srrommtype').val('Интересует квартира №: ' + r_id);
}
document.getElementById('f_modals').onclick = function(e)
{
if(e.target.id!= 'f_modals') return;
$(this).fadeOut(300).html('');
$('body').css('overflow', '');
$('body').css('padding-right', '0');
$('body').css('width', '');
$('body').removeClass('hidden');
}
$('body').on('click', '.js_getord', function(){
viewRomm.apply(this);
});
$('body').on('click', '.modal', function(){
view_form.apply(this);
});
$('.currency span').click(function(){
var type = this.getAttribute('data-type') * 1;
var vals = this.parentNode.parentNode;
$(vals).find('.currency span').removeClass('active');
$(this).addClass('active');
var min = $(vals).find('.min')[0];
var max = $(vals).find('.max')[0];
if(min.getAttribute('data-base') == null) min.setAttribute('data-base', min.innerHTML.split(' ')[1]);
if(max.getAttribute('data-base') == null) max.setAttribute('data-base', max.innerHTML.split(' ')[1]);
var new_min = '';
var new_max = '';
switch(type)
{
case 1:
new_max = max.getAttribute('data-base');
new_min = min.getAttribute('data-base');
break;
case 2:
new_max = Math.ceil(max.getAttribute('data-base') * 1 / 35);
new_min = Math.ceil(min.getAttribute('data-base') * 1 / 35);
break;
case 3:
new_max = Math.ceil(max.getAttribute('data-base') * 1 / 47);
new_min = Math.ceil(min.getAttribute('data-base') * 1 / 47);
break;
}
min.innerHTML = 'От ' + new_min;
max.innerHTML = 'От ' + new_max;
// console.log(min, max, new_min, new/_max, type);
});
if(typeof(start) != 'undefined' && start == false) return this;
new c.router;
Backbone.history.start({pushState: true});
$(document).on('click', 'a:not([data-href])', function (evt) {
if(this.parentNode.className.indexOf('data-href') >= 0)
{
document.location.href = this.href;
return this;
}
if(c.debug == true) console.log('[click a:not([data-href]) ] : click');
if($(this).parent().id == 'wp-admin-bar-dashboard') document.location.href= '/wp-admin/';
var href = $(this).attr('href');
var protocol = this.protocol + '//';
if (href.slice(protocol.length) !== protocol) {
evt.preventDefault();
var url = href.split('://');
url = url[1].split('/');
var geturl = function(url)
{
var out = '';
for(var i=0; i<url.length; i++)
{
if(typeof(url[i+1]) != 'undefined'){
if(url[i] == 'par.local' || url[i] == 'par.user2d.ru') continue;
out += url[i] + '/';
}
}
return out;
}
url = geturl(url);
if(url == 'par.local' || url=='par.user2d.ru'){
url = '/';
}
c.views.base.model.set({scroll_nav:false});
Backbone.history.navigate(decodeURIComponent(url), true);
}
});
/**
* переключение навигации по скролу
* @param {[type]} nr [description]
* @return {[type]} [description]
*/
// var scrollNav = function(nr)
// {
// var page = c.getActPageInRow(nr);
// c.views.base.model.set({scroll_nav:false});
// var key = page.key;
// if(key === false) key = '';
// Backbone.history.navigate(decodeURIComponent(key), true);
// }
var tmpscroll = 0;
var tmpdir = 0;
$(window).on('scroll', function(s)
{
var event = s;
var d = c.views.base.model.toJSON();
var s = window.pageYOffset || document.documentElement.scrollTop;
/**
* Переключатель направления прокрутки
*/
if(s > tmpscroll)
{
direction = 1;
c.views.base.model.set({direction:1});
c.views.base.model.trigger('nextpage');
}else if(s < tmpscroll){
direction = -1;
c.views.base.model.set({direction:-1});
c.views.base.model.trigger('prevpage');
}else{
direction = 0;
c.views.base.model.set({direction:0});
}
tmpscroll = s;
c.views.base.model.set({scroll:s});
});
})();
$(document).ready(function(){
$('.fancybox').fancybox();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment