Copied starter Meteor App files.
Cut and paste of the BasicMeteorApp.
This commit is contained in:
108
imports/util/polyfills/array.js
Normal file
108
imports/util/polyfills/array.js
Normal file
@@ -0,0 +1,108 @@
|
||||
// https://tc39.github.io/ecma262/#sec-array.prototype.includes
|
||||
if(!Array.prototype.includes) {
|
||||
Object.defineProperty(Array.prototype, 'includes', {
|
||||
value: function(searchElement, fromIndex) {
|
||||
|
||||
// 1. Let O be ? ToObject(this value).
|
||||
if (this == null) {
|
||||
throw new TypeError('"this" is null or not defined');
|
||||
}
|
||||
|
||||
let o = Object(this);
|
||||
|
||||
// 2. Let len be ? ToLength(? Get(O, "length")).
|
||||
let len = o.length >>> 0;
|
||||
|
||||
// 3. If len is 0, return false.
|
||||
if (len === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. Let n be ? ToInteger(fromIndex).
|
||||
// (If fromIndex is undefined, this step produces the value 0.)
|
||||
let n = fromIndex | 0;
|
||||
|
||||
// 5. If n ≥ 0, then
|
||||
// a. Let k be n.
|
||||
// 6. Else n < 0,
|
||||
// a. Let k be len + n.
|
||||
// b. If k < 0, let k be 0.
|
||||
let k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
|
||||
|
||||
// 7. Repeat, while k < len
|
||||
while (k < len) {
|
||||
// a. Let elementK be the result of ? Get(O, ! ToString(k)).
|
||||
// b. If SameValueZero(searchElement, elementK) is true, return true.
|
||||
// c. Increase k by 1.
|
||||
// NOTE: === provides the correct "SameValueZero" comparison needed here.
|
||||
if (o[k] === searchElement) {
|
||||
return true;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
|
||||
// 8. Return false
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//http://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another
|
||||
if(!Array.prototype.move) {
|
||||
Array.prototype.move = function (old_index, new_index) {
|
||||
if (new_index >= this.length) {
|
||||
let k = new_index - this.length;
|
||||
while ((k--) + 1) {
|
||||
this.push(undefined);
|
||||
}
|
||||
}
|
||||
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
|
||||
return this; // for testing purposes
|
||||
};
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
if(!Array.prototype.remove) {
|
||||
Array.prototype.remove = function(item) {
|
||||
let index = this.indexOf(item);
|
||||
|
||||
if(index != -1) {
|
||||
this.splice(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
// index is optional
|
||||
if(!Array.prototype.add) {
|
||||
Array.prototype.add = function(item, index) {
|
||||
if(index == undefined || isNaN(index) || index >= this.length) return this.push(item);
|
||||
else return this.splice(index, 0, item);
|
||||
}
|
||||
}
|
||||
|
||||
//My own implementation to work around Javascript's shitty naming and support for collection operations.
|
||||
// Sorts a contiguous section of the array.
|
||||
// Index is the index of the first element to be sorted (inclusive).
|
||||
// Length is the number of elements of the array to be sorted (must be >= 2). If the length + index is greater than the array length then it will be adjusted to the end of the array.
|
||||
// All other invalid inputs will result in no sorting action taken and no error.
|
||||
if(!Array.prototype.partialSort) {
|
||||
Array.prototype.partialSort = function(index, length, compareFunction) {
|
||||
if(index >= 0 && length >= 2 && index <= (this.length - 2)) {
|
||||
//Adjust the length so it doesn't over-run the array. This is the only error correction we will perform.
|
||||
if(index + length > this.length) length = this.length - index;
|
||||
|
||||
//Shallow copy of the data in the segment to be sorted.
|
||||
let sorted = this.slice(index, length + index);
|
||||
|
||||
sorted.sort(compareFunction);
|
||||
|
||||
//Put the sorted array elements back into the array.
|
||||
for(let i = index, j = 0; j < length; i++, j++) {
|
||||
this[i] = sorted[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
19
imports/util/polyfills/blaze.js
Normal file
19
imports/util/polyfills/blaze.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Get the parent template instance.
|
||||
* @param {Number} [levels] How many levels to go up. Default is 1
|
||||
* @returns {Blaze.TemplateInstance}
|
||||
*/
|
||||
Blaze.TemplateInstance.prototype.parentTemplate = Blaze.TemplateInstance.prototype.parentInstance = function(levels) {
|
||||
let view = this.view;
|
||||
|
||||
levels = (typeof levels === "undefined") ? 1 : levels;
|
||||
|
||||
while(view) {
|
||||
//if(view.name.substring(0, 9) === "Template." && !(levels--)) {
|
||||
if(view.template && !(levels--)) {
|
||||
//return view.templateInstance();
|
||||
return view.templateInstance();
|
||||
}
|
||||
view = view.parentView;
|
||||
}
|
||||
};
|
||||
71
imports/util/polyfills/date.js
Normal file
71
imports/util/polyfills/date.js
Normal file
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Add a method to get a timezone adjusted date for an input field that is a date picker.
|
||||
// Use $('input[name="date"]').val(new Date().toDateInputValue()) to set the date of the input field.
|
||||
//
|
||||
Date.prototype.toDateInputValue = (function() {
|
||||
let local = new Date(this);
|
||||
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
|
||||
return local.toJSON().slice(0,10);
|
||||
});
|
||||
|
||||
Date.prototype.getWeek = function() {
|
||||
let dowOffset = 1; // I am fixing this to indicate that the first day of the week is always Monday (weeks end on Sunday), for this application. This was a parameter in the original code.
|
||||
|
||||
//dowOffset = typeof(dowOffset) == 'number' ? dowOffset : 0; //default dowOffset to zero - This should check to ensure that dowOffset is between 0..6
|
||||
let newYear = new Date(this.getFullYear(),0,1);
|
||||
let day = newYear.getDay() - dowOffset; //the day of week the year begins on
|
||||
day = (day >= 0 ? day : day + 7);
|
||||
// The number of days from the beginning of the year to this.day
|
||||
let daynum = Math.floor((this.getTime() - newYear.getTime() - (this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
|
||||
let weeknum;
|
||||
|
||||
// I have removed the mid-week starting cutoff detection because in this app we always want to start with week #1 (never have a week zero).
|
||||
//if(day < 4) { //if the year starts before the middle of a week
|
||||
weeknum = Math.floor((daynum + day - 1) / 7) + 1;
|
||||
|
||||
// I have turned off the detection of whether the last days of the year belong to this year's last week or next year's first week. This gets too confusing and does not result in any additional usefulness.
|
||||
//if(weeknum > 52) {
|
||||
// nYear = new Date(this.getFullYear() + 1, 0, 1);
|
||||
// nday = nYear.getDay() - dowOffset;
|
||||
// nday = nday >= 0 ? nday : nday + 7;
|
||||
// // if the next year starts before the middle of the week, it is week #1 of that year
|
||||
// weeknum = nday < 4 ? 1 : 53;
|
||||
//}
|
||||
//}
|
||||
//else {
|
||||
// weeknum = Math.floor((daynum+day-1)/7);
|
||||
//}
|
||||
|
||||
return weeknum;
|
||||
};
|
||||
|
||||
Date.prototype.getUTCWeek = function() {
|
||||
let dowOffset = 1; // I am fixing this to indicate that the first day of the week is always Monday (weeks end on Sunday), for this application. This was a parameter in the original code.
|
||||
|
||||
//dowOffset = typeof(dowOffset) == 'number' ? dowOffset : 0; //default dowOffset to zero - This should check to ensure that dowOffset is between 0..6
|
||||
let newYear = new Date(this.getUTCFullYear(),0,1);
|
||||
let day = newYear.getDay() - dowOffset; //the day of week the year begins on
|
||||
day = (day >= 0 ? day : day + 7);
|
||||
// The number of days from the beginning of the year to this.day
|
||||
let daynum = Math.floor((this.getTime() - newYear.getTime() - (this.getTimezoneOffset() - newYear.getTimezoneOffset())*60000)/86400000) + 1;
|
||||
let weeknum;
|
||||
|
||||
// I have removed the mid-week starting cutoff detection because in this app we always want to start with week #1 (never have a week zero).
|
||||
//if(day < 4) { //if the year starts before the middle of a week
|
||||
weeknum = Math.floor((daynum + day - 1) / 7) + 1;
|
||||
|
||||
// I have turned off the detection of whether the last days of the year belong to this year's last week or next year's first week. This gets too confusing and does not result in any additional usefulness.
|
||||
//if(weeknum > 52) {
|
||||
// nYear = new Date(this.getFullYear() + 1, 0, 1);
|
||||
// nday = nYear.getDay() - dowOffset;
|
||||
// nday = nday >= 0 ? nday : nday + 7;
|
||||
// // if the next year starts before the middle of the week, it is week #1 of that year
|
||||
// weeknum = nday < 4 ? 1 : 53;
|
||||
//}
|
||||
//}
|
||||
//else {
|
||||
// weeknum = Math.floor((daynum+day-1)/7);
|
||||
//}
|
||||
|
||||
return weeknum;
|
||||
};
|
||||
3
imports/util/polyfills/regex.js
Normal file
3
imports/util/polyfills/regex.js
Normal file
@@ -0,0 +1,3 @@
|
||||
RegExp.escape = function(s) {
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
};
|
||||
Reference in New Issue
Block a user