chore(): fix typescript errors

This commit is contained in:
Adam Bradley
2016-01-10 01:05:46 -06:00
parent 3a88b9ff91
commit c05d19606a
4 changed files with 64 additions and 57 deletions

View File

@ -7,6 +7,7 @@ let isShowing = false;
* @private * @private
*/ */
export class ClickBlock { export class ClickBlock {
private _enabled: boolean = false;
enable() { enable() {
cbEle = document.createElement('click-block'); cbEle = document.createElement('click-block');

View File

@ -1,7 +1,11 @@
let win: any = window;
let doc: any = document;
let docEle: any = doc.documentElement;
// requestAnimationFrame is polyfilled for old Android // requestAnimationFrame is polyfilled for old Android
// within the web-animations polyfill // within the web-animations polyfill
export const raf = window.requestAnimationFrame; export const raf = win.requestAnimationFrame;
export function rafFrames(framesToWait, callback) { export function rafFrames(framesToWait, callback) {
framesToWait = Math.ceil(framesToWait); framesToWait = Math.ceil(framesToWait);
@ -16,14 +20,23 @@ export function rafFrames(framesToWait, callback) {
} }
} }
export let CSS = {}; export let CSS: {
animationStart?: string,
animationEnd?: string,
transform?: string,
transition?: string,
transitionDuration?: string,
transitionStart?: string,
transitionEnd?: string,
} = {};
(function() { (function() {
// transform // transform
var i, keys = ['webkitTransform', 'transform', '-webkit-transform', 'webkit-transform', var i, keys = ['webkitTransform', 'transform', '-webkit-transform', 'webkit-transform',
'-moz-transform', 'moz-transform', 'MozTransform', 'mozTransform', 'msTransform']; '-moz-transform', 'moz-transform', 'MozTransform', 'mozTransform', 'msTransform'];
for (i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
if (document.documentElement.style[keys[i]] !== undefined) { if (docEle.style[keys[i]] !== undefined) {
CSS.transform = keys[i]; CSS.transform = keys[i];
break; break;
} }
@ -32,7 +45,7 @@ export let CSS = {};
// transition // transition
keys = ['webkitTransition', 'mozTransition', 'msTransition', 'transition']; keys = ['webkitTransition', 'mozTransition', 'msTransition', 'transition'];
for (i = 0; i < keys.length; i++) { for (i = 0; i < keys.length; i++) {
if (document.documentElement.style[keys[i]] !== undefined) { if (docEle.style[keys[i]] !== undefined) {
CSS.transition = keys[i]; CSS.transition = keys[i];
break; break;
} }
@ -41,8 +54,6 @@ export let CSS = {};
// The only prefix we care about is webkit for transitions. // The only prefix we care about is webkit for transitions.
var isWebkit = CSS.transition.indexOf('webkit') > -1; var isWebkit = CSS.transition.indexOf('webkit') > -1;
CSS.prefix = isWebkit ? '-webkit-' : '';
// transition duration // transition duration
CSS.transitionDuration = (isWebkit ? '-webkit-' : '') + 'transition-duration'; CSS.transitionDuration = (isWebkit ? '-webkit-' : '') + 'transition-duration';
@ -50,29 +61,27 @@ export let CSS = {};
CSS.transitionEnd = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend'; CSS.transitionEnd = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend';
})(); })();
if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) { if (win.onanimationend === undefined && win.onwebkitanimationend !== undefined) {
CSS.animation = 'WebkitAnimation';
CSS.animationStart = 'webkitAnimationStart animationstart'; CSS.animationStart = 'webkitAnimationStart animationstart';
CSS.animationEnd = 'webkitAnimationEnd animationend'; CSS.animationEnd = 'webkitAnimationEnd animationend';
} else { } else {
CSS.animation = 'animation';
CSS.animationStart = 'animationstart'; CSS.animationStart = 'animationstart';
CSS.animationEnd = 'animationend'; CSS.animationEnd = 'animationend';
} }
export function transitionEnd(el:Element) { export function transitionEnd(el: HTMLElement) {
return cssPromise(el, CSS.transitionEnd); return cssPromise(el, CSS.transitionEnd);
} }
export function animationStart(el:Element, animationName) { export function animationStart(el: HTMLElement, animationName: string) {
return cssPromise(el, CSS.animationStart, animationName); return cssPromise(el, CSS.animationStart, animationName);
} }
export function animationEnd(el:Element, animationName) { export function animationEnd(el: HTMLElement, animationName: string) {
return cssPromise(el, CSS.animationEnd, animationName); return cssPromise(el, CSS.animationEnd, animationName);
} }
function cssPromise(el:Element, eventNames, animationName) { function cssPromise(el: HTMLElement, eventNames: string, animationName?: string) {
return new Promise(resolve => { return new Promise(resolve => {
eventNames.split(' ').forEach(eventName => { eventNames.split(' ').forEach(eventName => {
el.addEventListener(eventName, onEvent); el.addEventListener(eventName, onEvent);
@ -106,18 +115,18 @@ export function ready(callback) {
promise = new Promise(resolve => { callback = resolve; }); promise = new Promise(resolve => { callback = resolve; });
} }
if (document.readyState === 'complete' || document.readyState === 'interactive') { if (doc.readyState === 'complete' || doc.readyState === 'interactive') {
callback(); callback();
} else { } else {
function completed() { function completed() {
document.removeEventListener('DOMContentLoaded', completed, false); doc.removeEventListener('DOMContentLoaded', completed, false);
window.removeEventListener('load', completed, false); win.removeEventListener('load', completed, false);
callback(); callback();
} }
document.addEventListener('DOMContentLoaded', completed, false); doc.addEventListener('DOMContentLoaded', completed, false);
window.addEventListener('load', completed, false); win.addEventListener('load', completed, false);
} }
return promise; return promise;
@ -131,16 +140,16 @@ export function windowLoad(callback) {
promise = new Promise(resolve => { callback = resolve; }); promise = new Promise(resolve => { callback = resolve; });
} }
if (document.readyState === 'complete') { if (doc.readyState === 'complete') {
callback(); callback();
} else { } else {
function completed() { function completed() {
window.removeEventListener('load', completed, false); win.removeEventListener('load', completed, false);
callback(); callback();
} }
window.addEventListener('load', completed, false); win.addEventListener('load', completed, false);
} }
return promise; return promise;
@ -167,7 +176,7 @@ export function hasPointerMoved(threshold, startCoord, endCoord) {
} }
export function isActive(ele) { export function isActive(ele) {
return !!(ele && (document.activeElement === ele)); return !!(ele && (doc.activeElement === ele));
} }
export function hasFocus(ele) { export function hasFocus(ele) {
@ -182,17 +191,19 @@ export function isTextInput(ele) {
} }
export function hasFocusedTextInput() { export function hasFocusedTextInput() {
let ele = document.activeElement; let ele = doc.activeElement;
if (isTextInput(ele)) { if (isTextInput(ele)) {
return (ele.parentElement.querySelector(':focus') === ele); return (ele.parentElement.querySelector(':focus') === ele);
} }
return false; return false;
} }
let matchesFn; let matchesFn: string;
['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector'].some(fn => { let matchesMethods: Array<string> = ['matches','webkitMatchesSelector','mozMatchesSelector','msMatchesSelector'];
if (typeof document.documentElement[fn] == 'function') { matchesMethods.some((fn: string) => {
if (typeof docEle[fn] == 'function') {
matchesFn = fn; matchesFn = fn;
return true;
} }
}); });
@ -256,10 +267,10 @@ export function getDimensions(ion, ele) {
export function windowDimensions() { export function windowDimensions() {
if (!dimensionCache.win) { if (!dimensionCache.win) {
// make sure we got good values before caching // make sure we got good values before caching
if (window.innerWidth && window.innerHeight) { if (win.innerWidth && win.innerHeight) {
dimensionCache.win = { dimensionCache.win = {
width: window.innerWidth, width: win.innerWidth,
height: window.innerHeight height: win.innerHeight
}; };
} else { } else {
// do not cache bad values // do not cache bad values
@ -273,7 +284,7 @@ export function flushDimensionCache() {
dimensionCache = {}; dimensionCache = {};
} }
let dimensionCache = {}; let dimensionCache:any = {};
let dimensionIds = 0; let dimensionIds = 0;
function isStaticPositioned(element) { function isStaticPositioned(element) {
@ -285,11 +296,11 @@ function isStaticPositioned(element) {
* @param element * @param element
*/ */
export function parentOffsetEl(element) { export function parentOffsetEl(element) {
var offsetParent = element.offsetParent || document; var offsetParent = element.offsetParent || doc;
while (offsetParent && offsetParent !== document && isStaticPositioned(offsetParent)) { while (offsetParent && offsetParent !== doc && isStaticPositioned(offsetParent)) {
offsetParent = offsetParent.offsetParent; offsetParent = offsetParent.offsetParent;
} }
return offsetParent || document; return offsetParent || doc;
}; };
/** /**
@ -302,7 +313,7 @@ export function position(element) {
var elBCR = offset(element); var elBCR = offset(element);
var offsetParentBCR = { top: 0, left: 0 }; var offsetParentBCR = { top: 0, left: 0 };
var offsetParentEl = parentOffsetEl(element); var offsetParentEl = parentOffsetEl(element);
if (offsetParentEl != document) { if (offsetParentEl != doc) {
offsetParentBCR = offset(offsetParentEl); offsetParentBCR = offset(offsetParentEl);
offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop; offsetParentBCR.top += offsetParentEl.clientTop - offsetParentEl.scrollTop;
offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft; offsetParentBCR.left += offsetParentEl.clientLeft - offsetParentEl.scrollLeft;
@ -318,7 +329,7 @@ export function position(element) {
} }
/** /**
* Get the current coordinates of the element, relative to the document. * Get the current coordinates of the element, relative to the doc.
* Read-only equivalent of [jQuery's offset function](http://api.jquery.com/offset/). * Read-only equivalent of [jQuery's offset function](http://api.jquery.com/offset/).
* @param {element} element The element to get the offset of. * @param {element} element The element to get the offset of.
* @returns {object} Returns an object containing the properties top, left, width and height. * @returns {object} Returns an object containing the properties top, left, width and height.
@ -328,7 +339,7 @@ export function offset(element) {
return { return {
width: boundingClientRect.width || element.offsetWidth, width: boundingClientRect.width || element.offsetWidth,
height: boundingClientRect.height || element.offsetHeight, height: boundingClientRect.height || element.offsetHeight,
top: boundingClientRect.top + (window.pageYOffset || document.documentElement.scrollTop), top: boundingClientRect.top + (win.pageYOffset || docEle.scrollTop),
left: boundingClientRect.left + (window.pageXOffset || document.documentElement.scrollLeft) left: boundingClientRect.left + (win.pageXOffset || docEle.scrollLeft)
}; };
} }

View File

@ -1,5 +1,3 @@
import {Injectable} from 'angular2/core';
/** /**
* Events is a pub/sub style event system for sending and responding to application-level * Events is a pub/sub style event system for sending and responding to application-level
* events across your app. * events across your app.
@ -13,16 +11,13 @@ import {Injectable} from 'angular2/core';
* *
* // second page (listen for the user created event) * // second page (listen for the user created event)
* events.subscribe('user:created', (user) => { * events.subscribe('user:created', (user) => {
* console.log('Welcome', user); * console.log('Welcome', user);
* }); * });
* *
* ``` * ```
*/ */
@Injectable()
export class Events { export class Events {
constructor() { private _channels: Array<any>;
this.channels = [];
}
/** /**
* Subscribe to an event topic. Events that get posted to that topic * Subscribe to an event topic. Events that get posted to that topic
@ -32,11 +27,11 @@ export class Events {
* @param handler the event handler * @param handler the event handler
*/ */
subscribe(topic, ...handlers) { subscribe(topic, ...handlers) {
if(!this.channels[topic]) { if (!this._channels[topic]) {
this.channels[topic] = []; this._channels[topic] = [];
} }
handlers.forEach((handler) => { handlers.forEach((handler) => {
this.channels[topic].push(handler); this._channels[topic].push(handler);
}); });
} }
@ -50,22 +45,22 @@ export class Events {
* @return true if a handler was removed * @return true if a handler was removed
*/ */
unsubscribe(topic, handler) { unsubscribe(topic, handler) {
let t = this.channels[topic]; let t = this._channels[topic];
if(!t) { if (!t) {
// Wasn't found, wasn't removed // Wasn't found, wasn't removed
return false; return false;
} }
if(!handler) { if (!handler) {
// Remove all handlers for this topic // Remove all handlers for this topic
delete this.channels[topic]; delete this._channels[topic];
return true; return true;
} }
// We need to find and remove a specific handler // We need to find and remove a specific handler
let i = t.indexOf(handler); let i = t.indexOf(handler);
if(i < 0) { if (i < 0) {
// Wasn't found, wasn't removed // Wasn't found, wasn't removed
return false; return false;
} }
@ -73,8 +68,8 @@ export class Events {
t.splice(i, 1); t.splice(i, 1);
// If the channel is empty now, remove it from the channel map // If the channel is empty now, remove it from the channel map
if(!t.length) { if (!t.length) {
delete this.channels[topic]; delete this._channels[topic];
} }
return true; return true;
@ -87,8 +82,8 @@ export class Events {
* @param eventData the data to send as the event * @param eventData the data to send as the event
*/ */
publish(topic, ...args) { publish(topic, ...args) {
var t = this.channels[topic]; var t = this._channels[topic];
if(!t) { if (!t) {
return null; return null;
} }

View File

@ -1,8 +1,8 @@
export class FeatureDetect { export class FeatureDetect {
private _results: any = {};
run(window, document) { run(window, document) {
this._results = {};
for (let name in featureDetects) { for (let name in featureDetects) {
this._results[name] = featureDetects[name](window, document, document.body); this._results[name] = featureDetects[name](window, document, document.body);
} }