36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/js/calendar/calendar.js:
--------------------------------------------------------------------------------
1 | var calendar = {
2 | eventList: [],
3 | calendarLocation: '.calendar',
4 | updateInterval: 1000,
5 | updateDataInterval: 60000,
6 | fadeInterval: 1000,
7 | intervalId: null,
8 | dataIntervalId: null,
9 | maximumEntries: config.calendar.maximumEntries || 10
10 | }
11 |
12 | calendar.updateData = function (callback) {
13 |
14 | new ical_parser("calendar.php" + "?url="+encodeURIComponent(config.calendar.url), function(cal) {
15 | var events = cal.getEvents();
16 | this.eventList = [];
17 |
18 | for (var i in events) {
19 |
20 | var e = events[i];
21 | for (var key in e) {
22 | var value = e[key];
23 | var seperator = key.search(';');
24 | if (seperator >= 0) {
25 | var mainKey = key.substring(0,seperator);
26 | var subKey = key.substring(seperator+1);
27 |
28 | var dt;
29 | if (subKey == 'VALUE=DATE') {
30 | //date
31 | dt = new Date(value.substring(0,4), value.substring(4,6) - 1, value.substring(6,8));
32 | } else {
33 | //time
34 | dt = new Date(value.substring(0,4), value.substring(4,6) - 1, value.substring(6,8), value.substring(9,11), value.substring(11,13), value.substring(13,15));
35 | }
36 |
37 | if (mainKey == 'DTSTART') e.startDate = dt;
38 | if (mainKey == 'DTEND') e.endDate = dt;
39 | }
40 | }
41 |
42 | if (e.startDate == undefined){
43 | //some old events in Gmail Calendar is "start_date"
44 | //FIXME: problems with Gmail's TimeZone
45 | var days = moment(e.DTSTART).diff(moment(), 'days');
46 | var seconds = moment(e.DTSTART).diff(moment(), 'seconds');
47 | var startDate = moment(e.DTSTART);
48 | } else {
49 | var days = moment(e.startDate).diff(moment(), 'days');
50 | var seconds = moment(e.startDate).diff(moment(), 'seconds');
51 | var startDate = moment(e.startDate);
52 | }
53 |
54 | //only add fututre events, days doesn't work, we need to check seconds
55 | if (seconds >= 0) {
56 | if (seconds <= 60*60*5 || seconds >= 60*60*24*2) {
57 | var time_string = moment(startDate).fromNow();
58 | }else {
59 | var time_string = moment(startDate).calendar()
60 | }
61 | if (!e.RRULE) {
62 | this.eventList.push({'description':e.SUMMARY,'seconds':seconds,'days':time_string});
63 | }
64 | e.seconds = seconds;
65 | }
66 |
67 | // Special handling for rrule events
68 | if (e.RRULE) {
69 | var options = new RRule.parseString(e.RRULE);
70 | options.dtstart = e.startDate;
71 | var rule = new RRule(options);
72 |
73 | // TODO: don't use fixed end date here, use something like now() + 1 year
74 | var dates = rule.between(new Date(), new Date(2016,11,31), true, function (date, i){return i < 10});
75 | for (date in dates) {
76 | var dt = new Date(dates[date]);
77 | var days = moment(dt).diff(moment(), 'days');
78 | var seconds = moment(dt).diff(moment(), 'seconds');
79 | var startDate = moment(dt);
80 | if (seconds >= 0) {
81 | if (seconds <= 60*60*5 || seconds >= 60*60*24*2) {
82 | var time_string = moment(dt).fromNow();
83 | } else {
84 | var time_string = moment(dt).calendar()
85 | }
86 | this.eventList.push({'description':e.SUMMARY,'seconds':seconds,'days':time_string});
87 | }
88 | }
89 | }
90 | };
91 |
92 | this.eventList = this.eventList.sort(function(a,b){return a.seconds-b.seconds});
93 |
94 | // Limit the number of entries.
95 | this.eventList = this.eventList.slice(0, calendar.maximumEntries);
96 |
97 | if (callback !== undefined && Object.prototype.toString.call(callback) === '[object Function]') {
98 | callback(this.eventList);
99 | }
100 |
101 | }.bind(this));
102 |
103 | }
104 |
105 | calendar.updateCalendar = function (eventList) {
106 |
107 | table = $('
').addClass('xsmall').addClass('calendar-table');
108 | opacity = 1;
109 |
110 | for (var i in eventList) {
111 | var e = eventList[i];
112 |
113 | var row = $('
').html(e.days).addClass('days dimmed'));
116 | table.append(row);
117 |
118 | opacity -= 1 / eventList.length;
119 | }
120 |
121 | $(this.calendarLocation).updateWithText(table, this.fadeInterval);
122 |
123 | }
124 |
125 | calendar.init = function () {
126 |
127 | this.updateData(this.updateCalendar.bind(this));
128 |
129 | this.intervalId = setInterval(function () {
130 | this.updateCalendar(this.eventList)
131 | }.bind(this), this.updateInterval);
132 |
133 | this.dataIntervalId = setInterval(function () {
134 | this.updateData(this.updateCalendar.bind(this));
135 | }.bind(this), this.updateDataInterval);
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/js/compliments/compliments.js:
--------------------------------------------------------------------------------
1 | var compliments = {
2 | complimentLocation: '.compliment',
3 | currentCompliment: '',
4 | complimentList: {
5 | 'morning': config.compliments.morning,
6 | 'afternoon': config.compliments.afternoon,
7 | 'evening': config.compliments.evening
8 | },
9 | updateInterval: config.compliments.interval || 30000,
10 | fadeInterval: config.compliments.fadeInterval || 4000,
11 | intervalId: null
12 | };
13 |
14 | /**
15 | * Changes the compliment visible on the screen
16 | */
17 | compliments.updateCompliment = function () {
18 |
19 |
20 |
21 | var _list = [];
22 |
23 | var hour = moment().hour();
24 |
25 | // In the followign if statement we use .slice() on the
26 | // compliments array to make a copy by value.
27 | // This way the original array of compliments stays in tact.
28 |
29 | if (hour >= 3 && hour < 12) {
30 | // Morning compliments
31 | _list = compliments.complimentList['morning'].slice();
32 | } else if (hour >= 12 && hour < 17) {
33 | // Afternoon compliments
34 | _list = compliments.complimentList['afternoon'].slice();
35 | } else if (hour >= 17 || hour < 3) {
36 | // Evening compliments
37 | _list = compliments.complimentList['evening'].slice();
38 | } else {
39 | // Edge case in case something weird happens
40 | // This will select a compliment from all times of day
41 | Object.keys(compliments.complimentList).forEach(function (_curr) {
42 | _list = _list.concat(compliments.complimentList[_curr]).slice();
43 | });
44 | }
45 |
46 | // Search for the location of the current compliment in the list
47 | var _spliceIndex = _list.indexOf(compliments.currentCompliment);
48 |
49 | // If it exists, remove it so we don't see it again
50 | if (_spliceIndex !== -1) {
51 | _list.splice(_spliceIndex, 1);
52 | }
53 |
54 | // Randomly select a location
55 | var _randomIndex = Math.floor(Math.random() * _list.length);
56 | compliments.currentCompliment = _list[_randomIndex];
57 |
58 | $('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval);
59 |
60 | }
61 |
62 | compliments.init = function () {
63 |
64 | this.updateCompliment();
65 |
66 | this.intervalId = setInterval(function () {
67 | this.updateCompliment();
68 | }.bind(this), this.updateInterval)
69 |
70 | }
--------------------------------------------------------------------------------
/js/config.js:
--------------------------------------------------------------------------------
1 | var config = {
2 | lang: "zh-cn",
3 | time: {
4 | timeFormat: 24
5 | },
6 | weather: {
7 | params: {
8 | cityid: "",
9 | key: ""
10 | }
11 | },
12 | tem_hum: {
13 | mqttServer:"localhost",
14 | mqttServerPort:9001,
15 | mqttclientName:"magic_mirror_tem_hum",
16 | temperatureTopic:"/DHT"
17 | },
18 | compliments: {
19 | interval: 30000,
20 | fadeInterval: 4000,
21 | morning: [
22 | 'Good morning, handsome!',
23 | 'Enjoy your day!',
24 | 'How was your sleep?'
25 | ],
26 | afternoon: [
27 | 'Hello, beauty!',
28 | 'You look sexy!',
29 | 'Looking good today!'
30 | ],
31 | evening: [
32 | 'Wow, you look hot!',
33 | 'You look nice!',
34 | 'Hi, sexy!'
35 | ]
36 | },
37 | calendar: {
38 | maximumEntries: 10,
39 | url: ""
40 | },
41 | news: {
42 | feed: 'http://www.ftchinese.com/rss/news'
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/js/ical_parser.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Javascript ical Parser
3 | * Proof of concept method of reading icalendar (.ics) files with javascript.
4 | *
5 | * @author: Carl Saggs
6 | * @source: https://github.com/thybag/
7 | * @version: 0.2
8 | */
9 | function ical_parser(feed_url, callback){
10 | //store of unproccesed data.
11 | this.raw_data = null;
12 | //Store of proccessed data.
13 | this.events = [];
14 |
15 | /**
16 | * loadFile
17 | * Using AJAX to load the requested .ics file, passing it to the callback when completed.
18 | * @param url URL of .ics file
19 | * @param callback Function to call on completion.
20 | */
21 | this.loadFile = function(url, callback){
22 | //Create request object
23 | try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { }
24 | //Grab file
25 | xmlhttp.onreadystatechange = function(){
26 | if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
27 | //On success, run callback.
28 | callback(xmlhttp.responseText);
29 | }
30 | }
31 | xmlhttp.open("GET", url, true);
32 | xmlhttp.send(null);
33 | }
34 |
35 | /**
36 | * makeDate
37 | * Convert the dateformat used by ICalendar in to one more suitable for javascript.
38 | * @param String ical_date
39 | * @return dt object, includes javascript Date + day name, hour/minutes/day/month/year etc.
40 | */
41 | this.makeDate = function(ical_date){
42 | //break date apart
43 | var dtutc = {
44 | year: ical_date.substr(0,4),
45 | month: ical_date.substr(4,2),
46 | day: ical_date.substr(6,2),
47 | hour: ical_date.substr(9,2),
48 | minute: ical_date.substr(11,2)
49 | }
50 | //Create JS date (months start at 0 in JS - don't ask)
51 | var utcdatems = Date.UTC(dtutc.year, (dtutc.month-1), dtutc.day, dtutc.hour, dtutc.minute);
52 | var dt = {};
53 | dt.date = new Date(utcdatems);
54 |
55 | dt.year = dt.date.getFullYear();
56 | dt.month = ('0' + (dt.date.getMonth()+1)).slice(-2);
57 | dt.day = ('0' + dt.date.getDate()).slice(-2);
58 | dt.hour = ('0' + dt.date.getHours()).slice(-2);
59 | dt.minute = ('0' + dt.date.getMinutes()).slice(-2);
60 |
61 | //Get the full name of the given day
62 | dt.dayname =["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][dt.date.getDay()];
63 | dt.monthname = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ][dt.date.getMonth()] ;
64 |
65 | return dt;
66 | }
67 |
68 | /**
69 | * parseICAL
70 | * Convert the ICAL format in to a number of javascript objects (Each representing a date)
71 | *
72 | * @param data Raw ICAL data
73 | */
74 | this.parseICAL = function(data){
75 | //Ensure cal is empty
76 | this.events = [];
77 |
78 | //Clean string and split the file so we can handle it (line by line)
79 | cal_array = data.replace(new RegExp( "\\r", "g" ), "").replace(/\n /g,"").split("\n");
80 |
81 | //Keep track of when we are activly parsing an event
82 | var in_event = false;
83 | //Use as a holder for the current event being proccessed.
84 | var cur_event = null;
85 | for(var i=0;i')
137 | .replace(/\\n/g,' ')
138 | .replace(/\\,/g,',');
139 | }
140 |
141 | //Add the value to our event object.
142 | cur_event[type] = val;
143 | }
144 | }
145 | //Run this to finish proccessing our Events.
146 | this.complete();
147 | }
148 | /**
149 | * complete
150 | * Sort all events in to a sensible order and run the original callback
151 | */
152 | this.complete = function(){
153 | //Sort the data so its in date order.
154 | this.events.sort(function(a,b){
155 | return a.DTSTART-b.DTSTART;
156 | });
157 | //Run callback method, if was defined. (return self)
158 | if(typeof callback == 'function') callback(this);
159 | }
160 | /**
161 | * getEvents
162 | * return all events found in the ical file.
163 | *
164 | * @return list of events objects
165 | */
166 | this.getEvents = function(){
167 | return this.events;
168 | }
169 |
170 | /**
171 | * getFutureEvents
172 | * return all events sheduled to take place after the current date.
173 | *
174 | * @return list of events objects
175 | */
176 | this.getFutureEvents = function(){
177 | var future_events = [], current_date = new Date();
178 |
179 | this.events.forEach(function(itm){
180 | //If the event ends after the current time, add it to the array to return.
181 | if(itm.DTEND > current_date) future_events.push(itm);
182 | });
183 | return future_events;
184 | }
185 |
186 | /**
187 | * getPastEvents
188 | * return all events sheduled to take place before the current date.
189 | *
190 | * @return list of events objects
191 | */
192 | this.getPastEvents = function(){
193 | var past_events = [], current_date = new Date();
194 |
195 | this.events.forEach(function(itm){
196 | //If the event ended before the current time, add it to the array to return.
197 | if(itm.DTEND <= current_date) past_events.push(itm);
198 | });
199 | return past_events.reverse();
200 | }
201 |
202 | /**
203 | * load
204 | * load a new ICAL file.
205 | *
206 | * @param ical file url
207 | */
208 | this.load = function(ical_file){
209 | var tmp_this = this;
210 | this.raw_data = null;
211 | this.loadFile(ical_file, function(data){
212 | //if the file loads, store the data and invoke the parser
213 | tmp_this.raw_data = data;
214 | tmp_this.parseICAL(data);
215 | });
216 | }
217 |
218 | //Store this so we can use it in the callback from the load function.
219 | var tmp_this = this;
220 | //Store the feed url
221 | this.feed_url = feed_url;
222 | //Load the file
223 | this.load(this.feed_url);
224 | }
225 |
--------------------------------------------------------------------------------
/js/jquery.feedToJSON.js:
--------------------------------------------------------------------------------
1 | //jQuery extension to fetch an rss feed and return it as json via YQL
2 | //created by dboz@airshp.com
3 | (function($) {
4 |
5 | $.extend({
6 | feedToJson: function(options, callback) {
7 | if ($.isFunction(options)) {
8 | callback = options;
9 | options = null;
10 | }
11 | options = $.extend($.feedToJson.defaults,options);
12 | var url = options.yqlURL + options.yqlQS + "'" + encodeURIComponent(options.feed) + "'" + "&_nocache=" + options.cacheBuster;
13 | return $.getJSON(url, function(data){
14 | //console.log(data.query.results);
15 | data = data.query.results;
16 | $.isFunction(callback) && callback(data); //allows the callback function to be the only option
17 | $.isFunction(options.success) && options.success(data);
18 | });
19 | }
20 | });
21 |
22 | //defaults
23 | $.feedToJson.defaults = {
24 | yqlURL : 'http://query.yahooapis.com/v1/public/yql', //yql
25 | yqlQS : '?format=json&callback=?&q=select%20*%20from%20rss%20where%20url%3D', //yql query string
26 | feed:'http://instagr.am/tags/tacos/feed/recent.rss', //instagram recent posts tagged 'tacos'
27 | cachebuster: Math.floor((new Date().getTime()) / 1200 / 1000), //yql caches feeds, so we change the feed url every 20min
28 | success:null //success callback
29 | };
30 |
31 | })(jQuery);
32 | // eo feedToJson
33 |
34 |
35 |
--------------------------------------------------------------------------------
/js/main.js:
--------------------------------------------------------------------------------
1 | jQuery.fn.updateWithText = function(text, speed)
2 | {
3 | var dummy = $('').html(text);
4 |
5 | if ($(this).html() != dummy.html())
6 | {
7 | $(this).fadeOut(speed/2, function() {
8 | $(this).html(text);
9 | $(this).fadeIn(speed/2, function() {
10 | //done
11 | });
12 | });
13 | }
14 | }
15 |
16 | jQuery.fn.outerHTML = function(s) {
17 | return s
18 | ? this.before(s).remove()
19 | : jQuery("
").append(this.eq(0).clone()).html();
20 | };
21 |
22 | function roundVal(temp)
23 | {
24 | return Math.round(temp * 10) / 10;
25 | }
26 |
27 | jQuery(document).ready(function($) {
28 |
29 | var eventList = [];
30 |
31 | var lastCompliment;
32 | var compliment;
33 |
34 | moment.locale(config.lang);
35 |
36 | //connect do Xbee monitor
37 | // var socket = io.connect('http://rpi-alarm.local:8082');
38 | // socket.on('dishwasher', function (dishwasherReady) {
39 | // if (dishwasherReady) {
40 | // $('.dishwasher').fadeIn(2000);
41 | // $('.lower-third').fadeOut(2000);
42 | // } else {
43 | // $('.dishwasher').fadeOut(2000);
44 | // $('.lower-third').fadeIn(2000);
45 | // }
46 | // });
47 |
48 | version.init();
49 |
50 | time.init();
51 |
52 | weather.init();
53 |
54 | //calendar.init();
55 |
56 | //compliments.init();
57 |
58 | news.init();
59 |
60 | tem_hum.init();
61 |
62 | });
63 |
--------------------------------------------------------------------------------
/js/news/news.js:
--------------------------------------------------------------------------------
1 | // A lot of this code is from the original feedToJson function that was included with this project
2 | // The new code allows for multiple feeds to be used but a bunch of variables and such have literally been copied and pasted into this code and some help from here: http://jsfiddle.net/BDK46/
3 | // The original version can be found here: http://airshp.com/2011/jquery-plugin-feed-to-json/
4 | var news = {
5 | feed: config.news.feed || null,
6 | newsLocation: '.news',
7 | newsItems: [],
8 | seenNewsItem: [],
9 | _yqURL: 'http://query.yahooapis.com/v1/public/yql',
10 | _yqlQS: '?format=json&q=select%20*%20from%20rss%20where%20url%3D',
11 | _cacheBuster: Math.floor((new Date().getTime()) / 1200 / 1000),
12 | _failedAttempts: 0,
13 | fetchInterval: config.news.fetchInterval || 60000,
14 | updateInterval: config.news.interval || 5500,
15 | fadeInterval: 2000,
16 | intervalId: null,
17 | fetchNewsIntervalId: null
18 | }
19 |
20 | /**
21 | * Creates the query string that will be used to grab a converted RSS feed into a JSON object via Yahoo
22 | * @param {string} feed The original location of the RSS feed
23 | * @return {string} The new location of the RSS feed provided by Yahoo
24 | */
25 | news.buildQueryString = function (feed) {
26 |
27 | return this._yqURL + this._yqlQS + '\'' + encodeURIComponent(feed) + '\'';
28 |
29 | }
30 |
31 | /**
32 | * Fetches the news for each feed provided in the config file
33 | */
34 | news.fetchNews = function () {
35 |
36 | // Reset the news feed
37 | this.newsItems = [];
38 |
39 | this.feed.forEach(function (_curr) {
40 |
41 | var _yqUrlString = this.buildQueryString(_curr);
42 | this.fetchFeed(_yqUrlString);
43 |
44 | }.bind(this));
45 |
46 | }
47 |
48 | /**
49 | * Runs a GET request to Yahoo's service
50 | * @param {string} yqUrl The URL being used to grab the RSS feed (in JSON format)
51 | */
52 | news.fetchFeed = function (yqUrl) {
53 |
54 | $.ajax({
55 | type: 'GET',
56 | datatype:'jsonp',
57 | url: yqUrl,
58 | success: function (data) {
59 |
60 | if (data.query.count > 0) {
61 | this.parseFeed(data.query.results.item);
62 | } else {
63 | console.error('No feed results for: ' + yqUrl);
64 | }
65 |
66 | }.bind(this),
67 | error: function () {
68 | // non-specific error message that should be updated
69 | console.error('No feed results for: ' + yqUrl);
70 | }
71 | });
72 |
73 | }
74 |
75 | /**
76 | * Parses each item in a single news feed
77 | * @param {Object} data The news feed that was returned by Yahoo
78 | * @return {boolean} Confirms that the feed was parsed correctly
79 | */
80 | news.parseFeed = function (data) {
81 |
82 | var _rssItems = [];
83 |
84 | for (var i = 0, count = data.length; i < count; i++) {
85 |
86 | _rssItems.push(data[i].title);
87 |
88 | }
89 |
90 | this.newsItems = this.newsItems.concat(_rssItems);
91 |
92 | return true;
93 |
94 | }
95 |
96 | /**
97 | * Loops through each available and unseen news feed after it has been retrieved from Yahoo and shows it on the screen
98 | * When all news titles have been exhausted, the list resets and randomly chooses from the original set of items
99 | * @return {boolean} Confirms that there is a list of news items to loop through and that one has been shown on the screen
100 | */
101 | news.showNews = function () {
102 |
103 | // If all items have been seen, swap seen to unseen
104 | if (this.newsItems.length === 0 && this.seenNewsItem.length !== 0) {
105 |
106 | if (this._failedAttempts === 20) {
107 | console.error('Failed to show a news story 20 times, stopping any attempts');
108 | return false;
109 | }
110 |
111 | this._failedAttempts++;
112 |
113 | setTimeout(function () {
114 | this.showNews();
115 | }.bind(this), 3000);
116 |
117 | } else if (this.newsItems.length === 0 && this.seenNewsItem.length !== 0) {
118 | this.newsItems = this.seenNewsItem.splice(0);
119 | }
120 |
121 | var _location = Math.floor(Math.random() * this.newsItems.length);
122 |
123 | var _item = news.newsItems.splice(_location, 1)[0];
124 |
125 | this.seenNewsItem.push(_item);
126 |
127 | $(this.newsLocation).updateWithText(_item, this.fadeInterval);
128 |
129 | return true;
130 |
131 | }
132 |
133 | news.init = function () {
134 |
135 | if (this.feed === null || (this.feed instanceof Array === false && typeof this.feed !== 'string')) {
136 | return false;
137 | } else if (typeof this.feed === 'string') {
138 | this.feed = [this.feed];
139 | }
140 |
141 | this.fetchNews();
142 | this.showNews();
143 |
144 | this.fetchNewsIntervalId = setInterval(function () {
145 | this.fetchNews()
146 | }.bind(this), this.fetchInterval)
147 |
148 | this.intervalId = setInterval(function () {
149 | this.showNews();
150 | }.bind(this), this.updateInterval);
151 |
152 | }
--------------------------------------------------------------------------------
/js/paho/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Contributing to Paho
2 | ====================
3 |
4 | Thanks for your interest in this project.
5 |
6 | Project description:
7 | --------------------
8 |
9 | The Paho project has been created to provide scalable open-source implementations of open and standard messaging protocols aimed at new, existing, and emerging applications for Machine-to-Machine (M2M) and Internet of Things (IoT).
10 | Paho reflects the inherent physical and cost constraints of device connectivity. Its objectives include effective levels of decoupling between devices and applications, designed to keep markets open and encourage the rapid growth of scalable Web and Enterprise middleware and applications. Paho is being kicked off with MQTT publish/subscribe client implementations for use on embedded platforms, along with corresponding server support as determined by the community.
11 |
12 | - https://projects.eclipse.org/projects/technology.paho
13 |
14 | Developer resources:
15 | --------------------
16 |
17 | Information regarding source code management, builds, coding standards, and more.
18 |
19 | - https://projects.eclipse.org/projects/technology.paho/developer
20 |
21 | Contributor License Agreement:
22 | ------------------------------
23 |
24 | Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (CLA).
25 |
26 | - http://www.eclipse.org/legal/CLA.php
27 |
28 | Contact:
29 | --------
30 |
31 | Contact the project developers via the project's "dev" list.
32 |
33 | - https://dev.eclipse.org/mailman/listinfo/paho-dev
34 |
35 | Search for bugs:
36 | ----------------
37 |
38 | This project uses Bugzilla to track ongoing development and issues.
39 |
40 | - https://bugs.eclipse.org/bugs/buglist.cgi?product=Paho
41 |
42 | Create a new bug:
43 | -----------------
44 |
45 | Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome!
46 |
47 | - https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Paho
48 |
--------------------------------------------------------------------------------
/js/paho/about.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | About
5 |
6 |
7 |
About This Content
8 |
9 |
December 9, 2013
10 |
License
11 |
12 |
The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
13 | indicated below, the Content is provided to you under the terms and conditions of the
14 | Eclipse Public License Version 1.0 ("EPL") and Eclipse Distribution License Version 1.0 ("EDL").
15 | A copy of the EPL is available at
16 | http://www.eclipse.org/legal/epl-v10.html
17 | and a copy of the EDL is available at
18 | http://www.eclipse.org/org/documents/edl-v10.php.
19 | For purposes of the EPL, "Program" will mean the Content.
20 |
21 |
If you did not receive this Content directly from the Eclipse Foundation, the Content is
22 | being redistributed by another party ("Redistributor") and different terms and conditions may
23 | apply to your use of any object code in the Content. Check the Redistributor's license that was
24 | provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
25 | indicated below, the terms and conditions of the EPL still apply to any source code in the Content
26 | and such source code may be obtained at http://www.eclipse.org.
27 |
28 |
29 |
--------------------------------------------------------------------------------
/js/paho/edl-v10:
--------------------------------------------------------------------------------
1 |
2 | Eclipse Distribution License - v 1.0
3 |
4 | Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors.
5 |
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 |
10 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 | Neither the name of the Eclipse Foundation, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 |
16 |
--------------------------------------------------------------------------------
/js/paho/epl-v10:
--------------------------------------------------------------------------------
1 | Eclipse Public License - v 1.0
2 |
3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
4 |
5 | 1. DEFINITIONS
6 |
7 | "Contribution" means:
8 |
9 | a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
10 | b) in the case of each subsequent Contributor:
11 | i) changes to the Program, and
12 | ii) additions to the Program;
13 | where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
14 | "Contributor" means any person or entity that distributes the Program.
15 |
16 | "Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
17 |
18 | "Program" means the Contributions distributed in accordance with this Agreement.
19 |
20 | "Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
21 |
22 | 2. GRANT OF RIGHTS
23 |
24 | a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
25 | b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
26 | c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
27 | d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
28 | 3. REQUIREMENTS
29 |
30 | A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
31 |
32 | a) it complies with the terms and conditions of this Agreement; and
33 | b) its license agreement:
34 | i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
35 | ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
36 | iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
37 | iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
38 | When the Program is made available in source code form:
39 |
40 | a) it must be made available under this Agreement; and
41 | b) a copy of this Agreement must be included with each copy of the Program.
42 | Contributors may not remove or alter any copyright notices contained within the Program.
43 |
44 | Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
45 |
46 | 4. COMMERCIAL DISTRIBUTION
47 |
48 | Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
49 |
50 | For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
51 |
52 | 5. NO WARRANTY
53 |
54 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
55 |
56 | 6. DISCLAIMER OF LIABILITY
57 |
58 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59 |
60 | 7. GENERAL
61 |
62 | If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
63 |
64 | If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
65 |
66 | All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
67 |
68 | Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
69 |
70 | This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
71 |
--------------------------------------------------------------------------------
/js/paho/mqttws31-min.js:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2013, 2014 IBM Corp.
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Eclipse Distribution License v1.0 which accompany this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | * and the Eclipse Distribution License is available at
11 | * http://www.eclipse.org/org/documents/edl-v10.php.
12 | *
13 | *******************************************************************************/
14 |
15 | "undefined"===typeof Paho&&(Paho={});
16 | Paho.MQTT=function(u){function y(a,b,c){b[c++]=a>>8;b[c++]=a%256;return c}function r(a,b,c,h){h=y(b,c,h);F(a,c,h);return h+b}function m(a){for(var b=0,c=0;c=h&&(c++,b++),b+=3):127=e){var d=a.charCodeAt(++h);if(isNaN(d))throw Error(f(g.MALFORMED_UNICODE,[e,d]));e=(e-55296<<10)+(d-56320)+65536}127>=e?b[c++]=e:(2047>=e?b[c++]=e>>6&31|
17 | 192:(65535>=e?b[c++]=e>>12&15|224:(b[c++]=e>>18&7|240,b[c++]=e>>12&63|128),b[c++]=e>>6&63|128),b[c++]=e&63|128)}return b}function G(a,b,c){for(var h="",e,d=b;de)){var p=a[d++]-128;if(0>p)throw Error(f(g.MALFORMED_UTF,[e.toString(16),p.toString(16),""]));if(224>e)e=64*(e-192)+p;else{var t=a[d++]-128;if(0>t)throw Error(f(g.MALFORMED_UTF,[e.toString(16),p.toString(16),t.toString(16)]));if(240>e)e=4096*(e-224)+64*p+t;else{var l=a[d++]-128;if(0>l)throw Error(f(g.MALFORMED_UTF,
18 | [e.toString(16),p.toString(16),t.toString(16),l.toString(16)]));if(248>e)e=262144*(e-240)+4096*p+64*t+l;else throw Error(f(g.MALFORMED_UTF,[e.toString(16),p.toString(16),t.toString(16),l.toString(16)]));}}}65535>10)),e=56320+(e&1023));h+=String.fromCharCode(e)}return h}var A=function(a,b){for(var c in a)if(a.hasOwnProperty(c))if(b.hasOwnProperty(c)){if(typeof a[c]!==b[c])throw Error(f(g.INVALID_TYPE,[typeof a[c],c]));}else{var h="Unknown property, "+c+
19 | ". Valid properties are:";for(c in b)b.hasOwnProperty(c)&&(h=h+" "+c);throw Error(h);}},q=function(a,b){return function(){return a.apply(b,arguments)}},g={OK:{code:0,text:"AMQJSC0000I OK."},CONNECT_TIMEOUT:{code:1,text:"AMQJSC0001E Connect timed out."},SUBSCRIBE_TIMEOUT:{code:2,text:"AMQJS0002E Subscribe timed out."},UNSUBSCRIBE_TIMEOUT:{code:3,text:"AMQJS0003E Unsubscribe timed out."},PING_TIMEOUT:{code:4,text:"AMQJS0004E Ping timed out."},INTERNAL_ERROR:{code:5,text:"AMQJS0005E Internal error. Error Message: {0}, Stack trace: {1}"},
20 | CONNACK_RETURNCODE:{code:6,text:"AMQJS0006E Bad Connack return code:{0} {1}."},SOCKET_ERROR:{code:7,text:"AMQJS0007E Socket error:{0}."},SOCKET_CLOSE:{code:8,text:"AMQJS0008I Socket closed."},MALFORMED_UTF:{code:9,text:"AMQJS0009E Malformed UTF data:{0} {1} {2}."},UNSUPPORTED:{code:10,text:"AMQJS0010E {0} is not supported by this browser."},INVALID_STATE:{code:11,text:"AMQJS0011E Invalid state {0}."},INVALID_TYPE:{code:12,text:"AMQJS0012E Invalid type {0} for {1}."},INVALID_ARGUMENT:{code:13,text:"AMQJS0013E Invalid argument {0} for {1}."},
21 | UNSUPPORTED_OPERATION:{code:14,text:"AMQJS0014E Unsupported operation."},INVALID_STORED_DATA:{code:15,text:"AMQJS0015E Invalid data in local storage key={0} value={1}."},INVALID_MQTT_MESSAGE_TYPE:{code:16,text:"AMQJS0016E Invalid MQTT message type {0}."},MALFORMED_UNICODE:{code:17,text:"AMQJS0017E Malformed Unicode string:{0} {1}."}},J={0:"Connection Accepted",1:"Connection Refused: unacceptable protocol version",2:"Connection Refused: identifier rejected",3:"Connection Refused: server unavailable",
22 | 4:"Connection Refused: bad user name or password",5:"Connection Refused: not authorized"},f=function(a,b){var c=a.text;if(b)for(var h,e,d=0;d>7;0l);f=d.length+1;b=new ArrayBuffer(b+f);l=new Uint8Array(b);
25 | l[0]=a;l.set(d,1);if(3==this.type)f=r(this.payloadMessage.destinationName,h,l,f);else if(1==this.type){switch(this.mqttVersion){case 3:l.set(B,f);f+=B.length;break;case 4:l.set(C,f),f+=C.length}a=0;this.cleanSession&&(a=2);void 0!=this.willMessage&&(a=a|4|this.willMessage.qos<<3,this.willMessage.retained&&(a|=32));void 0!=this.userName&&(a|=128);void 0!=this.password&&(a|=64);l[f++]=a;f=y(this.keepAliveInterval,l,f)}void 0!=this.messageIdentifier&&(f=y(this.messageIdentifier,l,f));switch(this.type){case 1:f=
26 | r(this.clientId,m(this.clientId),l,f);void 0!=this.willMessage&&(f=r(this.willMessage.destinationName,m(this.willMessage.destinationName),l,f),f=y(e.byteLength,l,f),l.set(e,f),f+=e.byteLength);void 0!=this.userName&&(f=r(this.userName,m(this.userName),l,f));void 0!=this.password&&r(this.password,m(this.password),l,f);break;case 3:l.set(g,f);break;case 8:for(d=0;dthis.connectOptions.mqttVersion?new WebSocket(a,["mqttv3.1"]):new WebSocket(a,["mqtt"]);this.socket.binaryType=
37 | "arraybuffer";this.socket.onopen=q(this._on_socket_open,this);this.socket.onmessage=q(this._on_socket_message,this);this.socket.onerror=q(this._on_socket_error,this);this.socket.onclose=q(this._on_socket_close,this);this.sendPinger=new H(this,window,this.connectOptions.keepAliveInterval);this.receivePinger=new H(this,window,this.connectOptions.keepAliveInterval);this._connectTimeout=new D(this,window,this.connectOptions.timeout,this._disconnected,[g.CONNECT_TIMEOUT.code,f(g.CONNECT_TIMEOUT)])};k.prototype._schedule_message=
38 | function(a){this._msg_queue.push(a);this.connected&&this._process_queue()};k.prototype.store=function(a,b){var c={type:b.type,messageIdentifier:b.messageIdentifier,version:1};switch(b.type){case 3:b.pubRecReceived&&(c.pubRecReceived=!0);c.payloadMessage={};for(var h="",e=b.payloadMessage.payloadBytes,d=0;d=e[d]?h+"0"+e[d].toString(16):h+e[d].toString(16);c.payloadMessage.payloadHex=h;c.payloadMessage.qos=b.payloadMessage.qos;c.payloadMessage.destinationName=b.payloadMessage.destinationName;
39 | b.payloadMessage.duplicate&&(c.payloadMessage.duplicate=!0);b.payloadMessage.retained&&(c.payloadMessage.retained=!0);0==a.indexOf("Sent:")&&(void 0===b.sequence&&(b.sequence=++this._sequence),c.sequence=b.sequence);break;default:throw Error(f(g.INVALID_STORED_DATA,[key,c]));}localStorage.setItem(a+this._localKey+b.messageIdentifier,JSON.stringify(c))};k.prototype.restore=function(a){var b=localStorage.getItem(a),c=JSON.parse(b),h=new n(c.type,c);switch(c.type){case 3:for(var b=c.payloadMessage.payloadHex,
40 | e=new ArrayBuffer(b.length/2),e=new Uint8Array(e),d=0;2<=b.length;){var k=parseInt(b.substring(0,2),16),b=b.substring(2,b.length);e[d++]=k}b=new Paho.MQTT.Message(e);b.qos=c.payloadMessage.qos;b.destinationName=c.payloadMessage.destinationName;c.payloadMessage.duplicate&&(b.duplicate=!0);c.payloadMessage.retained&&(b.retained=!0);h.payloadMessage=b;break;default:throw Error(f(g.INVALID_STORED_DATA,[a,b]));}0==a.indexOf("Sent:"+this._localKey)?(h.payloadMessage.duplicate=!0,this._sentMessages[h.messageIdentifier]=
41 | h):0==a.indexOf("Received:"+this._localKey)&&(this._receivedMessages[h.messageIdentifier]=h)};k.prototype._process_queue=function(){for(var a=null,b=this._msg_queue.reverse();a=b.pop();)this._socket_send(a),this._notify_msg_sent[a]&&(this._notify_msg_sent[a](),delete this._notify_msg_sent[a])};k.prototype._requires_ack=function(a){var b=Object.keys(this._sentMessages).length;if(b>this.maxMessageIdentifier)throw Error("Too many messages:"+b);for(;void 0!==this._sentMessages[this._message_identifier];)this._message_identifier++;
42 | a.messageIdentifier=this._message_identifier;this._sentMessages[a.messageIdentifier]=a;3===a.type&&this.store("Sent:",a);this._message_identifier===this.maxMessageIdentifier&&(this._message_identifier=1)};k.prototype._on_socket_open=function(){var a=new n(1,this.connectOptions);a.clientId=this.clientId;this._socket_send(a)};k.prototype._on_socket_message=function(a){this._trace("Client._on_socket_message",a.data);this.receivePinger.reset();a=this._deframeMessages(a.data);for(var b=0;b>4,z=t&15,d=d+1,v=void 0,E=0,m=1;do{if(d==e.length){h=[null,k];break a}v=e[d++];E+=(v&127)*m;m*=128}while(0!=(v&128));v=d+E;if(v>e.length)h=[null,k];else{var w=new n(l);switch(l){case 2:e[d++]&
44 | 1&&(w.sessionPresent=!0);w.returnCode=e[d++];break;case 3:var k=z>>1&3,r=256*e[d]+e[d+1],d=d+2,u=G(e,d,r),d=d+r;0b)throw Error(f(g.INVALID_TYPE,[typeof b,"port"]));if("string"!==typeof c)throw Error(f(g.INVALID_TYPE,[typeof c,"path"]));e="ws://"+(-1!=a.indexOf(":")&&"["!=a.slice(0,1)&&"]"!=a.slice(-1)?"["+a+"]":a)+":"+b+c}for(var p=d=0;p=m&&p++;d++}if("string"!==typeof h||65535a.mqttVersion)throw Error(f(g.INVALID_ARGUMENT,[a.mqttVersion,"connectOptions.mqttVersion"]));void 0===a.mqttVersion?(a.mqttVersionExplicit=!1,a.mqttVersion=4):a.mqttVersionExplicit=!0;if(void 0===a.password&&void 0!==a.userName)throw Error(f(g.INVALID_ARGUMENT,
62 | [a.password,"connectOptions.password"]));if(a.willMessage){if(!(a.willMessage instanceof x))throw Error(f(g.INVALID_TYPE,[a.willMessage,"connectOptions.willMessage"]));a.willMessage.stringPayload;if("undefined"===typeof a.willMessage.destinationName)throw Error(f(g.INVALID_TYPE,[typeof a.willMessage.destinationName,"connectOptions.willMessage.destinationName"]));}"undefined"===typeof a.cleanSession&&(a.cleanSession=!0);if(a.hosts){if(!(a.hosts instanceof Array))throw Error(f(g.INVALID_ARGUMENT,[a.hosts,
63 | "connectOptions.hosts"]));if(1>a.hosts.length)throw Error(f(g.INVALID_ARGUMENT,[a.hosts,"connectOptions.hosts"]));for(var b=!1,d=0;da.ports[d])throw Error(f(g.INVALID_TYPE,[typeof a.ports[d],"connectOptions.ports["+d+"]"]));var b=a.hosts[d],h=
65 | a.ports[d];e="ws://"+(-1!=b.indexOf(":")?"["+b+"]":b)+":"+h+c;a.uris.push(e)}}}l.connect(a)};this.subscribe=function(a,b){if("string"!==typeof a)throw Error("Invalid argument:"+a);b=b||{};A(b,{qos:"number",invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"});if(b.timeout&&!b.onFailure)throw Error("subscribeOptions.timeout specified with no onFailure callback.");if("undefined"!==typeof b.qos&&0!==b.qos&&1!==b.qos&&2!==b.qos)throw Error(f(g.INVALID_ARGUMENT,[b.qos,
66 | "subscribeOptions.qos"]));l.subscribe(a,b)};this.unsubscribe=function(a,b){if("string"!==typeof a)throw Error("Invalid argument:"+a);b=b||{};A(b,{invocationContext:"object",onSuccess:"function",onFailure:"function",timeout:"number"});if(b.timeout&&!b.onFailure)throw Error("unsubscribeOptions.timeout specified with no onFailure callback.");l.unsubscribe(a,b)};this.send=function(a,b,c,d){var e;if(0==arguments.length)throw Error("Invalid argument.length");if(1==arguments.length){if(!(a instanceof x)&&
67 | "string"!==typeof a)throw Error("Invalid argument:"+typeof a);e=a;if("undefined"===typeof e.destinationName)throw Error(f(g.INVALID_ARGUMENT,[e.destinationName,"Message.destinationName"]));}else e=new x(b),e.destinationName=a,3<=arguments.length&&(e.qos=c),4<=arguments.length&&(e.retained=d);l.send(e)};this.disconnect=function(){l.disconnect()};this.getTraceLog=function(){return l.getTraceLog()};this.startTrace=function(){l.startTrace()};this.stopTrace=function(){l.stopTrace()};this.isConnected=function(){return l.connected}};
68 | I.prototype={get host(){return this._getHost()},set host(a){this._setHost(a)},get port(){return this._getPort()},set port(a){this._setPort(a)},get path(){return this._getPath()},set path(a){this._setPath(a)},get clientId(){return this._getClientId()},set clientId(a){this._setClientId(a)},get onConnectionLost(){return this._getOnConnectionLost()},set onConnectionLost(a){this._setOnConnectionLost(a)},get onMessageDelivered(){return this._getOnMessageDelivered()},set onMessageDelivered(a){this._setOnMessageDelivered(a)},
69 | get onMessageArrived(){return this._getOnMessageArrived()},set onMessageArrived(a){this._setOnMessageArrived(a)},get trace(){return this._getTrace()},set trace(a){this._setTrace(a)}};var x=function(a){var b;if("string"===typeof a||a instanceof ArrayBuffer||a instanceof Int8Array||a instanceof Uint8Array||a instanceof Int16Array||a instanceof Uint16Array||a instanceof Int32Array||a instanceof Uint32Array||a instanceof Float32Array||a instanceof Float64Array)b=a;else throw f(g.INVALID_ARGUMENT,[a,"newPayload"]);
70 | this._getPayloadString=function(){return"string"===typeof b?b:G(b,0,b.length)};this._getPayloadBytes=function(){if("string"===typeof b){var a=new ArrayBuffer(m(b)),a=new Uint8Array(a);F(b,a,0);return a}return b};var c=void 0;this._getDestinationName=function(){return c};this._setDestinationName=function(a){if("string"===typeof a)c=a;else throw Error(f(g.INVALID_ARGUMENT,[a,"newDestinationName"]));};var h=0;this._getQos=function(){return h};this._setQos=function(a){if(0===a||1===a||2===a)h=a;else throw Error("Invalid argument:"+
71 | a);};var e=!1;this._getRetained=function(){return e};this._setRetained=function(a){if("boolean"===typeof a)e=a;else throw Error(f(g.INVALID_ARGUMENT,[a,"newRetained"]));};var d=!1;this._getDuplicate=function(){return d};this._setDuplicate=function(a){d=a}};x.prototype={get payloadString(){return this._getPayloadString()},get payloadBytes(){return this._getPayloadBytes()},get destinationName(){return this._getDestinationName()},set destinationName(a){this._setDestinationName(a)},get qos(){return this._getQos()},
72 | set qos(a){this._setQos(a)},get retained(){return this._getRetained()},set retained(a){this._setRetained(a)},get duplicate(){return this._getDuplicate()},set duplicate(a){this._setDuplicate(a)}};return{Client:I,Message:x}}(window);
73 |
--------------------------------------------------------------------------------
/js/rrule.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * rrule.js - Library for working with recurrence rules for calendar dates.
3 | * https://github.com/jakubroztocil/rrule
4 | *
5 | * Copyright 2010, Jakub Roztocil and Lars Schoning
6 | * Licenced under the BSD licence.
7 | * https://github.com/jakubroztocil/rrule/blob/master/LICENCE
8 | *
9 | * Based on:
10 | * python-dateutil - Extensions to the standard Python datetime module.
11 | * Copyright (c) 2003-2011 - Gustavo Niemeyer
12 | * Copyright (c) 2012 - Tomi Pieviläinen
13 | * https://github.com/jakubroztocil/rrule/blob/master/LICENCE
14 | *
15 | */
16 | (function(root){
17 |
18 | var serverSide = typeof module !== 'undefined' && module.exports;
19 |
20 |
21 | var getnlp = function() {
22 | if (!getnlp._nlp) {
23 | if (serverSide) {
24 | // Lazy, runtime import to avoid circular refs.
25 | getnlp._nlp = require('./nlp')
26 | } else if (!(getnlp._nlp = root._RRuleNLP)) {
27 | throw new Error(
28 | 'You need to include rrule/nlp.js for fromText/toText to work.'
29 | )
30 | }
31 | }
32 | return getnlp._nlp;
33 | };
34 |
35 |
36 | //=============================================================================
37 | // Date utilities
38 | //=============================================================================
39 |
40 | /**
41 | * General date-related utilities.
42 | * Also handles several incompatibilities between JavaScript and Python
43 | *
44 | */
45 | var dateutil = {
46 |
47 | MONTH_DAYS: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
48 |
49 | /**
50 | * Number of milliseconds of one day
51 | */
52 | ONE_DAY: 1000 * 60 * 60 * 24,
53 |
54 | /**
55 | * @see:
56 | */
57 | MAXYEAR: 9999,
58 |
59 | /**
60 | * Python uses 1-Jan-1 as the base for calculating ordinals but we don't
61 | * want to confuse the JS engine with milliseconds > Number.MAX_NUMBER,
62 | * therefore we use 1-Jan-1970 instead
63 | */
64 | ORDINAL_BASE: new Date(1970, 0, 1),
65 |
66 | /**
67 | * Python: MO-SU: 0 - 6
68 | * JS: SU-SAT 0 - 6
69 | */
70 | PY_WEEKDAYS: [6, 0, 1, 2, 3, 4, 5],
71 |
72 | /**
73 | * py_date.timetuple()[7]
74 | */
75 | getYearDay: function(date) {
76 | var dateNoTime = new Date(
77 | date.getFullYear(), date.getMonth(), date.getDate());
78 | return Math.ceil(
79 | (dateNoTime - new Date(date.getFullYear(), 0, 1))
80 | / dateutil.ONE_DAY) + 1;
81 | },
82 |
83 | isLeapYear: function(year) {
84 | if (year instanceof Date) {
85 | year = year.getFullYear();
86 | }
87 | return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
88 | },
89 |
90 | /**
91 | * @return {Number} the date's timezone offset in ms
92 | */
93 | tzOffset: function(date) {
94 | return date.getTimezoneOffset() * 60 * 1000
95 | },
96 |
97 | /**
98 | * @see:
99 | */
100 | daysBetween: function(date1, date2) {
101 | // The number of milliseconds in one day
102 | // Convert both dates to milliseconds
103 | var date1_ms = date1.getTime() - dateutil.tzOffset(date1);
104 | var date2_ms = date2.getTime() - dateutil.tzOffset(date2);
105 | // Calculate the difference in milliseconds
106 | var difference_ms = Math.abs(date1_ms - date2_ms);
107 | // Convert back to days and return
108 | return Math.round(difference_ms / dateutil.ONE_DAY);
109 | },
110 |
111 | /**
112 | * @see:
113 | */
114 | toOrdinal: function(date) {
115 | return dateutil.daysBetween(date, dateutil.ORDINAL_BASE);
116 | },
117 |
118 | /**
119 | * @see -
120 | */
121 | fromOrdinal: function(ordinal) {
122 | var millisecsFromBase = ordinal * dateutil.ONE_DAY;
123 | return new Date(dateutil.ORDINAL_BASE.getTime()
124 | - dateutil.tzOffset(dateutil.ORDINAL_BASE)
125 | + millisecsFromBase
126 | + dateutil.tzOffset(new Date(millisecsFromBase)));
127 | },
128 |
129 | /**
130 | * @see:
131 | */
132 | monthRange: function(year, month) {
133 | var date = new Date(year, month, 1);
134 | return [dateutil.getWeekday(date), dateutil.getMonthDays(date)];
135 | },
136 |
137 | getMonthDays: function(date) {
138 | var month = date.getMonth();
139 | return month == 1 && dateutil.isLeapYear(date)
140 | ? 29
141 | : dateutil.MONTH_DAYS[month];
142 | },
143 |
144 | /**
145 | * @return {Number} python-like weekday
146 | */
147 | getWeekday: function(date) {
148 | return dateutil.PY_WEEKDAYS[date.getDay()];
149 | },
150 |
151 | /**
152 | * @see:
153 | */
154 | combine: function(date, time) {
155 | time = time || date;
156 | return new Date(
157 | date.getFullYear(), date.getMonth(), date.getDate(),
158 | time.getHours(), time.getMinutes(), time.getSeconds()
159 | );
160 | },
161 |
162 | clone: function(date) {
163 | var dolly = new Date(date.getTime());
164 | dolly.setMilliseconds(0);
165 | return dolly;
166 | },
167 |
168 | cloneDates: function(dates) {
169 | var clones = [];
170 | for (var i = 0; i < dates.length; i++) {
171 | clones.push(dateutil.clone(dates[i]));
172 | }
173 | return clones;
174 | },
175 |
176 | /**
177 | * Sorts an array of Date or dateutil.Time objects
178 | */
179 | sort: function(dates) {
180 | dates.sort(function(a, b){
181 | return a.getTime() - b.getTime();
182 | });
183 | },
184 |
185 | timeToUntilString: function(time) {
186 | var date = new Date(time);
187 | var comp, comps = [
188 | date.getUTCFullYear(),
189 | date.getUTCMonth() + 1,
190 | date.getUTCDate(),
191 | 'T',
192 | date.getUTCHours(),
193 | date.getUTCMinutes(),
194 | date.getUTCSeconds(),
195 | 'Z'
196 | ];
197 | for (var i = 0; i < comps.length; i++) {
198 | comp = comps[i];
199 | if (!/[TZ]/.test(comp) && comp < 10) {
200 | comps[i] = '0' + String(comp);
201 | }
202 | }
203 | return comps.join('');
204 | },
205 |
206 | untilStringToDate: function(until) {
207 | var re = /^(\d{4})(\d{2})(\d{2})(T(\d{2})(\d{2})(\d{2})Z)?$/;
208 | var bits = re.exec(until);
209 | if (!bits) {
210 | throw new Error('Invalid UNTIL value: ' + until)
211 | }
212 | return new Date(
213 | Date.UTC(bits[1],
214 | bits[2] - 1,
215 | bits[3],
216 | bits[5] || 0,
217 | bits[6] || 0,
218 | bits[7] || 0
219 | ));
220 | }
221 |
222 | };
223 |
224 | dateutil.Time = function(hour, minute, second) {
225 | this.hour = hour;
226 | this.minute = minute;
227 | this.second = second;
228 | };
229 |
230 | dateutil.Time.prototype = {
231 | getHours: function() {
232 | return this.hour;
233 | },
234 | getMinutes: function() {
235 | return this.minute;
236 | },
237 | getSeconds: function() {
238 | return this.second;
239 | },
240 | getTime: function() {
241 | return ((this.hour * 60 * 60)
242 | + (this.minute * 60)
243 | + this.second)
244 | * 1000;
245 | }
246 | };
247 |
248 |
249 | //=============================================================================
250 | // Helper functions
251 | //=============================================================================
252 |
253 |
254 | /**
255 | * Simplified version of python's range()
256 | */
257 | var range = function(start, end) {
258 | if (arguments.length === 1) {
259 | end = start;
260 | start = 0;
261 | }
262 | var rang = [];
263 | for (var i = start; i < end; i++) {
264 | rang.push(i);
265 | }
266 | return rang;
267 | };
268 | var repeat = function(value, times) {
269 | var i = 0, array = [];
270 | if (value instanceof Array) {
271 | for (; i < times; i++) {
272 | array[i] = [].concat(value);
273 | }
274 | } else {
275 | for (; i < times; i++) {
276 | array[i] = value;
277 | }
278 | }
279 | return array;
280 | };
281 |
282 |
283 | /**
284 | * closure/goog/math/math.js:modulo
285 | * Copyright 2006 The Closure Library Authors.
286 | * The % operator in JavaScript returns the remainder of a / b, but differs from
287 | * some other languages in that the result will have the same sign as the
288 | * dividend. For example, -1 % 8 == -1, whereas in some other languages
289 | * (such as Python) the result would be 7. This function emulates the more
290 | * correct modulo behavior, which is useful for certain applications such as
291 | * calculating an offset index in a circular list.
292 | *
293 | * @param {number} a The dividend.
294 | * @param {number} b The divisor.
295 | * @return {number} a % b where the result is between 0 and b (either 0 <= x < b
296 | * or b < x <= 0, depending on the sign of b).
297 | */
298 | var pymod = function(a, b) {
299 | var r = a % b;
300 | // If r and b differ in sign, add b to wrap the result to the correct sign.
301 | return (r * b < 0) ? r + b : r;
302 | };
303 |
304 |
305 | /**
306 | * @see:
307 | */
308 | var divmod = function(a, b) {
309 | return {div: Math.floor(a / b), mod: pymod(a, b)};
310 | };
311 |
312 |
313 | /**
314 | * Python-like boolean
315 | * @return {Boolean} value of an object/primitive, taking into account
316 | * the fact that in Python an empty list's/tuple's
317 | * boolean value is False, whereas in JS it's true
318 | */
319 | var plb = function(obj) {
320 | return (obj instanceof Array && obj.length == 0)
321 | ? false
322 | : Boolean(obj);
323 | };
324 |
325 |
326 | /**
327 | * Return true if a value is in an array
328 | */
329 | var contains = function(arr, val) {
330 | return arr.indexOf(val) != -1;
331 | };
332 |
333 |
334 | //=============================================================================
335 | // Date masks
336 | //=============================================================================
337 |
338 | // Every mask is 7 days longer to handle cross-year weekly periods.
339 |
340 | var M365MASK = [].concat(
341 | repeat(1, 31), repeat(2, 28), repeat(3, 31),
342 | repeat(4, 30), repeat(5, 31), repeat(6, 30),
343 | repeat(7, 31), repeat(8, 31), repeat(9, 30),
344 | repeat(10, 31), repeat(11, 30), repeat(12, 31),
345 | repeat(1, 7)
346 | );
347 | var M366MASK = [].concat(
348 | repeat(1, 31), repeat(2, 29), repeat(3, 31),
349 | repeat(4, 30), repeat(5, 31), repeat(6, 30),
350 | repeat(7, 31), repeat(8, 31), repeat(9, 30),
351 | repeat(10, 31), repeat(11, 30), repeat(12, 31),
352 | repeat(1, 7)
353 | );
354 |
355 | var
356 | M28 = range(1, 29),
357 | M29 = range(1, 30),
358 | M30 = range(1, 31),
359 | M31 = range(1, 32);
360 | var MDAY366MASK = [].concat(
361 | M31, M29, M31,
362 | M30, M31, M30,
363 | M31, M31, M30,
364 | M31, M30, M31,
365 | M31.slice(0, 7)
366 | );
367 | var MDAY365MASK = [].concat(
368 | M31, M28, M31,
369 | M30, M31, M30,
370 | M31, M31, M30,
371 | M31, M30, M31,
372 | M31.slice(0, 7)
373 | );
374 |
375 | M28 = range(-28, 0);
376 | M29 = range(-29, 0);
377 | M30 = range(-30, 0);
378 | M31 = range(-31, 0);
379 | var NMDAY366MASK = [].concat(
380 | M31, M29, M31,
381 | M30, M31, M30,
382 | M31, M31, M30,
383 | M31, M30, M31,
384 | M31.slice(0, 7)
385 | );
386 | var NMDAY365MASK = [].concat(
387 | M31, M28, M31,
388 | M30, M31, M30,
389 | M31, M31, M30,
390 | M31, M30, M31,
391 | M31.slice(0, 7)
392 | );
393 |
394 | var M366RANGE = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366];
395 | var M365RANGE = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
396 |
397 | var WDAYMASK = (function() {
398 | for (var wdaymask = [], i = 0; i < 55; i++) {
399 | wdaymask = wdaymask.concat(range(7));
400 | }
401 | return wdaymask;
402 | }());
403 |
404 |
405 | //=============================================================================
406 | // Weekday
407 | //=============================================================================
408 |
409 | var Weekday = function(weekday, n) {
410 | if (n === 0) {
411 | throw new Error('Can\'t create weekday with n == 0');
412 | }
413 | this.weekday = weekday;
414 | this.n = n;
415 | };
416 |
417 | Weekday.prototype = {
418 |
419 | // __call__ - Cannot call the object directly, do it through
420 | // e.g. RRule.TH.nth(-1) instead,
421 | nth: function(n) {
422 | return this.n == n ? this : new Weekday(this.weekday, n);
423 | },
424 |
425 | // __eq__
426 | equals: function(other) {
427 | return this.weekday == other.weekday && this.n == other.n;
428 | },
429 |
430 | // __repr__
431 | toString: function() {
432 | var s = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'][this.weekday];
433 | if (this.n) {
434 | s = (this.n > 0 ? '+' : '') + String(this.n) + s;
435 | }
436 | return s;
437 | },
438 |
439 | getJsWeekday: function() {
440 | return this.weekday == 6 ? 0 : this.weekday + 1;
441 | }
442 |
443 | };
444 |
445 |
446 | //=============================================================================
447 | // RRule
448 | //=============================================================================
449 |
450 | /**
451 | *
452 | * @param {Object?} options - see
453 | * The only required option is `freq`, one of RRule.YEARLY, RRule.MONTHLY, ...
454 | * @constructor
455 | */
456 | var RRule = function(options, noCache) {
457 |
458 | // RFC string
459 | this._string = null;
460 |
461 | options = options || {};
462 |
463 | this._cache = noCache ? null : {
464 | all: false,
465 | before: [],
466 | after: [],
467 | between: []
468 | };
469 |
470 | // used by toString()
471 | this.origOptions = {};
472 |
473 | var invalid = [],
474 | keys = Object.keys(options),
475 | defaultKeys = Object.keys(RRule.DEFAULT_OPTIONS);
476 |
477 | // Shallow copy for origOptions and check for invalid
478 | keys.forEach(function(key) {
479 | this.origOptions[key] = options[key];
480 | if (!contains(defaultKeys, key)) invalid.push(key);
481 | }, this);
482 |
483 | if (invalid.length) {
484 | throw new Error('Invalid options: ' + invalid.join(', '))
485 | }
486 |
487 | if (!RRule.FREQUENCIES[options.freq] && options.byeaster === null) {
488 | throw new Error('Invalid frequency: ' + String(options.freq))
489 | }
490 |
491 | // Merge in default options
492 | defaultKeys.forEach(function(key) {
493 | if (!contains(keys, key)) options[key] = RRule.DEFAULT_OPTIONS[key];
494 | });
495 |
496 | var opts = this.options = options;
497 |
498 | if (opts.byeaster !== null) {
499 | opts.freq = RRule.YEARLY;
500 | }
501 |
502 | if (!opts.dtstart) {
503 | opts.dtstart = new Date();
504 | opts.dtstart.setMilliseconds(0);
505 | }
506 |
507 | if (opts.wkst === null) {
508 | opts.wkst = RRule.MO.weekday;
509 | } else if (typeof opts.wkst == 'number') {
510 | // cool, just keep it like that
511 | } else {
512 | opts.wkst = opts.wkst.weekday;
513 | }
514 |
515 | if (opts.bysetpos !== null) {
516 | if (typeof opts.bysetpos == 'number') {
517 | opts.bysetpos = [opts.bysetpos];
518 | }
519 | for (var i = 0; i < opts.bysetpos.length; i++) {
520 | var v = opts.bysetpos[i];
521 | if (v == 0 || !(-366 <= v && v <= 366)) {
522 | throw new Error(
523 | 'bysetpos must be between 1 and 366,' +
524 | ' or between -366 and -1'
525 | );
526 | }
527 | }
528 | }
529 |
530 | if (!(plb(opts.byweekno) || plb(opts.byyearday)
531 | || plb(opts.bymonthday) || opts.byweekday !== null
532 | || opts.byeaster !== null))
533 | {
534 | switch (opts.freq) {
535 | case RRule.YEARLY:
536 | if (!opts.bymonth) {
537 | opts.bymonth = opts.dtstart.getMonth() + 1;
538 | }
539 | opts.bymonthday = opts.dtstart.getDate();
540 | break;
541 | case RRule.MONTHLY:
542 | opts.bymonthday = opts.dtstart.getDate();
543 | break;
544 | case RRule.WEEKLY:
545 | opts.byweekday = dateutil.getWeekday(
546 | opts.dtstart);
547 | break;
548 | }
549 | }
550 |
551 | // bymonth
552 | if (opts.bymonth !== null
553 | && !(opts.bymonth instanceof Array)) {
554 | opts.bymonth = [opts.bymonth];
555 | }
556 |
557 | // byyearday
558 | if (opts.byyearday !== null
559 | && !(opts.byyearday instanceof Array)) {
560 | opts.byyearday = [opts.byyearday];
561 | }
562 |
563 | // bymonthday
564 | if (opts.bymonthday === null) {
565 | opts.bymonthday = [];
566 | opts.bynmonthday = [];
567 | } else if (opts.bymonthday instanceof Array) {
568 | var bymonthday = [], bynmonthday = [];
569 |
570 | for (i = 0; i < opts.bymonthday.length; i++) {
571 | var v = opts.bymonthday[i];
572 | if (v > 0) {
573 | bymonthday.push(v);
574 | } else if (v < 0) {
575 | bynmonthday.push(v);
576 | }
577 | }
578 | opts.bymonthday = bymonthday;
579 | opts.bynmonthday = bynmonthday;
580 | } else {
581 | if (opts.bymonthday < 0) {
582 | opts.bynmonthday = [opts.bymonthday];
583 | opts.bymonthday = [];
584 | } else {
585 | opts.bynmonthday = [];
586 | opts.bymonthday = [opts.bymonthday];
587 | }
588 | }
589 |
590 | // byweekno
591 | if (opts.byweekno !== null
592 | && !(opts.byweekno instanceof Array)) {
593 | opts.byweekno = [opts.byweekno];
594 | }
595 |
596 | // byweekday / bynweekday
597 | if (opts.byweekday === null) {
598 | opts.bynweekday = null;
599 | } else if (typeof opts.byweekday == 'number') {
600 | opts.byweekday = [opts.byweekday];
601 | opts.bynweekday = null;
602 |
603 | } else if (opts.byweekday instanceof Weekday) {
604 |
605 | if (!opts.byweekday.n || opts.freq > RRule.MONTHLY) {
606 | opts.byweekday = [opts.byweekday.weekday];
607 | opts.bynweekday = null;
608 | } else {
609 | opts.bynweekday = [
610 | [opts.byweekday.weekday,
611 | opts.byweekday.n]
612 | ];
613 | opts.byweekday = null;
614 | }
615 |
616 | } else {
617 | var byweekday = [], bynweekday = [];
618 |
619 | for (i = 0; i < opts.byweekday.length; i++) {
620 | var wday = opts.byweekday[i];
621 |
622 | if (typeof wday == 'number') {
623 | byweekday.push(wday);
624 | } else if (!wday.n || opts.freq > RRule.MONTHLY) {
625 | byweekday.push(wday.weekday);
626 | } else {
627 | bynweekday.push([wday.weekday, wday.n]);
628 | }
629 | }
630 | opts.byweekday = plb(byweekday) ? byweekday : null;
631 | opts.bynweekday = plb(bynweekday) ? bynweekday : null;
632 | }
633 |
634 | // byhour
635 | if (opts.byhour === null) {
636 | opts.byhour = (opts.freq < RRule.HOURLY)
637 | ? [opts.dtstart.getHours()]
638 | : null;
639 | } else if (typeof opts.byhour == 'number') {
640 | opts.byhour = [opts.byhour];
641 | }
642 |
643 | // byminute
644 | if (opts.byminute === null) {
645 | opts.byminute = (opts.freq < RRule.MINUTELY)
646 | ? [opts.dtstart.getMinutes()]
647 | : null;
648 | } else if (typeof opts.byminute == 'number') {
649 | opts.byminute = [opts.byminute];
650 | }
651 |
652 | // bysecond
653 | if (opts.bysecond === null) {
654 | opts.bysecond = (opts.freq < RRule.SECONDLY)
655 | ? [opts.dtstart.getSeconds()]
656 | : null;
657 | } else if (typeof opts.bysecond == 'number') {
658 | opts.bysecond = [opts.bysecond];
659 | }
660 |
661 | if (opts.freq >= RRule.HOURLY) {
662 | this.timeset = null;
663 | } else {
664 | this.timeset = [];
665 | for (i = 0; i < opts.byhour.length; i++) {
666 | var hour = opts.byhour[i];
667 | for (var j = 0; j < opts.byminute.length; j++) {
668 | var minute = opts.byminute[j];
669 | for (var k = 0; k < opts.bysecond.length; k++) {
670 | var second = opts.bysecond[k];
671 | // python:
672 | // datetime.time(hour, minute, second,
673 | // tzinfo=self._tzinfo))
674 | this.timeset.push(new dateutil.Time(hour, minute, second));
675 | }
676 | }
677 | }
678 | dateutil.sort(this.timeset);
679 | }
680 |
681 | };
682 | //}}}
683 |
684 | // RRule class 'constants'
685 |
686 | RRule.FREQUENCIES = [
687 | 'YEARLY', 'MONTHLY', 'WEEKLY', 'DAILY',
688 | 'HOURLY', 'MINUTELY', 'SECONDLY'
689 | ];
690 |
691 | RRule.YEARLY = 0;
692 | RRule.MONTHLY = 1;
693 | RRule.WEEKLY = 2;
694 | RRule.DAILY = 3;
695 | RRule.HOURLY = 4;
696 | RRule.MINUTELY = 5;
697 | RRule.SECONDLY = 6;
698 |
699 | RRule.MO = new Weekday(0);
700 | RRule.TU = new Weekday(1);
701 | RRule.WE = new Weekday(2);
702 | RRule.TH = new Weekday(3);
703 | RRule.FR = new Weekday(4);
704 | RRule.SA = new Weekday(5);
705 | RRule.SU = new Weekday(6);
706 |
707 | RRule.DEFAULT_OPTIONS = {
708 | freq: null,
709 | dtstart: null,
710 | interval: 1,
711 | wkst: RRule.MO,
712 | count: null,
713 | until: null,
714 | bysetpos: null,
715 | bymonth: null,
716 | bymonthday: null,
717 | byyearday: null,
718 | byweekno: null,
719 | byweekday: null,
720 | byhour: null,
721 | byminute: null,
722 | bysecond: null,
723 | byeaster: null
724 | };
725 |
726 |
727 |
728 | RRule.parseText = function(text, language) {
729 | return getnlp().parseText(text, language)
730 | };
731 |
732 | RRule.fromText = function(text, language) {
733 | return getnlp().fromText(text, language)
734 | };
735 |
736 | RRule.optionsToString = function(options) {
737 | var key, keys, defaultKeys, value, strValues, pairs = [];
738 |
739 | keys = Object.keys(options);
740 | defaultKeys = Object.keys(RRule.DEFAULT_OPTIONS);
741 |
742 | for (var i = 0; i < keys.length; i++) {
743 |
744 | if (!contains(defaultKeys, keys[i])) continue;
745 |
746 | key = keys[i].toUpperCase();
747 | value = options[keys[i]];
748 | strValues = [];
749 |
750 | if (value === null || value instanceof Array && !value.length) {
751 | continue;
752 | }
753 |
754 | switch (key) {
755 | case 'FREQ':
756 | value = RRule.FREQUENCIES[options.freq];
757 | break;
758 | case 'WKST':
759 | value = value.toString();
760 | break;
761 | case 'BYWEEKDAY':
762 | /*
763 | NOTE: BYWEEKDAY is a special case.
764 | RRule() deconstructs the rule.options.byweekday array
765 | into an array of Weekday arguments.
766 | On the other hand, rule.origOptions is an array of Weekdays.
767 | We need to handle both cases here.
768 | It might be worth change RRule to keep the Weekdays.
769 |
770 | Also, BYWEEKDAY (used by RRule) vs. BYDAY (RFC)
771 |
772 | */
773 | key = 'BYDAY';
774 | if (!(value instanceof Array)) {
775 | value = [value];
776 | }
777 | for (var wday, j = 0; j < value.length; j++) {
778 | wday = value[j];
779 | if (wday instanceof Weekday) {
780 | // good
781 | } else if (wday instanceof Array) {
782 | wday = new Weekday(wday[0], wday[1]);
783 | } else {
784 | wday = new Weekday(wday);
785 | }
786 | strValues[j] = wday.toString();
787 | }
788 | value = strValues;
789 | break;
790 | case'DTSTART':
791 | case'UNTIL':
792 | value = dateutil.timeToUntilString(value);
793 | break;
794 | default:
795 | if (value instanceof Array) {
796 | for (var j = 0; j < value.length; j++) {
797 | strValues[j] = String(value[j]);
798 | }
799 | value = strValues;
800 | } else {
801 | value = String(value);
802 | }
803 |
804 | }
805 | pairs.push([key, value]);
806 | }
807 |
808 | var strings = [];
809 | for (var i = 0; i < pairs.length; i++) {
810 | var attr = pairs[i];
811 | strings.push(attr[0] + '=' + attr[1].toString());
812 | }
813 | return strings.join(';');
814 |
815 | };
816 |
817 | RRule.prototype = {
818 |
819 | /**
820 | * @param {Function} iterator - optional function that will be called
821 | * on each date that is added. It can return false
822 | * to stop the iteration.
823 | * @return Array containing all recurrences.
824 | */
825 | all: function(iterator) {
826 | if (iterator) {
827 | return this._iter(new CallbackIterResult('all', {}, iterator));
828 | } else {
829 | var result = this._cacheGet('all');
830 | if (result === false) {
831 | result = this._iter(new IterResult('all', {}));
832 | this._cacheAdd('all', result);
833 | }
834 | return result;
835 | }
836 | },
837 |
838 | /**
839 | * Returns all the occurrences of the rrule between after and before.
840 | * The inc keyword defines what happens if after and/or before are
841 | * themselves occurrences. With inc == True, they will be included in the
842 | * list, if they are found in the recurrence set.
843 | * @return Array
844 | */
845 | between: function(after, before, inc, iterator) {
846 | var args = {
847 | before: before,
848 | after: after,
849 | inc: inc
850 | }
851 |
852 | if (iterator) {
853 | return this._iter(
854 | new CallbackIterResult('between', args, iterator));
855 | } else {
856 | var result = this._cacheGet('between', args);
857 | if (result === false) {
858 | result = this._iter(new IterResult('between', args));
859 | this._cacheAdd('between', result, args);
860 | }
861 | return result;
862 | }
863 | },
864 |
865 | /**
866 | * Returns the last recurrence before the given datetime instance.
867 | * The inc keyword defines what happens if dt is an occurrence.
868 | * With inc == True, if dt itself is an occurrence, it will be returned.
869 | * @return Date or null
870 | */
871 | before: function(dt, inc) {
872 | var args = {
873 | dt: dt,
874 | inc: inc
875 | },
876 | result = this._cacheGet('before', args);
877 | if (result === false) {
878 | result = this._iter(new IterResult('before', args));
879 | this._cacheAdd('before', result, args);
880 | }
881 | return result;
882 | },
883 |
884 | /**
885 | * Returns the first recurrence after the given datetime instance.
886 | * The inc keyword defines what happens if dt is an occurrence.
887 | * With inc == True, if dt itself is an occurrence, it will be returned.
888 | * @return Date or null
889 | */
890 | after: function(dt, inc) {
891 | var args = {
892 | dt: dt,
893 | inc: inc
894 | },
895 | result = this._cacheGet('after', args);
896 | if (result === false) {
897 | result = this._iter(new IterResult('after', args));
898 | this._cacheAdd('after', result, args);
899 | }
900 | return result;
901 | },
902 |
903 | /**
904 | * Returns the number of recurrences in this set. It will have go trough
905 | * the whole recurrence, if this hasn't been done before.
906 | */
907 | count: function() {
908 | return this.all().length;
909 | },
910 |
911 | /**
912 | * Converts the rrule into its string representation
913 | * @see
914 | * @return String
915 | */
916 | toString: function() {
917 | return RRule.optionsToString(this.origOptions);
918 | },
919 |
920 | /**
921 | * Will convert all rules described in nlp:ToText
922 | * to text.
923 | */
924 | toText: function(gettext, language) {
925 | return getnlp().toText(this, gettext, language);
926 | },
927 |
928 | isFullyConvertibleToText: function() {
929 | return getnlp().isFullyConvertible(this)
930 | },
931 |
932 | /**
933 | * @param {String} what - all/before/after/between
934 | * @param {Array,Date} value - an array of dates, one date, or null
935 | * @param {Object?} args - _iter arguments
936 | */
937 | _cacheAdd: function(what, value, args) {
938 |
939 | if (!this._cache) return;
940 |
941 | if (value) {
942 | value = (value instanceof Date)
943 | ? dateutil.clone(value)
944 | : dateutil.cloneDates(value);
945 | }
946 |
947 | if (what == 'all') {
948 | this._cache.all = value;
949 | } else {
950 | args._value = value;
951 | this._cache[what].push(args);
952 | }
953 |
954 | },
955 |
956 | /**
957 | * @return false - not in the cache
958 | * null - cached, but zero occurrences (before/after)
959 | * Date - cached (before/after)
960 | * [] - cached, but zero occurrences (all/between)
961 | * [Date1, DateN] - cached (all/between)
962 | */
963 | _cacheGet: function(what, args) {
964 |
965 | if (!this._cache) {
966 | return false;
967 | }
968 |
969 | var cached = false;
970 |
971 | if (what == 'all') {
972 | cached = this._cache.all;
973 | } else {
974 | // Let's see whether we've already called the
975 | // 'what' method with the same 'args'
976 | loopItems:
977 | for (var item, i = 0; i < this._cache[what].length; i++) {
978 | item = this._cache[what][i];
979 | for (var k in args) {
980 | if (args.hasOwnProperty(k)
981 | && String(args[k]) != String(item[k])) {
982 | continue loopItems;
983 | }
984 | }
985 | cached = item._value;
986 | break;
987 | }
988 | }
989 |
990 | if (!cached && this._cache.all) {
991 | // Not in the cache, but we already know all the occurrences,
992 | // so we can find the correct dates from the cached ones.
993 | var iterResult = new IterResult(what, args);
994 | for (var i = 0; i < this._cache.all.length; i++) {
995 | if (!iterResult.accept(this._cache.all[i])) {
996 | break;
997 | }
998 | }
999 | cached = iterResult.getValue();
1000 | this._cacheAdd(what, cached, args);
1001 | }
1002 |
1003 | return cached instanceof Array
1004 | ? dateutil.cloneDates(cached)
1005 | : (cached instanceof Date
1006 | ? dateutil.clone(cached)
1007 | : cached);
1008 | },
1009 |
1010 | /**
1011 | * @return a RRule instance with the same freq and options
1012 | * as this one (cache is not cloned)
1013 | */
1014 | clone: function() {
1015 | return new RRule(this.origOptions);
1016 | },
1017 |
1018 | _iter: function(iterResult) {
1019 |
1020 | /* Since JavaScript doesn't have the python's yield operator (<1.7),
1021 | we use the IterResult object that tells us when to stop iterating.
1022 |
1023 | */
1024 |
1025 | var dtstart = this.options.dtstart;
1026 |
1027 | var
1028 | year = dtstart.getFullYear(),
1029 | month = dtstart.getMonth() + 1,
1030 | day = dtstart.getDate(),
1031 | hour = dtstart.getHours(),
1032 | minute = dtstart.getMinutes(),
1033 | second = dtstart.getSeconds(),
1034 | weekday = dateutil.getWeekday(dtstart),
1035 | yearday = dateutil.getYearDay(dtstart);
1036 |
1037 | // Some local variables to speed things up a bit
1038 | var
1039 | freq = this.options.freq,
1040 | interval = this.options.interval,
1041 | wkst = this.options.wkst,
1042 | until = this.options.until,
1043 | bymonth = this.options.bymonth,
1044 | byweekno = this.options.byweekno,
1045 | byyearday = this.options.byyearday,
1046 | byweekday = this.options.byweekday,
1047 | byeaster = this.options.byeaster,
1048 | bymonthday = this.options.bymonthday,
1049 | bynmonthday = this.options.bynmonthday,
1050 | bysetpos = this.options.bysetpos,
1051 | byhour = this.options.byhour,
1052 | byminute = this.options.byminute,
1053 | bysecond = this.options.bysecond;
1054 |
1055 | var ii = new Iterinfo(this);
1056 | ii.rebuild(year, month);
1057 |
1058 | var getdayset = {};
1059 | getdayset[RRule.YEARLY] = ii.ydayset;
1060 | getdayset[RRule.MONTHLY] = ii.mdayset;
1061 | getdayset[RRule.WEEKLY] = ii.wdayset;
1062 | getdayset[RRule.DAILY] = ii.ddayset;
1063 | getdayset[RRule.HOURLY] = ii.ddayset;
1064 | getdayset[RRule.MINUTELY] = ii.ddayset;
1065 | getdayset[RRule.SECONDLY] = ii.ddayset;
1066 |
1067 | getdayset = getdayset[freq];
1068 |
1069 | var timeset;
1070 | if (freq < RRule.HOURLY) {
1071 | timeset = this.timeset;
1072 | } else {
1073 | var gettimeset = {};
1074 | gettimeset[RRule.HOURLY] = ii.htimeset;
1075 | gettimeset[RRule.MINUTELY] = ii.mtimeset;
1076 | gettimeset[RRule.SECONDLY] = ii.stimeset;
1077 | gettimeset = gettimeset[freq];
1078 | if ((freq >= RRule.HOURLY && plb(byhour) && !contains(byhour, hour)) ||
1079 | (freq >= RRule.MINUTELY && plb(byminute) && !contains(byminute, minute)) ||
1080 | (freq >= RRule.SECONDLY && plb(bysecond) && !contains(bysecond, minute)))
1081 | {
1082 | timeset = [];
1083 | } else {
1084 | timeset = gettimeset.call(ii, hour, minute, second);
1085 | }
1086 | }
1087 |
1088 | var filtered, total = 0, count = this.options.count;
1089 |
1090 | var iterNo = 0;
1091 |
1092 | var i, j, k, dm, div, mod, tmp, pos, dayset, start, end, fixday;
1093 |
1094 | while (true) {
1095 |
1096 | // Get dayset with the right frequency
1097 | tmp = getdayset.call(ii, year, month, day);
1098 | dayset = tmp[0]; start = tmp[1]; end = tmp[2];
1099 |
1100 | // Do the "hard" work ;-)
1101 | filtered = false;
1102 | for (j = start; j < end; j++) {
1103 |
1104 | i = dayset[j];
1105 |
1106 | if ((plb(bymonth) && !contains(bymonth, ii.mmask[i])) ||
1107 | (plb(byweekno) && !ii.wnomask[i]) ||
1108 | (plb(byweekday) && !contains(byweekday, ii.wdaymask[i])) ||
1109 | (plb(ii.nwdaymask) && !ii.nwdaymask[i]) ||
1110 | (byeaster !== null && !contains(ii.eastermask, i)) ||
1111 | (
1112 | (plb(bymonthday) || plb(bynmonthday)) &&
1113 | !contains(bymonthday, ii.mdaymask[i]) &&
1114 | !contains(bynmonthday, ii.nmdaymask[i])
1115 | )
1116 | ||
1117 | (
1118 | plb(byyearday)
1119 | &&
1120 | (
1121 | (
1122 | i < ii.yearlen &&
1123 | !contains(byyearday, i + 1) &&
1124 | !contains(byyearday, -ii.yearlen + i)
1125 | )
1126 | ||
1127 | (
1128 | i >= ii.yearlen &&
1129 | !contains(byyearday, i + 1 - ii.yearlen) &&
1130 | !contains(byyearday, -ii.nextyearlen + i - ii.yearlen)
1131 | )
1132 | )
1133 | )
1134 | )
1135 | {
1136 | dayset[i] = null;
1137 | filtered = true;
1138 | }
1139 | }
1140 |
1141 | // Output results
1142 | if (plb(bysetpos) && plb(timeset)) {
1143 |
1144 | var daypos, timepos, poslist = [];
1145 |
1146 | for (i, j = 0; j < bysetpos.length; j++) {
1147 | var pos = bysetpos[j];
1148 | if (pos < 0) {
1149 | daypos = Math.floor(pos / timeset.length);
1150 | timepos = pymod(pos, timeset.length);
1151 | } else {
1152 | daypos = Math.floor((pos - 1) / timeset.length);
1153 | timepos = pymod((pos - 1), timeset.length);
1154 | }
1155 |
1156 | try {
1157 | tmp = [];
1158 | for (k = start; k < end; k++) {
1159 | var val = dayset[k];
1160 | if (val === null) {
1161 | continue;
1162 | }
1163 | tmp.push(val);
1164 | }
1165 | if (daypos < 0) {
1166 | // we're trying to emulate python's aList[-n]
1167 | i = tmp.slice(daypos)[0];
1168 | } else {
1169 | i = tmp[daypos];
1170 | }
1171 |
1172 | var time = timeset[timepos];
1173 |
1174 | var date = dateutil.fromOrdinal(ii.yearordinal + i);
1175 | var res = dateutil.combine(date, time);
1176 | // XXX: can this ever be in the array?
1177 | // - compare the actual date instead?
1178 | if (!contains(poslist, res)) {
1179 | poslist.push(res);
1180 | }
1181 | } catch (e) {}
1182 | }
1183 |
1184 | dateutil.sort(poslist);
1185 |
1186 | for (j = 0; j < poslist.length; j++) {
1187 | var res = poslist[j];
1188 | if (until && res > until) {
1189 | this._len = total;
1190 | return iterResult.getValue();
1191 | } else if (res >= dtstart) {
1192 | ++total;
1193 | if (!iterResult.accept(res)) {
1194 | return iterResult.getValue();
1195 | }
1196 | if (count) {
1197 | --count;
1198 | if (!count) {
1199 | this._len = total;
1200 | return iterResult.getValue();
1201 | }
1202 | }
1203 | }
1204 | }
1205 |
1206 | } else {
1207 | for (j = start; j < end; j++) {
1208 | i = dayset[j];
1209 | if (i !== null) {
1210 | var date = dateutil.fromOrdinal(ii.yearordinal + i);
1211 | for (k = 0; k < timeset.length; k++) {
1212 | var time = timeset[k];
1213 | var res = dateutil.combine(date, time);
1214 | if (until && res > until) {
1215 | this._len = total;
1216 | return iterResult.getValue();
1217 | } else if (res >= dtstart) {
1218 | ++total;
1219 | if (!iterResult.accept(res)) {
1220 | return iterResult.getValue();
1221 | }
1222 | if (count) {
1223 | --count;
1224 | if (!count) {
1225 | this._len = total;
1226 | return iterResult.getValue();
1227 | }
1228 | }
1229 | }
1230 | }
1231 | }
1232 | }
1233 | }
1234 |
1235 | // Handle frequency and interval
1236 | fixday = false;
1237 | if (freq == RRule.YEARLY) {
1238 | year += interval;
1239 | if (year > dateutil.MAXYEAR) {
1240 | this._len = total;
1241 | return iterResult.getValue();
1242 | }
1243 | ii.rebuild(year, month);
1244 | } else if (freq == RRule.MONTHLY) {
1245 | month += interval;
1246 | if (month > 12) {
1247 | div = Math.floor(month / 12);
1248 | mod = pymod(month, 12);
1249 | month = mod;
1250 | year += div;
1251 | if (month == 0) {
1252 | month = 12;
1253 | --year;
1254 | }
1255 | if (year > dateutil.MAXYEAR) {
1256 | this._len = total;
1257 | return iterResult.getValue();
1258 | }
1259 | }
1260 | ii.rebuild(year, month);
1261 | } else if (freq == RRule.WEEKLY) {
1262 | if (wkst > weekday) {
1263 | day += -(weekday + 1 + (6 - wkst)) + interval * 7;
1264 | } else {
1265 | day += -(weekday - wkst) + interval * 7;
1266 | }
1267 | weekday = wkst;
1268 | fixday = true;
1269 | } else if (freq == RRule.DAILY) {
1270 | day += interval;
1271 | fixday = true;
1272 | } else if (freq == RRule.HOURLY) {
1273 | if (filtered) {
1274 | // Jump to one iteration before next day
1275 | hour += Math.floor((23 - hour) / interval) * interval;
1276 | }
1277 | while (true) {
1278 | hour += interval;
1279 | dm = divmod(hour, 24);
1280 | div = dm.div;
1281 | mod = dm.mod;
1282 | if (div) {
1283 | hour = mod;
1284 | day += div;
1285 | fixday = true;
1286 | }
1287 | if (!plb(byhour) || contains(byhour, hour)) {
1288 | break;
1289 | }
1290 | }
1291 | timeset = gettimeset.call(ii, hour, minute, second);
1292 | } else if (freq == RRule.MINUTELY) {
1293 | if (filtered) {
1294 | // Jump to one iteration before next day
1295 | minute += Math.floor(
1296 | (1439 - (hour * 60 + minute)) / interval) * interval;
1297 | }
1298 | while(true) {
1299 | minute += interval;
1300 | dm = divmod(minute, 60);
1301 | div = dm.div;
1302 | mod = dm.mod;
1303 | if (div) {
1304 | minute = mod;
1305 | hour += div;
1306 | dm = divmod(hour, 24);
1307 | div = dm.div;
1308 | mod = dm.mod;
1309 | if (div) {
1310 | hour = mod;
1311 | day += div;
1312 | fixday = true;
1313 | filtered = false;
1314 | }
1315 | }
1316 | if ((!plb(byhour) || contains(byhour, hour)) &&
1317 | (!plb(byminute) || contains(byminute, minute))) {
1318 | break;
1319 | }
1320 | }
1321 | timeset = gettimeset.call(ii, hour, minute, second);
1322 | } else if (freq == RRule.SECONDLY) {
1323 | if (filtered) {
1324 | // Jump to one iteration before next day
1325 | second += Math.floor(
1326 | (86399 - (hour * 3600 + minute * 60 + second))
1327 | / interval) * interval;
1328 | }
1329 | while (true) {
1330 | second += interval;
1331 | dm = divmod(second, 60);
1332 | div = dm.div;
1333 | mod = dm.mod;
1334 | if (div) {
1335 | second = mod;
1336 | minute += div;
1337 | dm = divmod(minute, 60);
1338 | div = dm.div;
1339 | mod = dm.mod;
1340 | if (div) {
1341 | minute = mod;
1342 | hour += div;
1343 | dm = divmod(hour, 24);
1344 | div = dm.div;
1345 | mod = dm.mod;
1346 | if (div) {
1347 | hour = mod;
1348 | day += div;
1349 | fixday = true;
1350 | }
1351 | }
1352 | }
1353 | if ((!plb(byhour) || contains(byhour, hour)) &&
1354 | (!plb(byminute) || contains(byminute, minute)) &&
1355 | (!plb(bysecond) || contains(bysecond, second)))
1356 | {
1357 | break;
1358 | }
1359 | }
1360 | timeset = gettimeset.call(ii, hour, minute, second);
1361 | }
1362 |
1363 | if (fixday && day > 28) {
1364 | var daysinmonth = dateutil.monthRange(year, month - 1)[1];
1365 | if (day > daysinmonth) {
1366 | while (day > daysinmonth) {
1367 | day -= daysinmonth;
1368 | ++month;
1369 | if (month == 13) {
1370 | month = 1;
1371 | ++year;
1372 | if (year > dateutil.MAXYEAR) {
1373 | this._len = total;
1374 | return iterResult.getValue();
1375 | }
1376 | }
1377 | daysinmonth = dateutil.monthRange(year, month - 1)[1];
1378 | }
1379 | ii.rebuild(year, month);
1380 | }
1381 | }
1382 | }
1383 | }
1384 |
1385 | };
1386 |
1387 |
1388 | RRule.parseString = function(rfcString) {
1389 | rfcString = rfcString.replace(/^\s+|\s+$/, '');
1390 | if (!rfcString.length) {
1391 | return null;
1392 | }
1393 |
1394 | var i, j, key, value, attr,
1395 | attrs = rfcString.split(';'),
1396 | options = {};
1397 |
1398 | for (i = 0; i < attrs.length; i++) {
1399 | attr = attrs[i].split('=');
1400 | key = attr[0];
1401 | value = attr[1];
1402 | switch (key) {
1403 | case 'FREQ':
1404 | options.freq = RRule[value];
1405 | break;
1406 | case 'WKST':
1407 | options.wkst = RRule[value];
1408 | break;
1409 | case 'COUNT':
1410 | case 'INTERVAL':
1411 | case 'BYSETPOS':
1412 | case 'BYMONTH':
1413 | case 'BYMONTHDAY':
1414 | case 'BYYEARDAY':
1415 | case 'BYWEEKNO':
1416 | case 'BYHOUR':
1417 | case 'BYMINUTE':
1418 | case 'BYSECOND':
1419 | if (value.indexOf(',') != -1) {
1420 | value = value.split(',');
1421 | for (j = 0; j < value.length; j++) {
1422 | if (/^[+-]?\d+$/.test(value[j])) {
1423 | value[j] = Number(value[j]);
1424 | }
1425 | }
1426 | } else if (/^[+-]?\d+$/.test(value)) {
1427 | value = Number(value);
1428 | }
1429 | key = key.toLowerCase();
1430 | options[key] = value;
1431 | break;
1432 | case 'BYDAY': // => byweekday
1433 | var n, wday, day, days = value.split(',');
1434 | options.byweekday = [];
1435 | for (j = 0; j < days.length; j++) {
1436 | day = days[j];
1437 | if (day.length == 2) { // MO, TU, ...
1438 | wday = RRule[day]; // wday instanceof Weekday
1439 | options.byweekday.push(wday);
1440 | } else { // -1MO, +3FR, 1SO, ...
1441 | day = day.match(/^([+-]?\d)([A-Z]{2})$/);
1442 | n = Number(day[1]);
1443 | wday = day[2];
1444 | wday = RRule[wday].weekday;
1445 | options.byweekday.push(new Weekday(wday, n));
1446 | }
1447 | }
1448 | break;
1449 | case 'DTSTART':
1450 | options.dtstart = dateutil.untilStringToDate(value);
1451 | break;
1452 | case 'UNTIL':
1453 | options.until = dateutil.untilStringToDate(value);
1454 | break;
1455 | case 'BYEASTER':
1456 | options.byeaster = Number(value);
1457 | break;
1458 | default:
1459 | throw new Error("Unknown RRULE property '" + key + "'");
1460 | }
1461 | }
1462 | return options;
1463 | };
1464 |
1465 |
1466 | RRule.fromString = function(string) {
1467 | return new RRule(RRule.parseString(string));
1468 | };
1469 |
1470 |
1471 | //=============================================================================
1472 | // Iterinfo
1473 | //=============================================================================
1474 |
1475 | var Iterinfo = function(rrule) {
1476 | this.rrule = rrule;
1477 | this.lastyear = null;
1478 | this.lastmonth = null;
1479 | this.yearlen = null;
1480 | this.nextyearlen = null;
1481 | this.yearordinal = null;
1482 | this.yearweekday = null;
1483 | this.mmask = null;
1484 | this.mrange = null;
1485 | this.mdaymask = null;
1486 | this.nmdaymask = null;
1487 | this.wdaymask = null;
1488 | this.wnomask = null;
1489 | this.nwdaymask = null;
1490 | this.eastermask = null;
1491 | };
1492 |
1493 | Iterinfo.prototype.easter = function(y, offset) {
1494 | offset = offset || 0;
1495 |
1496 | var a = y % 19,
1497 | b = Math.floor(y / 100),
1498 | c = y % 100,
1499 | d = Math.floor(b / 4),
1500 | e = b % 4,
1501 | f = Math.floor((b + 8) / 25),
1502 | g = Math.floor((b - f + 1) / 3),
1503 | h = Math.floor(19 * a + b - d - g + 15) % 30,
1504 | i = Math.floor(c / 4),
1505 | k = c % 4,
1506 | l = Math.floor(32 + 2 * e + 2 * i - h - k) % 7,
1507 | m = Math.floor((a + 11 * h + 22 * l) / 451),
1508 | month = Math.floor((h + l - 7 * m + 114) / 31),
1509 | day = (h + l - 7 * m + 114) % 31 + 1,
1510 | date = Date.UTC(y, month - 1, day + offset),
1511 | yearStart = Date.UTC(y, 0, 1);
1512 |
1513 | return [ Math.ceil((date - yearStart) / (1000 * 60 * 60 * 24)) ];
1514 | }
1515 |
1516 | Iterinfo.prototype.rebuild = function(year, month) {
1517 |
1518 | var rr = this.rrule;
1519 |
1520 | if (year != this.lastyear) {
1521 |
1522 | this.yearlen = dateutil.isLeapYear(year) ? 366 : 365;
1523 | this.nextyearlen = dateutil.isLeapYear(year + 1) ? 366 : 365;
1524 | var firstyday = new Date(year, 0, 1);
1525 |
1526 | this.yearordinal = dateutil.toOrdinal(firstyday);
1527 | this.yearweekday = dateutil.getWeekday(firstyday);
1528 |
1529 | var wday = dateutil.getWeekday(new Date(year, 0, 1));
1530 |
1531 | if (this.yearlen == 365) {
1532 | this.mmask = [].concat(M365MASK);
1533 | this.mdaymask = [].concat(MDAY365MASK);
1534 | this.nmdaymask = [].concat(NMDAY365MASK);
1535 | this.wdaymask = WDAYMASK.slice(wday);
1536 | this.mrange = [].concat(M365RANGE);
1537 | } else {
1538 | this.mmask = [].concat(M366MASK);
1539 | this.mdaymask = [].concat(MDAY366MASK);
1540 | this.nmdaymask = [].concat(NMDAY366MASK);
1541 | this.wdaymask = WDAYMASK.slice(wday);
1542 | this.mrange = [].concat(M366RANGE);
1543 | }
1544 |
1545 | if (!plb(rr.options.byweekno)) {
1546 | this.wnomask = null;
1547 | } else {
1548 | this.wnomask = repeat(0, this.yearlen + 7);
1549 | var no1wkst, firstwkst, wyearlen;
1550 | no1wkst = firstwkst = pymod(
1551 | 7 - this.yearweekday + rr.options.wkst, 7);
1552 | if (no1wkst >= 4) {
1553 | no1wkst = 0;
1554 | // Number of days in the year, plus the days we got
1555 | // from last year.
1556 | wyearlen = this.yearlen + pymod(
1557 | this.yearweekday - rr.options.wkst, 7);
1558 | } else {
1559 | // Number of days in the year, minus the days we
1560 | // left in last year.
1561 | wyearlen = this.yearlen - no1wkst;
1562 | }
1563 | var div = Math.floor(wyearlen / 7);
1564 | var mod = pymod(wyearlen, 7);
1565 | var numweeks = Math.floor(div + (mod / 4));
1566 | for (var n, i, j = 0; j < rr.options.byweekno.length; j++) {
1567 | n = rr.options.byweekno[j];
1568 | if (n < 0) {
1569 | n += numweeks + 1;
1570 | } if (!(0 < n && n <= numweeks)) {
1571 | continue;
1572 | } if (n > 1) {
1573 | i = no1wkst + (n - 1) * 7;
1574 | if (no1wkst != firstwkst) {
1575 | i -= 7-firstwkst;
1576 | }
1577 | } else {
1578 | i = no1wkst;
1579 | }
1580 | for (var k = 0; k < 7; k++) {
1581 | this.wnomask[i] = 1;
1582 | i++;
1583 | if (this.wdaymask[i] == rr.options.wkst) {
1584 | break;
1585 | }
1586 | }
1587 | }
1588 |
1589 | if (contains(rr.options.byweekno, 1)) {
1590 | // Check week number 1 of next year as well
1591 | // orig-TODO : Check -numweeks for next year.
1592 | var i = no1wkst + numweeks * 7;
1593 | if (no1wkst != firstwkst) {
1594 | i -= 7 - firstwkst;
1595 | }
1596 | if (i < this.yearlen) {
1597 | // If week starts in next year, we
1598 | // don't care about it.
1599 | for (var j = 0; j < 7; j++) {
1600 | this.wnomask[i] = 1;
1601 | i += 1;
1602 | if (this.wdaymask[i] == rr.options.wkst) {
1603 | break;
1604 | }
1605 | }
1606 | }
1607 | }
1608 |
1609 | if (no1wkst) {
1610 | // Check last week number of last year as
1611 | // well. If no1wkst is 0, either the year
1612 | // started on week start, or week number 1
1613 | // got days from last year, so there are no
1614 | // days from last year's last week number in
1615 | // this year.
1616 | var lnumweeks;
1617 | if (!contains(rr.options.byweekno, -1)) {
1618 | var lyearweekday = dateutil.getWeekday(
1619 | new Date(year - 1, 0, 1));
1620 | var lno1wkst = pymod(
1621 | 7 - lyearweekday + rr.options.wkst, 7);
1622 | var lyearlen = dateutil.isLeapYear(year - 1) ? 366 : 365;
1623 | if (lno1wkst >= 4) {
1624 | lno1wkst = 0;
1625 | lnumweeks = Math.floor(
1626 | 52
1627 | + pymod(
1628 | lyearlen + pymod(
1629 | lyearweekday - rr.options.wkst, 7), 7)
1630 | / 4);
1631 | } else {
1632 | lnumweeks = Math.floor(
1633 | 52 + pymod(this.yearlen - no1wkst, 7) / 4);
1634 | }
1635 | } else {
1636 | lnumweeks = -1;
1637 | }
1638 | if (contains(rr.options.byweekno, lnumweeks)) {
1639 | for (var i = 0; i < no1wkst; i++) {
1640 | this.wnomask[i] = 1;
1641 | }
1642 | }
1643 | }
1644 | }
1645 | }
1646 |
1647 | if (plb(rr.options.bynweekday)
1648 | && (month != this.lastmonth || year != this.lastyear)) {
1649 | var ranges = [];
1650 | if (rr.options.freq == RRule.YEARLY) {
1651 | if (plb(rr.options.bymonth)) {
1652 | for (j = 0; j < rr.options.bymonth.length; j++) {
1653 | month = rr.options.bymonth[j];
1654 | ranges.push(this.mrange.slice(month - 1, month + 1));
1655 | }
1656 | } else {
1657 | ranges = [[0, this.yearlen]];
1658 | }
1659 | } else if (rr.options.freq == RRule.MONTHLY) {
1660 | ranges = [this.mrange.slice(month - 1, month + 1)];
1661 | }
1662 | if (plb(ranges)) {
1663 | // Weekly frequency won't get here, so we may not
1664 | // care about cross-year weekly periods.
1665 | this.nwdaymask = repeat(0, this.yearlen);
1666 |
1667 | for (var j = 0; j < ranges.length; j++) {
1668 | var rang = ranges[j];
1669 | var first = rang[0], last = rang[1];
1670 | last -= 1;
1671 | for (var k = 0; k < rr.options.bynweekday.length; k++) {
1672 | var wday = rr.options.bynweekday[k][0],
1673 | n = rr.options.bynweekday[k][1];
1674 | if (n < 0) {
1675 | i = last + (n + 1) * 7;
1676 | i -= pymod(this.wdaymask[i] - wday, 7);
1677 | } else {
1678 | i = first + (n - 1) * 7;
1679 | i += pymod(7 - this.wdaymask[i] + wday, 7);
1680 | }
1681 | if (first <= i && i <= last) {
1682 | this.nwdaymask[i] = 1;
1683 | }
1684 | }
1685 | }
1686 |
1687 | }
1688 |
1689 | this.lastyear = year;
1690 | this.lastmonth = month;
1691 | }
1692 |
1693 | if (rr.options.byeaster !== null) {
1694 | this.eastermask = this.easter(year, rr.options.byeaster);
1695 | }
1696 | };
1697 |
1698 | Iterinfo.prototype.ydayset = function(year, month, day) {
1699 | return [range(this.yearlen), 0, this.yearlen];
1700 | };
1701 |
1702 | Iterinfo.prototype.mdayset = function(year, month, day) {
1703 | var set = repeat(null, this.yearlen);
1704 | var start = this.mrange[month-1];
1705 | var end = this.mrange[month];
1706 | for (var i = start; i < end; i++) {
1707 | set[i] = i;
1708 | }
1709 | return [set, start, end];
1710 | };
1711 |
1712 | Iterinfo.prototype.wdayset = function(year, month, day) {
1713 |
1714 | // We need to handle cross-year weeks here.
1715 | var set = repeat(null, this.yearlen + 7);
1716 | var i = dateutil.toOrdinal(
1717 | new Date(year, month - 1, day)) - this.yearordinal;
1718 | var start = i;
1719 | for (var j = 0; j < 7; j++) {
1720 | set[i] = i;
1721 | ++i;
1722 | if (this.wdaymask[i] == this.rrule.options.wkst) {
1723 | break;
1724 | }
1725 | }
1726 | return [set, start, i];
1727 | };
1728 |
1729 | Iterinfo.prototype.ddayset = function(year, month, day) {
1730 | var set = repeat(null, this.yearlen);
1731 | var i = dateutil.toOrdinal(
1732 | new Date(year, month - 1, day)) - this.yearordinal;
1733 | set[i] = i;
1734 | return [set, i, i + 1];
1735 | };
1736 |
1737 | Iterinfo.prototype.htimeset = function(hour, minute, second) {
1738 | var set = [], rr = this.rrule;
1739 | for (var i = 0; i < rr.options.byminute.length; i++) {
1740 | minute = rr.options.byminute[i];
1741 | for (var j = 0; j < rr.options.bysecond.length; j++) {
1742 | second = rr.options.bysecond[j];
1743 | set.push(new dateutil.Time(hour, minute, second));
1744 | }
1745 | }
1746 | dateutil.sort(set);
1747 | return set;
1748 | };
1749 |
1750 | Iterinfo.prototype.mtimeset = function(hour, minute, second) {
1751 | var set = [], rr = this.rrule;
1752 | for (var j = 0; j < rr.options.bysecond.length; j++) {
1753 | second = rr.options.bysecond[j];
1754 | set.push(new dateutil.Time(hour, minute, second));
1755 | }
1756 | dateutil.sort(set);
1757 | return set;
1758 | };
1759 |
1760 | Iterinfo.prototype.stimeset = function(hour, minute, second) {
1761 | return [new dateutil.Time(hour, minute, second)];
1762 | };
1763 |
1764 |
1765 | //=============================================================================
1766 | // Results
1767 | //=============================================================================
1768 |
1769 | /**
1770 | * This class helps us to emulate python's generators, sorta.
1771 | */
1772 | var IterResult = function(method, args) {
1773 | this.init(method, args)
1774 | };
1775 |
1776 | IterResult.prototype = {
1777 |
1778 | init: function(method, args) {
1779 | this.method = method;
1780 | this.args = args;
1781 |
1782 | this._result = [];
1783 |
1784 | this.minDate = null;
1785 | this.maxDate = null;
1786 |
1787 | if (method == 'between') {
1788 | this.maxDate = args.inc
1789 | ? args.before
1790 | : new Date(args.before.getTime() - 1);
1791 | this.minDate = args.inc
1792 | ? args.after
1793 | : new Date(args.after.getTime() + 1);
1794 | } else if (method == 'before') {
1795 | this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1);
1796 | } else if (method == 'after') {
1797 | this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1);
1798 | }
1799 | },
1800 |
1801 | /**
1802 | * Possibly adds a date into the result.
1803 | *
1804 | * @param {Date} date - the date isn't necessarly added to the result
1805 | * list (if it is too late/too early)
1806 | * @return {Boolean} true if it makes sense to continue the iteration;
1807 | * false if we're done.
1808 | */
1809 | accept: function(date) {
1810 | var tooEarly = this.minDate && date < this.minDate,
1811 | tooLate = this.maxDate && date > this.maxDate;
1812 |
1813 | if (this.method == 'between') {
1814 | if (tooEarly)
1815 | return true;
1816 | if (tooLate)
1817 | return false;
1818 | } else if (this.method == 'before') {
1819 | if (tooLate)
1820 | return false;
1821 | } else if (this.method == 'after') {
1822 | if (tooEarly)
1823 | return true;
1824 | this.add(date);
1825 | return false;
1826 | }
1827 |
1828 | return this.add(date);
1829 |
1830 | },
1831 |
1832 | /**
1833 | *
1834 | * @param {Date} date that is part of the result.
1835 | * @return {Boolean} whether we are interested in more values.
1836 | */
1837 | add: function(date) {
1838 | this._result.push(date);
1839 | return true;
1840 | },
1841 |
1842 | /**
1843 | * 'before' and 'after' return only one date, whereas 'all'
1844 | * and 'between' an array.
1845 | * @return {Date,Array?}
1846 | */
1847 | getValue: function() {
1848 | switch (this.method) {
1849 | case 'all':
1850 | case 'between':
1851 | return this._result;
1852 | case 'before':
1853 | case 'after':
1854 | return this._result.length
1855 | ? this._result[this._result.length - 1]
1856 | : null;
1857 | }
1858 | }
1859 |
1860 | };
1861 |
1862 |
1863 | /**
1864 | * IterResult subclass that calls a callback function on each add,
1865 | * and stops iterating when the callback returns false.
1866 | */
1867 | var CallbackIterResult = function(method, args, iterator) {
1868 | var allowedMethods = ['all', 'between'];
1869 | if (!contains(allowedMethods, method)) {
1870 | throw new Error('Invalid method "' + method
1871 | + '". Only all and between works with iterator.');
1872 | }
1873 | this.add = function(date) {
1874 | if (iterator(date, this._result.length)) {
1875 | this._result.push(date);
1876 | return true;
1877 | }
1878 | return false;
1879 |
1880 | };
1881 |
1882 | this.init(method, args);
1883 |
1884 | };
1885 | CallbackIterResult.prototype = IterResult.prototype;
1886 |
1887 |
1888 | //=============================================================================
1889 | // Export
1890 | //=============================================================================
1891 |
1892 | if (serverSide) {
1893 | module.exports = {
1894 | RRule: RRule
1895 | // rruleset: rruleset
1896 | }
1897 | }
1898 | if (typeof ender === 'undefined') {
1899 | root['RRule'] = RRule;
1900 | // root['rruleset'] = rruleset;
1901 | }
1902 |
1903 | if (typeof define === "function" && define.amd) {
1904 | /*global define:false */
1905 | define("rrule", [], function () {
1906 | return RRule;
1907 | });
1908 | }
1909 |
1910 | }(this));
1911 |
--------------------------------------------------------------------------------
/js/skycons.js:
--------------------------------------------------------------------------------
1 | (function(global) {
2 | "use strict";
3 |
4 | /* Set up a RequestAnimationFrame shim so we can animate efficiently FOR
5 | * GREAT JUSTICE. */
6 | var requestInterval, cancelInterval;
7 |
8 | (function() {
9 | var raf = global.requestAnimationFrame ||
10 | global.webkitRequestAnimationFrame ||
11 | global.mozRequestAnimationFrame ||
12 | global.oRequestAnimationFrame ||
13 | global.msRequestAnimationFrame ,
14 | caf = global.cancelAnimationFrame ||
15 | global.webkitCancelAnimationFrame ||
16 | global.mozCancelAnimationFrame ||
17 | global.oCancelAnimationFrame ||
18 | global.msCancelAnimationFrame ;
19 |
20 | if(raf && caf) {
21 | requestInterval = function(fn, delay) {
22 | var handle = {value: null};
23 |
24 | function loop() {
25 | handle.value = raf(loop);
26 | fn();
27 | }
28 |
29 | loop();
30 | return handle;
31 | };
32 |
33 | cancelInterval = function(handle) {
34 | caf(handle.value);
35 | };
36 | }
37 |
38 | else {
39 | requestInterval = setInterval;
40 | cancelInterval = clearInterval;
41 | }
42 | }());
43 |
44 | /* Catmull-rom spline stuffs. */
45 | /*
46 | function upsample(n, spline) {
47 | var polyline = [],
48 | len = spline.length,
49 | bx = spline[0],
50 | by = spline[1],
51 | cx = spline[2],
52 | cy = spline[3],
53 | dx = spline[4],
54 | dy = spline[5],
55 | i, j, ax, ay, px, qx, rx, sx, py, qy, ry, sy, t;
56 | for(i = 6; i !== spline.length; i += 2) {
57 | ax = bx;
58 | bx = cx;
59 | cx = dx;
60 | dx = spline[i];
61 | px = -0.5 * ax + 1.5 * bx - 1.5 * cx + 0.5 * dx;
62 | qx = ax - 2.5 * bx + 2.0 * cx - 0.5 * dx;
63 | rx = -0.5 * ax + 0.5 * cx ;
64 | sx = bx ;
65 | ay = by;
66 | by = cy;
67 | cy = dy;
68 | dy = spline[i + 1];
69 | py = -0.5 * ay + 1.5 * by - 1.5 * cy + 0.5 * dy;
70 | qy = ay - 2.5 * by + 2.0 * cy - 0.5 * dy;
71 | ry = -0.5 * ay + 0.5 * cy ;
72 | sy = by ;
73 | for(j = 0; j !== n; ++j) {
74 | t = j / n;
75 | polyline.push(
76 | ((px * t + qx) * t + rx) * t + sx,
77 | ((py * t + qy) * t + ry) * t + sy
78 | );
79 | }
80 | }
81 | polyline.push(
82 | px + qx + rx + sx,
83 | py + qy + ry + sy
84 | );
85 | return polyline;
86 | }
87 | function downsample(n, polyline) {
88 | var len = 0,
89 | i, dx, dy;
90 | for(i = 2; i !== polyline.length; i += 2) {
91 | dx = polyline[i] - polyline[i - 2];
92 | dy = polyline[i + 1] - polyline[i - 1];
93 | len += Math.sqrt(dx * dx + dy * dy);
94 | }
95 | len /= n;
96 | var small = [],
97 | target = len,
98 | min = 0,
99 | max, t;
100 | small.push(polyline[0], polyline[1]);
101 | for(i = 2; i !== polyline.length; i += 2) {
102 | dx = polyline[i] - polyline[i - 2];
103 | dy = polyline[i + 1] - polyline[i - 1];
104 | max = min + Math.sqrt(dx * dx + dy * dy);
105 | if(max> target) {
106 | t = (target - min) / (max - min);
107 | small.push(
108 | polyline[i - 2] + dx * t,
109 | polyline[i - 1] + dy * t
110 | );
111 | target += len;
112 | }
113 | min = max;
114 | }
115 | small.push(polyline[polyline.length - 2], polyline[polyline.length - 1]);
116 | return small;
117 | }
118 | */
119 |
120 | /* Define skycon things. */
121 | /* FIXME: I'm *really really* sorry that this code is so gross. Really, I am.
122 | * I'll try to clean it up eventually! Promise! */
123 | var KEYFRAME = 500,
124 | STROKE = 0.08,
125 | TAU = 2.0 * Math.PI,
126 | TWO_OVER_SQRT_2 = 2.0 / Math.sqrt(2);
127 |
128 | function circle(ctx, x, y, r) {
129 | ctx.beginPath();
130 | ctx.arc(x, y, r, 0, TAU, false);
131 | ctx.fill();
132 | }
133 |
134 | function line(ctx, ax, ay, bx, by) {
135 | ctx.beginPath();
136 | ctx.moveTo(ax, ay);
137 | ctx.lineTo(bx, by);
138 | ctx.stroke();
139 | }
140 |
141 | function puff(ctx, t, cx, cy, rx, ry, rmin, rmax) {
142 | var c = Math.cos(t * TAU),
143 | s = Math.sin(t * TAU);
144 |
145 | rmax -= rmin;
146 |
147 | circle(
148 | ctx,
149 | cx - s * rx,
150 | cy + c * ry + rmax * 0.5,
151 | rmin + (1 - c * 0.5) * rmax
152 | );
153 | }
154 |
155 | function puffs(ctx, t, cx, cy, rx, ry, rmin, rmax) {
156 | var i;
157 |
158 | for(i = 5; i--; )
159 | puff(ctx, t + i / 5, cx, cy, rx, ry, rmin, rmax);
160 | }
161 |
162 | function cloud(ctx, t, cx, cy, cw, s, color) {
163 | t /= 30000;
164 |
165 | var a = cw * 0.21,
166 | b = cw * 0.12,
167 | c = cw * 0.24,
168 | d = cw * 0.28;
169 |
170 | ctx.fillStyle = color;
171 | puffs(ctx, t, cx, cy, a, b, c, d);
172 |
173 | ctx.globalCompositeOperation = 'destination-out';
174 | puffs(ctx, t, cx, cy, a, b, c - s, d - s);
175 | ctx.globalCompositeOperation = 'source-over';
176 | }
177 |
178 | function sun(ctx, t, cx, cy, cw, s, color) {
179 | t /= 120000;
180 |
181 | var a = cw * 0.25 - s * 0.5,
182 | b = cw * 0.32 + s * 0.5,
183 | c = cw * 0.50 - s * 0.5,
184 | i, p, cos, sin;
185 |
186 | ctx.strokeStyle = color;
187 | ctx.lineWidth = s;
188 | ctx.lineCap = "round";
189 | ctx.lineJoin = "round";
190 |
191 | ctx.beginPath();
192 | ctx.arc(cx, cy, a, 0, TAU, false);
193 | ctx.stroke();
194 |
195 | for(i = 8; i--; ) {
196 | p = (t + i / 8) * TAU;
197 | cos = Math.cos(p);
198 | sin = Math.sin(p);
199 | line(ctx, cx + cos * b, cy + sin * b, cx + cos * c, cy + sin * c);
200 | }
201 | }
202 |
203 | function moon(ctx, t, cx, cy, cw, s, color) {
204 | t /= 15000;
205 |
206 | var a = cw * 0.29 - s * 0.5,
207 | b = cw * 0.05,
208 | c = Math.cos(t * TAU),
209 | p = c * TAU / -16;
210 |
211 | ctx.strokeStyle = color;
212 | ctx.lineWidth = s;
213 | ctx.lineCap = "round";
214 | ctx.lineJoin = "round";
215 |
216 | cx += c * b;
217 |
218 | ctx.beginPath();
219 | ctx.arc(cx, cy, a, p + TAU / 8, p + TAU * 7 / 8, false);
220 | ctx.arc(cx + Math.cos(p) * a * TWO_OVER_SQRT_2, cy + Math.sin(p) * a * TWO_OVER_SQRT_2, a, p + TAU * 5 / 8, p + TAU * 3 / 8, true);
221 | ctx.closePath();
222 | ctx.stroke();
223 | }
224 |
225 | function rain(ctx, t, cx, cy, cw, s, color) {
226 | t /= 1350;
227 |
228 | var a = cw * 0.16,
229 | b = TAU * 11 / 12,
230 | c = TAU * 7 / 12,
231 | i, p, x, y;
232 |
233 | ctx.fillStyle = color;
234 |
235 | for(i = 4; i--; ) {
236 | p = (t + i / 4) % 1;
237 | x = cx + ((i - 1.5) / 1.5) * (i === 1 || i === 2 ? -1 : 1) * a;
238 | y = cy + p * p * cw;
239 | ctx.beginPath();
240 | ctx.moveTo(x, y - s * 1.5);
241 | ctx.arc(x, y, s * 0.75, b, c, false);
242 | ctx.fill();
243 | }
244 | }
245 |
246 | function sleet(ctx, t, cx, cy, cw, s, color) {
247 | t /= 750;
248 |
249 | var a = cw * 0.1875,
250 | b = TAU * 11 / 12,
251 | c = TAU * 7 / 12,
252 | i, p, x, y;
253 |
254 | ctx.strokeStyle = color;
255 | ctx.lineWidth = s * 0.5;
256 | ctx.lineCap = "round";
257 | ctx.lineJoin = "round";
258 |
259 | for(i = 4; i--; ) {
260 | p = (t + i / 4) % 1;
261 | x = Math.floor(cx + ((i - 1.5) / 1.5) * (i === 1 || i === 2 ? -1 : 1) * a) + 0.5;
262 | y = cy + p * cw;
263 | line(ctx, x, y - s * 1.5, x, y + s * 1.5);
264 | }
265 | }
266 |
267 | function snow(ctx, t, cx, cy, cw, s, color) {
268 | t /= 3000;
269 |
270 | var a = cw * 0.16,
271 | b = s * 0.75,
272 | u = t * TAU * 0.7,
273 | ux = Math.cos(u) * b,
274 | uy = Math.sin(u) * b,
275 | v = u + TAU / 3,
276 | vx = Math.cos(v) * b,
277 | vy = Math.sin(v) * b,
278 | w = u + TAU * 2 / 3,
279 | wx = Math.cos(w) * b,
280 | wy = Math.sin(w) * b,
281 | i, p, x, y;
282 |
283 | ctx.strokeStyle = color;
284 | ctx.lineWidth = s * 0.5;
285 | ctx.lineCap = "round";
286 | ctx.lineJoin = "round";
287 |
288 | for(i = 4; i--; ) {
289 | p = (t + i / 4) % 1;
290 | x = cx + Math.sin((p + i / 4) * TAU) * a;
291 | y = cy + p * cw;
292 |
293 | line(ctx, x - ux, y - uy, x + ux, y + uy);
294 | line(ctx, x - vx, y - vy, x + vx, y + vy);
295 | line(ctx, x - wx, y - wy, x + wx, y + wy);
296 | }
297 | }
298 |
299 | function fogbank(ctx, t, cx, cy, cw, s, color) {
300 | t /= 30000;
301 |
302 | var a = cw * 0.21,
303 | b = cw * 0.06,
304 | c = cw * 0.21,
305 | d = cw * 0.28;
306 |
307 | ctx.fillStyle = color;
308 | puffs(ctx, t, cx, cy, a, b, c, d);
309 |
310 | ctx.globalCompositeOperation = 'destination-out';
311 | puffs(ctx, t, cx, cy, a, b, c - s, d - s);
312 | ctx.globalCompositeOperation = 'source-over';
313 | }
314 |
315 | /*
316 | var WIND_PATHS = [
317 | downsample(63, upsample(8, [
318 | -1.00, -0.28,
319 | -0.75, -0.18,
320 | -0.50, 0.12,
321 | -0.20, 0.12,
322 | -0.04, -0.04,
323 | -0.07, -0.18,
324 | -0.19, -0.18,
325 | -0.23, -0.05,
326 | -0.12, 0.11,
327 | 0.02, 0.16,
328 | 0.20, 0.15,
329 | 0.50, 0.07,
330 | 0.75, 0.18,
331 | 1.00, 0.28
332 | ])),
333 | downsample(31, upsample(16, [
334 | -1.00, -0.10,
335 | -0.75, 0.00,
336 | -0.50, 0.10,
337 | -0.25, 0.14,
338 | 0.00, 0.10,
339 | 0.25, 0.00,
340 | 0.50, -0.10,
341 | 0.75, -0.14,
342 | 1.00, -0.10
343 | ]))
344 | ];
345 | */
346 |
347 | var WIND_PATHS = [
348 | [
349 | -0.7500, -0.1800, -0.7219, -0.1527, -0.6971, -0.1225,
350 | -0.6739, -0.0910, -0.6516, -0.0588, -0.6298, -0.0262,
351 | -0.6083, 0.0065, -0.5868, 0.0396, -0.5643, 0.0731,
352 | -0.5372, 0.1041, -0.5033, 0.1259, -0.4662, 0.1406,
353 | -0.4275, 0.1493, -0.3881, 0.1530, -0.3487, 0.1526,
354 | -0.3095, 0.1488, -0.2708, 0.1421, -0.2319, 0.1342,
355 | -0.1943, 0.1217, -0.1600, 0.1025, -0.1290, 0.0785,
356 | -0.1012, 0.0509, -0.0764, 0.0206, -0.0547, -0.0120,
357 | -0.0378, -0.0472, -0.0324, -0.0857, -0.0389, -0.1241,
358 | -0.0546, -0.1599, -0.0814, -0.1876, -0.1193, -0.1964,
359 | -0.1582, -0.1935, -0.1931, -0.1769, -0.2157, -0.1453,
360 | -0.2290, -0.1085, -0.2327, -0.0697, -0.2240, -0.0317,
361 | -0.2064, 0.0033, -0.1853, 0.0362, -0.1613, 0.0672,
362 | -0.1350, 0.0961, -0.1051, 0.1213, -0.0706, 0.1397,
363 | -0.0332, 0.1512, 0.0053, 0.1580, 0.0442, 0.1624,
364 | 0.0833, 0.1636, 0.1224, 0.1615, 0.1613, 0.1565,
365 | 0.1999, 0.1500, 0.2378, 0.1402, 0.2749, 0.1279,
366 | 0.3118, 0.1147, 0.3487, 0.1015, 0.3858, 0.0892,
367 | 0.4236, 0.0787, 0.4621, 0.0715, 0.5012, 0.0702,
368 | 0.5398, 0.0766, 0.5768, 0.0890, 0.6123, 0.1055,
369 | 0.6466, 0.1244, 0.6805, 0.1440, 0.7147, 0.1630,
370 | 0.7500, 0.1800
371 | ],
372 | [
373 | -0.7500, 0.0000, -0.7033, 0.0195, -0.6569, 0.0399,
374 | -0.6104, 0.0600, -0.5634, 0.0789, -0.5155, 0.0954,
375 | -0.4667, 0.1089, -0.4174, 0.1206, -0.3676, 0.1299,
376 | -0.3174, 0.1365, -0.2669, 0.1398, -0.2162, 0.1391,
377 | -0.1658, 0.1347, -0.1157, 0.1271, -0.0661, 0.1169,
378 | -0.0170, 0.1046, 0.0316, 0.0903, 0.0791, 0.0728,
379 | 0.1259, 0.0534, 0.1723, 0.0331, 0.2188, 0.0129,
380 | 0.2656, -0.0064, 0.3122, -0.0263, 0.3586, -0.0466,
381 | 0.4052, -0.0665, 0.4525, -0.0847, 0.5007, -0.1002,
382 | 0.5497, -0.1130, 0.5991, -0.1240, 0.6491, -0.1325,
383 | 0.6994, -0.1380, 0.7500, -0.1400
384 | ]
385 | ],
386 | WIND_OFFSETS = [
387 | {start: 0.36, end: 0.11},
388 | {start: 0.56, end: 0.16}
389 | ];
390 |
391 | function leaf(ctx, t, x, y, cw, s, color) {
392 | var a = cw / 8,
393 | b = a / 3,
394 | c = 2 * b,
395 | d = (t % 1) * TAU,
396 | e = Math.cos(d),
397 | f = Math.sin(d);
398 |
399 | ctx.fillStyle = color;
400 | ctx.strokeStyle = color;
401 | ctx.lineWidth = s;
402 | ctx.lineCap = "round";
403 | ctx.lineJoin = "round";
404 |
405 | ctx.beginPath();
406 | ctx.arc(x , y , a, d , d + Math.PI, false);
407 | ctx.arc(x - b * e, y - b * f, c, d + Math.PI, d , false);
408 | ctx.arc(x + c * e, y + c * f, b, d + Math.PI, d , true );
409 | ctx.globalCompositeOperation = 'destination-out';
410 | ctx.fill();
411 | ctx.globalCompositeOperation = 'source-over';
412 | ctx.stroke();
413 | }
414 |
415 | function swoosh(ctx, t, cx, cy, cw, s, index, total, color) {
416 | t /= 2500;
417 |
418 | var path = WIND_PATHS[index],
419 | a = (t + index - WIND_OFFSETS[index].start) % total,
420 | c = (t + index - WIND_OFFSETS[index].end ) % total,
421 | e = (t + index ) % total,
422 | b, d, f, i;
423 |
424 | ctx.strokeStyle = color;
425 | ctx.lineWidth = s;
426 | ctx.lineCap = "round";
427 | ctx.lineJoin = "round";
428 |
429 | if(a < 1) {
430 | ctx.beginPath();
431 |
432 | a *= path.length / 2 - 1;
433 | b = Math.floor(a);
434 | a -= b;
435 | b *= 2;
436 | b += 2;
437 |
438 | ctx.moveTo(
439 | cx + (path[b - 2] * (1 - a) + path[b] * a) * cw,
440 | cy + (path[b - 1] * (1 - a) + path[b + 1] * a) * cw
441 | );
442 |
443 | if(c < 1) {
444 | c *= path.length / 2 - 1;
445 | d = Math.floor(c);
446 | c -= d;
447 | d *= 2;
448 | d += 2;
449 |
450 | for(i = b; i !== d; i += 2)
451 | ctx.lineTo(cx + path[i] * cw, cy + path[i + 1] * cw);
452 |
453 | ctx.lineTo(
454 | cx + (path[d - 2] * (1 - c) + path[d] * c) * cw,
455 | cy + (path[d - 1] * (1 - c) + path[d + 1] * c) * cw
456 | );
457 | }
458 |
459 | else
460 | for(i = b; i !== path.length; i += 2)
461 | ctx.lineTo(cx + path[i] * cw, cy + path[i + 1] * cw);
462 |
463 | ctx.stroke();
464 | }
465 |
466 | else if(c < 1) {
467 | ctx.beginPath();
468 |
469 | c *= path.length / 2 - 1;
470 | d = Math.floor(c);
471 | c -= d;
472 | d *= 2;
473 | d += 2;
474 |
475 | ctx.moveTo(cx + path[0] * cw, cy + path[1] * cw);
476 |
477 | for(i = 2; i !== d; i += 2)
478 | ctx.lineTo(cx + path[i] * cw, cy + path[i + 1] * cw);
479 |
480 | ctx.lineTo(
481 | cx + (path[d - 2] * (1 - c) + path[d] * c) * cw,
482 | cy + (path[d - 1] * (1 - c) + path[d + 1] * c) * cw
483 | );
484 |
485 | ctx.stroke();
486 | }
487 |
488 | if(e < 1) {
489 | e *= path.length / 2 - 1;
490 | f = Math.floor(e);
491 | e -= f;
492 | f *= 2;
493 | f += 2;
494 |
495 | leaf(
496 | ctx,
497 | t,
498 | cx + (path[f - 2] * (1 - e) + path[f] * e) * cw,
499 | cy + (path[f - 1] * (1 - e) + path[f + 1] * e) * cw,
500 | cw,
501 | s,
502 | color
503 | );
504 | }
505 | }
506 |
507 | var Skycons = function(opts) {
508 | this.list = [];
509 | this.interval = null;
510 | this.color = opts && opts.color ? opts.color : "black";
511 | this.resizeClear = !!(opts && opts.resizeClear);
512 | };
513 |
514 | Skycons.CLEAR_DAY = function(ctx, t, color) {
515 | var w = ctx.canvas.width,
516 | h = ctx.canvas.height,
517 | s = Math.min(w, h);
518 |
519 | sun(ctx, t, w * 0.5, h * 0.5, s, s * STROKE, color);
520 | };
521 |
522 | Skycons.CLEAR_NIGHT = function(ctx, t, color) {
523 | var w = ctx.canvas.width,
524 | h = ctx.canvas.height,
525 | s = Math.min(w, h);
526 |
527 | moon(ctx, t, w * 0.5, h * 0.5, s, s * STROKE, color);
528 | };
529 |
530 | Skycons.PARTLY_CLOUDY_DAY = function(ctx, t, color) {
531 | var w = ctx.canvas.width,
532 | h = ctx.canvas.height,
533 | s = Math.min(w, h);
534 |
535 | sun(ctx, t, w * 0.625, h * 0.375, s * 0.75, s * STROKE, color);
536 | cloud(ctx, t, w * 0.375, h * 0.625, s * 0.75, s * STROKE, color);
537 | };
538 |
539 | Skycons.PARTLY_CLOUDY_NIGHT = function(ctx, t, color) {
540 | var w = ctx.canvas.width,
541 | h = ctx.canvas.height,
542 | s = Math.min(w, h);
543 |
544 | moon(ctx, t, w * 0.667, h * 0.375, s * 0.75, s * STROKE, color);
545 | cloud(ctx, t, w * 0.375, h * 0.625, s * 0.75, s * STROKE, color);
546 | };
547 |
548 | Skycons.CLOUDY = function(ctx, t, color) {
549 | var w = ctx.canvas.width,
550 | h = ctx.canvas.height,
551 | s = Math.min(w, h);
552 |
553 | cloud(ctx, t, w * 0.5, h * 0.5, s, s * STROKE, color);
554 | };
555 |
556 | Skycons.RAIN = function(ctx, t, color) {
557 | var w = ctx.canvas.width,
558 | h = ctx.canvas.height,
559 | s = Math.min(w, h);
560 |
561 | rain(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
562 | cloud(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
563 | };
564 |
565 | Skycons.SLEET = function(ctx, t, color) {
566 | var w = ctx.canvas.width,
567 | h = ctx.canvas.height,
568 | s = Math.min(w, h);
569 |
570 | sleet(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
571 | cloud(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
572 | };
573 |
574 | Skycons.SNOW = function(ctx, t, color) {
575 | var w = ctx.canvas.width,
576 | h = ctx.canvas.height,
577 | s = Math.min(w, h);
578 |
579 | snow(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
580 | cloud(ctx, t, w * 0.5, h * 0.37, s * 0.9, s * STROKE, color);
581 | };
582 |
583 | Skycons.WIND = function(ctx, t, color) {
584 | var w = ctx.canvas.width,
585 | h = ctx.canvas.height,
586 | s = Math.min(w, h);
587 |
588 | swoosh(ctx, t, w * 0.5, h * 0.5, s, s * STROKE, 0, 2, color);
589 | swoosh(ctx, t, w * 0.5, h * 0.5, s, s * STROKE, 1, 2, color);
590 | };
591 |
592 | Skycons.FOG = function(ctx, t, color) {
593 | var w = ctx.canvas.width,
594 | h = ctx.canvas.height,
595 | s = Math.min(w, h),
596 | k = s * STROKE;
597 |
598 | fogbank(ctx, t, w * 0.5, h * 0.32, s * 0.75, k, color);
599 |
600 | t /= 5000;
601 |
602 | var a = Math.cos((t) * TAU) * s * 0.02,
603 | b = Math.cos((t + 0.25) * TAU) * s * 0.02,
604 | c = Math.cos((t + 0.50) * TAU) * s * 0.02,
605 | d = Math.cos((t + 0.75) * TAU) * s * 0.02,
606 | n = h * 0.936,
607 | e = Math.floor(n - k * 0.5) + 0.5,
608 | f = Math.floor(n - k * 2.5) + 0.5;
609 |
610 | ctx.strokeStyle = color;
611 | ctx.lineWidth = k;
612 | ctx.lineCap = "round";
613 | ctx.lineJoin = "round";
614 |
615 | line(ctx, a + w * 0.2 + k * 0.5, e, b + w * 0.8 - k * 0.5, e);
616 | line(ctx, c + w * 0.2 + k * 0.5, f, d + w * 0.8 - k * 0.5, f);
617 | };
618 |
619 | Skycons.prototype = {
620 | _determineDrawingFunction: function(draw) {
621 | if(typeof draw === "string")
622 | draw = Skycons[draw.toUpperCase().replace(/-/g, "_")] || null;
623 |
624 | return draw;
625 | },
626 | add: function(el, draw) {
627 | var obj;
628 |
629 | if(typeof el === "string")
630 | el = document.getElementById(el);
631 |
632 | // Does nothing if canvas name doesn't exists
633 | if(el === null)
634 | return;
635 |
636 | draw = this._determineDrawingFunction(draw);
637 |
638 | // Does nothing if the draw function isn't actually a function
639 | if(typeof draw !== "function")
640 | return;
641 |
642 | obj = {
643 | element: el,
644 | context: el.getContext("2d"),
645 | drawing: draw
646 | };
647 |
648 | this.list.push(obj);
649 | this.draw(obj, KEYFRAME);
650 | },
651 | set: function(el, draw) {
652 | var i;
653 |
654 | if(typeof el === "string")
655 | el = document.getElementById(el);
656 |
657 | for(i = this.list.length; i--; )
658 | if(this.list[i].element === el) {
659 | this.list[i].drawing = this._determineDrawingFunction(draw);
660 | this.draw(this.list[i], KEYFRAME);
661 | return;
662 | }
663 |
664 | this.add(el, draw);
665 | },
666 | remove: function(el) {
667 | var i;
668 |
669 | if(typeof el === "string")
670 | el = document.getElementById(el);
671 |
672 | for(i = this.list.length; i--; )
673 | if(this.list[i].element === el) {
674 | this.list.splice(i, 1);
675 | return;
676 | }
677 | },
678 | draw: function(obj, time) {
679 | var canvas = obj.context.canvas;
680 |
681 | if(this.resizeClear)
682 | canvas.width = canvas.width;
683 |
684 | else
685 | obj.context.clearRect(0, 0, canvas.width, canvas.height);
686 |
687 | obj.drawing(obj.context, time, this.color);
688 | },
689 | play: function() {
690 | var self = this;
691 |
692 | this.pause();
693 | this.interval = requestInterval(function() {
694 | var now = Date.now(),
695 | i;
696 |
697 | for(i = self.list.length; i--; )
698 | self.draw(self.list[i], now);
699 | }, 1000 / 60);
700 | },
701 | pause: function() {
702 | var i;
703 |
704 | if(this.interval) {
705 | cancelInterval(this.interval);
706 | this.interval = null;
707 | }
708 | }
709 | };
710 |
711 | global.Skycons = Skycons;
712 | }(this));
--------------------------------------------------------------------------------
/js/socket.io.min.js:
--------------------------------------------------------------------------------
1 | /*! Socket.IO.min.js build:0.9.16, production. Copyright(c) 2011 LearnBoost MIT Licensed */
2 | var io="undefined"==typeof module?{}:module.exports;(function(){(function(a,b){var c=a;c.version="0.9.16",c.protocol=1,c.transports=[],c.j=[],c.sockets={},c.connect=function(a,d){var e=c.util.parseUri(a),f,g;b&&b.location&&(e.protocol=e.protocol||b.location.protocol.slice(0,-1),e.host=e.host||(b.document?b.document.domain:b.location.hostname),e.port=e.port||b.location.port),f=c.util.uniqueUri(e);var h={host:e.host,secure:"https"==e.protocol,port:e.port||("https"==e.protocol?443:80),query:e.query||""};c.util.merge(h,d);if(h["force new connection"]||!c.sockets[f])g=new c.Socket(h);return!h["force new connection"]&&g&&(c.sockets[f]=g),g=g||c.sockets[f],g.of(e.path.length>1?e.path:"")}})("object"==typeof module?module.exports:this.io={},this),function(a,b){var c=a.util={},d=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];c.parseUri=function(a){var b=d.exec(a||""),c={},f=14;while(f--)c[e[f]]=b[f]||"";return c},c.uniqueUri=function(a){var c=a.protocol,d=a.host,e=a.port;return"document"in b?(d=d||document.domain,e=e||(c=="https"&&document.location.protocol!=="https:"?443:document.location.port)):(d=d||"localhost",!e&&c=="https"&&(e=443)),(c||"http")+"://"+d+":"+(e||80)},c.query=function(a,b){var d=c.chunkQuery(a||""),e=[];c.merge(d,c.chunkQuery(b||""));for(var f in d)d.hasOwnProperty(f)&&e.push(f+"="+d[f]);return e.length?"?"+e.join("&"):""},c.chunkQuery=function(a){var b={},c=a.split("&"),d=0,e=c.length,f;for(;db.length?a:b,f=a.length>b.length?b:a;for(var g=0,h=f.length;g0&&a.splice(0,1)[0]!=c.transport.name);a.length?h(a):c.publish("connect_failed")}}},c.options["connect timeout"]))})}c.sessionid=d,c.closeTimeout=f*1e3,c.heartbeatTimeout=e*1e3,c.transports||(c.transports=c.origTransports=g?b.util.intersect(g.split(","),c.options.transports):c.options.transports),c.setHeartbeatTimeout(),h(c.transports),c.once("connect",function(){clearTimeout(c.connectTimeoutTimer),a&&typeof a=="function"&&a()})}),this},d.prototype.setHeartbeatTimeout=function(){clearTimeout(this.heartbeatTimeoutTimer);if(this.transport&&!this.transport.heartbeats())return;var a=this;this.heartbeatTimeoutTimer=setTimeout(function(){a.transport.onClose()},this.heartbeatTimeout)},d.prototype.packet=function(a){return this.connected&&!this.doBuffer?this.transport.packet(a):this.buffer.push(a),this},d.prototype.setBuffer=function(a){this.doBuffer=a,!a&&this.connected&&this.buffer.length&&(this.options.manualFlush||this.flushBuffer())},d.prototype.flushBuffer=function(){this.transport.payload(this.buffer),this.buffer=[]},d.prototype.disconnect=function(){if(this.connected||this.connecting)this.open&&this.of("").packet({type:"disconnect"}),this.onDisconnect("booted");return this},d.prototype.disconnectSync=function(){var a=b.util.request(),c=["http"+(this.options.secure?"s":"")+":/",this.options.host+":"+this.options.port,this.options.resource,b.protocol,"",this.sessionid].join("/")+"/?disconnect=1";a.open("GET",c,!1),a.send(null),this.onDisconnect("booted")},d.prototype.isXDomain=function(){var a=c.location.port||("https:"==c.location.protocol?443:80);return this.options.host!==c.location.hostname||this.options.port!=a},d.prototype.onConnect=function(){this.connected||(this.connected=!0,this.connecting=!1,this.doBuffer||this.setBuffer(!1),this.emit("connect"))},d.prototype.onOpen=function(){this.open=!0},d.prototype.onClose=function(){this.open=!1,clearTimeout(this.heartbeatTimeoutTimer)},d.prototype.onPacket=function(a){this.of(a.endpoint).onPacket(a)},d.prototype.onError=function(a){a&&a.advice&&a.advice==="reconnect"&&(this.connected||this.connecting)&&(this.disconnect(),this.options.reconnect&&this.reconnect()),this.publish("error",a&&a.reason?a.reason:a)},d.prototype.onDisconnect=function(a){var b=this.connected,c=this.connecting;this.connected=!1,this.connecting=!1,this.open=!1;if(b||c)this.transport.close(),this.transport.clearTimeouts(),b&&(this.publish("disconnect",a),"booted"!=a&&this.options.reconnect&&!this.reconnecting&&this.reconnect())},d.prototype.reconnect=function(){function e(){if(a.connected){for(var b in a.namespaces)a.namespaces.hasOwnProperty(b)&&""!==b&&a.namespaces[b].packet({type:"connect"});a.publish("reconnect",a.transport.name,a.reconnectionAttempts)}clearTimeout(a.reconnectionTimer),a.removeListener("connect_failed",f),a.removeListener("connect",f),a.reconnecting=!1,delete a.reconnectionAttempts,delete a.reconnectionDelay,delete a.reconnectionTimer,delete a.redoTransports,a.options["try multiple transports"]=c}function f(){if(!a.reconnecting)return;if(a.connected)return e();if(a.connecting&&a.reconnecting)return a.reconnectionTimer=setTimeout(f,1e3);a.reconnectionAttempts++>=b?a.redoTransports?(a.publish("reconnect_failed"),e()):(a.on("connect_failed",f),a.options["try multiple transports"]=!0,a.transports=a.origTransports,a.transport=a.getTransport(),a.redoTransports=!0,a.connect()):(a.reconnectionDelay=10:!1},c.xdomainCheck=function(){return!0},typeof window!="undefined"&&(WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0),b.transports.push("flashsocket")}("undefined"!=typeof io?io.Transport:module.exports,"undefined"!=typeof io?io:module.parent.exports);if("undefined"!=typeof window)var swfobject=function(){function A(){if(t)return;try{var a=i.getElementsByTagName("body")[0].appendChild(Q("span"));a.parentNode.removeChild(a)}catch(b){return}t=!0;var c=l.length;for(var d=0;d0)for(var c=0;c0){var g=P(d);if(g)if(S(m[c].swfVersion)&&!(y.wk&&y.wk<312))U(d,!0),e&&(f.success=!0,f.ref=G(d),e(f));else if(m[c].expressInstall&&H()){var h={};h.data=m[c].expressInstall,h.width=g.getAttribute("width")||"0",h.height=g.getAttribute("height")||"0",g.getAttribute("class")&&(h.styleclass=g.getAttribute("class")),g.getAttribute("align")&&(h.align=g.getAttribute("align"));var i={},j=g.getElementsByTagName("param"),k=j.length;for(var l=0;l');h.outerHTML='",n[n.length]=c.id,g=P(c.id)}else{var m=Q(b);m.setAttribute("type",e);for(var o in c)c[o]!=Object.prototype[o]&&(o.toLowerCase()=="styleclass"?m.setAttribute("class",c[o]):o.toLowerCase()!="classid"&&m.setAttribute(o,c[o]));for(var p in d)d[p]!=Object.prototype[p]&&p.toLowerCase()!="movie"&&M(m,p,d[p]);h.parentNode.replaceChild(m,h),g=m}}return g}function M(a,b,c){var d=Q("param");d.setAttribute("name",b),d.setAttribute("value",c),a.appendChild(d)}function N(a){var b=P(a);b&&b.nodeName=="OBJECT"&&(y.ie&&y.win?(b.style.display="none",function(){b.readyState==4?O(a):setTimeout(arguments.callee,10)}()):b.parentNode.removeChild(b))}function O(a){var b=P(a);if(b){for(var c in b)typeof b[c]=="function"&&(b[c]=null);b.parentNode.removeChild(b)}}function P(a){var b=null;try{b=i.getElementById(a)}catch(c){}return b}function Q(a){return i.createElement(a)}function R(a,b,c){a.attachEvent(b,c),o[o.length]=[a,b,c]}function S(a){var b=y.pv,c=a.split(".");return c[0]=parseInt(c[0],10),c[1]=parseInt(c[1],10)||0,c[2]=parseInt(c[2],10)||0,b[0]>c[0]||b[0]==c[0]&&b[1]>c[1]||b[0]==c[0]&&b[1]==c[1]&&b[2]>=c[2]?!0:!1}function T(c,d,e,f){if(y.ie&&y.mac)return;var g=i.getElementsByTagName("head")[0];if(!g)return;var h=e&&typeof e=="string"?e:"screen";f&&(v=null,w=null);if(!v||w!=h){var j=Q("style");j.setAttribute("type","text/css"),j.setAttribute("media",h),v=g.appendChild(j),y.ie&&y.win&&typeof i.styleSheets!=a&&i.styleSheets.length>0&&(v=i.styleSheets[i.styleSheets.length-1]),w=h}y.ie&&y.win?v&&typeof v.addRule==b&&v.addRule(c,d):v&&typeof i.createTextNode!=a&&v.appendChild(i.createTextNode(c+" {"+d+"}"))}function U(a,b){if(!x)return;var c=b?"visible":"hidden";t&&P(a)?P(a).style.visibility=c:T("#"+a,"visibility:"+c)}function V(b){var c=/[\\\"<>\.;]/,d=c.exec(b)!=null;return d&&typeof encodeURIComponent!=a?encodeURIComponent(b):b}var a="undefined",b="object",c="Shockwave Flash",d="ShockwaveFlash.ShockwaveFlash",e="application/x-shockwave-flash",f="SWFObjectExprInst",g="onreadystatechange",h=window,i=document,j=navigator,k=!1,l=[D],m=[],n=[],o=[],p,q,r,s,t=!1,u=!1,v,w,x=!0,y=function(){var f=typeof i.getElementById!=a&&typeof i.getElementsByTagName!=a&&typeof i.createElement!=a,g=j.userAgent.toLowerCase(),l=j.platform.toLowerCase(),m=l?/win/.test(l):/win/.test(g),n=l?/mac/.test(l):/mac/.test(g),o=/webkit/.test(g)?parseFloat(g.replace(/^.*webkit\/(\d+(\.\d+)?).*$/,"$1")):!1,p=!1,q=[0,0,0],r=null;if(typeof j.plugins!=a&&typeof j.plugins[c]==b)r=j.plugins[c].description,r&&(typeof j.mimeTypes==a||!j.mimeTypes[e]||!!j.mimeTypes[e].enabledPlugin)&&(k=!0,p=!1,r=r.replace(/^.*\s+(\S+\s+\S+$)/,"$1"),q[0]=parseInt(r.replace(/^(.*)\..*$/,"$1"),10),q[1]=parseInt(r.replace(/^.*\.(.*)\s.*$/,"$1"),10),q[2]=/[a-zA-Z]/.test(r)?parseInt(r.replace(/^.*[a-zA-Z]+(.*)$/,"$1"),10):0);else if(typeof h[["Active"].concat("Object").join("X")]!=a)try{var s=new(window[["Active"].concat("Object").join("X")])(d);s&&(r=s.GetVariable("$version"),r&&(p=!0,r=r.split(" ")[1].split(","),q=[parseInt(r[0],10),parseInt(r[1],10),parseInt(r[2],10)]))}catch(t){}return{w3:f,pv:q,wk:o,ie:p,win:m,mac:n}}(),z=function(){if(!y.w3)return;(typeof i.readyState!=a&&i.readyState=="complete"||typeof i.readyState==a&&(i.getElementsByTagName("body")[0]||i.body))&&A(),t||(typeof i.addEventListener!=a&&i.addEventListener("DOMContentLoaded",A,!1),y.ie&&y.win&&(i.attachEvent(g,function(){i.readyState=="complete"&&(i.detachEvent(g,arguments.callee),A())}),h==top&&function(){if(t)return;try{i.documentElement.doScroll("left")}catch(a){setTimeout(arguments.callee,0);return}A()}()),y.wk&&function(){if(t)return;if(!/loaded|complete/.test(i.readyState)){setTimeout(arguments.callee,0);return}A()}(),C(A))}(),W=function(){y.ie&&y.win&&window.attachEvent("onunload",function(){var a=o.length;for(var b=0;b= 10.0.0 is required.");return}location.protocol=="file:"&&a.error("WARNING: web-socket-js doesn't work in file:///... URL unless you set Flash Security Settings properly. Open the page via Web server i.e. http://..."),WebSocket=function(a,b,c,d,e){var f=this;f.__id=WebSocket.__nextId++,WebSocket.__instances[f.__id]=f,f.readyState=WebSocket.CONNECTING,f.bufferedAmount=0,f.__events={},b?typeof b=="string"&&(b=[b]):b=[],setTimeout(function(){WebSocket.__addTask(function(){WebSocket.__flash.create(f.__id,a,b,c||null,d||0,e||null)})},0)},WebSocket.prototype.send=function(a){if(this.readyState==WebSocket.CONNECTING)throw"INVALID_STATE_ERR: Web Socket connection has not been established";var b=WebSocket.__flash.send(this.__id,encodeURIComponent(a));return b<0?!0:(this.bufferedAmount+=b,!1)},WebSocket.prototype.close=function(){if(this.readyState==WebSocket.CLOSED||this.readyState==WebSocket.CLOSING)return;this.readyState=WebSocket.CLOSING,WebSocket.__flash.close(this.__id)},WebSocket.prototype.addEventListener=function(a,b,c){a in this.__events||(this.__events[a]=[]),this.__events[a].push(b)},WebSocket.prototype.removeEventListener=function(a,b,c){if(!(a in this.__events))return;var d=this.__events[a];for(var e=d.length-1;e>=0;--e)if(d[e]===b){d.splice(e,1);break}},WebSocket.prototype.dispatchEvent=function(a){var b=this.__events[a.type]||[];for(var c=0;c