mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +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) {
|
export function renderDateTime(template: string, value: DateTimeData, locale: LocaleData) {
|
||||||
@ -466,8 +466,6 @@ const FORMAT_KEYS = [
|
|||||||
{ f: FORMAT_a, k: 'ampm' },
|
{ 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 = [
|
const DAY_NAMES = [
|
||||||
'Sunday',
|
'Sunday',
|
||||||
'Monday',
|
'Monday',
|
||||||
|
@ -81,7 +81,7 @@ export let CSS: {
|
|||||||
'-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 ((<any>document.documentElement.style)[keys[i]] !== undefined) {
|
||||||
CSS.transform = keys[i];
|
CSS.transform = keys[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,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 ((<any>document.documentElement.style)[keys[i]] !== undefined) {
|
||||||
CSS.transition = keys[i];
|
CSS.transition = keys[i];
|
||||||
break;
|
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
|
// get coordinates for either a mouse click
|
||||||
// or a touch depending on the given event
|
// or a touch depending on the given event
|
||||||
let c = { x: 0, y: 0 };
|
let c = { x: 0, y: 0 };
|
||||||
@ -203,7 +203,7 @@ export function pointerCoord(ev: any): Coordinates {
|
|||||||
return c;
|
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 deltaX = (startCoord.x - endCoord.x);
|
||||||
let deltaY = (startCoord.y - endCoord.y);
|
let deltaY = (startCoord.y - endCoord.y);
|
||||||
let distance = deltaX * deltaX + deltaY * deltaY;
|
let distance = deltaX * deltaX + deltaY * deltaY;
|
||||||
@ -247,30 +247,30 @@ export function copyInputAttributes(srcElement: HTMLElement, destElement: HTMLEl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let matchesFn: string;
|
// TODO: Add to external polyfill script
|
||||||
let matchesMethods = ['matches', 'webkitMatchesSelector', 'mozMatchesSelector', 'msMatchesSelector'];
|
if (typeof Element.prototype.matches !== 'function') {
|
||||||
matchesMethods.some((fn: string) => {
|
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector || function matches(selector) {
|
||||||
if (typeof document.documentElement[fn] === 'function') {
|
var element = this;
|
||||||
matchesFn = fn;
|
var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
|
||||||
return true;
|
var index = 0;
|
||||||
|
while (elements[index] && elements[index] !== element) {
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
});
|
return Boolean(elements[index]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function closest(ele: HTMLElement, selector: string, checkSelf?: boolean) {
|
if (typeof Element.prototype.closest !== 'function') {
|
||||||
if (ele && matchesFn) {
|
Element.prototype.closest = function closest(selector) {
|
||||||
|
var element = this;
|
||||||
// traverse parents
|
while (element && element.nodeType === 1) {
|
||||||
ele = (checkSelf ? ele : ele.parentElement);
|
if (element.matches(selector)) {
|
||||||
|
return element;
|
||||||
while (ele !== null) {
|
|
||||||
if (ele[matchesFn](selector)) {
|
|
||||||
return ele;
|
|
||||||
}
|
}
|
||||||
ele = ele.parentElement;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ export function flushDimensionCache() {
|
|||||||
let dimensionCache: any = {};
|
let dimensionCache: any = {};
|
||||||
|
|
||||||
|
|
||||||
export interface Coordinates {
|
export interface PointerCoordinates {
|
||||||
x?: number;
|
x?: number;
|
||||||
y?: 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
|
* @name Events
|
||||||
* @description
|
* @description
|
||||||
@ -101,3 +107,59 @@ export class Events {
|
|||||||
return responses;
|
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