var ALL0W_SEARCH = true; $(window).on( "load" , function() { var CONFIG = { "data_file":"/events/data/test-data.json", //"data_file":"https://yjgtk4f7le.execute-api.us-west-2.amazonaws.com/dev/event/json", "cascade_data_file":"/render/page.act?id=298034500a0e02374704844e5e09ac53&confId=298034500a0e02374704844e6ef1ccb1&demarcate=false&fullscreen=true",//linfield "templates_file":"/events/data/templates.html", "cascade_templates_file":"/render/file.act?id=591ceabe0a0e023736779e573d20f833&type=file&forceDownload=false&rewrite=false",//linfield "pagination_template":"test pagination template", "paginate": "No", "size_large": 10, "size_small": 4, "size_special": 3, "days_in_past": 1000, "minCalendarWidth": 992, "multi_filter_selection": true, "date_str_format": "MM.DD.YY", "day_str_format": "DD", "time_str_format": "h:mm a.", "day_cell_length": 5, "filter_and_or": "or", "add_link": "http://www.cascadefactory.com", "and_filters": [], "ccmsURLPart": "cascadeweb", "testURLPart": "linfield.edu3", "relativePathFromRoot": "", "basePathToDetail": "", "containerSelector": ".calendar-ul, .calendar-ol" }; var inCascade = window.location.href.indexOf( CONFIG.ccmsURLPart ) > -1; var inDev = window.location.href.indexOf( CONFIG.testURLPart ) > -1; var inLocal = window.location.href.indexOf( "localhost" ) > -1; if( inCascade ) { CONFIG.relativePathFromRoot = ""; CONFIG.basePathToDetail = ""; } else if( inDev ) { CONFIG.relativePathFromRoot = "/b0-47D59" + CONFIG.relativePathFromRoot; CONFIG.basePathToDetail = "/b0-47D59" + CONFIG.basePathToDetail; } else if( inLocal ) { CONFIG.data_file = "/elements/CFEvent/cfevent-data.json"; //CONFIG.data_file = "https://yjgtk4f7le.execute-api.us-west-2.amazonaws.com/dev/event/json"; CONFIG.templates_file = "/elements/CFEvent/templates.html"; CONFIG.relativePathFromRoot = ""; CONFIG.basePathToDetail = ""; } var EVENTS_BASE = CONFIG.relativePathFromRoot; var EVENTS_LINK_BASE = CONFIG.basePathToDetail; //var IS_LIST = false; var IS_CALENDAR_LAYOUT = true; function getContainerSelector() { return CONFIG.containerSelector;//IS_CALENDAR_LAYOUT ? ".calendar-calendar" : ".calendar-list"; } function cleanTag( tag , keepPipe ) { return keepPipe ? tag.toLowerCase().replace( /[^a-z|]/g , '' ) : tag.toLowerCase().replace( /[^a-z]/g , '' ); } var CalendarEventModel = Backbone.Model.extend({ cleanAttributes: function() { var tmplink = this.get( "link" ).replace( /&/g , "&" ); tmplink = EVENTS_LINK_BASE + tmplink; //tmplink = "http://www.cascadefactory.com/event/2018/02/cmcc-entrepreneur-training-workshops.html"; //var tmpalt = this.get( "imageAlt" ) == "" ? this.get( "title" ) : this.get( "imageAlt" ); this.set( { link: tmplink ,url: tmplink //,imgAlt: "" //,image: "" ,subtitle: "" ,url: tmplink ,searchString: ( this.get( "title" ) + " " + this.get( "description" ) + " " + this.get( "location" ) + " " + this.get( "tags" ) ).toLowerCase() ,tags: cleanTag( this.get( "tags" ) , true ) ,speaker: "" } ); /*if( this.get( "image" ) == "" ) { this.set( "image" , "http://dev.cascadefactory.com/columbia/images/events1.png" ); }*/ } ,initialize: function() { try { if( typeof this.get( "startTime" ) == "undefined" ) { throw( "Invalid Event" ); } this.set( "parentId" , this.get( "id" ) ); if( this.collection && this.collection.uniqueTags ) { let tmpGroupArr = this.get( "tags" ).split( "||" ); for( let x = 0; x < tmpGroupArr.length; x++ ) { if( tmpGroupArr[ x ] != "" ) { //if( this.collection.uniqueTags.indexOf( tmpTagArr[ i ] ) == -1 ) { //this.collection.uniqueTags.push( tmpTagArr[ i ] ); //} let tmpTagArr = tmpGroupArr[ x ].split( "|" ); //let tmpTagArr = this.get( "tags" ).split( "|" ); for( let i = 0; i < tmpTagArr.length; i++ ) { if( tmpTagArr[ i ] != "" && this.collection.uniqueTags.indexOf( tmpTagArr[ i ] ) == -1 ) { this.collection.uniqueTags.push( tmpTagArr[ i ] ); this.collection.uniqueTagsSym.push( tmpTagArr[ i ].replace( /[^a-zA-Z]/g , "" ) ); } } } } } //this.cleanAttributes(); //this.formatDates(); } catch( err ) { this.collection.remove( this ); console.error( err + " Item was removed from the collection." ); } } ,setLinkWithTime: function() { var tmp = this.get( "link" ); var results = new RegExp( '[\?&]date=([^&#]*)' ).exec( tmp ); var tmpTime = this.get( "startTime" ) + "-" + this.get( "endTime" ) + ( this.get( "isAllDay" ) ? "-1" : "" ); if( results ) { tmp = tmp.replace( results[1] , tmpTime ); } else { tmp += ( ( tmp.indexOf( "?" ) > -1 ? "&" : "?" ) + "date=" + tmpTime ); } //this.set( "link" , encodeURI( tmp ) ); this.set( "link" , tmp ); this.set( "url" , tmp ); } ,formatDates: function() { var stime = this.get( "startTime" ); var startMoment = moment( stime ); if( stime == "" || stime == 0 || !startMoment.isValid() ) throw( "Invalid Start Time '" + this.get( "startTime" ) + "' for item with title " + this.get( "title" ) + "." ); //console.log(startMoment.utcOffset() +" " + stime); //stime = stime + ( startMoment.utcOffset() * -1 * 60 * 1000 ); //console.log( stime ); //startMoment = moment( stime ); var startMomentZeroHour = moment( stime ); //console.log( moment( stime ) ); //console.log( moment( stime ).valueOf() ); //this.set( "startMomentGMT" , moment( stime ).utc() ); this.set( "startMomentGMT" , moment( stime ).utc() );//.add( startMomentZeroHour.utcOffset() , 'minutes' ) ); startMomentZeroHour = startMomentZeroHour.startOf( 'day' ); /* if( this.get( "isMultiDay" ) && !this.get( "isFirstDay" ) && !this.get( "isLastDay" ) ) { this.set( "isAllDay" , true ); } */ if( this.get( "isAllDay" ) ) { startMoment = startMoment.startOf( 'day' ); } var endMoment = moment( stime ); var endMomentZeroHour = moment( stime ); endMomentZeroHour = endMomentZeroHour.startOf( 'day' ); var monthStr = startMoment.format( "MMM" ); //var dayStr = startMoment.format( "dd" ); var dateStrFull = startMoment.format( CONFIG.date_str_format ); var dayStrFull = startMoment.format( CONFIG.day_str_format ); var timeStrFull = startMoment.format( CONFIG.time_str_format ).replace( ":00" , "" ); var timeStrTiny = startMoment.format( "h:mma" ).replace( ":00" , "" ).replace( "am" , "" ).replace( "pm" , "p" ); if( CONFIG.time_str_format.indexOf( "." ) == CONFIG.time_str_format.length - 1 ) { timeStrFull = timeStrFull.replace( "am" , "a.m." ).replace( "pm" , "p.m." ).replace( ".." , "." ); } this.set({ day: startMoment.date() ,month: startMoment.month() ,year: startMoment.year() ,monthStr: monthStr ,dayName: startMoment.format( "dddd" ) //,dayStr: dayStr /*default end date to start date*/ /*,dayEnd: startMoment.date() ,monthEnd: startMoment.month() ,yearEnd: startMoment.year()*/ }); var endtime = this.get( "endTime" ); if( endtime != 0 && endtime != this.get( "startTime" ) ) { endMoment = moment( endtime ); //endtime = endtime + ( endMoment.utcOffset() * -1 * 60 * 1000 ); endMoment = moment( endtime ); if( endtime == "" || endtime == 0 || !endMoment.isValid() ) throw( "Invalid End Time '" + endtime + "' for item with title " + this.get( "title" ) + "." ); endMomentZeroHour = moment( parseInt( endtime ) ); endMomentZeroHour = endMomentZeroHour.startOf( 'day' ); timeStrFull = timeStrFull + " - " + endMoment.format( CONFIG.time_str_format ).replace( ":00" , "" ); if( CONFIG.time_str_format.indexOf( "." ) == CONFIG.time_str_format.length - 1 ) { timeStrFull = timeStrFull.replace( "am" , "a.m." ).replace( "pm" , "p.m." ).replace( ".." , "." ); } } if( this.get( "isAllDay" ) ) { timeStrFull = "All Day"; timeStrTiny = ""; } this.set( "isMultiDay" , startMoment.diff( endMoment , 'days' ) != 0 ); /*if( this.get( "isMultiDay" ) ) { console.log( startMoment.diff( endMoment , 'days' ) ); console.log( this.attributes ); }*/ if( this.get( "isMultiDay" ) && this.isParent() ) { //dateStrFull = startMoment.format( 'ddd, MMMM DD, YYYY' ) + " through " + endMoment.format( 'ddd, MMMM DD, YYYY' ); dateStrFull = startMoment.format( CONFIG.date_str_format ) + " through " + endMoment.format( CONFIG.date_str_format ); dayStrFull = startMoment.format( CONFIG.day_str_format ) + " - " + endMoment.format( CONFIG.day_str_format ); } this.set( "startMoment" , startMoment ); this.set( "endMoment" , endMoment ); this.set( "timeStr" , timeStrFull ); this.set( "timeStrTiny" , timeStrTiny ); this.set( "dateStr" , dateStrFull ); this.set( "listDateStr" , dateStrFull + ",
" + timeStrFull ); //this.set( "fullDate" , dateStrFull + " " + timeStrFull ); this.set( "monthName" , startMoment.format( 'MMM' ).toLowerCase() ); this.set( "monthNameLong" , startMoment.format( 'MMMM' ) ); this.set( "dayStr" , dayStrFull ); //this.set( "dayStr" , startMoment.format( 'DD' ) ); this.set( "googleCalDate" , startMoment.utc().format( 'YYYYMMDD[T]HHmmss[Z]' ) ); this.set( "googleCalDateEnd" , endMoment.utc().format( '[/]YYYYMMDD[T]HHmmss[Z]' ) ); this.set( "endMomentZeroHour" , endMomentZeroHour ); this.set( "startMomentZeroHour" , startMomentZeroHour ); } ,resetMultidayEndDateForLists: function() { return false; if( this.get( "isMultiDay" ) && this.get( "id" ) == this.get( "parentId" ) ) { var sames = this.collection.where( { "parentId" : this.get( "parentId" ) } ); //if( sames.length > 0 ) { var tmpmax = 0; var tmpmaxidx = 0; var tmp; for( var i = 0; i < sames.length; i++ ) { tmp = sames[ i ].get( "id" ) if( tmp > tmpmax ) { tmpmax = tmp; tmpmaxidx = i; } } var endtime = sames[ tmpmaxidx ].get( "endTime" ); var startMoment = moment( this.get( "startTime" ) ); var endMoment = moment( endtime ); //this.formatDates(); var dateStrFull; //if( ! this.get( "endMomentZeroHour" ).isSame( this.get( "startMomentZeroHour" ) ) ) dateStrFull = startMoment.format( 'ddd MMM D, h:mm a' ).replace( ":00" , "" ) + "
to
" + endMoment.format( 'ddd MMM D, h:mm a' ).replace( ":00" , "" ); //else //dateStrFull = startMoment.format( 'ddd MMM D, h:mm a' ).replace( ":00" , "" ) + " - " + endMoment.format( 'h:mm a' ).replace( ":00" , "" ); this.set( "listDateStr" , dateStrFull ); this.set( "listDate" , dateStrFull + " " + this.get( "timeStr" ) ); //} } } ,setLevel: function( idx , doReset ) { if( this.isParent() ) { this.set( "lvl" , idx ); this.set( "colorIdx" , idx ); } else { var p = this.collection.where( { "id" : this.get( "parentId") } ); p = p[0]; if( p.get( "lvl" ) === null || doReset ) { p.set( "lvl" , idx ); } if( p.get( "colorIdx" ) === null ) { p.set( "colorIdx" , idx ); } this.set( "lvl" , p.get( "lvl" ) ); this.set( "colorIdx" , p.get( "colorIdx" ) ); } return this.get( "lvl" ); } ,totalDays: function() { if( ! this.get( "totalDays" ) ) { var tmp = this.collection.where( { "parentId" : this.get( "parentId") } ); _.each( tmp , function( m ) { m.set( "totalDays" , tmp.length ); }); } return this.get( "totalDays" ); } ,firstStartTime: function() { return this.collection.find( { "id" : this.get( "parentId" ) } ).get( "startTime" ); } ,isParent: function() { return this.get( "id" ) == this.get( "parentId" ); } ,isFeatured: function() { return ( !this.get( "isMultiDay" ) || this.get( "id" ) == this.get( "parentId" ) ) && this.get( "tags" ).indexOf( "Featured" ) > -1; } ,search: function( val ) { return this.get( "searchString" ).indexOf( val ) > -1; } ,defaults: { description: "" ,location: "default location" ,gcalDateEnd: "" ,endtime: "" ,tags: "" ,url: "" ,link: "" ,image: "" ,imageAlt: "" ,lvl: null ,colorIdx: null ,recurInterval: 1 } }); var DayEventCollection = Backbone.Collection.extend({ url: "" ,model: CalendarEventModel ,initialize: function( a , options ) { this.upcomingList = options ? options.upcomingList : false; } ,comparator: function(a,b) { var startTimeCompVal = 0; if( App.IsSearch || this.upcomingList ) startTimeCompVal = a.get( "startMoment" ) <= b.get( "startMoment" ) ? -1 : 1; else if( IS_CALENDAR_LAYOUT && ( a.get( "isMultiDay" ) || b.get( "isMultiDay" ) ) ) { if( ! b.get( "isMultiDay" ) ) { startTimeCompVal = -1; } else if( ! a.get( "isMultiDay" ) ) { startTimeCompVal = 1; } else if( a.firstStartTime() == b.firstStartTime() ) { if( a.totalDays() == b.totalDays() ) { startTimeCompVal = a.get( "title" ) < b.get( "title" ) ? -1 : 1; } else startTimeCompVal = a.totalDays() > b.totalDays() ? -1 : 1; } else { startTimeCompVal = a.firstStartTime() < b.firstStartTime() ? -1 : 1; } } else if( a.get( "isAllDay" ) ) startTimeCompVal = -1; else if( b.get( "isAllDay" ) ) startTimeCompVal = 1; else { atime = a.get( "startTime" ) - a.get( "startMomentZeroHour" ); btime = b.get( "startTime" ) - b.get( "startMomentZeroHour" ); if( atime == btime ) { startTimeCompVal = a.get( "title" ) < b.get( "title" ) ? -1 : 1; } else { startTimeCompVal = a.get( "startTime" ) < b.get( "startTime" ) ? -1 : 1; } } return startTimeCompVal; } }); var CalendarEventCollection = Backbone.Collection.extend({ url: "" ,model: CalendarEventModel ,uniqueTags: [] ,uniqueTagsSym: [] ,resetMultidayEndDateForLists: function() { for( var i = 0; i < this.length; i++ ) { this.at( i ).resetMultidayEndDateForLists(); } } ,getFeaturedEvents: function() { return _calendarEvents.filter( function( item , idx ) { return item.isFeatured() && (Filters.length == 0 || Filters.match( item.get( "tags" ) )); }); } ,initialize: function() { this.on( "multiplesAdded" , function() { var clonedItem; this.each( function( item ) { //clonedItem = item.clone(); //clonedItem.id = 0; //console.log( "aaa" + this.length ); //this.add( clonedItem ) //console.log( "bbb" + this.length ); //console.log( item.id ); } , this ); } , this ); var self = this; this.on( "reset" , function() { self.createRepeats(); self.createMultidays(); /* this.each( function( item ) { item.cleanAttributes(); item.formatDates(); } , this); */ this.trigger( "multiplesAdded" ); }); } ,createRepeats: function() { var clonedItem; var curId = this.length + 1; var recurPattern; var recurInterval; var momentPattern; var nearestSameDay; var stopMoment; var recurringDays; var recurCount; var initialWeekDay; var initialMonth; var initialWeekOfMonth; var initialNthDayOfMonth; var initialDaySpan; var initialSecondSpan; this.each( function( item ) { //console.log( item.get( "endMomentZeroHour" ).diff( item.get( "startMomentZeroHour" ) , 'days' ) ); /*this used to be done in model's initialize, but is currently more efficient to call here*/ item.cleanAttributes(); item.formatDates(); if( item.get( "isRecurring" ) && item.get( "stopTime" ) != 0 ) {// || item.get( "startMomentZeroHour" ).diff( item.get( "endMomentZeroHour" ) , 'days' ) != 0 ) { //get pattern recurPattern = item.get( "recurPattern" ); recurInterval = item.get( "recurInterval" ); momentPattern = "days"; switch( recurPattern ) { case "Weekly": momentPattern = "weeks"; break; case "Monthly": momentPattern = "months"; break; case "Yearly": momentPattern = "years"; break; default: momentPattern = "days"; } //get nearestSameDay nearestSameDay = ( recurPattern == "Monthly" || recurPattern == "Yearly" ) && ( item.get( "recurOn" ) == "w" || item.get( "recurOn" ) == "Same day of week" ); //get stopDate stopMoment = moment( item.get( "stopTime" ) ).startOf( 'day' ); //set initial weekday and month if( nearestSameDay ) { initialWeekDay = item.get( "startMoment" ).utc().day(); initialMonth = item.get( "startMoment" ).utc().month(); initialDaySpan = item.get( "endMoment" ).diff( item.get( "startMoment" ) , 'days' ); initialSecondSpan = item.get( "endMoment" ).diff( item.get( "startMoment" ) , 'seconds' ); var tmp = item.get( "startMoment" ); //initialWeekOfMonth = item.get( "startMoment" ).utc().isoWeek() - item.get( "startMoment" ).utc().subtract('days', item.get( "startMoment" ).utc().date() - 1).isoWeek() + 1; initialWeekOfMonth = tmp.week() - moment.utc(tmp).startOf( 'month' ).week() + 1; initialNthDayOfMonth = tmp.week() - moment.utc(tmp).startOf( 'month' ).week(); if( moment.utc(tmp).startOf( 'month' ).day() <= initialWeekDay ) initialNthDayOfMonth++; } //get recurringDays for daily or !nearestSameDay recurringDays = ""; if( recurPattern != "Weekly" && !nearestSameDay ) recurringDays = item.get( "recurDays" ); //set recurCount recurCount = stopMoment.diff( item.get( "startMomentZeroHour" ) , momentPattern ); recurCount = Math.floor( recurCount / recurInterval ); //for i to recurCount clonedItem = item.clone(); for( var i = 0; i < recurCount; i++ ) { clonedItem.set( "startTime" , moment( clonedItem.get( "startTime" ) ).add( recurInterval, momentPattern ).valueOf() ); if( nearestSameDay ) { var tmp = moment.utc( clonedItem.get( "startTime" ) ); var tmpNewMonth = tmp.month(); if( tmp.day() != initialWeekDay ) tmp = tmp.day( initialWeekDay ); if( tmp.month() != tmpNewMonth ) tmp = tmp.add( ( tmpNewMonth - tmp.month() ) , 'week' ); var nthDayOfMonth = tmp.week() - moment.utc(tmp).startOf( 'month' ).week(); if( moment.utc(tmp).startOf( 'month' ).day() <= initialWeekDay ) nthDayOfMonth++; clonedItem.set( "startTime" , tmp.valueOf() ); if( initialNthDayOfMonth != nthDayOfMonth ) { tmp.add( initialNthDayOfMonth - nthDayOfMonth , 'week' ); clonedItem.set( "startTime" , moment( clonedItem.get( "startTime" ) ).add( initialNthDayOfMonth - nthDayOfMonth , 'week' ).valueOf() ); } //clonedItem.set( "startTime" , tmp.utc().valueOf() ); clonedItem.set( "endTime" , moment( clonedItem.get( "startTime" ) ).add( initialSecondSpan , 'seconds' ).valueOf() ); } else { clonedItem.set( "endTime" , moment( clonedItem.get( "endTime" ) ).add( recurInterval, momentPattern ).valueOf() ); } //if day is one of recurringDays or recurringDays is empty if( recurringDays == "" || recurringDays.indexOf( moment( clonedItem.get( "startTime" ) ).format( "ddd" ) ) > -1 ) { clonedItem.set( "id" ,curId ); clonedItem.set( "parentId" ,curId++ ); clonedItem.formatDates(); clonedItem.setLinkWithTime(); this.add( clonedItem ); } clonedItem = clonedItem.clone(); } } } , this ); } ,createMultidays: function() { var clonedItem; var curId = this.length + 1; var recurPattern; var momentPattern; var nearestSameDay; var stopMoment; var recurringDays; var recurCount; this.each( function( item ) { //console.log( item.get( "endMomentZeroHour" ).diff( item.get( "startMomentZeroHour" ) , 'days' ) ); /*this used to be done in model's initialize, but is currently more efficient to call here*/ //item.cleanAttributes(); //item.formatDates(); if( item.get( "isMultiDay" ) ) {// || item.get( "startMomentZeroHour" ).diff( item.get( "endMomentZeroHour" ) , 'days' ) != 0 ) { momentPattern = "days"; stopMoment = item.get( "endMomentZeroHour" ); recurCount = stopMoment.diff( item.get( "startMomentZeroHour" ) , momentPattern ); clonedItem = new CalendarEventModel( item.attributes ); clonedItem.set( "parentId" , item.id ); for( var i = 0; i < recurCount; i++ ) { clonedItem.set( "startTime" , moment( clonedItem.get( "startTime" ) ).add( 1, momentPattern ).valueOf() ); //clonedItem.set( "endTime" , moment( clonedItem.get( "endTime" ) ).add( 1, momentPattern ).valueOf() ); clonedItem.set( "id" ,curId++ ); if( i == recurCount - 1 ) clonedItem.set( "isLastDay" , true ); clonedItem.formatDates(); clonedItem.set( "isMultiDay" , true ); this.add( clonedItem ); clonedItem = clonedItem.clone(); clonedItem.set( "parentId" , item.id ); } } } , this ); } }); var CalendarEventView = Backbone.View.extend({ tagName: "div" ,className: "" ,events: { "click .event_categories img": "clearFilters" ,"click .cal-ical": "icalClick" ,"click .cal-exch": "exchClick" } ,clearFilters: function( e ) { e.preventDefault(); Filters.clear(); App.navigate(); } ,icalClick: function( e ) { e.preventDefault(); makeIcalEventFile( this.model.get( "startTime" ) , this.model.get( "startTime" ) , this.model.get( "endTime" ) , this.model.get( "title" ) , this.model.get( "plain" ) , this.model.get( "location" ), this.model.get( "link" ) ); return false; } ,exchClick: function( e ) { e.preventDefault(); makeExchangeEventFile( this.model.get( "startTime" ) , this.model.get( "startTime" ) , this.model.get( "endTime" ) , this.model.get( "title" ) , this.model.get( "description" ) , this.model.get( "location" ), this.model.get( "link" ) ); return false; } ,render: function( isMultiDay , parent , doReset , isRowEnding , daysSpannedThisWeek ) { this.template = _.template( CONFIG.calendar_item_template ); var className = "lvl lvl-" + this.model.get( "lvl" ); className += " lvl-color-" + this.model.get( "colorIdx" ); className += this.model.get( "isMultiDay" ) ? " multi-day" : this.model.get( "isAllDay" ) ? " all-day" : " single"; if( ! this.model.isParent() ) { if( doReset ) { if( ! this.model.get( "isLastDay" ) ) { className += " first-day"; className += " multi-span-" + daysSpannedThisWeek; } } else { className += " extension"; } } else if( this.model.get( "isMultiDay" ) ) { className += " first-day"; className += " multi-span-" + daysSpannedThisWeek; if( isRowEnding ) { className += " row-last-day"; } } this.model.set( "className" , className ); $(parent).append(this.template( this.model.toJSON() )); this.el = $(parent).children()[0]; this.$el = $(this.el); this.delegateEvents(); return this; } }); /*function fixDayCellSize( view ) { if( $(window).width() > 767 ) { view.$el.find( ".date" )[0].style.padding = "0px 10px"; var tmp = Math.ceil( ( view.$el.height() - 64 ) / 2 ); if( view.$el.find( ".date" ).length > 0 ) view.$el.find( ".date" )[0].style.padding = tmp + "px 10px"; } else { view.$el.find( ".date" )[0].style.padding = "44px 10px"; } }*/ var DayModel = Backbone.Model.extend({ defaults: { "monthStr" : "" } ,initialize: function() { var renderDate = new Date( this.get("year"), this.get("month"), this.get("day") ); var renderMoment = moment( renderDate ); this.set( "renderMoment" , renderMoment ); this.set( "day" , renderMoment.date() ); this.set( "weekday" , renderMoment.day() ); this.set( "month" , renderMoment.month() ); this.set( "year" , renderMoment.year() ); this.set( "dayName" , renderMoment.format( 'dddd' ) ); this.set( "monthName" , renderMoment.format( 'MMMM' ) ); this.set( "renderMomentZeroHour" , renderMoment.startOf( 'day' ).valueOf() ); } }); var DayView = Backbone.View.extend({ //tagName: "article" //,className: "dayView" events: { "click .view-more": "onViewMoreClick" ,"click .view-more-cancel": "onViewMoreCancelClick" } ,onViewMoreCancelClick: function( e ) { e.preventDefault(); Calendar.$el.toggleClass( "list-cal" ); this.$el.parent().children().show() this.rerender(); this.$el.find( ".view-more" ).show(); this.$el.find( ".view-more-cancel" ).hide(); } ,onViewMoreClick: function( e ) { e.preventDefault(); Calendar.$el.toggleClass( "list-cal" ); this.$el.parent().children().hide() this.$el.show(); this.rerender(); this.$el.find( ".view-more" ).hide(); this.$el.find( ".view-more-cancel" ).show(); /*need to make this not rerender just hide show something instead*/ //Calendar.format = "day"; //Calendar.day = this.model.get( "day" ); //App.navigate(); } ,initialize: function() { this.template = _.template( CONFIG.calendar_day_container_template ); this.isFeaturedList = false; this.currentDayEvents = null; this.views = []; } ,_setOptions: function() { this.hasFilters = Filters.length > 0; //this.isFeaturedList = this.hasFilters && Filters.match( "Featured" ); } ,hasEvents: function() { return this.collection.length > 0; } ,rerender: function() { this.$el.html( '' ); this.render( false , true ); } ,render: function( parent , isParentNotNeeded ) { this._setOptions(); this.template = _.template( CONFIG.calendar_day_container_template ); if( parent && !isParentNotNeeded ) { if( IS_CALENDAR_LAYOUT ) { $( parent ).append( this.template( this.model.toJSON() ) ); this.el = $( parent ).children().last(); this.$el = $( this.el ); this.$el.css( "zIndex" , 50 - this.model.get( "day" ) ); } else { //this.template = _.template( CONFIG.list_day_container_template ); this.el = parent; this.$el = $( this.el ); } } else if ( isParentNotNeeded ) { this.$el.html( $(this.template( this.model.toJSON() )).html() ); } if( this.model.get( "isInCurrentMonth" ) ) { var self = this; //this.$el.html( this.template( this.model.toJSON() ) ); this.views = []; var currentMultiDayEvents = []; if( this.currentDayEvents == null ) { //console.log( this.model.get( "day" ) ); this.currentDayEvents = _calendarEvents.filter( function( event ) { return ( ( self.model.get( "renderMomentZeroHour" ) == event.get( "startMomentZeroHour" ) /*|| ( self.isFeaturedList && Filters.match( event.get( "tags" ) ) )*/ ) && ( Filters.match( event.get( "tags" ) ) ) && ( IS_CALENDAR_LAYOUT || event.isParent() ) /*&& ( SITE_FILTER == "" || event.get( "site" ).indexOf( SITE_FILTER ) > -1 || event.get( "isSystemWide" ) )*/ && ( Calendar.searchText == "" || event.search( Calendar.searchText ) ) ); }); } /*create a collection that will sort itself*/ this.collection = new DayEventCollection( this.currentDayEvents ); if( this.currentDayEvents.length > 0 ) { $( '.datepicker-days td[data-day="' + this.model.get( "renderMoment" ).format( "MM/DD/YYYY" ) + '"]' ).addClass( "has-events" ); } /*display each event in the current day*/ var lvl = 0; var prevLvl = 0; var doReset = this.model.get( "weekday" ) == 0 || (this.model.get( "day" ) == 1 && this.model.get( "weekday" ) != 6 ); var isRowEnding = this.model.get( "weekday" ) == 6; var tmpLen = this.collection.length; if( Calendar.isCalendarLayout() && this.collection.length > CONFIG.day_cell_length ) { tmpLen = CONFIG.day_cell_length; this.$el.find( ".view-more" ).show(); this.$el.find( ".view-more .more" ).html( this.collection.length - CONFIG.day_cell_length ); } else { this.$el.find( ".view-more" ).hide(); } _.each( this.collection.models.slice( 0 , tmpLen ), function( event , idx ) { prevLvl = lvl; lvl = event.setLevel( lvl , doReset ) + 1; let daysSpannedThisWeek = event.get( "endMoment" ).diff( self.model.get( "renderMoment" ) , 'days' ) + 1; daysSpannedThisWeek = daysSpannedThisWeek > 7 ? ( 7 - self.model.get( "weekday" ) ) : daysSpannedThisWeek; tmpdiff = lvl - prevLvl - 1; if( tmpdiff > 0 && IS_CALENDAR_LAYOUT ) { //console.log( self.model.get( "renderMoment" ).format() + " - " + tmpdiff + " - " + lvl + " - " + prevLvl + " - " + event.get( "title" ) ); for( var i = 0; i < tmpdiff; i++ ) $( self.el.find( "ol,ul" )[0] ).append( '
  • ' ); } var eventView = new CalendarEventView( { model: event } ); if( IS_CALENDAR_LAYOUT ) { eventView.render( false , self.el.find( "ol,ul" )[0] , doReset , isRowEnding , daysSpannedThisWeek ); } else { eventView.render( false , self.el , doReset , isRowEnding , daysSpannedThisWeek ); } self.views.push( eventView ); }); this.$el.show(); this.$el.toggleClass( "empty" , !this.hasEvents() ); this.$el.toggleClass( "today" , ( this.model.get( "day" ) == ( new Date().getDate() ) && this.model.get( "month" ) == ( new Date().getMonth() ) ) ); } else { //this.$el.html( this.template( this.model.toJSON() ) ); this.$el.addClass( "otherMonth" ); } this.delegateEvents(); return this; } }); var MonthView = Backbone.View.extend({ tmpMaxHeight: 150 ,initialize: function() { this.hasEvents = false; this.isFeaturedList = false; this.views = []; } ,_advanceDay: function() { this.tmpWeek = this.tmpDays == 7 ? this.tmpWeek + 1 : this.tmpWeek; this.tmpDays = this.tmpDays == 7 ? 1 : this.tmpDays + 1; } ,rerender: function() { return this.render( this.monthToShow, this.yearToShow, this.dayToStart, this.dayCountToShow , true ); } ,render: function( monthToShow , yearToShow , dayToStart , dayCountToShow , isRerender ) { this.monthToShow = monthToShow; this.yearToShow = yearToShow; this.dayToStart = dayToStart; this.dayCountToShow = dayCountToShow; this.el = $(getContainerSelector())[0]; this.$el = $(getContainerSelector()); this.$el.empty(); //SITE_FILTER = this.$el.data( 'filter' ); if( false && isRerender ) { $.each( this.dayViews , function( idx , view ) { view.rerender(); }) } else { this.dayViews = []; this.firstOfMonth = new Date( yearToShow , monthToShow , 1 ); var firstWeekDayOfMonth = this.firstOfMonth.getDay(); this.tmpDays = 1; this.tmpWeek = 1; if( ! dayCountToShow ) { for( var d = 0; d < firstWeekDayOfMonth; d++ ) { this.dayViews.push( new DayView( { model: new DayModel( { isInCurrentMonth: false ,day: ( daysInMonth( Calendar.getPreviousMonth()+1 , Calendar.getPreviousMonthYear() ) +1 - ( firstWeekDayOfMonth - d - 1 ) ) ,week: this.tmpWeek ,month: monthToShow ,year: yearToShow } ) } ) ); this.addDayView( this.dayViews[ this.dayViews.length - 1 ] , d , this.tmpWeek , this.tmpDays ); this._advanceDay(); } } this.hasEvents = false; this.isFeaturedList = false; var tmpDayView; var numOfDays = dayCountToShow ? dayCountToShow - 1 : daysInMonth( monthToShow + 1 , yearToShow ); var startDay = dayCountToShow ? dayToStart : 1; for( var d = startDay; d <= numOfDays + startDay; d++ ) { this.dayViews.push( new DayView( { model: new DayModel( { isInCurrentMonth: true ,day: d ,week: this.tmpWeek ,month: monthToShow ,year: yearToShow } ) } ) ); tmpDayView = this.dayViews[ this.dayViews.length - 1 ]; this.addDayView( tmpDayView , d , this.tmpWeek , this.tmpDays ); this.views.push( tmpDayView ); this.hasEvents = this.hasEvents || this.dayViews[ this.dayViews.length - 1 ].hasEvents(); if( tmpDayView.isFeaturedList ) { d = 32; this.isFeaturedList = true; } this._advanceDay(); } tmpDayView = null; if( ! dayCountToShow ) { for( var d = 1; d <= ( 8 - this.tmpDays ); d++ ) { this.dayViews.push( new DayView( { model: new DayModel( { isInCurrentMonth: false ,day: d ,week: this.tmpWeek ,month: monthToShow ,year: yearToShow } ) } ) ); this.addDayView( this.dayViews[ this.dayViews.length - 1 ] , d , this.tmpWeek , this.tmpDays ); } } else { /*more events option*/ /*event views in the list share the same $el as this month view and its day views*/ /*for(var i = CONFIG.size_large; i < this.views[ 0 ].$el.children().length; i++ ) { $( this.views[ 0 ].$el.children()[ i ] ).hide(); } var self = this; $( "#more-events" ).one( 'click' , function( e ) { self.showMoreEvents( e ); } );*/ } } this.showEmpty(); return this; } ,getEmptyString: function() { var ret = _.template( CONFIG.empty_default )( { period : Calendar.format } ); return ret; } ,showEmpty: function() { if( ! this.hasEvents ) { this.$el.html( '
  • ' + this.getEmptyString() + '
  • ' ); } } ,showMoreEvents: function( e ) { e.preventDefault(); var stillHidden = this.views[ 0 ].$el.children( ":hidden" ); for(var i = 0; i < CONFIG.size_large && i < stillHidden.length; i++ ) { $( stillHidden[ i ] ).show(); } if( stillHidden.length > CONFIG.size_large ) { var self = this; $( "#more-events" ).one( 'click' , function( e ) { self.showMoreEvents( e ); } ); } else { $( "#more-events" ).hide(); } } ,addDayView: function( view , monthDay , monthWeek , weekDay ) { view.render( this.$el ); return this; } }); var FeatureItemView = Backbone.View.extend({ tagName: "li" ,initialize: function() { this.template = _.template( CONFIG.feature_template ); } ,render: function() { //console.log( this.model ); this.$el.html(this.template(this.model.attributes)); return this; } }); var FeatureView = Backbone.View.extend({ el: "#feature-slides" ,render: function() { if( this.$el.length > 0 ) { this.$el.empty(); this.collection.each( function( item , idx ) { //item.resetMultidayEndDateForLists(); $( "#feature-slides-nav" ).append( '
  • ' ); this.$el.append( new FeatureItemView( { model: item } ).render().$el.html() ); } , this); } } }); var CalendarView = Backbone.View.extend({ el: "#calendar" ,events: { "click .nextPeriod": "nextPeriodClick" ,"click .previousPeriod": "previousPeriodClick" ,"click .view-month": "viewMonthClick" ,"click .view-week": "viewWeekClick" ,"click .view-day": "viewDayClick" ,"click .view-today": "viewTodayClick" ,"change #cal-search": "onSearchChange" } ,initialize: function() { var self = this; this.format = "month"; this.searchText = ""; if( this.$el.length > 0 ) { this.listenTo( _calendarEvents , "multiplesAdded" , function() { //_calendarEvents.resetMultidayEndDateForLists(); self.render(); //FeatureSlider.collection = new Backbone.Collection( _calendarEvents.getFeaturedEvents() ); //FeatureSlider.render(); }); } } ,ui: { period: $( '.thisPeriod' ) } ,isCalendarLayout: function() { return ! this.$el.hasClass( "list-cal" ); } ,_cleanDate: function() { var renderDate = new Date( this.year, this.month - 1 , this.day ); if( this.format == "week" && renderDate.getDay() != 0 ) { this.day = renderDate.getDate() - renderDate.getDay(); renderDate = new Date( this.year, this.month - 1 , this.day ); } this.day = renderDate.getDate(); this.month = renderDate.getMonth() + 1; this.year = renderDate.getFullYear(); return renderDate; } ,_setCurPeriodText: function( daysToShow ) { var renderDate = this._cleanDate(); var monthStr = getMonthName( renderDate ); this.ui.period = $( '.thisPeriod' ); if( this.format == "month" ) this.ui.period.html( monthStr + " " + this.year ); else if (this.format == "week" ) { var tmpEndDate = new Date( this.year, this.month - 1 , ( this.day + daysToShow ) ); var tmpEndDay = tmpEndDate.getDate(); if( tmpEndDay < this.day ) tmpEndDay = getMonthName( tmpEndDate ) + " " + tmpEndDay; this.ui.period.html( monthStr + " " + this.day + " – " + tmpEndDay + ", " + this.year ); } else { this.ui.period.html( monthStr + " " + this.day + ", " + this.year ); } } ,render: function() { //this.setActiveNavLink(); //$("#event_filter_heading").text(''); if( typeof this.monthView == "undefined" ) { var calType = Filters.getCalendarType() || "main"; this.$el.html( CONFIG.calendar_layouts[ calType ] ); registerGlobalEvents(); this.monthView = new MonthView(); } var daysToShow = this.format == "week" ? 7 : this.format == "day" ? 1 : 0; if( this.$el.hasClass( "special" ) ) { this.format = "week"; daysToShow = "3"; CONFIG.calendar_day_container_template = CONFIG.special_calendar_day_container_template; CONFIG.calendar_item_template = CONFIG.special_calendar_item_template; } $( ".view-month, .view-week, .view-day" ).removeClass( "active-range" ); $( ".view-" + this.format ).addClass( "active-range" ); this._setPrevNext(); this._setCurPeriodText( daysToShow - 1 ); App.setDatePickerTime(); App.forceList(); this.monthView.render( this.month - 1 , this.year , this.day , daysToShow ) this.trigger( "rendered" ); /* var tmp = CONFIG.empty + monthStr; if( this.searchText != "" ) { tmp = CONFIG.empty_search; } else if( this.monthView.isFeaturedList ) { tmp = CONFIG.empty_featured; $("#featured_events>button").toggleClass( 'activeButton' , true ); } else if( Filters.length > 0 ) { tmp = CONFIG.empty_category + Filters.at( 0 ).get( "val" ); $( "#select-category-option" ).val( Filters.at( 0 ).get( "val" ) ); } $( '#event_filter_heading' ).html( tmp ).show(); } else { if( this.monthView.isFeaturedList ) { $( '#event_filter_heading' ).html( "Featured Events" ).show(); $("#featured_events>button").toggleClass( 'activeButton' , true ); } else if( Filters.length > 0 ) { $( '#event_filter_heading' ).html( Filters.at( 0 ).get( "val" ) ).show(); $( "#select-category-option" ).val( Filters.at( 0 ).get( "val" ) ); tmp = $($(".calImage")[0]).attr( "src" ); $(".calImage").attr( "src" , tmp.replace( ".png" , "2.png" ) ); } } setTimeout( function() { $( "td.day.active" ).removeClass( "active" ); } , 300 ); */ } ,_setPrevNext: function() { var data = { "period" : this.format.charAt(0).toUpperCase() + this.format.slice(1) }; if( ! this._prevTemplate ) { this._prevTemplate = _.template( CONFIG.previous_template ); this._nextTemplate = _.template( CONFIG.next_template ); } $( ".previousPeriod" ).html( this._prevTemplate( data ) );//.attr( "title" , "Previous " + data.period ); $( ".nextPeriod" ).html( this._nextTemplate( data ) );//.attr( "title" , "Next " + data.period ); } ,onSearchChange: function( e ) { Calendar.searchText = e.target.value; this.render(); } ,getNextMonth: function() { return this.month == 12 ? 1 : this.month + 1; } ,getPreviousMonth: function() { return this.month == 1 ? 12 : this.month - 1; } ,getNextMonthYear: function() { return this.month == 12 ? this.year + 1 : this.year; } ,getPreviousMonthYear: function() { return this.month == 1 ? this.year - 1 : this.year; } ,previousPeriodClick: function( e ) { e.preventDefault(); if( Calendar.format == "month" ) { Calendar.year = Calendar.getPreviousMonthYear(); Calendar.month = Calendar.getPreviousMonth(); } else if( Calendar.format == "week" ) { Calendar.day -= 7; } else if( Calendar.format == "day" ) { Calendar.day -= 1; } App.navigate(); return false; } ,nextPeriodClick: function( e ) { e.preventDefault(); if( Calendar.format == "month" ) { Calendar.year = Calendar.getNextMonthYear(); Calendar.month = Calendar.getNextMonth(); } else if( Calendar.format == "week" ) { Calendar.day += 7; } else if( Calendar.format == "day" ) { Calendar.day += 1; } App.navigate(); return false; } ,viewMonthClick: function( e ) { e.preventDefault(); Calendar.format = "month"; App.navigate(); } ,viewWeekClick: function( e ) { e.preventDefault(); Calendar.format = "week"; App.navigate(); } ,viewDayClick: function( e ) { e.preventDefault(); Calendar.format = "day"; App.navigate(); } ,viewTodayClick: function( e ) { e.preventDefault(); Calendar.year = moment().year(); Calendar.month = moment().month() + 1; Calendar.day = moment().date(); App.navigate(); } //,prevPeriodClick: ,getDateParamStr: function() { return this.month + "," + this.day + "," + this.year + "," + this.format; } /*,setActiveNavLink: function() { $('a[class^="view-"]').removeClass('active'); //$('.datepicker-container').datepicker( 'setDate' , new Date( this.year , this.month - 1 , this.day ) ); if (this.format == 'month') { $('.view-month').addClass('active'); } else if (this.format == 'week') { $('.view-week').addClass('active'); } else if (this.format == 'day') { $('.view-day').addClass('active'); } }*/ }); var FilterModel = Backbone.Model.extend({}); var FilterCollection = Backbone.Collection.extend({ model: FilterModel ,initialize: function() { this.on( "add" , function ( a, b, c ) { //this. }); } ,_filterUISelector: function() { } ,match: function( val ) { return CONFIG.filter_and_or.toLowerCase() == "and" ? this.matchAnd( val ) : this.matchOr( val ); } ,matchAnd: function( val ) { var ret = true val = "|"+val+"|"; for( var i = 0; i < this.length; i++ ) { tVal = this.at( i ).get( "val" ); if( val.indexOf( "|"+tVal+"|" ) == -1 && ( CONFIG.and_filters.length == 0 || CONFIG.and_filters.indexOf( tVal ) == -1 ) ) { ret = false; } } return ret; } ,matchOr: function( val ) { var ret = this.length == 0; var andRet = false; var andFilterIsUsed = false; var orFilterIsUsed = false; val = "|"+val+"|"; for( var i = 0; i < this.length; i++ ) { tVal = this.at( i ).get( "val" ); if( CONFIG.and_filters.length > 0 && CONFIG.and_filters.indexOf( tVal ) > -1 ) { andFilterIsUsed = true; andRet = andRet || val.indexOf( "|"+tVal+"|" ) > -1; } else if( ! ret ) { orFilterIsUsed = true; ret = val.indexOf( "|"+tVal+"|" ) > -1; } } ret = andFilterIsUsed && orFilterIsUsed ? ret && andRet : andFilterIsUsed ? andRet : ret; return ret; } ,getCalendarType: function() { var ret = CONFIG.and_filters.length > 0 ? CONFIG.and_filters[ 0 ] : ""; var idx = 0; for( var i = 0; i < this.length; i++ ) { tVal = this.at( i ).get( "val" ); if( CONFIG.and_filters.length > 0 ) { idx = CONFIG.and_filters.indexOf( tVal ); if( idx > -1 ) { ret = CONFIG.and_filters[ idx ]; } } } return ret; } ,getURLString: function() { var ret = ""; var ret2 = ""; //this.getBGsFromCheckedInputs(); $.each( this.models , function( idx , filter ) { if( filter.get( "val" ).indexOf( "bg" ) == 0 ) { ret2 += ( ret2 != "" ? "," : "" ) + filter.get( "val" );//.substring( 2 ); } else if( CONFIG.and_filters.length == 0 || CONFIG.and_filters.indexOf( filter.get( "val" ) ) == -1 ) { ret += ( ret != "" ? "," : "" ) + filter.get( "val" ); } }); ret = ( ret != "" ? "/" : "" ) + ret; ret2 = ( ret2 != "" ? "/bg" : "" ) + ret2; return ret + ret2; } ,fillFromCSV: function( csv ) { if( csv ) { var tmpModels = []; if( this.getCalendarType() ) { tmpModels = [ { "val": this.getCalendarType() } ]; } var classSelector = ""; var self = this; if( csv ) { var ct = 0; $.each( csv.split( "," ) , function( idx , val ) { val = cleanTag( val ); tmpModels.push( { "val": val } ); classSelector += ( ct++ == 0 ? "" : ", " ) + ".filters li a[data-filter='" + val + "']"; }); } this.reset( tmpModels ); //$( ".filter-container input" ).prop( 'checked' , false ); //$( classSelector ).prop( 'checked' , true ); //$( classSelector ).addClass( 'active' ); /*if( $( classSelector ).length > 0 ) { $( "#filterAll" ).parent().removeClass("hide"); } else { $( "#filterAll" ).parent().addClass("hide"); }*/ } } ,setActiveFilters: function() { var classSelector = ""; var ct = 0; this.each( function( filter ) { classSelector += ( ct++ == 0 ? "" : ", " ) + ".filters li a[data-filter='" + filter.get( "val" ) + "']"; }); $( classSelector ).addClass( 'active' ); } ,clear: function () { Filters.reset([]); $( ".filters li a" ).removeClass( 'active' ); } ,addFilter: function( val ) { var ret = false; val = cleanTag( val ); if( Filters.where( { "val": val } ).length == 0 ) { Filters.add( { "val": val } ); ret = true; } $( ".filters li a[data-filter='" + val + "']" ).addClass( 'active' ); return ret; //$( ".filters li a[data-filter='" + val + "']" ).prop( 'checked' , true ); } ,removeFilter: function( val ) { val = cleanTag( val ); Filters.remove( Filters.where( { "val": val } ) ); //$( ".filters li a[data-filter='" + val + "']" ).prop( 'checked' , false ); $( ".filters li a[data-filter='" + val + "']" ).removeClass( 'active' ); } ,toggleFilter: function( val ) { var added = this.addFilter( val ); if( ! added ) this.removeFilter( val ); return added; } }); var Router = Backbone.Router.extend({ routes: { "": "start" ,":date(/:filter)": "show" } ,show: function( dateParam , filtercsv ) { var splitdate = dateParam.split( "," ); if( /*the number of items is more or less than needed for the date*/ ( splitdate.length != 3 && splitdate.length != 4 ) || splitdate[ 0 ].match( /[a-zA-Z]/ ) || splitdate[ 1 ].match( /[a-zA-Z]/ ) || splitdate[ 2 ].match( /[a-zA-Z]/ ) ) { /*dateParam is actually filtercsv*/ this.filterOnly( dateParam ); } else { this.showFromDate( dateParam , filtercsv ); } } ,showFromDate: function( dateParam , filtercsv ) { var tmp = dateParam.split( "," ); Filters.fillFromCSV( filtercsv ); Calendar.month = parseInt( tmp[ 0 ] ); Calendar.day = parseInt( tmp[ 1 ] ); Calendar.year = parseInt( tmp[ 2 ] ); Calendar.format = tmp[ 3 ]; App.fetchAndShow(); } ,filterOnly: function( filtercsv ) { var now = moment(); this.showFromDate( ( now.month() + 1 ) + "," + now.date() + "," + now.year() + ",month" , filtercsv ); } ,start: function() { this.filterOnly( "" ); } }); var BasicListView = Backbone.View.extend({ initialize: function() { this.listenTo( _calendarEvents , "multiplesAdded" , function() { this.render(); this.renderFeatured(); } , this ); } ,render: function() { var self = this; $( "ul.event-list, ol.event-list, .event-list > ol, .event-list > ul, .event-list.special, .events-div" ).each( function( idx , ele ) { Filters.clear() let tmpFilters = $( ele ).data( 'filter' ); if(!tmpFilters) tmpFilters = $( ele ).data( 'tags' ) if( tmpFilters ) { tmpFilters = tmpFilters.split( tmpFilters.indexOf( "|" ) ? "|" : "," ); for( let i = 0; i < tmpFilters.length; i++ ) { if( tmpFilters[ i ] != "" ) Filters.addFilter( tmpFilters[ i ] ); } } else { Filters.clear(); } let upcomingArr = self.getUpcomingEvents(); var upcoming = new DayEventCollection( upcomingArr , { "upcomingList" : true } ); var size = $( ele ).hasClass( "Small" ) || $( ele ).hasClass( "small" ) || $( ele ).parent().hasClass( "small" ) || $( ele ).data( "small" ) || ( $( ele ).data( "size" ) && $( ele ).data( "size" ).toString().toLowerCase() == "small" ) ? CONFIG.size_small : CONFIG.size_large; setTemplatesFromFile(); var tmp = $( ele ).hasClass( "Small" ) || $( ele ).hasClass( "small" ) || $( ele ).parent().hasClass( "small" ) || $( ele ).data( "small" ) || ( $( ele ).data( "size" ) && $( ele ).data( "size" ).toString().toLowerCase() == "small" ) ? CONFIG.small_list_item_template : CONFIG.list_item_template; if( $( ele ).data( "type" ) && CONFIG.list_layouts[ $( ele ).data( "type" ) ] ) { tmp = CONFIG.list_layouts[ $( ele ).data( "type" ) ]; } else if( $( ele ).data( "special" ) || $( ele ).hasClass( "special" ) || $( ele ).parent().hasClass( "special" ) ) { tmp = CONFIG.special_list_item_template; size = CONFIG.size_special; } else if( $( ele ).data( "special2" ) || $( ele ).hasClass( "special2" ) || $( ele ).parent().hasClass( "special2" ) ) { tmp = CONFIG.special2_list_item_template; size = CONFIG.size_special2; } var tmpSpecificSize = parseInt( $( ele ).data( "size" ) ); if( ! isNaN( tmpSpecificSize ) ) { size = tmpSpecificSize; } self.template = _.template( tmp ); $( ele ).empty(); for( var i = 0; i < size && i < upcomingArr.length; i++ ) { $( ele ).append( self.template( upcoming.at( i ).toJSON() ) ); } }); this.findCategorySelect(); this.findSearchInput(); this.afterRender(); } ,afterRender: function() { if( $(".carousel-event-list").slick ) { $(".carousel-event-list").slick({ infinite: true, slidesToShow: 3, slidesToScroll: 1, autoplay: false, arrows: true, dots: false, responsive: [{ breakpoint: 992, settings: { slidesToShow: 2, slidesToScroll: 1, } }, { breakpoint: 767, settings: { slidesToShow: 1, slidesToScroll: 1, } }, { breakpoint: 510, settings: { slidesToShow: 1, slidesToScroll: 1, arrows: false, dots: true, } } ] }); } } ,getUpcomingEvents: function() { let upcomingArr = ALL0W_SEARCH ? this.getEventsFromFiltersCollection() : this.getEventsFromStaticFilters(); return upcomingArr; } ,getEventsFromFiltersCollection: function() { let curTime = moment(); let events = _.filter(_calendarEvents.models, function( item ) { let ret = false; if( item.get( "startMomentZeroHour" ) ) { if( item.isParent() && ( Filters.length == 0 || Filters.match( item.get( "tags" ) ) ) ) { ret = ( item.get( "startMomentZeroHour" ).diff( curTime , 'days' ) > (CONFIG.days_in_past * -1) ) || ( item.get( "endMomentZeroHour" ).diff( curTime , 'days' ) > (CONFIG.days_in_past * -1) ); if( ret && Calendar.searchText != "" ) { ret = item.search( Calendar.searchText ) } } } return ret; }); return events; } ,getEventsFromStaticFilters: function() { let curTime = moment(); let filter = this.getStaticFilters( $( ele ) ); let events = _.filter(_calendarEvents.models, function( item ) { let ret = false; if( item.get( "startMomentZeroHour" ) ) { if( item.isParent() && ( filter == "" || item.get( "tags" ).indexOf( filter ) > -1 ) ) { ret = ( item.get( "startMomentZeroHour" ).diff( curTime , 'days' ) > (CONFIG.days_in_past * -1) ) || ( item.get( "endMomentZeroHour" ).diff( curTime , 'days' ) > (CONFIG.days_in_past * -1) ); } } return ret; }); return events; } ,findSearchInput: function() { this.$searchTextbox = $( "#event-search-textbox,#filters-search" ); if( this.$searchTextbox.length > 0 ) { this.$searchTextbox.on( "change" , function( e ) { e.preventDefault(); Calendar.searchText = this.$searchTextbox.val().length > 3 ? this.$searchTextbox.val() : ""; this.render(); } ); } } ,findCategorySelect: function() { this.$categorySelect = $( "#event-category-select" ); if( this.$categorySelect.length > 0 ) { if( CONFIG.generate_filters_from_data ) { this.$categorySelect.empty(); this.$categorySelect.append( '' ); for( let i = 0; i < _calendarEvents.uniqueTags.length; i++ ) { this.$categorySelect.append( '' ); } } else { this.$categorySelect.find( "option" ).each( function( idx ) { if( $( this ).val() != "" && _calendarEvents.uniqueTagsSym.indexOf( $( this ).val().replace( /[^a-zA-Z]/g , "" ) ) == -1 ) { $( this ).prop( 'disabled' , 'disabled' ); } }); } this.$categorySelect.on( "change" , function( e ) { e.preventDefault(); Filters.clear(); Filters.addFilter( this.$categorySelect.val() ); this.render(); } ); } } ,renderFeatured: function() { var curTime = moment();//.valueOf(); var self = this; $( ".featured-grid" ).each( function( idx , ele ) { var filter = self.getStaticFilters( $( ele ) ); var upcomingArr = _.filter(_calendarEvents.models, function( item ) { var ret = false; if( item.get( "startMomentZeroHour" ) ) { if( item.isParent() && ( filter == "" || item.get( "tags" ).indexOf( filter ) > -1 ) ) ret = item.get( "startMomentZeroHour" ).diff( curTime , 'days' ) > (CONFIG.days_in_past * -1); } return ret; }); var upcoming = new DayEventCollection( upcomingArr , { "upcomingList" : true } ); var tmphtml = '
    View All Events
    '; $( ele ).html( tmphtml ); //var tmp = CONFIG.list_item_template; //this.template = _.template( tmp ); //for( var i = 0; i < size && i < upcomingArr.length; i++ ) { //$( ele ).append( this.template( upcoming.at( i ).toJSON() ) ); //} }); } ,getStaticFilters: function( $ele ) { if( $ele.data( 'filter' ) ) { return $ele.data( 'filter' ); } else if( $ele.data( 'category' ) ) { return $ele.data( 'category' ); } else if( $ele.data( 'tag' ) ) { return $ele.data( 'tag' ); } else { return ""; } } }); var AppView = Backbone.View.extend({ router: new Router() ,start: function() { var self = this; /*$.getJSON( CONFIG_URL , function( data ) { CONFIG = data[0];*/ Backbone.history.start(); this.forceList(); this.loadStaticFilters(); this.doDatepicker(); /*}).fail(function(a,b,v) { console.log(a); console.log(b); });*/ } ,navigate: function() { if( Calendar.format == "month" ) { var today = new Date(); Calendar.day = today.getDate(); if( Calendar.month == 2 && Calendar.day > 28 ) Calendar.day = 28; else if( Calendar.day == 31 && [1,3,5,7,8,10,12].indexOf( Calendar.month ) == -1 ) Calendar.day -= 1; } //Calendar.setActiveNavLink(); this.router.navigate( Calendar.getDateParamStr() + Filters.getURLString() , {trigger: true} ); } ,doDatepicker: function() { var self = this; this.activeCalRender = false; this.miniCalAction = false; if( $('.datepicker-container').length > 0 ) { $('.datepicker-container').datetimepicker({ inline: true }); $('.datepicker-container').on('dp.update', function(e) { if( ! self.activeCalRender ) { Calendar.day = e.viewDate.date(); Calendar.month = e.viewDate.month() + 1; Calendar.year = e.viewDate.year(); Calendar.format = "month"; self.miniCalAction = true; App.navigate(); } self.activeCalRender = false; }); $('.datepicker-container').on('dp.change', function(e) { if( ! self.activeCalRender ) { Calendar.day = e.date.date(); Calendar.month = e.date.month() + 1; Calendar.year = e.date.year(); Calendar.format = "day"; self.miniCalAction = true; App.navigate(); } self.activeCalRender = false; }); /*Calendar.on( "rendered" , function() { self.activeCalRender = true; $('.datepicker-container').data("DateTimePicker").date( new Date( Calendar.year , Calendar.month - 1 , Calendar.day ) ); });*/ } } ,setDatePickerTime: function() { this.activeCalRender = true; if( $('.datepicker-container').length > 0 ) $('.datepicker-container').data("DateTimePicker").date( new Date( Calendar.year , Calendar.month - 1 , Calendar.day ) ); } ,fetchAndShow: function() { if( _calendarEvents.models.length == 0 ) { _calendarEvents.url = inCascade ? CONFIG.cascade_data_file : EVENTS_BASE + CONFIG.data_file.replace( "&" , "&" ); if( CONFIG.templates_file ) { var templateURL = inCascade ? CONFIG.cascade_templates_file : EVENTS_BASE + CONFIG.templates_file.replace( "&" , "&" ); $.get( templateURL , function( data ) { $( 'body' ).append( data ); setTemplatesFromFile() _calendarEvents.fetch(); }); } else { _calendarEvents.fetch(); } } else { Calendar.render(); //FeatureSlider.collection = new Backbone.Collection( _calendarEvents.getFeaturedEvents() ); //FeatureSlider.render(); } } ,loadStaticFilters: function() { if( Calendar.$el.data( 'filter' ) ) { Filters.addFilter( Calendar.$el.data( 'filter' ) ); } else if( Calendar.$el.data( 'category' ) ) { Filters.addFilter( Calendar.$el.data( 'category' ) ); } else if( Calendar.$el.data( 'tags' ) ) { Filters.addFilter( Calendar.$el.data( 'tags' ) ); } } ,forceList: function() { if( ! Calendar.$el.data( "list" ) ) { Calendar.$el.toggleClass( "list-cal" , Calendar.format != "month" || $( window ).width() < CONFIG.minCalendarWidth ); if( $( window ).width() >= CONFIG.minCalendarWidth ) { $(".filter-list").show(); } } } }); var _calendarEvents = new CalendarEventCollection(); var Filters = new FilterCollection(); var Calendar = new CalendarView(); var BasicList = new BasicListView(); //var FeatureSlider = new FeatureView(); var App = new AppView(); App.start(); $(window).on( "resize" , function() { App.forceList(); Calendar.monthView.rerender(); }); function setTemplatesFromFile() { if( CONFIG.templates_file ) { CONFIG.calendar_layouts = {}; CONFIG.list_layouts = {}; $( ".template.calendar" ).each( function( idx , item ) { if( $( item ).data( "type" ) ) { CONFIG.calendar_layouts[ $( item ).data( "type" ) ] = $( item ).html(); } }); $( ".template.list" ).each( function( idx , item ) { if( $( item ).data( "type" ) ) { CONFIG.list_layouts[ $( item ).data( "type" ) ] = $( item ).html(); } }); CONFIG.next_template = $( "#next_template" ).html(); CONFIG.previous_template = $( "#previous_template" ).html(); CONFIG.calendar_day_container_template = $( "#calendar_day_container_template" ).html(); CONFIG.calendar_item_template = $( "#calendar_item_template" ).html(); CONFIG.special_calendar_day_container_template = $( "#special_calendar_day_container_template" ).html(); CONFIG.special_calendar_item_template = $( "#special_calendar_item_template" ).html(); CONFIG.special_list_item_template = $( "#special_list_item_template" ).html(); CONFIG.list_item_template = $( "#list_item_template" ).html(); CONFIG.small_list_item_template = $( "#small_list_item_template" ).html(); CONFIG.empty_default = $( "#empty_default" ).html(); //console.log( CONFIG ); } } function daysInMonth(month,year) { return new Date(year, month, -1).getDate(); } function getMonthName( date ) { return moment( date ).format( 'MMMM' ); } function registerGlobalEvents() { Filters.setActiveFilters(); $( '.filters li a' ).click( function( e ) { e.preventDefault(); filterLink( e.target ) } ); $(".mob-filters-trigger").click(function(){ e.preventDefault(); $(".filter-list").slideToggle("fast"); }); $(document).on( 'filterLink' , function( e , val ) { if( CONFIG.multi_filter_selection ) Filters.toggleFilter( val ); else { var clearingSame = false; //if( val == "Featured" && Filters.length > 0 && Filters.at( 0 ).get( "val" ) == "Featured" ) if( Filters.length > 0 && Filters.at( 0 ).get( "val" ).toLowerCase() == val.toLowerCase() ) clearingSame = true; Filters.clear(); if( !clearingSame ) Filters.addFilter( val ); } //Calendar.format = "month"; App.navigate(); }); } }); function filterLink( ele ) { $(document).trigger( "filterLink" , (typeof( ele ) == "string" ? ele : $(ele).data( 'filter' ) ? $(ele).data( 'filter' ) : ele.innerHTML ) ); return false; } // Added by Bob $(document).ready(function(){ $(".mob-filters-trigger").click(function(){ $(".filter-list").slideToggle("fast"); }); }); /*let fontSize = Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)[0]); let newBreakPoint = (fontSize*62-18); var isInDesktopMode = ($(window).width() > newBreakPoint); $(window).resize(function() { let fontSize = Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)[0]); let newBreakPoint = (fontSize*62-18); if ($(window).width() > newBreakPoint) { isInDesktopMode = true; $(".filter-list").removeAttr("style"); } else if (isInDesktopMode) { isInDesktopMode = false; $(".filter-list").hide(); } }); */