chore(build): rename ionic directory to src and update all references in the build process.

This commit is contained in:
Josh Thomas
2016-05-19 13:20:59 -05:00
parent 8470ae04ac
commit c8f760f080
595 changed files with 73 additions and 87 deletions

View File

@ -0,0 +1,39 @@
import {Gesture} from './gesture';
import {defaults} from '../util';
export class DragGesture extends Gesture {
public dragging: boolean;
constructor(element, opts = {}) {
defaults(opts, {});
super(element, opts);
}
listen() {
super.listen();
this.on('panstart', ev => {
if (this.onDragStart(ev) !== false) {
this.dragging = true;
}
});
this.on('panmove', ev => {
if (!this.dragging) return;
if (this.onDrag(ev) === false) {
this.dragging = false;
}
});
this.on('panend', ev => {
if (!this.dragging) return;
this.onDragEnd(ev);
this.dragging = false;
});
}
onDrag(ev: any): boolean { return true; }
onDragStart(ev: any): boolean { return true; }
onDragEnd(ev: any): void {}
}

76
src/gestures/gesture.ts Normal file
View File

@ -0,0 +1,76 @@
import {defaults, assign} from '../util';
import {Hammer, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL} from './hammer';
/**
* A gesture recognizer class.
*
* TODO(mlynch): Re-enable the DOM event simulation that was causing issues (or verify hammer does this already, it might);
*/
export class Gesture {
private _hammer: any;
private _options: any;
private _callbacks: any = {};
public element: HTMLElement;
public direction: string;
public isListening: boolean = false;
constructor(element, opts: any = {}) {
defaults(opts, {
domEvents: true
});
this.element = element;
// Map 'x' or 'y' string to hammerjs opts
this.direction = opts.direction || 'x';
opts.direction = this.direction === 'x' ?
DIRECTION_HORIZONTAL :
DIRECTION_VERTICAL;
this._options = opts;
}
options(opts: any) {
assign(this._options, opts);
}
on(type: string, cb: Function) {
if (type === 'pinch' || type === 'rotate') {
this._hammer.get('pinch').set({enable: true});
}
this._hammer.on(type, cb);
(this._callbacks[type] || (this._callbacks[type] = [])).push(cb);
}
off(type: string, cb: Function) {
this._hammer.off(type, this._callbacks[type] ? cb : null);
}
listen() {
if (!this.isListening) {
this._hammer = Hammer(this.element, this._options);
}
this.isListening = true;
}
unlisten() {
var type, i;
if (this._hammer && this.isListening) {
for (type in this._callbacks) {
for (i = 0; i < this._callbacks[type].length; i++) {
this._hammer.off(type, this._callbacks[type]);
}
}
this._hammer.destroy();
}
this._callbacks = {};
this._hammer = null;
this.isListening = false;
}
destroy() {
this.unlisten();
this.element = this._options = null;
}
}

2472
src/gestures/hammer.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
import {SlideGesture} from './slide-gesture';
import {defaults} from '../util/util';
import {windowDimensions} from '../util/dom';
export class SlideEdgeGesture extends SlideGesture {
public edges: Array<string>;
public maxEdgeStart: any;
private _d: any;
constructor(element: HTMLElement, opts: any = {}) {
defaults(opts, {
edge: 'left',
maxEdgeStart: 50
});
super(element, opts);
// Can check corners through use of eg 'left top'
this.edges = opts.edge.split(' ');
this.maxEdgeStart = opts.maxEdgeStart;
}
canStart(ev: any): boolean {
this._d = this.getContainerDimensions();
return this.edges.every(edge => this._checkEdge(edge, ev.center));
}
getContainerDimensions() {
return {
left: 0,
top: 0,
width: windowDimensions().width,
height: windowDimensions().height
};
}
_checkEdge(edge, pos) {
switch (edge) {
case 'left': return pos.x <= this._d.left + this.maxEdgeStart;
case 'right': return pos.x >= this._d.width - this.maxEdgeStart;
case 'top': return pos.y <= this._d.top + this.maxEdgeStart;
case 'bottom': return pos.y >= this._d.height - this.maxEdgeStart;
}
}
}

View File

@ -0,0 +1,94 @@
import {DragGesture} from './drag-gesture';
import {clamp} from '../util';
export class SlideGesture extends DragGesture {
public slide: SlideData = null;
constructor(element, opts = {}) {
super(element, opts);
this.element = element;
}
/*
* Get the min and max for the slide. pageX/pageY.
* Only called on dragstart.
*/
getSlideBoundaries(slide: SlideData, ev: any) {
return {
min: 0,
max: this.element.offsetWidth
};
}
/*
* Get the element's pos when the drag starts.
* For example, an open side menu starts at 100% and a closed
* sidemenu starts at 0%.
*/
getElementStartPos(slide: SlideData, ev: any) {
return 0;
}
canStart(ev: any): boolean {
return true;
}
onDragStart(ev: any): boolean {
if (!this.canStart(ev)) {
return false;
}
this.slide = {};
this.onSlideBeforeStart(this.slide, ev);
var {min, max} = this.getSlideBoundaries(this.slide, ev);
this.slide.min = min;
this.slide.max = max;
this.slide.elementStartPos = this.getElementStartPos(this.slide, ev);
this.slide.pointerStartPos = ev.center[this.direction];
this.slide.started = true;
this.onSlideStart(this.slide, ev);
return true;
}
onDrag(ev: any): boolean {
if (!this.slide || !this.slide.started) {
return false;
}
this.slide.pos = ev.center[this.direction];
this.slide.distance = clamp(
this.slide.min,
this.slide.pos - this.slide.pointerStartPos + this.slide.elementStartPos,
this.slide.max
);
this.slide.delta = this.slide.pos - this.slide.pointerStartPos;
this.onSlide(this.slide, ev);
return true;
}
onDragEnd(ev: any) {
if (!this.slide || !this.slide.started) return;
this.onSlideEnd(this.slide, ev);
this.slide = null;
}
onSlideBeforeStart(slide?: SlideData, ev?: any): void {}
onSlideStart(slide?: SlideData, ev?: any): void {}
onSlide(slide?: SlideData, ev?: any): void {}
onSlideEnd(slide?: SlideData, ev?: any): void {}
}
export interface SlideData {
min?: number;
max?: number;
distance?: number;
delta?: number;
started?: boolean;
pos?: any;
pointerStartPos?: number;
elementStartPos?: number;
}