Skip to content

Commit

Permalink
Add custom behaviour to clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielhpugliese committed Jan 10, 2015
1 parent 20d93c4 commit 0481608
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ Smart package for SuperCalendar. Google Calendar-like as smart package

http://supercalendar.meteor.com

## Mantained by CodersTV

This package is used and mantained by [CodersTV](http://coderstv.com)

## Install

To install in a new project:
Expand All @@ -28,19 +24,34 @@ In your body or any template, you can simply add the calendar view (required), n
</body>
```

## Configuration
## Custom behaviour

Override pre-defined function events within `CalendarOptions.events` to add your own behaviours.

Example (if you want to override a click on a day square):
```javascript
Meteor.startup(function () {
SuperCalendar.events.onDayClick = function (event, template) {
// put your custom code here.
};
});
```

### Events

Those are events supported by now. Create an issue to request more:

* onDayClick: when users click on a day square.
* onEventClick: when users click on a registered event.

If you want to have your own event view/model, just rewrite
`new_event_modal` and `event_details` views. Use `Calendar` collection to
add events.
## Model configuration

I'm using [Mesosphere](https://github.com/copleykj/Mesosphere) for form validation. Take a look how to do it in
lib/forms.js
Use `Calendar` collection to add events. If you don't want to publish it all, create an issue to request the removal.

## Third party projects included

Thanks for those wonderful packages I'm using:
* [Anti:Modals](https://atmospherejs.com/anti/modals) for modals
* [Mesosphere](https://github.com/copleykj/Mesosphere) for form
* [Anti:Modals](https://atmospherejs.com/anti/modals) for modals. Take a look how to to it in `client/lib/app.js`
* [Mesosphere](https://github.com/copleykj/Mesosphere) for form. Take a look how to do it in `lib/forms.js`
validation
* [FullCalendar](http://arshaw.com/fullcalendar/) for Google Calendar-like UI
23 changes: 23 additions & 0 deletions client/lib/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SuperCalendar = {
events: {
onEventClick: function (e, t) {
var eventId = e.target.id || $(e.target).closest('.fc-event-hori').attr('id');
var calEvent = Calendar.findOne(eventId);

AntiModals.overlay('event_details', {
data: calEvent
});
},
onDayClick: function (e) {
var target = event;
var date = $(target).parents('.fc-day').attr('data-date') || $(target).attr('data-date');

AntiModals.overlay('new_event_modal', {
data: {
date: date
}
});
}
}
};

18 changes: 3 additions & 15 deletions client/views/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,11 @@ Template.calendar.rendered = function () {
};

Template.calendar.events({
'click .fc-square, click .fc-day' : function (event) {
var target = event.target;
var date = $(target).parents('.fc-day').attr('data-date') || $(target).attr('data-date');

AntiModals.overlay('new_event_modal', {
data: {
date: date
}
});
'click .fc-square, click .fc-day': function (e, t) {
return SuperCalendar.events.onDayClick(e, t);
},
'click .fc-event': function (e, t) {
var eventId = e.target.id || $(e.target).closest('.fc-event-hori').attr('id');
var calEvent = Calendar.findOne(eventId);

AntiModals.overlay('event_details', {
data: calEvent
});
return SuperCalendar.events.onEventClick(e, t);
}
});

Expand Down
4 changes: 3 additions & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: "gabrielhpugliese:supercalendar",
summary: "Google Calendar-like as smart package",
version: "0.4.0",
version: "0.5.0",
git: "https://github.com/gabrielhpugliese/meteor_supercalendar"
});

Expand All @@ -22,6 +22,7 @@ Package.onUse(function (api, where) {
'less',
], 'client');
api.add_files([
'client/lib/app.js',
'client/stylesheets/calendar.less',
'client/stylesheets/fullcalendar.css',
'client/stylesheets/fullcalendar.print.css',
Expand Down Expand Up @@ -50,6 +51,7 @@ Package.onUse(function (api, where) {

if (typeof api.export !== 'undefined') {
api.export('Calendar', ['client', 'server']);
api.export('SuperCalendar', ['client']);
}

});

0 comments on commit 0481608

Please sign in to comment.