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 () { }); // 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('td.' + self.opt.currentDayClass).index(), onestep = self.opt.cellsToScroll, allDays = $calendar.find('.'+self.opt.daysClass+' td').length, stepsCount, currenCount; self.stepWidth = onestep*width; self.calendarWidth = width* allDays; if(currentDay > 0){ currentDay++; stepsCount = allDays / onestep; currenCount = allDays / currentDay; result = stepsCount - currenCount; self.currentDay =currentDay; if (result) { result = Math.floor(result-1); offset = onestep * result * width; } else { offset = 0; } }else{ self.currentDay = 0; offset = 0; } return offset; }; this.currentOffset = currentWeekOffset(); //$(document).ready(function () { // //}); this.$messages = [] $(function () { $noEventsField.each(function () { if (!$(this).attr('colspan') || $(this).attr('colspan') == 1) { $(this).find('.' + self.opt.eventWrapClass).addClass('small'); }else if($(this).width() > self.stepWidth){ self.$messages.push( $('.message',$(this)) .width(self.stepWidth) .css({marginLeft:self.currentOffset+'px'}) ); } }); $('.' + self.opt.eventsClass).each(function () { index++; if (index == 3) { $(this).addClass('grey'); } if (index == 4) { $(this).addClass('grey'); index = 0; } }); }); $(window).load(function () { $scrollBox.mCustomScrollbar({ axis: 'y', horizontalScroll: true, setLeft:'-'+EXPO.profile.calendar.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 } }); //$('.mCSB_scrollTools_horizontal',$scrollBox).hide(); //$('.mCSB_scrollTools_horizontal',$scrollBox).css({'opacity':0}); //$scrollBox.mCustomScrollbar("scrollTo", currentWeekOffset()); }); $leftScroll.on('click', function () { if(self.currentOffset >= self.stepWidth){ self.currentOffset -= scrollStep; $scrollBox.mCustomScrollbar("scrollTo", '+=' + scrollStep); for (var i =0; i< self.$messages.length; i++){ var marginLeft = parseInt(self.$messages[i].inlineStyle("margin-left")); if(marginLeft> 0){ self.$messages[i].css({marginLeft:self.currentOffset+'px'}); } } } }); $rightScroll.on('click', function () { if((self.currentOffset + self.stepWidth) < self.calendarWidth){ self.currentOffset+= scrollStep; $scrollBox.mCustomScrollbar("scrollTo", '-=' + scrollStep); for (var i =0; i< self.$messages.length; i++){ var marginLeft = parseInt(self.$messages[i].inlineStyle("margin-left")); if((marginLeft +self.$messages[i].width())< self.calendarWidth){ self.$messages[i].css({marginLeft:self.currentOffset+'px'}); } } } }); $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; }); }; return that; }()); }