Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #90 from Polymer/master
Browse files Browse the repository at this point in the history
7/11 master -> stable
  • Loading branch information
dfreedm committed Jul 11, 2013
2 parents b3b4a6a + ea792e1 commit c70e384
Show file tree
Hide file tree
Showing 21 changed files with 390 additions and 269 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
node_modules
pointerevents.min.js
pointerevents.min.js.map
pointerevents.dev.js
32 changes: 16 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-karma-0.9.1');
grunt.loadNpmTasks('grunt-karma');

var os = require('os').type();
var browsers = ['Chrome', 'Firefox'];
var sourceFiles = grunt.file.readJSON('build.json');

if (os == 'Darwin') {
browsers.push('ChromeCanary');
}
Expand All @@ -13,27 +16,24 @@ module.exports = function(grunt) {
}

grunt.initConfig({
concat: {
pointerevents: {
options: {
stripBanners: true,
banner: grunt.file.read('LICENSE')
},
src: sourceFiles,
dest: 'pointerevents.dev.js'
}
},
uglify: {
pointerevents: {
options: {
sourceMap: 'pointerevents.min.js.map',
banner: grunt.file.read('LICENSE')
},
dest: 'pointerevents.min.js',
src: [
'src/boot.js',
'src/touch-action.js',
'src/PointerEvent.js',
'src/pointermap.js',
'src/sidetable.js',
'src/dispatcher.js',
'src/installer.js',
'src/mouse.js',
'src/touch.js',
'src/ms.js',
'src/platform-events.js',
'src/capture.js',
]
src: sourceFiles
}
},
karma: {
Expand All @@ -53,7 +53,7 @@ module.exports = function(grunt) {
}
});

grunt.registerTask('default', 'uglify');
grunt.registerTask('default', ['concat', 'uglify']);
grunt.registerTask('test', 'karma:polymer');
grunt.registerTask('test-buildbot', 'karma:buildbot');
};
14 changes: 14 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
"src/boot.js",
"src/touch-action.js",
"src/PointerEvent.js",
"src/pointermap.js",
"src/sidetable.js",
"src/dispatcher.js",
"src/installer.js",
"src/mouse.js",
"src/touch.js",
"src/ms.js",
"src/platform-events.js",
"src/capture.js"
]
160 changes: 82 additions & 78 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,78 +1,82 @@
// Karma configuration

// base path, that will be used to resolve files and exclude
basePath = '';

// list of files / patterns to load in the browser
files = [
'node_modules/chai/chai.js',
'node_modules/chai-spies/chai-spies.js',
'src/boot.js',
'src/PointerEvent.js',
'src/pointermap.js',
'src/sidetable.js',
'src/dispatcher.js',
'src/installer.js',
'src/mouse.js',
'src/touch.js',
'src/ms.js',
'src/platform-events.js',
'src/capture.js',
'tests/setup.js',
'tests/karma-setup.js',
'tests/!(setup|karma-setup).js'
];

// list of files to exclude
exclude = [];

frameworks = ['mocha'];

// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['progress'];

// web server port
port = 9876;

// cli runner port
runnerPort = 9100;

// enable / disable colors in the output (reporters and logs)
colors = true;

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_INFO;

// enable / disable watching file and executing tests whenever any file changes
autoWatch = false;

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['ChromeCanary'];

// If browser does not capture in given timeout [ms], kill it
captureTimeout = 50000;

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun = true;

reportSlowThan = 500;

preprocessors = {};

plugins = [
'karma-mocha',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-script-launcher',
'karma-crbot-reporter'
];
module.exports = function(karma) {
karma.configure({
// Karma configuration

// base path, that will be used to resolve files and exclude
basePath: '',

// list of files / patterns to load in the browser
files: [
'node_modules/chai/chai.js',
'node_modules/chai-spies/chai-spies.js',
'src/boot.js',
'src/PointerEvent.js',
'src/pointermap.js',
'src/sidetable.js',
'src/dispatcher.js',
'src/installer.js',
'src/mouse.js',
'src/touch.js',
'src/ms.js',
'src/platform-events.js',
'src/capture.js',
'tests/setup.js',
'tests/karma-setup.js',
'tests/!(setup|karma-setup).js'
],

// list of files to exclude
exclude: [],

frameworks: ['mocha'],

// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters: ['progress'],

// web server port
port: 9876,

// cli runner port
runnerPort: 9100,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: karma.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['ChromeCanary'],

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 50000,

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,

reportSlowThan: 500,

preprocessors: {},

plugins: [
'karma-mocha',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-script-launcher',
'karma-crbot-reporter'
]
});
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"mocha": "*",
"chai": "*",
"chai-spies": "*",
"grunt": "*",
"grunt-contrib-uglify": "*",
"grunt-contrib-yuidoc": "*",
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-yuidoc": "~0.4.0",
"karma-mocha": "*",
"karma-script-launcher": "*",
"karma-crbot-reporter": "*",
"grunt-karma-0.9.1": "~0.4.3"
"grunt-karma": "~0.5.0"
},
"scripts": {
"test": "grunt test"
Expand Down
4 changes: 2 additions & 2 deletions samples/scroller/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
scroller.setAttribute('touch-action', 'pan-y');
}
function scroll() {
scroller.setAttribute('touch-action', 'scroll');
scroller.setAttribute('touch-action', 'auto');
}
function none() {
scroller.setAttribute('touch-action', 'none');
Expand All @@ -62,7 +62,7 @@
'pointercancel'
].forEach(function(e) {
document.addEventListener(e, function(e) {
console.log(e.type, e.clientX, e.clientY);
console.log(e.type, e.target, e.clientX, e.clientY);
});
});
</script>
Expand Down
1 change: 0 additions & 1 deletion samples/shadow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
s.appendChild(pd);
// Register shadow dom touch-action
PointerEventsPolyfill.register(s);
PointerEventsPolyfill.setTouchAction(s, host.getAttribute('touch-action'));
// event listeners
host.addEventListener('pointerdown', function(e){ console.log(e.target) });
d.addEventListener('pointerdown', function(e){ console.log(e.target) });
Expand Down
4 changes: 3 additions & 1 deletion src/PointerEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,7 @@
}

// attach to window
scope.PointerEvent = PointerEvent;
if (!scope.PointerEvent) {
scope.PointerEvent = PointerEvent;
}
})(window);
40 changes: 35 additions & 5 deletions src/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,33 @@
return inEl.shadowRoot || inEl.webkitShadowRoot;
}
},
canTarget: function(scope) {
return scope && Boolean(scope.elementFromPoint);
canTarget: function(shadow) {
return shadow && Boolean(shadow.elementFromPoint);
},
targetingShadow: function(inEl) {
var s = this.shadow(inEl);
if (this.canTarget(s)) {
return s;
}
},
olderShadow: function(shadow) {
var os = shadow.olderShadowRoot;
if (!os) {
var se = shadow.querySelector('shadow');
if (se) {
os = se.olderShadowRoot;
}
}
return os;
},
allShadows: function(element) {
var shadows = [], s = this.shadow(element);
while(s) {
shadows.push(s);
s = this.olderShadow(s);
}
return shadows;
},
searchRoot: function(inRoot, x, y) {
if (inRoot) {
var t = inRoot.elementFromPoint(x, y);
Expand All @@ -32,9 +50,7 @@
st = sr.elementFromPoint(x, y);
if (!st) {
// check for older shadows
os = sr.querySelector('shadow');
// check the older shadow if available
sr = os && os.olderShadowRoot;
sr = this.olderShadow(sr);
} else {
// shadowed element may contain a shadow root
var ssr = this.targetingShadow(st);
Expand All @@ -45,8 +61,22 @@
return t;
}
},
owner: function(element) {
var s = element;
// walk up until you hit the shadow root or document
while (s.parentNode) {
s = s.parentNode;
}
return s;
},
findTarget: function(inEvent) {
var x = inEvent.clientX, y = inEvent.clientY;
// if the listener is in the shadow root, it is much faster to start there
var s = this.owner(inEvent.target);
// if x, y is not in this root, fall back to document search
if (!s.elementFromPoint(x, y)) {
s = document;
}
return this.searchRoot(document, x, y);
}
};
Expand Down
Loading

0 comments on commit c70e384

Please sign in to comment.