Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #407 #408

Closed
wants to merge 11 commits into from
Closed
10 changes: 8 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

let path = require('path');
var path = require('path');

let config = {
var config = {
globs: {
core: [
'node_modules/fastclick/lib/fastclick.js',
Expand All @@ -20,6 +20,9 @@ let config = {
'src/js/gestures/**/*.js',
'src/js/mobile-angular-ui.gestures.js'
],
gesturesDef: [
'src/js/gestures/**/*.d.ts'
],
fonts: 'node_modules/font-awesome/fonts/fontawesome-webfont.*',
vendorLess: [
path.resolve(__dirname, 'src/less'),
Expand Down Expand Up @@ -66,4 +69,7 @@ config.globs.js = []
.concat(config.globs.components)
.concat(config.globs.gestures);

config.globs.typescript = []
.concat(config.globs.gesturesDef);

module.exports = config;
49 changes: 30 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
let config = require('./config');
let gulp = require('gulp');
let temp = require('temp');
var config = require('./config');
var gulp = require('gulp');
var temp = require('temp');

/* ========================================
= Requiring stuffs =
========================================*/

let concat = require('gulp-concat');
let csso = require('gulp-csso');
let del = require('del');
let less = require('gulp-less');
let mobilizer = require('gulp-mobilizer');
let path = require('path');
let rename = require('gulp-rename');
let seq = require('gulp-sequence');
let sourcemaps = require('gulp-sourcemaps');
let uglify = require('gulp-uglify');
let connect = require('gulp-connect');
let waitOn = require('wait-on');
var concat = require('gulp-concat');
var csso = require('gulp-csso');
var del = require('del');
var less = require('gulp-less');
var mobilizer = require('gulp-mobilizer');
var path = require('path');
var rename = require('gulp-rename');
var seq = require('gulp-sequence');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var connect = require('gulp-connect');
var waitOn = require('wait-on');

/* ================================================
= Report Errors to Console =
Expand Down Expand Up @@ -48,7 +48,7 @@ gulp.task('fonts', function() {
= Compile, minify, mobilize less =
======================================================================*/

let CSS_TEMP_DIR = temp.path({prefix: 'maui-css'});
var CSS_TEMP_DIR = temp.path({prefix: 'maui-css'});

gulp.task('css:less', function() {
gulp.src([
Expand Down Expand Up @@ -116,7 +116,7 @@ gulp.task('css', function(done) {
= Compile and minify js generating source maps =
====================================================================*/

let compileJs = function(dest, src) {
var compileJs = function(dest, src) {
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(concat(dest))
Expand All @@ -141,6 +141,17 @@ gulp.task('js:main', function() {

gulp.task('js', ['js:main', 'js:gestures', 'js:core']);

/* ==================================
= Copy typescript definitions =
===================================*/

gulp.task('ts:definitions', function() {
return gulp.src(config.globs.typescript)
.pipe(gulp.dest(path.join('dist', 'js')));
});

gulp.task('ts', ['ts:definitions']);

/* ======================================
= Build Sequence =
======================================*/
Expand Down Expand Up @@ -169,15 +180,15 @@ gulp.task('build:wait', waitFor([
]));

gulp.task('build', function(done) {
seq('clean', ['fonts', 'css', 'js'], 'build:wait', done);
seq('clean', ['fonts', 'css', 'js', 'ts'], 'build:wait', done);
});

/* ==========================================
= Dev watch and connect =
==========================================*/

gulp.task('dev', function(done) {
let tasks = [];
var tasks = [];

tasks.push('connect');
tasks.push('watch');
Expand Down
14 changes: 14 additions & 0 deletions src/js/gestures/swipe.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface ElementFn {
(element: ng.IAugmentedJQuery): ng.IAugmentedJQuery;
}

interface ValidFn {
(): boolean;
}

interface SwipeOptions {
sensitiveArea?: ElementFn;
movementTarget?: ElementFn;
preventPullToRefresh?: boolean;
valid?: ValidFn;
}
7 changes: 6 additions & 1 deletion src/js/gestures/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
return {
link: function(scope, elem, attrs) {
var onSwipe = $parse(attrs[directiveName]);
var options;
if (attrs.uiMobileOptions) {
var parseFn = $parse(attrs.uiMobileOptions);
options = parseFn(scope);
}
$swipe.bind(elem, {
end: function(swipe, event) {
if (swipe.direction === direction.toUpperCase()) {
Expand All @@ -141,7 +146,7 @@
}
}
}
});
}, options);
}
};
}]);
Expand Down
50 changes: 49 additions & 1 deletion src/js/gestures/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@
return $element[0].ownerDocument.documentElement.getBoundingClientRect();
};

var MOVEMENT_TARGET = function($element) {
return $element[0].ownerDocument;
};

/**
* Set default pointer events option.
* Pointer Events option specifies a device-by-device map between device specific events and
Expand Down Expand Up @@ -179,6 +183,7 @@
this.setMovementThreshold = function(v) {
MOVEMENT_THRESHOLD = v;
};

/**
* Set default sensitive area.
*
Expand Down Expand Up @@ -212,6 +217,32 @@
SENSITIVE_AREA = fnOrElementOrRect;
};

/**
* Set default movement target.
*
* The movement target is the element on wich we register mouse move / end / cancel after first touch.
*
* By default movement target is defined as `ownerDocument`
*
* ie.
*
* ``` js
* $setMovementTarget(function($element) {
* return $element;
* });
* ```
*
* @param {function} movementTarget The new default movement target,
* taking an element and returning another
* element
*
* @method setMovementTarget
* @memberOf mobile-angular-ui.gestures.touch~$touch.$touchProvider
*/
this.setMovementTarget = function(fn) {
MOVEMENT_TARGET = fn;
};

//
// Shorthands for minification
//
Expand Down Expand Up @@ -438,14 +469,19 @@

// ensure element to be an angular element
$element = angular.element($element);
var $html = angular.element('html');

options = options || {};
// uses default pointer types in case of none passed
var pointerTypes = options.pointerTypes || POINTER_TYPES;
var isValid = options.valid === undefined ? VALID : options.valid;
var movementThreshold = options.movementThreshold === undefined ? MOVEMENT_THRESHOLD : options.movementThreshold;
var sensitiveArea = options.sensitiveArea === undefined ? SENSITIVE_AREA : options.sensitiveArea;
var movementTarget = options.movementTarget === undefined ? MOVEMENT_TARGET : options.movementTarget;

// Cancel refresh
var oldTouchAction;
var oldOverflowY;
// first and last touch
var t0;
var tl;
Expand All @@ -461,7 +497,7 @@
var moveEventHandler = eventHandlers.move;
var cancelEventHandler = eventHandlers.cancel;

var $movementTarget = angular.element($element[0].ownerDocument);
var $movementTarget = angular.element(movementTarget($element));
var onTouchMove;
var onTouchEnd;
var onTouchCancel;
Expand All @@ -473,6 +509,9 @@
if (cancelEvents) {
$movementTarget.off(cancelEvents, onTouchCancel);
}
if (options.preventPullToRefresh) {
$html.css({'touch-action': oldTouchAction, 'overflow-y': oldOverflowY});
}
};

var isActive = function() {
Expand All @@ -489,6 +528,14 @@
if (event.touches && event.touches.length > 1) {
return;
}

// Pull down refresh prevent
if (options.preventPullToRefresh) {
oldTouchAction = $html.css('touch-action');
oldOverflowY = $html.css('overflow-y');
$html.css({'touch-action': 'pan-down', 'overflow-y': 'hidden'});
}

tl = t0 = buildTouchInfo('touchstart', getCoordinates(event));
$movementTarget.on(moveEvents, onTouchMove);
$movementTarget.on(endEvents, onTouchEnd);
Expand All @@ -511,6 +558,7 @@

// on touchMove
onTouchMove = function(event) {

// don't handle multi-touch
if (event.touches && event.touches.length > 1) {
return;
Expand Down