You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
291 lines
7.5 KiB
291 lines
7.5 KiB
var EXPO = EXPO || {}; //isolated namespace
|
|
EXPO.profile = EXPO.profile || {};
|
|
if (EXPO.profile.calendar) {
|
|
console.warn('WARNING: EXPO.profile.calendar is already defined!');
|
|
} else {
|
|
|
|
EXPO.profile.calendar = (function () {
|
|
// dependencies
|
|
var com = EXPO.common;
|
|
|
|
// variables
|
|
var that = {};
|
|
|
|
that.opt = {}; //свойства по умолчанию
|
|
//private
|
|
$(function () {
|
|
/**
|
|
* events list below calendar
|
|
*/
|
|
$('#btn_delete').on('click', function(e){
|
|
e.preventDefault();
|
|
var expos = $("input[name=expo]:checkbox:checked").map(function(){
|
|
return $(this).val();
|
|
}).get();
|
|
var confs = $("input[name=conf]:checkbox:checked").map(function(){
|
|
return $(this).val();
|
|
}).get();
|
|
var seminars = $("input[name=seminar]:checkbox:checked").map(function(){
|
|
return $(this).val();
|
|
}).get();
|
|
var webinars = $("input[name=webinar]:checkbox:checked").map(function(){
|
|
return $(this).val();
|
|
}).get();
|
|
var sendData = {'expo': JSON.stringify(expos),
|
|
'conf':JSON.stringify(confs),
|
|
'seminar':JSON.stringify(seminars),
|
|
'webinar': JSON.stringify(webinars)}
|
|
$.get('/profile/calendar/remove/', sendData, function(data){
|
|
if(data.success){
|
|
location.reload();
|
|
}
|
|
})
|
|
});
|
|
});
|
|
|
|
// methods
|
|
//инициализация общих свойств
|
|
that.init = function (options) {
|
|
$.extend(this.opt, options);
|
|
|
|
/**
|
|
* scrolling calendar object
|
|
* depend on mCustomScroll Jquery plugin
|
|
* @type {*|jQuery|HTMLElement}
|
|
*/
|
|
var self = this,
|
|
$scrollBox = $('#' + this.opt.scrollBoxId),
|
|
$calendar = $('#' + this.opt.calenadrId),
|
|
currentDayOffset = $calendar.find('td.' + this.opt.currentDayClass).index() * this.opt.cellWidth,
|
|
$leftScroll = $('#' + this.opt.scrollLeftId),
|
|
$rightScroll = $('#' + this.opt.scrollRightId),
|
|
$noEventsField = $('.' + this.opt.noEventsClass),
|
|
$calendarToggle = $('.' + this.opt.calendarToggleClass),
|
|
scrollStep = this.opt.cellWidth * this.opt.cellsToScroll,
|
|
index = 0,
|
|
/**
|
|
*offset to curent week ( week in which today is)
|
|
* @returns {number} - offset in pixels
|
|
*/
|
|
//
|
|
currentWeekOffset = function () {
|
|
var offset = 0,
|
|
result = 0,
|
|
width = self.opt.cellWidth,
|
|
$calendar = $('#' + self.opt.calenadrId),
|
|
currentDay = $calendar.find('.'+self.opt.daysClass+' td.' + self.opt.currentDayClass).index(),
|
|
onestep = self.opt.cellsToScroll,
|
|
allDays = $calendar.find('.'+self.opt.daysClass+' td').length,
|
|
stepsCount,
|
|
currenCount;
|
|
|
|
if(currentDay > 0){
|
|
currentDay++;
|
|
stepsCount = allDays / onestep;
|
|
currenCount = allDays / currentDay;
|
|
|
|
result = Math.floor(stepsCount) - Math.floor(currenCount);
|
|
|
|
|
|
self.currentDay =currentDay;
|
|
if (result) {
|
|
result--;
|
|
result--;
|
|
offset = onestep * result * width;
|
|
} else {
|
|
|
|
offset = 0;
|
|
}
|
|
}else{
|
|
self.currentDay = 0;
|
|
offset = 0;
|
|
}
|
|
|
|
|
|
return offset;
|
|
|
|
};
|
|
this.$leftScroll = $leftScroll;
|
|
this.$rightScroll = $rightScroll;
|
|
this.currentOffset = currentWeekOffset();
|
|
//this.currentOffset = 0;
|
|
|
|
this.scrollStep = scrollStep;
|
|
this.$scrollBox = $scrollBox;
|
|
this.$messages = [];
|
|
this.stepWidth = self.opt.cellsToScroll*self.opt.cellWidth;
|
|
|
|
|
|
$(function () {
|
|
/**
|
|
* no marked events message
|
|
*/
|
|
$noEventsField.each(function () {
|
|
var parentOffset = parseInt($(this).offset().left, 10),
|
|
$message = $('.message',$(this));
|
|
/**
|
|
* remove sidebar width
|
|
*/
|
|
if(parentOffset){
|
|
parentOffset -=312;
|
|
}else{
|
|
parentOffset +=312;
|
|
}
|
|
if (!$(this).attr('colspan') || $(this).attr('colspan') == 1) {
|
|
$(this).find('.' + self.opt.eventWrapClass).addClass('small');
|
|
}else if($(this).width() > self.stepWidth){
|
|
$message.width(self.stepWidth)
|
|
if(parentOffset <0){
|
|
$message.css({marginLeft:Math.abs(parentOffset+ self.stepWidth)+'px'});
|
|
}
|
|
self.$messages.push($message);
|
|
}
|
|
});
|
|
$('.' + self.opt.eventsClass+":even").addClass('grey');
|
|
});
|
|
|
|
$(window).load(function () {
|
|
self.calendarWidth = self.opt.cellWidth* $calendar.find('.'+self.opt.daysClass+' td').length;
|
|
$scrollBox.mCustomScrollbar({
|
|
axis: 'y',
|
|
horizontalScroll: true,
|
|
setLeft:'-'+self.currentOffset+'px',
|
|
mouseWheel:{enable:false},
|
|
scrollButtons:{enable:false},
|
|
contentTouchScroll:false,
|
|
scrollInertia:1000,
|
|
timeout:0,
|
|
advanced: { // Advanced options
|
|
autoScrollOnFocus: false,
|
|
updateOnContentResize: false, // Scrollbar will be updated on content resize
|
|
updateOnBrowserResize: false // Scrollbar will be updated on browser resize
|
|
},
|
|
keyboard:{
|
|
enable:false
|
|
},
|
|
callbacks:{
|
|
onScroll: function(){
|
|
self.$leftScroll.off("click").one('click', function () {
|
|
self.scrollLeft(self);
|
|
});
|
|
self.$rightScroll.off("click").one('click', function () {
|
|
self.scrollRight(self);
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
});
|
|
self.$leftScroll.one('click', function () {
|
|
self.scrollLeft(self);
|
|
});
|
|
self.$rightScroll.one('click', function () {
|
|
self.scrollRight(self);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
$calendarToggle.on('click', function () {
|
|
var $switch = $(this);
|
|
var $sect = $switch.closest('.ep-sect');
|
|
var $sectBody = $sect.children('div.ep-sect-body');
|
|
|
|
if ($sect.hasClass('eps-opened')) {
|
|
$rightScroll.hide();
|
|
$leftScroll.hide();
|
|
$sectBody
|
|
.stop()
|
|
.animate({
|
|
opacity: 0
|
|
}, 300, function () {
|
|
$sect.removeClass('eps-opened');
|
|
});
|
|
} else {
|
|
$rightScroll.show();
|
|
$leftScroll.show();
|
|
$sectBody
|
|
.stop()
|
|
.animate({
|
|
opacity: 1
|
|
}, 300, function () {
|
|
$sect.addClass('eps-opened');
|
|
});
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
};
|
|
/**
|
|
* scroll calendar
|
|
* @param self
|
|
* @returns {boolean}
|
|
*/
|
|
that.scrollRight = function (self) {
|
|
if(!self){
|
|
self = this;
|
|
}
|
|
if((self.currentOffset + self.stepWidth) < self.calendarWidth){
|
|
|
|
self.currentOffset+= self.scrollStep;
|
|
|
|
console.log("!!! right scroll fired!");
|
|
self.$scrollBox.mCustomScrollbar("scrollTo", '-=' + self.scrollStep);
|
|
self.offsetMessages();
|
|
}else{
|
|
self.$rightScroll.one('click', function () {
|
|
self.scrollRight(self);
|
|
});
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* scroll calendar backward
|
|
* @param self
|
|
* @returns {boolean}
|
|
*/
|
|
that.scrollLeft = function (self) {
|
|
if(!self){
|
|
self = this;
|
|
}
|
|
if(self.currentOffset >= self.stepWidth){
|
|
self.currentOffset -= self.scrollStep;
|
|
console.log("!!! left scroll fired!");
|
|
self.$scrollBox.mCustomScrollbar("scrollTo", '+=' + self.scrollStep);
|
|
self.offsetMessages(self);
|
|
}else{
|
|
self.$leftScroll.one('click', function () {
|
|
self.scrollLeft(self);
|
|
});
|
|
}
|
|
return false;
|
|
};
|
|
/**
|
|
* make message "no marked events" visible on current week slide
|
|
* @param self - context
|
|
*/
|
|
that.offsetMessages = function (self) {
|
|
if(!self){
|
|
self = this;
|
|
}
|
|
for (var i =0; i< self.$messages.length; i++){
|
|
var parentWidth = self.$messages[i].parent().width(),
|
|
parentOffset = parseInt(self.$messages[i].parent().offset().left, 10) ;
|
|
if(parentOffset){
|
|
parentOffset -= 312
|
|
}else{
|
|
parentOffset += 312
|
|
|
|
}
|
|
if(parentWidth > self.stepWidth){
|
|
// message block went over the left edge
|
|
if(parentOffset <0){
|
|
self.$messages[i].css({marginLeft:Math.abs(parentOffset+ self.stepWidth)+'px'});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
return that;
|
|
}());
|
|
}
|
|
|