diff --git a/modules/angular2/src/render/dom/events/event_manager.js b/modules/angular2/src/render/dom/events/event_manager.js deleted file mode 100644 index 78d5854c7b..0000000000 --- a/modules/angular2/src/render/dom/events/event_manager.js +++ /dev/null @@ -1,94 +0,0 @@ -import {isBlank, BaseException, isPresent, StringWrapper} from 'angular2/src/facade/lang'; -import {DOM} from 'angular2/src/dom/dom_adapter'; -import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; -import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; - -var BUBBLE_SYMBOL = '^'; - -export class EventManager { - _plugins: List; - _zone: VmTurnZone; - - constructor(plugins: List, zone: VmTurnZone) { - this._zone = zone; - this._plugins = plugins; - for (var i = 0; i < plugins.length; i++) { - plugins[i].manager = this; - } - } - - addEventListener(element, eventName: string, handler: Function) { - var shouldSupportBubble = eventName[0] == BUBBLE_SYMBOL; - if (shouldSupportBubble) { - eventName = StringWrapper.substring(eventName, 1); - } - - var plugin = this._findPluginFor(eventName); - plugin.addEventListener(element, eventName, handler, shouldSupportBubble); - } - - getZone(): VmTurnZone { - return this._zone; - } - - _findPluginFor(eventName: string): EventManagerPlugin { - var plugins = this._plugins; - for (var i = 0; i < plugins.length; i++) { - var plugin = plugins[i]; - if (plugin.supports(eventName)) { - return plugin; - } - } - throw new BaseException(`No event manager plugin found for event ${eventName}`); - } -} - -export class EventManagerPlugin { - manager: EventManager; - - // We are assuming here that all plugins support bubbled and non-bubbled events. - // That is equivalent to having supporting $event.target - // The bubbling flag (currently ^) is stripped before calling the supports and - // addEventListener methods. - supports(eventName: string): boolean { - return false; - } - - addEventListener(element, eventName: string, handler: Function, - shouldSupportBubble: boolean) { - throw "not implemented"; - } -} - -export class DomEventsPlugin extends EventManagerPlugin { - manager: EventManager; - - // This plugin should come last in the list of plugins, because it accepts all - // events. - supports(eventName: string): boolean { - return true; - } - - addEventListener(element, eventName: string, handler: Function, - shouldSupportBubble: boolean) { - var outsideHandler = shouldSupportBubble ? - DomEventsPlugin.bubbleCallback(element, handler, this.manager._zone) : - DomEventsPlugin.sameElementCallback(element, handler, this.manager._zone); - - this.manager._zone.runOutsideAngular(() => { - DOM.on(element, eventName, outsideHandler); - }); - } - - static sameElementCallback(element, handler, zone) { - return (event) => { - if (event.target === element) { - zone.run(() => handler(event)); - } - }; - } - - static bubbleCallback(element, handler, zone) { - return (event) => zone.run(() => handler(event)); - } -} diff --git a/modules/angular2/src/render/dom/events/hammer_common.js b/modules/angular2/src/render/dom/events/hammer_common.js deleted file mode 100644 index 13270f2fd1..0000000000 --- a/modules/angular2/src/render/dom/events/hammer_common.js +++ /dev/null @@ -1,52 +0,0 @@ -import {EventManagerPlugin} from './event_manager'; -import {StringMapWrapper} from 'angular2/src/facade/collection'; - -var _eventNames = { - // pan - 'pan': true, - 'panstart': true, - 'panmove': true, - 'panend': true, - 'pancancel': true, - 'panleft': true, - 'panright': true, - 'panup': true, - 'pandown': true, - // pinch - 'pinch': true, - 'pinchstart': true, - 'pinchmove': true, - 'pinchend': true, - 'pinchcancel': true, - 'pinchin': true, - 'pinchout': true, - // press - 'press': true, - 'pressup': true, - // rotate - 'rotate': true, - 'rotatestart': true, - 'rotatemove': true, - 'rotateend': true, - 'rotatecancel': true, - // swipe - 'swipe': true, - 'swipeleft': true, - 'swiperight': true, - 'swipeup': true, - 'swipedown': true, - // tap - 'tap': true, -}; - - -export class HammerGesturesPluginCommon extends EventManagerPlugin { - constructor() { - super(); - } - - supports(eventName: string): boolean { - eventName = eventName.toLowerCase(); - return StringMapWrapper.contains(_eventNames, eventName); - } -} diff --git a/modules/angular2/src/render/dom/events/hammer_gestures.dart b/modules/angular2/src/render/dom/events/hammer_gestures.dart deleted file mode 100644 index edb2332b30..0000000000 --- a/modules/angular2/src/render/dom/events/hammer_gestures.dart +++ /dev/null @@ -1,86 +0,0 @@ -library angular.events; - -import 'dart:html'; -import './hammer_common.dart'; -import '../../facade/lang.dart' show BaseException; - -import 'dart:js' as js; - -class HammerGesturesPlugin extends HammerGesturesPluginCommon { - bool supports(String eventName) { - if (!super.supports(eventName)) return false; - - if (!js.context.hasProperty('Hammer')) { - throw new BaseException('Hammer.js is not loaded, can not bind ${eventName} event'); - } - - return true; - } - - addEventListener(Element element, String eventName, Function handler, bool shouldSupportBubble) { - if (shouldSupportBubble) throw new BaseException('Hammer.js plugin does not support bubbling gestures.'); - var zone = this.manager.getZone(); - eventName = eventName.toLowerCase(); - - zone.runOutsideAngular(() { - // Creating the manager bind events, must be done outside of angular - var mc = new js.JsObject(js.context['Hammer'], [element]); - - var jsObj = mc.callMethod('get', ['pinch']); - jsObj.callMethod('set', [new js.JsObject.jsify({'enable': true})]); - jsObj = mc.callMethod('get', ['rotate']); - jsObj.callMethod('set', [new js.JsObject.jsify({'enable': true})]); - - mc.callMethod('on', [ - eventName, - (eventObj) { - zone.run(() { - var dartEvent = new HammerEvent._fromJsEvent(eventObj); - handler(dartEvent); - }); - } - ]); - }); - } -} - -class HammerEvent { - num angle; - num centerX; - num centerY; - int deltaTime; - int deltaX; - int deltaY; - int direction; - int distance; - num rotation; - num scale; - Node target; - int timeStamp; - String type; - num velocity; - num velocityX; - num velocityY; - js.JsObject jsEvent; - - HammerEvent._fromJsEvent(js.JsObject event) { - angle = event['angle']; - var center = event['center']; - centerX = center['x']; - centerY = center['y']; - deltaTime = event['deltaTime']; - deltaX = event['deltaX']; - deltaY = event['deltaY']; - direction = event['direction']; - distance = event['distance']; - rotation = event['rotation']; - scale = event['scale']; - target = event['target']; - timeStamp = event['timeStamp']; - type = event['type']; - velocity = event['velocity']; - velocityX = event['velocityX']; - velocityY = event['velocityY']; - jsEvent = event; - } -} diff --git a/modules/angular2/src/render/dom/events/hammer_gestures.es6 b/modules/angular2/src/render/dom/events/hammer_gestures.es6 deleted file mode 100644 index b5baabcbc5..0000000000 --- a/modules/angular2/src/render/dom/events/hammer_gestures.es6 +++ /dev/null @@ -1,37 +0,0 @@ -import {HammerGesturesPluginCommon} from './hammer_common'; -import {isPresent, BaseException} from 'angular2/src/facade/lang'; - -export class HammerGesturesPlugin extends HammerGesturesPluginCommon { - constructor() { - super(); - } - - supports(eventName:string):boolean { - if (!super.supports(eventName)) return false; - - if (!isPresent(window.Hammer)) { - throw new BaseException(`Hammer.js is not loaded, can not bind ${eventName} event`); - } - - return true; - } - - addEventListener(element, eventName:string, handler:Function, shouldSupportBubble: boolean) { - if (shouldSupportBubble) throw new BaseException('Hammer.js plugin does not support bubbling gestures.'); - var zone = this.manager.getZone(); - eventName = eventName.toLowerCase(); - - zone.runOutsideAngular(function () { - // Creating the manager bind events, must be done outside of angular - var mc = new Hammer(element); - mc.get('pinch').set({enable: true}); - mc.get('rotate').set({enable: true}); - - mc.on(eventName, function (eventObj) { - zone.run(function () { - handler(eventObj); - }); - }); - }); - } -} diff --git a/modules/angular2/src/services/url_resolver.js b/modules/angular2/src/services/url_resolver.js deleted file mode 100644 index dec2a9f78c..0000000000 --- a/modules/angular2/src/services/url_resolver.js +++ /dev/null @@ -1,36 +0,0 @@ -import {isPresent, isBlank, RegExpWrapper, BaseException} from 'angular2/src/facade/lang'; -import {DOM} from 'angular2/src/dom/dom_adapter'; - -export class UrlResolver { - static a; - - constructor() { - if (isBlank(UrlResolver.a)) { - UrlResolver.a = DOM.createElement('a'); - } - } - - resolve(baseUrl: string, url: string): string { - if (isBlank(baseUrl)) { - DOM.resolveAndSetHref(UrlResolver.a, url, null); - return DOM.getHref(UrlResolver.a); - } - - if (isBlank(url) || url == '') return baseUrl; - - if (url[0] == '/') { - throw new BaseException(`Could not resolve the url ${url} from ${baseUrl}`); - } - - var m = RegExpWrapper.firstMatch(_schemeRe, url); - - if (isPresent(m[1])) { - return url; - } - - DOM.resolveAndSetHref(UrlResolver.a, baseUrl, url); - return DOM.getHref(UrlResolver.a); - } -} - -var _schemeRe = RegExpWrapper.create('^([^:/?#]+:)?'); diff --git a/modules/angular2/src/services/xhr.js b/modules/angular2/src/services/xhr.js deleted file mode 100644 index 839e336eda..0000000000 --- a/modules/angular2/src/services/xhr.js +++ /dev/null @@ -1,10 +0,0 @@ -// import {Promise} from 'angular2/src/facade/async'; - -export {XHR} from 'angular2/src/core/compiler/xhr/xhr'; - -// TODO: export an own interface as soon as core/compiler/xhr is no more needed... -// export class XHR { -// get(url: string): Promise { -// return null; -// } -// } diff --git a/modules/angular2/src/services/xhr_impl.dart b/modules/angular2/src/services/xhr_impl.dart deleted file mode 100644 index 4217a0877e..0000000000 --- a/modules/angular2/src/services/xhr_impl.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'dart:async'; -import 'dart:html'; -import './xhr.dart' show XHR; - -class XHRImpl extends XHR { - Future get(String url) { - return HttpRequest.request(url).then( - (HttpRequest request) => request.responseText, - onError: (Error e) => throw 'Failed to load $url' - ); - } -} diff --git a/modules/angular2/src/services/xhr_impl.es6 b/modules/angular2/src/services/xhr_impl.es6 deleted file mode 100644 index c0648aa6b8..0000000000 --- a/modules/angular2/src/services/xhr_impl.es6 +++ /dev/null @@ -1,27 +0,0 @@ -import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; -import {XHR} from './xhr'; - -export class XHRImpl extends XHR { - get(url: string): Promise { - var completer = PromiseWrapper.completer(); - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.responseType = 'text'; - - xhr.onload = function() { - var status = xhr.status; - if (200 <= status && status <= 300) { - completer.resolve(xhr.responseText); - } else { - completer.reject(`Failed to load ${url}`); - } - }; - - xhr.onerror = function() { - completer.reject(`Failed to load ${url}`); - }; - - xhr.send(); - return completer.promise; - } -} diff --git a/modules/angular2/test/services/url_resolver_spec.js b/modules/angular2/test/services/url_resolver_spec.js deleted file mode 100644 index a8c10f1b9d..0000000000 --- a/modules/angular2/test/services/url_resolver_spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib'; -import {UrlResolver} from 'angular2/src/services/url_resolver'; - -export function main() { - describe('UrlResolver', () => { - var resolver = new UrlResolver(); - - it('should add a relative path to the base url', () => { - expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar'); - expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar'); - expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar'); - expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar'); - }); - - it('should replace the base path', () => { - expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar'); - expect(resolver.resolve('http://www.foo.com/baz', './bar')).toEqual('http://www.foo.com/bar'); - }); - - it('should append to the base path', () => { - expect(resolver.resolve('http://www.foo.com/baz/', 'bar')).toEqual('http://www.foo.com/baz/bar'); - expect(resolver.resolve('http://www.foo.com/baz/', './bar')).toEqual('http://www.foo.com/baz/bar'); - }); - - it('should support ".." in the path', () => { - expect(resolver.resolve('http://www.foo.com/baz/', '../bar')).toEqual('http://www.foo.com/bar'); - expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar')).toEqual('http://www.foo.com/1/bar'); - expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar')).toEqual('http://www.foo.com/1/2/biz/bar'); - expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar')).toEqual('http://www.foo.com/bar'); - }); - - it('should ignore the base path when the url has a scheme', () => { - expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com')).toEqual('http://www.bar.com'); - }) - - it('should throw when the url start with "/"', () => { - expect(() => { - resolver.resolve('http://www.foo.com/1/2', '/test'); - }).toThrowError(); - }); - }); -}