Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: pkg/observe/lib/html.dart

Issue 817483003: delete observe from the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/observe/PATENTS ('k') | pkg/observe/lib/mirrors_used.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // TODO(jmesserly): can we handle this more elegantly?
6 // In general, it seems like we want a convenient way to take a Stream plus a
7 // getter and convert this into an Observable.
8
9 /// Helpers for exposing dart:html as observable data.
10 library observe.html;
11
12 import 'dart:html';
13
14 import 'observe.dart';
15
16 /// An observable version of [window.location.hash].
17 final ObservableLocationHash windowLocation = new ObservableLocationHash._();
18
19 class ObservableLocationHash extends ChangeNotifier {
20 Object _currentHash;
21
22 ObservableLocationHash._() {
23 // listen on changes to #hash in the URL
24 // Note: listen on both popState and hashChange, because IE9 doesn't support
25 // history API. See http://dartbug.com/5483
26 // TODO(jmesserly): only listen to these if someone is listening to our
27 // changes.
28 window.onHashChange.listen(_notifyHashChange);
29 window.onPopState.listen(_notifyHashChange);
30
31 _currentHash = hash;
32 }
33
34 @reflectable String get hash => window.location.hash;
35
36 /// Pushes a new URL state, similar to the affect of clicking a link.
37 /// Has no effect if the [value] already equals [window.location.hash].
38 @reflectable void set hash(String value) {
39 if (value == hash) return;
40
41 window.history.pushState(null, '', value);
42 _notifyHashChange(null);
43 }
44
45 void _notifyHashChange(_) {
46 var oldValue = _currentHash;
47 _currentHash = hash;
48 notifyPropertyChange(#hash, oldValue, _currentHash);
49 }
50 }
51
52 /// *Deprecated* use [CssClassSet.toggle] instead.
53 ///
54 /// Add or remove CSS class [className] based on the [value].
55 @deprecated
56 void updateCssClass(Element element, String className, bool value) {
57 if (value == true) {
58 element.classes.add(className);
59 } else {
60 element.classes.remove(className);
61 }
62 }
63
64 /// *Deprecated* use `class="{{ binding }}"` in your HTML instead. It will also
65 /// work on a `<polymer-element>`.
66 ///
67 /// Bind a CSS class to the observable [object] and property [path].
68 @deprecated
69 PathObserver bindCssClass(Element element, String className,
70 Observable object, String path) {
71
72 callback(value) {
73 updateCssClass(element, className, value);
74 }
75
76 var obs = new PathObserver(object, path);
77 callback(obs.open(callback));
78 return obs;
79 }
OLDNEW
« no previous file with comments | « pkg/observe/PATENTS ('k') | pkg/observe/lib/mirrors_used.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698