kalendae_assets 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +4 -0
  3. data/README.md +10 -2
  4. data/Rakefile +9 -0
  5. data/kalendae_assets.gemspec +5 -2
  6. data/lib/kalendae_assets/version.rb +1 -1
  7. data/test/dummy/README.rdoc +261 -0
  8. data/test/dummy/Rakefile +7 -0
  9. data/test/dummy/app/assets/javascripts/application.js +16 -0
  10. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  11. data/test/dummy/app/controllers/application_controller.rb +3 -0
  12. data/test/dummy/app/helpers/application_helper.rb +2 -0
  13. data/test/dummy/app/mailers/.gitkeep +0 -0
  14. data/test/dummy/app/models/.gitkeep +0 -0
  15. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  16. data/test/dummy/config/application.rb +56 -0
  17. data/test/dummy/config/boot.rb +10 -0
  18. data/test/dummy/config/database.yml +25 -0
  19. data/test/dummy/config/environment.rb +5 -0
  20. data/test/dummy/config/environments/development.rb +37 -0
  21. data/test/dummy/config/environments/production.rb +67 -0
  22. data/test/dummy/config/environments/test.rb +37 -0
  23. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  24. data/test/dummy/config/initializers/inflections.rb +15 -0
  25. data/test/dummy/config/initializers/mime_types.rb +5 -0
  26. data/test/dummy/config/initializers/secret_token.rb +7 -0
  27. data/test/dummy/config/initializers/session_store.rb +8 -0
  28. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  29. data/test/dummy/config/locales/en.yml +5 -0
  30. data/test/dummy/config/routes.rb +58 -0
  31. data/test/dummy/config.ru +4 -0
  32. data/test/dummy/db/test.sqlite3 +0 -0
  33. data/test/dummy/lib/assets/.gitkeep +0 -0
  34. data/test/dummy/log/.gitkeep +0 -0
  35. data/test/dummy/public/404.html +26 -0
  36. data/test/dummy/public/422.html +26 -0
  37. data/test/dummy/public/500.html +25 -0
  38. data/test/dummy/public/favicon.ico +0 -0
  39. data/test/dummy/script/rails +6 -0
  40. data/test/integration/kalendae_assets_integration_spec.rb +14 -0
  41. data/test/lib/kalendae_assets_spec.rb +11 -0
  42. data/test/spec_helper.rb +16 -0
  43. data/vendor/assets/javascripts/kalendae.js +94 -94
  44. data/vendor/assets/stylesheets/kalendae.css +2 -1
  45. metadata +116 -10
@@ -12,7 +12,7 @@ var today;
12
12
  var Kalendae = function (targetElement, options) {
13
13
  //if the first argument isn't an element and isn't a string, assume that it is the options object
14
14
  if (!(targetElement instanceof Element || typeof targetElement === 'string')) options = targetElement;
15
-
15
+
16
16
  var self = this,
17
17
  classes = self.classes,
18
18
  opts = self.settings = util.merge(self.defaults, {attachTo:targetElement}, options || {}),
@@ -29,14 +29,14 @@ var Kalendae = function (targetElement, options) {
29
29
  $span,
30
30
  i = 0,
31
31
  j = opts.months;
32
-
32
+
33
33
  //generate the column headers (Su, Mo, Tu, etc)
34
34
  i = 7;
35
35
  while (i--) {
36
36
  columnHeaders.push( startDay.format('ddd').substr(0,opts.columnHeaderLength) );
37
37
  startDay.add('days',1);
38
38
  }
39
-
39
+
40
40
  //setup publish/subscribe and apply any subscriptions passed in settings
41
41
  MinPubSub(self);
42
42
  if (typeof opts.subscribe === 'object') {
@@ -44,7 +44,7 @@ var Kalendae = function (targetElement, options) {
44
44
  self.subscribe(i, opts.subscribe[i]);
45
45
  }
46
46
  }
47
-
47
+
48
48
  //process default selected dates
49
49
  self._sel = [];
50
50
  if (!!opts.selected) self.setSelected(opts.selected, false);
@@ -58,8 +58,8 @@ var Kalendae = function (targetElement, options) {
58
58
  vsd = moment();
59
59
  }
60
60
  self.viewStartDate = vsd.date(1);
61
-
62
-
61
+
62
+
63
63
  if (typeof opts.blackout === 'function') {
64
64
  self.blackout = opts.blackout;
65
65
  } else if (!!opts.blackout) {
@@ -69,34 +69,34 @@ var Kalendae = function (targetElement, options) {
69
69
  if (input < 1 || !self._sel || self._sel.length < 1) return false;
70
70
  var i = bdates.length;
71
71
  while (i--) if (bdates[i].valueOf() === input) return true;
72
- return false;
72
+ return false;
73
73
  }
74
74
  } else {
75
75
  self.blackout = function () {return false;}
76
76
  }
77
-
78
-
77
+
78
+
79
79
  self.direction = self.directions[opts.direction] ? self.directions[opts.direction] : self.directions['any'];
80
-
81
-
80
+
81
+
82
82
  //for the total months setting, generate N calendar views and add them to the container
83
83
  j = Math.max(opts.months,1);
84
84
  while (j--) {
85
85
  $cal = util.make('div', {'class':classes.calendar}, $container);
86
-
86
+
87
87
  $cal.setAttribute('data-cal-index', j);
88
88
  if (opts.months > 1) {
89
89
  if (j == Math.max(opts.months-1,1)) util.addClassName($cal, classes.monthFirst);
90
90
  else if (j === 0) util.addClassName($cal, classes.monthLast);
91
91
  else util.addClassName($cal, classes.monthMiddle);
92
92
  }
93
-
93
+
94
94
  //title bar
95
95
  $title = util.make('div', {'class':classes.title}, $cal);
96
96
  util.make('a', {'class':classes.previous}, $title); //previous button
97
97
  util.make('a', {'class':classes.next}, $title); //next button
98
98
  $caption = util.make('span', {'class':classes.caption}, $title); //title caption
99
-
99
+
100
100
  //column headers
101
101
  $header = util.make('div', {'class':classes.header}, $cal);
102
102
  i = 0;
@@ -118,12 +118,12 @@ var Kalendae = function (targetElement, options) {
118
118
  caption:$caption,
119
119
  days:dayNodes
120
120
  });
121
-
121
+
122
122
  if (j) util.make('div', {'class':classes.monthSeparator}, $container);
123
123
  }
124
-
124
+
125
125
  self.draw();
126
-
126
+
127
127
  util.addEvent($container, 'mousedown', function (event, target) {
128
128
  var clickedDate;
129
129
  if (util.hasClassName(target, classes.next)) {
@@ -132,8 +132,8 @@ var Kalendae = function (targetElement, options) {
132
132
  self.viewStartDate.add('months',1);
133
133
  self.draw();
134
134
  }
135
- return false;
136
-
135
+ return false;
136
+
137
137
  } else if (util.hasClassName(target, classes.previous)) {
138
138
  //PREVIOUS MONTH BUTTON
139
139
  if (self.publish('view-changed', self, ['previous']) !== false) {
@@ -141,13 +141,13 @@ var Kalendae = function (targetElement, options) {
141
141
  self.draw();
142
142
  }
143
143
  return false;
144
-
145
-
144
+
145
+
146
146
  } else if (util.hasClassName(target.parentNode, classes.days) && util.hasClassName(target, classes.dayActive) && (clickedDate = target.getAttribute('data-date'))) {
147
147
  //DAY CLICK
148
148
  clickedDate = moment(clickedDate, opts.dayAttributeFormat);
149
149
  if (self.publish('date-clicked', self, [clickedDate]) !== false) {
150
-
150
+
151
151
  switch (opts.mode) {
152
152
  case 'multiple':
153
153
  if (!self.addSelected(clickedDate)) self.removeSelected(clickedDate);
@@ -164,16 +164,16 @@ var Kalendae = function (targetElement, options) {
164
164
 
165
165
  }
166
166
  return false;
167
-
167
+
168
168
  }
169
169
  return false;
170
170
  });
171
-
171
+
172
172
 
173
173
  if (!!(opts.attachTo = util.$(opts.attachTo))) {
174
174
  opts.attachTo.appendChild($container);
175
175
  }
176
-
176
+
177
177
  };
178
178
 
179
179
  Kalendae.prototype = {
@@ -193,10 +193,10 @@ Kalendae.prototype = {
193
193
  titleFormat: 'MMMM, YYYY', /* format mask for month titles. See momentjs.com for rules */
194
194
  dayNumberFormat: 'D', /* format mask for individual days */
195
195
  dayAttributeFormat: 'YYYY-MM-DD', /* format mask for the data-date attribute set on every span */
196
- parseSplitDelimiter: /,\s*|\s*-\s*/, /* regex to use for splitting multiple dates from a passed string */
196
+ parseSplitDelimiter: /,\s*|\s+-\s+/, /* regex to use for splitting multiple dates from a passed string */
197
197
  rangeDelimiter: ' - ', /* string to use between dates when outputting in range mode */
198
198
  multipleDelimiter: ', ', /* string to use between dates when outputting in multiple mode */
199
-
199
+
200
200
  dateClassMap: {}
201
201
  },
202
202
  classes : {
@@ -218,15 +218,15 @@ Kalendae.prototype = {
218
218
  dayToday :'k-today',
219
219
  monthSeparator :'k-separator'
220
220
  },
221
-
221
+
222
222
  directions: {
223
- 'past' :function (date) {return moment(date).valueOf() >= today.valueOf();},
224
- 'today-past' :function (date) {return moment(date).valueOf() > today.valueOf();},
225
- 'any' :function (date) {return false;},
226
- 'today-future' :function (date) {return moment(date).valueOf() < today.valueOf();},
223
+ 'past' :function (date) {return moment(date).valueOf() >= today.valueOf();},
224
+ 'today-past' :function (date) {return moment(date).valueOf() > today.valueOf();},
225
+ 'any' :function (date) {return false;},
226
+ 'today-future' :function (date) {return moment(date).valueOf() < today.valueOf();},
227
227
  'future' :function (date) {return moment(date).valueOf() <= today.valueOf();}
228
228
  },
229
-
229
+
230
230
  getSelectedAsDates : function () {
231
231
  var out = [];
232
232
  var i=0, c = this._sel.length;
@@ -235,7 +235,7 @@ Kalendae.prototype = {
235
235
  }
236
236
  return out;
237
237
  },
238
-
238
+
239
239
  getSelectedAsText : function (format) {
240
240
  var out = [];
241
241
  var i=0, c = this._sel.length;
@@ -244,7 +244,7 @@ Kalendae.prototype = {
244
244
  }
245
245
  return out;
246
246
  },
247
-
247
+
248
248
  getSelectedRaw : function () {
249
249
  var out = [];
250
250
  var i=0, c = this._sel.length;
@@ -253,7 +253,7 @@ Kalendae.prototype = {
253
253
  }
254
254
  return out;
255
255
  },
256
-
256
+
257
257
  getSelected : function (format) {
258
258
  var sel = this.getSelectedAsText(format);
259
259
  switch (this.settings.mode) {
@@ -270,7 +270,7 @@ Kalendae.prototype = {
270
270
  return sel[0];
271
271
  }
272
272
  },
273
-
273
+
274
274
  isSelected : function (input) {
275
275
  input = moment(input).hours(0).minutes(0).seconds(0).milliseconds(0).valueOf();
276
276
  if (input < 1 || !this._sel || this._sel.length < 1) return false;
@@ -304,14 +304,14 @@ Kalendae.prototype = {
304
304
 
305
305
  return false;
306
306
  },
307
-
307
+
308
308
  setSelected : function (input, draw) {
309
309
  this._sel = parseDates(input, this.settings.parseSplitDelimiter, this.settings.format);
310
310
  this._sel.sort(function (a,b) {return a.valueOf() - b.valueOf();});
311
311
 
312
312
  if (draw !== false) this.draw();
313
313
  },
314
-
314
+
315
315
  addSelected : function (date, draw) {
316
316
  date = moment(date).hours(0).minutes(0).seconds(0).milliseconds(0);
317
317
  switch (this.settings.mode) {
@@ -338,7 +338,7 @@ Kalendae.prototype = {
338
338
  if (draw !== false) this.draw();
339
339
  return true;
340
340
  },
341
-
341
+
342
342
  removeSelected : function (date, draw) {
343
343
  date = moment(date).hours(0).minutes(0).seconds(0).milliseconds(0).valueOf();
344
344
  var i = this._sel.length;
@@ -352,7 +352,7 @@ Kalendae.prototype = {
352
352
  }
353
353
  return false;
354
354
  },
355
-
355
+
356
356
  draw : function draw() {
357
357
  // return;
358
358
  var month = moment(this.viewStartDate),
@@ -368,7 +368,7 @@ Kalendae.prototype = {
368
368
  opts = this.settings;
369
369
 
370
370
  c = this.calendars.length;
371
-
371
+
372
372
  var viewDelta = ({
373
373
  'past' : c-1,
374
374
  'today-past' : c-1,
@@ -376,12 +376,12 @@ Kalendae.prototype = {
376
376
  'today-future' : 0,
377
377
  'future' : 0
378
378
  })[this.settings.direction];
379
-
379
+
380
380
  if (viewDelta) month = month.subtract({M:viewDelta});
381
381
 
382
382
  do {
383
383
  day = moment(month).date(1);
384
- day.day( day.day() < this.settings.weekStart ? this.settings.weekStart-7 : this.settings.weekStart);
384
+ day.day( day.day() < this.settings.weekStart ? this.settings.weekStart-7 : this.settings.weekStart);
385
385
  //if the first day of the month is less than our week start, back up a week
386
386
 
387
387
  cal = this.calendars[i];
@@ -407,7 +407,7 @@ Kalendae.prototype = {
407
407
  $span.innerHTML = day.format(opts.dayNumberFormat);
408
408
  $span.className = klass.join(' ');
409
409
  $span.setAttribute('data-date', dateString);
410
-
410
+
411
411
 
412
412
  day.add('days',1);
413
413
  } while (++j < 42);
@@ -419,19 +419,19 @@ Kalendae.prototype = {
419
419
 
420
420
  var parseDates = function (input, delimiter, format) {
421
421
  var output = [];
422
-
422
+
423
423
  if (typeof input === 'string') {
424
- input = input.split(delimiter);
424
+ input = input.split(delimiter);
425
425
  } else if (!util.isArray(input)) {
426
426
  input = [input];
427
427
  }
428
-
428
+
429
429
  c = input.length;
430
430
  i = 0;
431
431
  do {
432
432
  if (input[i]) output.push( moment(input[i], format).hours(0).minutes(0).seconds(0).milliseconds(0) );
433
433
  } while (++i < c);
434
-
434
+
435
435
  return output;
436
436
  }
437
437
 
@@ -445,11 +445,11 @@ var util = Kalendae.util = {
445
445
  $: function (elem) {
446
446
  return (typeof elem == 'string') ? document.getElementById(elem) : elem;
447
447
  },
448
-
448
+
449
449
  $$: function (selector) {
450
450
  return document.querySelectorAll(selector);
451
451
  },
452
-
452
+
453
453
  make: function (tagName, attributes, attach) {
454
454
  var k, e = document.createElement(tagName);
455
455
  if (!!attributes) for (k in attributes) if (attributes.hasOwnProperty(k)) e.setAttribute(k, attributes[k]);
@@ -463,7 +463,7 @@ var util = Kalendae.util = {
463
463
  // shamelessly copied from jQuery
464
464
  return elem.offsetWidth > 0 || elem.offsetHeight > 0;
465
465
  },
466
-
466
+
467
467
  domReady:function (f){/in/.test(document.readyState) ? setTimeout(function() {util.domReady(f);},9) : f()},
468
468
 
469
469
  // Adds a listener callback to a DOM element which is fired on a specified
@@ -499,7 +499,7 @@ var util = Kalendae.util = {
499
499
  elem.removeEventListener(event, listener, false);
500
500
  }
501
501
  },
502
-
502
+
503
503
  hasClassName: function(elem, className) { //copied and modified from Prototype.js
504
504
  if (!(elem = util.$(elem))) return false;
505
505
  var eClassName = elem.className;
@@ -520,14 +520,14 @@ var util = Kalendae.util = {
520
520
  var x = elem.offsetLeft,
521
521
  y = elem.offsetTop,
522
522
  r = {};
523
-
523
+
524
524
  if (!isInner) {
525
525
  while ((elem = elem.offsetParent)) {
526
526
  x += elem.offsetLeft;
527
527
  y += elem.offsetTop;
528
528
  }
529
529
  }
530
-
530
+
531
531
  r[0] = r.left = x;
532
532
  r[1] = r.top = y;
533
533
  return r;
@@ -540,15 +540,15 @@ var util = Kalendae.util = {
540
540
  getWidth: function (elem) {
541
541
  return elem.offsetWidth || elem.scrollWidth;
542
542
  },
543
-
544
-
545
- // TEXT FUNCTIONS
546
-
543
+
544
+
545
+ // TEXT FUNCTIONS
546
+
547
547
  trimString: function (input) {
548
548
  return input.replace(/^\s+/, '').replace(/\s+$/, '');
549
549
  },
550
-
551
-
550
+
551
+
552
552
  // OBJECT FUNCTIONS
553
553
 
554
554
  merge: function () {
@@ -556,7 +556,7 @@ var util = Kalendae.util = {
556
556
  * Syntax: util.extend([true], object1, object2, ... objectN)
557
557
  * If first argument is true, function will merge recursively.
558
558
  */
559
-
559
+
560
560
  var deep = (arguments[0]===true),
561
561
  d = {},
562
562
  i = deep?1:0;
@@ -576,15 +576,15 @@ var util = Kalendae.util = {
576
576
  }
577
577
  return d;
578
578
  },
579
-
579
+
580
580
  isArray: function (array) {
581
581
  return !(
582
- !array ||
583
- (!array.length || array.length === 0) ||
584
- typeof array !== 'object' ||
585
- !array.constructor ||
586
- array.nodeType ||
587
- array.item
582
+ !array ||
583
+ (!array.length || array.length === 0) ||
584
+ typeof array !== 'object' ||
585
+ !array.constructor ||
586
+ array.nodeType ||
587
+ array.item
588
588
  );
589
589
  }
590
590
  };
@@ -605,7 +605,7 @@ Kalendae.util.domReady(function () {
605
605
  //otherwise, insert a flat calendar into the element.
606
606
  new Kalendae({attachTo:e});
607
607
  }
608
-
608
+
609
609
  }
610
610
  });
611
611
 
@@ -614,29 +614,29 @@ Kalendae.Input = function (targetElement, options) {
614
614
  overwriteInput;
615
615
 
616
616
  if (!$input || $input.tagName !== 'INPUT') throw "First argument for Kalendae.Input must be an <input> element or a valid element id.";
617
-
617
+
618
618
  var self = this,
619
619
  classes = self.classes
620
620
  opts = self.settings = util.merge(self.defaults, options);
621
-
621
+
622
622
  //force attachment to the body
623
623
  opts.attachTo = window.document.body;
624
624
 
625
625
  //if no override provided, use the input's contents
626
626
  if (!opts.selected) opts.selected = $input.value;
627
627
  else overwriteInput = true;
628
-
628
+
629
629
  //call our parent constructor
630
630
  Kalendae.call(self, opts);
631
-
631
+
632
632
  if (overwriteInput) $input.value = self.getSelected();
633
-
633
+
634
634
  var $container = self.container,
635
635
  noclose = false;
636
-
636
+
637
637
  $container.style.display = 'none';
638
638
  util.addClassName($container, classes.positioned);
639
-
639
+
640
640
  util.addEvent($container, 'mousedown', function (event, target) {
641
641
  noclose = true; //IE8 doesn't obey event blocking when it comes to focusing, so we have to do this shit.
642
642
  });
@@ -648,7 +648,7 @@ Kalendae.Input = function (targetElement, options) {
648
648
  self.setSelected(this.value);
649
649
  self.show();
650
650
  });
651
-
651
+
652
652
  util.addEvent($input, 'blur', function () {
653
653
  if (noclose) {
654
654
  noclose = false;
@@ -659,11 +659,11 @@ Kalendae.Input = function (targetElement, options) {
659
659
  util.addEvent($input, 'keyup', function (event) {
660
660
  self.setSelected(this.value);
661
661
  });
662
-
662
+
663
663
  self.subscribe('change', function () {
664
664
  $input.value = self.getSelected();
665
665
  });
666
-
666
+
667
667
  };
668
668
 
669
669
  Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
@@ -675,15 +675,15 @@ Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
675
675
  }),
676
676
  classes : util.merge(Kalendae.prototype.classes, {
677
677
  positioned : 'k-floating'
678
-
678
+
679
679
  }),
680
-
680
+
681
681
  show : function () {
682
682
  var $container = this.container,
683
683
  style = $container.style,
684
684
  $input = this.input,
685
685
  pos = util.getPosition($input);
686
-
686
+
687
687
  style.display = '';
688
688
  switch (opts.side) {
689
689
  case 'left':
@@ -705,13 +705,13 @@ Kalendae.Input.prototype = util.merge(Kalendae.prototype, {
705
705
  style.top = (pos.top + util.getHeight($input) + this.settings.offsetTop) + 'px';
706
706
  break;
707
707
  }
708
-
708
+
709
709
  },
710
-
710
+
711
711
  hide : function () {
712
712
  this.container.style.display = 'none';
713
713
  }
714
-
714
+
715
715
  });
716
716
 
717
717
 
@@ -728,22 +728,22 @@ var MinPubSub = function(d){
728
728
 
729
729
  // the topic/subscription hash
730
730
  var cache = d.c_ || {}; //check for "c_" cache for unit testing
731
-
731
+
732
732
  d.publish = function(/* String */ topic, /* Object */ target, /* Array? */ args){
733
- // summary:
733
+ // summary:
734
734
  // Publish some data on a named topic.
735
735
  // topic: String
736
736
  // The channel to publish on
737
737
  // args: Array?
738
738
  // The data to publish. Each array item is converted into an ordered
739
- // arguments on the subscribed functions.
739
+ // arguments on the subscribed functions.
740
740
  //
741
741
  // example:
742
742
  // Publish stuff on '/some/topic'. Anything subscribed will be called
743
743
  // with a function signature like: function(a,b,c){ ... }
744
744
  //
745
745
  // publish("/some/topic", ["a","b","c"]);
746
-
746
+
747
747
  var subs = cache[topic],
748
748
  len = subs ? subs.length : 0,
749
749
  r;
@@ -761,13 +761,13 @@ var MinPubSub = function(d){
761
761
  // topic: String
762
762
  // The channel to subscribe to
763
763
  // callback: Function
764
- // The handler event. Anytime something is publish'ed on a
764
+ // The handler event. Anytime something is publish'ed on a
765
765
  // subscribed channel, the callback will be called with the
766
766
  // published array as ordered arguments.
767
767
  //
768
768
  // returns: Array
769
769
  // A handle which can be used to unsubscribe this particular subscription.
770
- //
770
+ //
771
771
  // example:
772
772
  // subscribe("/some/topic", function(a, b, c){ /* handle data */ });
773
773
 
@@ -789,11 +789,11 @@ var MinPubSub = function(d){
789
789
  // example:
790
790
  // var handle = subscribe("/some/topic", function(){});
791
791
  // unsubscribe(handle);
792
-
792
+
793
793
  var subs = cache[handle[0]],
794
794
  callback = handle[1],
795
795
  len = subs ? subs.length : 0;
796
-
796
+
797
797
  while(len--){
798
798
  if(subs[len] === callback){
799
799
  subs.splice(len, 1);
@@ -71,6 +71,7 @@
71
71
  text-align:right;
72
72
  width:13px;
73
73
  height:1.1em;
74
+ line-height:1em;
74
75
  padding:2px 3px 2px 2px;
75
76
  border:1px solid transparent;
76
77
  border-radius:3px;
@@ -115,4 +116,4 @@
115
116
  border-color:#666;
116
117
  }
117
118
 
118
- .kalendae span.k-out-of-month {color:#ddd;}
119
+ .kalendae span.k-out-of-month {color:#ddd;}