Git Product home page Git Product logo

timetable-knockout.js's Introduction

timetable-knockout.js

Original code and readme was made by Grible in the component Timetable.js.

Vanilla javascript plugin for building nice responsive timetables. Provides a simple javascript interface to add events and locations which can be rendered to nice HTML. Works on mobile devices as well.

Installation

Download or clone the repository.

Load the plugin and styles in your HTML from the dist folder, remember to load knockout first and then timetable-knockout.js:

<link rel="stylesheet" href="timetable-knockoutjs.css">
<script src="knockout.js"></script>
<script src="timetable-knockout.js"></script>

Add a timetable placeholder:

<div class="timetable"></div>

Usage

Create two observableArrays, one for Locations and other for Events:

var locations = ko.observableArray([]);
var events = ko.observableArray([]);

Make a timetable object passing the observableArrays created, optionally set the scope in hours (the visible hours in the timetable):

var timetable = new Timetable(locations, events);
timetable.setScope(9, 17); // optional, only whole hours between 0 and 23

Add some locations:

locations.push("Silent Disco");
locations.push("Nile", "Len Room", "Maas Room");

Add your events creating an event object and pushing it to your events observableArray createEvent(name, location, startDate, endDate[, options]):

var myEvent = timetable.createEvent('Frankadelic', 'Nile', new Date(2017,12,12,13,55), new Date(2017,12,12,20,30));
events.push(myEvent);

In addition, you can pass options such as URLs, classes, data-* attributes(data-bind also works), or color through an object:

var options1 = {
  url: '#',
  class: 'vip',
  data: {
    id: 4,
    ticketType: 'VIP'
  },
  color: "black"
}
var options2 = {
  url: '#',
  class: 'vip',
  data: {
    id: 4,
    ticketType: 'VIP'
  }
}
var myEvent1 = timetable.createEvent('Frankadelic', 'Nile', new Date(2017,12,12,13,55), new Date(2017,12,12,20,30), options1);
var myEvent2 = timetable.createEvent('Frankadelic', 'Len Room', new Date(2017,12,12,13,55), new Date(2017,12,12,20,30), options2);
events.push(myEvent1, myEvent2);

You don't need to render anything, all the render is made automatically when locations or events change.

That's it!

Browser Support

Timetable-knockout.js has been designed to work with modern browsers (only). It has been tested with the latest version of the most common browsers.

timetable-knockout.js's People

Contributors

chr0m1ng avatar matalmeida avatar

Watchers

James Cloos avatar  avatar

timetable-knockout.js's Issues

Convert the Objects from prototypes for class

What you think about this refac? Would be worth?

From this:

var Timetable = function (locations, events) {
    this.scope = {
        hourStart: 0,
        hourEnd: 23
    };
    this.locations = locations.extend({notify: 'always'});
    this.events = events;
    this.oldLocations = [];
    this.oldEvents = [];
    this.locations.subscribe((value) => this.locationSubscriber(value));
    this.events.subscribe((value) => this.eventSubscriber(value));
};

To this:

class Timetable {
  constructor(locations, events) {
    this.scope = {
        hourStart: 0,
        hourEnd: 23
    };
    this.locations = locations.extend({ notify: 'always' });
    this.events = events;
    this.oldLocations = [];
    this.oldEvents = [];
    this.locations.subscribe((value) => this.locationSubscriber(value));
    this.events.subscribe((value) => this.eventSubscriber(value));
  }

  // ....

}

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.