UNPKG

este-library-oldschool

Version:

Library for github.com/steida/este.git

104 lines (95 loc) 2.98 kB
// Generated by github.com/steida/coffee2closure 900.1.18 /** @fileoverview Click handler for client side routing. - Handle only relevant anchors, see este.dom.isRoutingClick. - Uses Polymer's PointerEvents to enable fast click on touch devices. Another trick, but this one does not work on iOS also sometimes we need zoom. https://plus.google.com/u/0/+RickByers/posts/ej7nsuoaaDa */ var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.superClass_ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; goog.provide('este.labs.events.RoutingClickHandler'); goog.require('este.Base'); goog.require('este.dom'); goog.require('este.thirdParty.pointerEvents'); /** @param {Element=} element @constructor @extends {este.Base} */ este.labs.events.RoutingClickHandler = function(element) { this.element = element != null ? element : document.documentElement; este.labs.events.RoutingClickHandler.superClass_.constructor.call(this); este.thirdParty.pointerEvents.install(); this.registerEvents(); } extend(este.labs.events.RoutingClickHandler, superClass); /** @type {Element} @protected */ este.labs.events.RoutingClickHandler.prototype.element = null; /** @protected */ este.labs.events.RoutingClickHandler.prototype.registerEvents = function() { this.on(this.element, goog.events.EventType.CLICK, this.onElementClick); if (!este.thirdParty.pointerEvents.isSupported()) { return; } return this.on(this.element, goog.events.EventType.POINTERUP, this.onElementPointerUp); }; /** @param {goog.events.BrowserEvent} e @protected */ este.labs.events.RoutingClickHandler.prototype.onElementClick = function(e) { var anchor; anchor = this.tryGetRoutingAnchor(e); if (!anchor) { return; } e.preventDefault(); if (este.thirdParty.pointerEvents.isSupported()) { return; } return this.dispatchClick(anchor); }; /** @param {goog.events.BrowserEvent} e @protected */ este.labs.events.RoutingClickHandler.prototype.onElementPointerUp = function(e) { var anchor; anchor = this.tryGetRoutingAnchor(e); if (!anchor) { return; } return this.dispatchClick(anchor); }; /** @param {goog.events.BrowserEvent} e @return {Element} @protected */ este.labs.events.RoutingClickHandler.prototype.tryGetRoutingAnchor = function(e) { var anchor; if (!este.dom.isRoutingEvent(e)) { return null; } anchor = goog.dom.getAncestorByTagNameAndClass(e.target, goog.dom.TagName.A); if (!anchor || !este.dom.isRoutingAnchor(anchor)) { return null; } return anchor; }; /** @param {Element} anchor @protected */ este.labs.events.RoutingClickHandler.prototype.dispatchClick = function(anchor) { return this.dispatchEvent({ target: anchor, type: goog.events.EventType.CLICK }); };