mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 05:21:52 +08:00
style(util): tslint updates
This commit is contained in:
@ -1,4 +0,0 @@
|
||||
import * as domUtil from './util/dom';
|
||||
export const dom = domUtil;
|
||||
export * from './util/util';
|
||||
export * from './util/datetime-util';
|
@ -1,4 +1,4 @@
|
||||
import { isBlank, isPresent, isString, isObject, assign } from './util';
|
||||
import { assign, isBlank, isPresent, isString } from './util';
|
||||
|
||||
|
||||
export function renderDateTime(template: string, value: DateTimeData, locale: LocaleData) {
|
||||
@ -466,8 +466,6 @@ const FORMAT_KEYS = [
|
||||
{ f: FORMAT_a, k: 'ampm' },
|
||||
];
|
||||
|
||||
const FORMAT_REGEX = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|DD?D?D?|ddd?d?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|.)/g;
|
||||
|
||||
const DAY_NAMES = [
|
||||
'Sunday',
|
||||
'Monday',
|
||||
|
@ -81,7 +81,7 @@ export let CSS: {
|
||||
'-moz-transform', 'moz-transform', 'MozTransform', 'mozTransform', 'msTransform'];
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
if (document.documentElement.style[keys[i]] !== undefined) {
|
||||
if ((<any>document.documentElement.style)[keys[i]] !== undefined) {
|
||||
CSS.transform = keys[i];
|
||||
break;
|
||||
}
|
||||
@ -90,7 +90,7 @@ export let CSS: {
|
||||
// transition
|
||||
keys = ['webkitTransition', 'mozTransition', 'msTransition', 'transition'];
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
if (document.documentElement.style[keys[i]] !== undefined) {
|
||||
if ((<any>document.documentElement.style)[keys[i]] !== undefined) {
|
||||
CSS.transition = keys[i];
|
||||
break;
|
||||
}
|
||||
@ -188,7 +188,7 @@ export function windowLoad(callback?: Function) {
|
||||
}
|
||||
}
|
||||
|
||||
export function pointerCoord(ev: any): Coordinates {
|
||||
export function pointerCoord(ev: any): PointerCoordinates {
|
||||
// get coordinates for either a mouse click
|
||||
// or a touch depending on the given event
|
||||
let c = { x: 0, y: 0 };
|
||||
@ -203,7 +203,7 @@ export function pointerCoord(ev: any): Coordinates {
|
||||
return c;
|
||||
}
|
||||
|
||||
export function hasPointerMoved(threshold: number, startCoord: Coordinates, endCoord: Coordinates) {
|
||||
export function hasPointerMoved(threshold: number, startCoord: PointerCoordinates, endCoord: PointerCoordinates) {
|
||||
let deltaX = (startCoord.x - endCoord.x);
|
||||
let deltaY = (startCoord.y - endCoord.y);
|
||||
let distance = deltaX * deltaX + deltaY * deltaY;
|
||||
@ -247,30 +247,30 @@ export function copyInputAttributes(srcElement: HTMLElement, destElement: HTMLEl
|
||||
}
|
||||
}
|
||||
|
||||
let matchesFn: string;
|
||||
let matchesMethods = ['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector'];
|
||||
matchesMethods.some((fn: string) => {
|
||||
if (typeof document.documentElement[fn] === 'function') {
|
||||
matchesFn = fn;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
export function closest(ele: HTMLElement, selector: string, checkSelf?: boolean) {
|
||||
if (ele && matchesFn) {
|
||||
|
||||
// traverse parents
|
||||
ele = (checkSelf ? ele : ele.parentElement);
|
||||
|
||||
while (ele !== null) {
|
||||
if (ele[matchesFn](selector)) {
|
||||
return ele;
|
||||
}
|
||||
ele = ele.parentElement;
|
||||
// TODO: Add to external polyfill script
|
||||
if (typeof Element.prototype.matches !== 'function') {
|
||||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector || function matches(selector) {
|
||||
var element = this;
|
||||
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
|
||||
var index = 0;
|
||||
while (elements[index] && elements[index] !== element) {
|
||||
++index;
|
||||
}
|
||||
}
|
||||
return Boolean(elements[index]);
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
if (typeof Element.prototype.closest !== 'function') {
|
||||
Element.prototype.closest = function closest(selector) {
|
||||
var element = this;
|
||||
while (element && element.nodeType === 1) {
|
||||
if (element.matches(selector)) {
|
||||
return element;
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -328,7 +328,7 @@ export function flushDimensionCache() {
|
||||
let dimensionCache: any = {};
|
||||
|
||||
|
||||
export interface Coordinates {
|
||||
export interface PointerCoordinates {
|
||||
x?: number;
|
||||
y?: number;
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
import { APP_INITIALIZER } from '@angular/core';
|
||||
|
||||
import { nativeTimeout } from '../util/dom';
|
||||
import { Platform } from '../platform/platform';
|
||||
import { ScrollView } from '../util/scroll-view';
|
||||
|
||||
/**
|
||||
* @name Events
|
||||
* @description
|
||||
@ -101,3 +107,59 @@ export class Events {
|
||||
return responses;
|
||||
}
|
||||
}
|
||||
|
||||
export function setupEvents(platform: Platform): Events {
|
||||
const events = new Events();
|
||||
|
||||
// start listening for resizes XXms after the app starts
|
||||
nativeTimeout(() => {
|
||||
window.addEventListener('online', (ev) => {
|
||||
events.publish('app:online', ev);
|
||||
}, false);
|
||||
|
||||
window.addEventListener('offline', (ev) => {
|
||||
events.publish('app:offline', ev);
|
||||
}, false);
|
||||
|
||||
window.addEventListener('orientationchange', (ev) => {
|
||||
events.publish('app:rotated', ev);
|
||||
});
|
||||
|
||||
// When that status taps, we respond
|
||||
window.addEventListener('statusTap', (ev) => {
|
||||
// TODO: Make this more better
|
||||
let el = <HTMLElement>document.elementFromPoint(platform.width() / 2, platform.height() / 2);
|
||||
if (!el) { return; }
|
||||
|
||||
let content = <HTMLElement>el.closest('.scroll-content');
|
||||
if (content) {
|
||||
var scroll = new ScrollView(content);
|
||||
scroll.scrollTo(0, 0, 300);
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
platform.windowResize();
|
||||
});
|
||||
|
||||
}, 2000);
|
||||
|
||||
return events;
|
||||
}
|
||||
|
||||
export function setupProvideEvents(platform: Platform) {
|
||||
return function() {
|
||||
return setupEvents(platform);
|
||||
};
|
||||
}
|
||||
|
||||
export function provideEvents() {
|
||||
return {
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: setupProvideEvents,
|
||||
deps: [
|
||||
Platform
|
||||
],
|
||||
multi: true
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user