Code Monkey home page Code Monkey logo

bootstrap-calendar's Introduction

Bootstrap Calendar

A Full view calendar based on Twitter Bootstrap. Please try the demo.

Bootstrap full calendar

Why?

Why did I start this project? Well, I believe there are no good full view calendar's out there with native Bootstrap support. In fact I could not find even one. A different UI and UX concept approach is also used.

Features

  • Reusable - there is no UI in this calendar. All buttons to switch view or load events are done separately. You will end up with your own uniquie calendar design.
  • Template based - all view like year, month, week or day are based on templates. You can easily change how it looks or style it or even add new custom view.
  • LESS - easy adjust and style your calendar with less variables file.
  • AJAX - It uses AJAX to feed calendar with events. You provide URL and just return by this URL JSON list of events.
  • i18n - language files are connected separately. You can easily translate the calendar into your own language. Holidays are also diplayed on the calendar according to your language

How to use

Install

You can install it with bower package manager.

$ bower install bootstrap-calendar

Bower will automatically install all dependencies. Then by running

$ bower list --path

You will see list of the files you need to include to your document.

Quick setup

You will need to include the bootstrap css and calendar css. Here is the minimum setup.

	<!DOCTYPE html>
	<html>
	<head>
		<title>Minimum Setup</title>
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<link rel="stylesheet" href="css/calendar.css">
	</head>
	<body>

		<div id="calendar"></div>

		<script type="text/javascript" src="js/vendor/jquery-1.9.1.js"></script>
		<script type="text/javascript" src="js/vendor/underscore-min.js"></script>
		<script type="text/javascript" src="js/calendar.js"></script>
		<script type="text/javascript">
			var calendar = $("#calendar").calendar(
				{
					tmpl_path: "/tmpls/",
					events_source: function () { return []; }
				});			
		</script>
	</body>
	</html>

Bootstrap Calendar depends on jQuery and underscore.js is used as a template engine. For the calendar you only have to include the calendar.css and calendar.js files. If you want to localize your Calendar, it's enough to add this line before including calendar.js:

	<script type="text/javascript" src="js/language/xx-XX.js"></script>

Where xx-XX is the language code. When you initializing the calendar, you have to specify this language code:

	<script type="text/javascript">
		var calendar = $('#calendar').calendar({language: 'xx-XX'});
	</script>

Feed with events

To feed the calendar with events you should use events_source parameter. It may be a function, array or URL. In all cases you have to set it with valid events array.

See events.json.php file for more details.

start and end contain dates when event starts (inclusive) and ends (exclusive) in Unix timestamp. Classes are event-important, event-success, event-warning, event-info, event-inverse and event-special. This wil change the color of your event indicators.

Feed URL

var calendar = $('#calendar').calendar({events_source: '/api/events.php'});

It will send two parameters by GET named from and to, which will tell you what period is required. You have to return it in JSON structure like this

{
	"success": 1,
	"result": [
		{
			"id": 293,
			"title": "Event 1",
			"url": "http://example.com",
			"class": "event-important",
			"start": 12039485678000, // Milliseconds
			"end": 1234576967000 // Milliseconds
		},
		...
	]
}

Feed array

You can set events list array directly to events_source parameter.

	var calendar = $('#calendar').calendar({
	    events_source: [
            {
                "id": 293,
                "title": "Event 1",
                "url": "http://example.com",
                "class": "event-important",
                "start": 12039485678000, // Milliseconds
                "end": 1234576967000 // Milliseconds
            },
            ...
        ]});

Feed function

Or you can use function. You have to return array of events.

	var calendar = $('#calendar').calendar({events_source: function(){
	    return  [
           {
               "id": 293,
               "title": "Event 1",
               "url": "http://example.com",
               "class": "event-important",
               "start": 12039485678000, // Milliseconds
               "end": 1234576967000 // Milliseconds
           },
           ...
       ];
	}});

PHP example

Note that start and end dates are in milliseconds, thus you need to divide it by 1000 to get seconds. PHP example.

    $start = date('Y-m-d h:i:s', ($_GET['start'] / 1000));

If you have an error you can return

	{
		"success": 0,
		"error": "error message here"
	}

Here is the example of PHP script.

<?php
$db    = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');
$start = $_REQUEST['from'] / 1000;
$end   = $_REQUEST['to'] / 1000;
$sql   = sprintf('SELECT * FROM events WHERE `datetime` BETWEEN %s and %s',
    $db->quote(date('Y-m-d', $start)), $db->quote(date('Y-m-d', $end)));

$out = array();
foreach($db->query($sql) as $row) {
    $out[] = array(
        'id' => $row->id,
        'title' => $row->name,
        'url' => Helper::url($row->id),
        'start' => strtotime($row->datetime) . '000',
        'end' => strtotime($row->datetime_end) .'000'
    );
}

echo json_encode(array('success' => 1, 'result' => $out));
exit;

Another example of PHP script (without connecting with the Database).

<?php
$out = array();
 
 for($i=1; $i<=15; $i++){ 	//from day 01 to day 15
	$data = date('Y-m-d', strtotime("+".$i." days"));
	$out[] = array(
     	'id' => $i,
		'title' => 'Event name '.$i,
		'url' => Helper::url($id),
		'class' => 'event-important',
		'start' => strtotime($data).'000'
	);
}
 
echo json_encode(array('success' => 1, 'result' => $out));
exit;
?>

Usage warning.

You cannot use the calendar from a local file. The following error will be displayed : Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin.

Using Ajax with local resources (file:///), is not permited. You will need to deploy this to the web instead.

Modal popup

You can enable a bootstrap modal popup to show when clicking an event instead of redirecting to event.url. To enable boostrap modal, first add the modal html to your page and provide boostrap-calendar with the ID:

    <div class="modal hide fade" id="events-modal">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3 class="modal-title">Event</h3>
        </div>
        <div class="modal-body" style="height: 400px">
        </div>
        <div class="modal-footer">
            <a href="#" data-dismiss="modal" class="btn">Close</a>
        </div>
    </div>

and then set:

modal: "#events-modal"

This will enable the modal, and populate it with an iframe with the contents of event.url .

For Bootstrap v3, use

    <div class="modal fade" id="events-modal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h3 class="modal-title">Event</h3>
                </div>
                <div class="modal-body" style="height: 400px">
                </div>
                <div class="modal-footer">
                    <a href="#" data-dismiss="modal" class="btn">Close</a>
                </div>
            </div>
        </div>
    </div>

Modal content source

There are three options for populating the contents of the modal, controlled by the modal_type option:

  • iframe (default) - populates modal with iframe, iframe.src set to event.url
  • ajax - gets html from event.url, this is useful when you just have a snippet of html and want to take advantage of styles in the calendar page
  • template - will render a template (example in tmpls/modal.html) that gets the event and a reference to the calendar object.

Modal title

The modal title can be customized by defining the modal_title option as a function. This function will receive the event as its only parameter. For example, this could be used to set the title of the modal to the title of the event:

modal_title: function(event) { return event.title }

A calendar set up to use modals would look like this:

$("#calendar").calendar({modal : "#events-modal", modal_type : "ajax", modal_title : function (e) { return e.title }})

bootstrap-calendar's People

Contributors

aguillem avatar alfredbez avatar andreiavram avatar chrisjohnson00 avatar cybot avatar danguilherme avatar edwardfernando avatar eleazan avatar fruitl00p avatar gremlyn avatar guisevero avatar infernalslam avatar izar-cz avatar jakobdo avatar joenilson avatar katajakasa avatar lancezh avatar lopez-alex avatar mauromorello avatar mlocati avatar najlepsiwebdesigner avatar orinx avatar poyeyo avatar sandlbn avatar serhioromano avatar standino avatar steliosph avatar suhindra avatar teclliure avatar vestimir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bootstrap-calendar's Issues

start/end dates for ajax post

lets say i want the events for May 2013, it seems that the start date sent to the ajax post is 30th April 2013 23:59:59 and the finish value is 31st May 22:59:59 (i think)

Could this not be in start: 1st May 2013 00:00:00 to 1st June 2013 00:00:00?

I think this works better when querying dates in databases? But I could be wrong....

Move events

The ability to move events is very important for web based applications. The idea is to hold small event circle and drag movable events. Calendar will highlight day and you can drop it there.

Callback will be triggered to handle event movement.

Time zone conversion

Would be useful to have 2 new parameters

timezone: {
    convert: true,
    original: '+4'
}

This will convers server time to local according to server time zone and local time zone difference.

Reference #65

Uncaught SyntaxError: Unexpected token ILLEGAL

When trying to use bootstrap calendar I get the following error. Am using the example JSON provided from the repo but it fails to work.

The stacktrace for the "Uncaught SyntaxError: Unexpected token ILLEGAL" is as follows:

Uncaught SyntaxError: Unexpected token ILLEGAL underscore-min.js:5
j.template underscore-min.js:5
(anonymous function) calendar.js:615
c jquery-1.10.2.min.js:4
p.add jquery-1.10.2.min.js:4
Calendar._loadTemplate calendar.js:614
Calendar._render calendar.js:217
Calendar.view calendar.js:454
Calendar calendar.js:194
$.fn.calendar calendar.js:768
(anonymous function) my-app/groups/:73
c jquery-1.10.2.min.js:4
p.fireWith jquery-1.10.2.min.js:4
x.extend.ready jquery-1.10.2.min.js:4

No access to the cal variable in week-days template

The cal variable doesn't seem to be passed to the week-days template, like it is with other templates. I need this for additional language changes, but I can't, because it says "cal is not defined".

Any idea how to fix this? I've tried looking around in calendar.js, but I haven't found where you tell it to pass the cal variable.

Calendar view responsiveness

First of all, this calendar looks great. Thanks for putting this project up! I would definitely want to use something like this for an application or two I have in mind.

However, I couldn't help but notice that in the demo when clicking any of the top right buttons, it takes a few seconds for the screen to update the calendar. Sometimes, certain actions seem worse than other times, though.

If you switch between Year/Month/Week, you will can see the delay in effect. Compare to something like http://arshaw.com/fullcalendar/. Probably an unfair comparison, as that seems like a mature jquery calendar.

Is this expected behavior for now? I just wanted to open an issue to start discussion on why this might be the case, etc.

Calendar breaks under latest jQuery (1.10.2)

Calendar mostly functions using latest jQuery rather than the bundled 1.8.3 version, however it breaks when clicking on a day for the event list slide down.

Here's the specific console error when clicking on a day in month view:

Uncaught TypeError: undefined is not a function

calendar.set_options() does not update the calendar view

If I call calendar.set_options({ view: 'year' });, I want the calendar to auto refresh and show the "year" view, what doesn't happen.
I have to call calendar.render() in sequence to make the right view to be rendered. I don't know if calling render after the calendar is actually rendered will give me troubles (like throwing extra and unnecessary HTML in the calendar container);
Is that an expected behavior? Can it be improved?

Day start/end bug found, fix provided

Hi,

You calendar is awesome but I've found a bug in that a day's time range (start and end) were only 86400 milliseconds apart rather than 86400000 milliseconds. This means that single day events were not showing in the month view. The fix needs to be applied in calendar.js line 272.

Hope this is helpful. :-)

Language not defined?

I clearly have language defined in my options var as 'nl-NL' (made myself a dutch translation; not finished, I will do a PR when I'm done). However, I keep getting 'Uncaught ReferenceError: language is not defined'. Any ideas as to why this is happening?

bootstrap-calender in Ruby on Rails

What needs to be done for this calendar to work in ruby on rails.

I copied calendar.js, calenader.min.js, bootstrap.min.js, underscore-min.js however get ReferenceError: _ is not defined not defined in calendare.min.js.

Is there something I am missing?

Starting on Monday

Great calendar!

It looks like if I set the calendar to start on Monday, first_day: 1, September 2013 is missing it's first day.

image

Double slide

Could you look at this I cannot find where it is.

When you click on day cell it unfold list of events, if you click on empty cell it folds events list. But if you click again on events cell it unfold twice.

Can't fire it up

Hi,

I'm having trouble with the "minimum setup" example in the description. After adding

var calendar = $('#calendar').calendar();

to my html file, all I get in return is a console error:

Error: Calendar: Events load URL is not set

The same thing happens when I try this

var calendar = $('#calendar').calendar({events_url:''});

I know you're supposed to bring in data over an URL/JSON api but it would be nice to be able to preview the calendar without it. Sometimes you need to design a website before all the backend data access is ready (and previewing the calendar this way would help a lot with that)

For the record, I'm using jQuery 1.10.2, Bootstrap 2.3.2, Underscore 1.5.1 and your 0.0.9 release.

Tooltips not working on month view

I've integrated the calendar on a project and it looks and functions great. The one thing that I didn't like was that the circles didn't have tool tips.
After I looked into it, I found that you already have enabled the tool tips in calender.js.
However, the tool tip never appears.
I've looked into this for about 4 hours now with no progress... so I figured I'd submit this issue. JS isn't my forte.
I also notice that you are using the old bootstrap method for tool tips (rel="tooltip"). This was changed in 2.2 of bootstrap I think, rel="tooltip" doesn't pass html validation, they now use data-toggle="tooltip". Unfortunately after updating to use the latest method, it had no effect on showing the tool tip.

Calendar reload issue (when changing views)

The calendar is not reloading its event when changing from one view to another.
Steps to reproduce the problem:

In the "month" view... (note the 3 events)
gitissue-1

(in background, did a calendar.set_options({ view: 'year' }); and then calendar.render())
change to the "year" view...(the 3 events are still there)
gitissue-2

(now, in background, did a calendar.navigate('today'))
The calendar will attempt to show the year that "today" is in... (Note the 3 events again)
gitissue-3

After a small delay, other 2 events show up, in August. Those events are real, they exist in my database, but the calendar didn't show them when I set the view.
gitissue-4

When calendar.set_options() is called and the view is changed (a setViewMode() would be better, wouldn't it?), the calendar should reload its content.

New translation strings problem

Having a global language variable holding all the translations for the current language may be problematic in case we need to add another translatable string.
For instance, if the calendar needs a new hypothetical title_weekday key of the language JavaScript object, then all the current translations must be updated to contain it.
A better solution could be to have a language dictionary (in en_US?) integrated in the base calendar.js file, with all the keys. Then Calendar should parse the localization files and override the English strings with the localized ones.
I'm thinking to something like:

function Calendar(params, context, localizedStrings) {
   this.localization = $.extend({}, defaultLocalization, localizedStrings);
}

This issue is strictly associated to #36

Bootstrap 3

I can't find anyone having asked this before, so I'll go ahead!

Is there an opinion as to whether bootstrap-calendar should be updated to work with Bootstrap 3? Or another branch be maintained? Just wondering, I'd be happy to contribute if there is an existing effort.

Holidays could be integrated in language files

What about adding holidays to language files?
I'm thinking of having the same functionality of first_day: in order of precedence:

  1. If a holidays object is present in options we use it
  2. If a holidays object is present in calendar_languages[...] we use it
  3. Finally we use a new holidays object (for en-US) in the defaults_extended object

If it's ok for you I can proceed with a pull request...

Avoid storing events data in tags and use JavaScript objects

In templates, we sometimes use the javascript objects containing events data, and sometimes we store and retrieve the events data from html attributes.

What about using always javascript objects? So, if the events contain custom data the users can retrieve these data.

In addition to having cleaner and simpler templates, it's sometimes a requirements because not all data can be stored in html attributes in a fashionable manner (think for example at event attributes that are javascript objects).

starting date on the calendar

hi serhio,
this is great calendar for bootstrap.
i've trying to work on implentation the calendar to my project.
i'm making an meeting room reservation system, in which the calendar showing the event that called from the database.
but i kinda stuck at modifying the starting date on the calendar.
when the calendar opened at my system, it always showing 11 week of year 2013 (the event showing march 2nd week).
where do i modify the script so the system starting on today date? i know that i could access today date with clicking on today button, but i want the system to start showing today date as default.
and for the events.json.php i've tried to make some json data for the system to catch. but the system couldn't get the output.
as i tinker with the output, the calendar is accepting data that formatted as string (not json).
kindly need your enlightment on this serhio, thank you.

Can we use it?

It may sound like a really dumb question.
In fact, I found your bundle while searching a good calendar to integrate with bootstrap for a quick project.

It looks really great and I wish to give it a try, but I am quite affraid by the limitation you mentioned in the readme file.
What would be the drawbacks of using this bundle ? Any known limitation ?

Referential issue with default values for defaults.position.start and defaults.position.end

There is a peculiar referential issue relating to the Date instances assigned to the defaults.position object that only becomes apparent when attempting to use multiple Calendars on a single page, as I am doing for a project which requires inter-linked Calendars rather than the drill-down type support by bootstrap-calendar.

See below for a simple example:

// Create a Month-view Calendar initialised to Oct 2013
monthCalendar = $("#monthCalendar").calendar({
  events_url: "url",
  view: "month",
  day: "2013-10-01"
});

// Create a Week-view
weekCalendar = $("#weekCalendar").calendar({
  events_url: "url",
  view: "week",
  day: "2013-09-23"
});

// Now, if we attempt to use monthCalendar.navigate it will behave incorrectly
monthCalendar.navigate("next"); // This will not seem to load the next month
monthCalendar.navigate("next"); // This will load the next month!

I dug into things using the Chrome debugger and noted that during the this._init_position() call during the construction of the weekCalendar object that the Date instance pointed to by this.position.start was the same as the Date instance pointed to by the defaults.position.start.

The result of this was that the .start and .end values for monthCalendar get over-written during the constructon of the weekCalendar and result in the monthCalendar having .start and .end values that do not match what it was configured with initially.

This in turn causes the navigation feature to behave erratically.

I was able to circumvent this issue as follows:

// Create a Month-view Calendar initialised to Oct 2013
monthCalendar = $("#monthCalendar").calendar({
  events_url: "url",
  view: "month",
  day: "2013-10-01",
  position: {
    start: new Date(),
    end: new Date()
  }
});

// Create a Week-view
weekCalendar = $("#weekCalendar").calendar({
  events_url: "url",
  view: "week",
  day: "2013-09-23",
  position: {
    start: new Date(),
    end: new Date()
  }
});

// Now, if we attempt to use monthCalendar.navigate it will behave correctly
monthCalendar.navigate("next"); // This will load the next month!

The underlying issue here is that jQuery.extend does not really support a true deep-copy it seems and is unable to clone instances of objects like Date when performing a deep-copy.

I would recommend that the values for defaults.position.start and defaults.position.end be set to null and then initialised to a new Date() instances following the call to jQuery.extend in the Calendar constructor function.

Internet Explorer 8 compatibility

If you want Internet Exploder 8 compatibility you need to replace "class" parameter with any other (my suggestion 'style_class') because IE interpreter bugs with class as reserved name.

HowTo push more data in events array/object

It seems I'm not able to display extra data I added to the json file.
I was able to show it on the right hand list but unable to also get data to the event list inside the calendar.

I suppose the function should be 'events' or 'event' but I struggle to find where the data gets filled into '$(event).data('event-class')' for example.

I hope you can point me to the right file.

Add visibility to calendar properties

First, I am using your component and I think it is really cool, thanks for sharing it.

The problem I am facing right now is that I want to know more about the calendar "status", like which range of date it is showing, or in which view mode it is, and more information a calendar could give to me. In my case, for example, I want to enable the "Go to today" button only if the user is not really seeing today.
gitissue
But I didn't see a way to do it, as I don't know the actual range of the calendar (or I don't know where to find it). What I can call is the calendar.title() (which I think it should be getTitle()), but a localized string will not help me on this.

Thank you, and forgive me if I missed something.

Can't start Up

I have a question.

When i set up everything like on the documentation in the Firefox on JavaScript Error i have something like:

TypeError: this.options.templates[this.options.view] is not a function

and the calendar don't start

Navigation buttons not working

I'm currently having an issue where the navigation buttons aren't doing anything.

This is my code:

<button class="btn" data-calendar-nav="prev"><<</button>
<button class="btn" data-calendar-nav="today">[Today]</button>
<button class="btn" data-calendar-nav="next">>></button>

No JS errors appear, nor do I think the prototype.navigate is ever called.

According to the Chrome dev console, JS files are being loaded in the following order:

  • jQuery
  • jQuery UI
  • Bootstrap
  • Underscore
  • Calendar Language file (nl-NL.js made by me)
  • Calendar
  • App.js

Composer Install

As composer is now the official SF2 package manager, it could be nice to be able to install this bundle through composer.

Break breaks closure compiler

Hi Sergey

I tried to compile/compress calendar.js with the closure compiler. It raises a warning telling that break is an invalid property id.
Even if everything works fine, but what about renaming this break to something like stopCycling or so?

Day view not working in bootstrap 2 or 3

Hi, I am looking at using this in an upcoming project as its a perfect fir for my needs. Unfortunately the day view shows nothing but a couple of event dots.

The console is showing nothing out of the ordinary. Is this a known issue?
I have attached a screenshot for you
screenshot from 2013-09-29 08 05 47

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.