-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds event normalization via Polymer.dom(event), api includes:
* rootTarget: the original or root target before shadow retargeting (equivalent of event.path[0] or event.target under Shady DOM) * localTarget: retargeted event target (equivalent of event.target under Shadow DOM) * path: array of nodes through which event will pass (equivalent of event.path under Shadow DOM)
- Loading branch information
Steven Orvell
committed
Mar 16, 2015
1 parent
269cdb3
commit 739de80
Showing
7 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!-- | ||
@license | ||
Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<link rel="import" href="settings.html"> | ||
<script> | ||
|
||
Polymer.EventApi = (function() { | ||
|
||
var Settings = Polymer.Settings; | ||
|
||
var EventApi = function(event) { | ||
this.event = event; | ||
}; | ||
|
||
if (Settings.useShadow) { | ||
|
||
EventApi.prototype = { | ||
|
||
get rootTarget() { | ||
return this.event.path[0]; | ||
}, | ||
|
||
get localTarget() { | ||
return this.event.target; | ||
}, | ||
|
||
get path() { | ||
return this.event.path; | ||
} | ||
|
||
}; | ||
|
||
} else { | ||
|
||
EventApi.prototype = { | ||
|
||
get rootTarget() { | ||
return this.event.target; | ||
}, | ||
|
||
get localTarget() { | ||
var current = this.event.currentTarget; | ||
var currentRoot = current && current._ownerShadyRoot; | ||
var p$ = this.path; | ||
for (var i=0; i < p$.length; i++) { | ||
if (p$[i]._ownerShadyRoot === currentRoot) { | ||
return p$[i]; | ||
} | ||
} | ||
}, | ||
|
||
// TODO(sorvell): should include <content> elements | ||
get path() { | ||
if (!this.event._path) { | ||
var path = []; | ||
var o = this.rootTarget; | ||
while (o) { | ||
path.push(o); | ||
o = Polymer.dom(o).parentNode || o.host; | ||
} | ||
this.event._path = path; | ||
} | ||
return this.event._path; | ||
} | ||
|
||
}; | ||
|
||
} | ||
|
||
var factory = function(event) { | ||
if (!event.__eventApi) { | ||
event.__eventApi = new EventApi(event); | ||
} | ||
return event.__eventApi; | ||
} | ||
|
||
return { | ||
factory: factory | ||
}; | ||
|
||
})(); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters