vendor/assets/javascripts/event_cal.js in event_cal-1.2 vs vendor/assets/javascripts/event_cal.js in event_cal-1.2.1
- old
+ new
@@ -1,12 +1,12 @@
-// Generated by CoffeeScript 1.3.1
+// Generated by CoffeeScript 1.3.3
(function() {
var $, CalendarApplication, CalendarDate, CalendarDatesController, CalendarEvent, CalendarEventsController, Controller, Events, Log, Model, Module, Spine, createObject, isArray, isBlank, makeArray, moduleKeywords,
__slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Events = {
bind: function(ev, callback) {
var calls, evs, name, _i, _len;
@@ -92,12 +92,10 @@
moduleKeywords = ['included', 'extended'];
Module = (function() {
- Module.name = 'Module';
-
Module.include = function(obj) {
var key, value, _ref;
if (!obj) {
throw new Error('include(obj) requires obj');
}
@@ -156,12 +154,10 @@
Model = (function(_super) {
__extends(Model, _super);
- Model.name = 'Model';
-
Model.extend(Events);
Model.records = {};
Model.crecords = {};
@@ -645,12 +641,10 @@
Controller = (function(_super) {
__extends(Controller, _super);
- Controller.name = 'Controller';
-
Controller.include(Events);
Controller.include(Log);
Controller.prototype.eventSplitter = /^(\S+)\s*(.*)$/;
@@ -873,12 +867,10 @@
var Result;
Result = (function(_super) {
__extends(Result, _super);
- Result.name = 'Result';
-
function Result() {
return Result.__super__.constructor.apply(this, arguments);
}
return Result;
@@ -903,12 +895,10 @@
}
Instance = (function(_super) {
__extends(Instance, _super);
- Instance.name = 'Instance';
-
function Instance() {
return Instance.__super__.constructor.apply(this, arguments);
}
return Instance;
@@ -922,12 +912,10 @@
CalendarDate = (function(_super) {
__extends(CalendarDate, _super);
- CalendarDate.name = 'CalendarDate';
-
function CalendarDate() {
return CalendarDate.__super__.constructor.apply(this, arguments);
}
CalendarDate.configure('CalendarDate', 'element', 'date', 'active');
@@ -952,12 +940,10 @@
CalendarEvent = (function(_super) {
__extends(CalendarEvent, _super);
- CalendarEvent.name = 'CalendarEvent';
-
function CalendarEvent() {
return CalendarEvent.__super__.constructor.apply(this, arguments);
}
CalendarEvent.configure('CalendarEvent', 'held_on', 'active', 'element');
@@ -991,12 +977,10 @@
CalendarDatesController = (function(_super) {
__extends(CalendarDatesController, _super);
- CalendarDatesController.name = 'CalendarDatesController';
-
function CalendarDatesController(element) {
this.element = element;
this.initializeDates();
}
@@ -1046,12 +1030,10 @@
CalendarEventsController = (function(_super) {
__extends(CalendarEventsController, _super);
- CalendarEventsController.name = 'CalendarEventsController';
-
function CalendarEventsController(element) {
var el, event, _i, _len, _ref;
_ref = element.find('.event_detail');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
el = _ref[_i];
@@ -1082,35 +1064,54 @@
window.CalendarEventsController = CalendarEventsController;
CalendarApplication = (function() {
var calendarElements;
- CalendarApplication.name = 'CalendarApplication';
-
function CalendarApplication() {}
calendarElements = {
'ul.dates': CalendarDatesController,
'ul.event_details': CalendarEventsController
};
- CalendarApplication.initialize = function() {
- var controller, el, element, _results;
- _results = [];
+ CalendarApplication.initialize = function(options) {
+ var controller, el, element, _i, _len, _ref;
+ if (options == null) {
+ options = {};
+ }
for (element in calendarElements) {
controller = calendarElements[element];
- _results.push((function() {
- var _i, _len, _ref, _results1;
- _ref = $(element);
- _results1 = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- el = _ref[_i];
- _results1.push(new controller($(el)));
- }
- return _results1;
- })());
+ _ref = $(element);
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ el = _ref[_i];
+ new controller($(el));
+ }
}
- return _results;
+ if (options.history) {
+ return this.initializeHistory(options.basePath);
+ }
+ };
+
+ CalendarApplication.initializeHistory = function(basePath) {
+ CalendarDate.all().map(function(date) {
+ return date.element.bind('click', function(event) {
+ var _ref;
+ return typeof window !== "undefined" && window !== null ? (_ref = window.history) != null ? _ref.pushState({
+ dateObjectId: date.id
+ }, null, "" + basePath + "/" + (date.toPath())) : void 0 : void 0;
+ });
+ });
+ return typeof window !== "undefined" && window !== null ? window.onpopstate = function(event) {
+ var date, _ref;
+ if (((_ref = event.state) != null ? _ref.dateObjectId : void 0) != null) {
+ date = CalendarDate.find(event.state.dateObjectId);
+ date.trigger('activate');
+ CalendarDate.deactivateAllDates();
+ return date.updateAttributes({
+ active: true
+ });
+ }
+ } : void 0;
};
return CalendarApplication;
})();