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

Side by Side Diff: samples/pop_pop_win/web/platform_web.dart

Issue 242443008: samples/pop_pop_win: now based on StageXL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tiny nit Created 6 years, 8 months 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 | « samples/pop_pop_win/web/index.html ('k') | samples/pop_pop_win/web/resources/audio/audio.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library ppw_platform_web; 1 library ppw_platform_web;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:html'; 4 import 'dart:html';
5 import 'package:pop_pop_win/platform_target.dart'; 5 import 'package:pop_pop_win/platform_target.dart';
6 6
7 class PlatformWeb extends PlatformTarget { 7 class PlatformWeb extends PlatformTarget {
8 static const String _BIG_HASH = '#big';
9 static const String _ABOUT_HASH = '#about'; 8 static const String _ABOUT_HASH = '#about';
9 bool _sizeAccessed = false;
10 10
11 final StreamController _aboutController = new StreamController(sync: true); 11 final StreamController _aboutController = new StreamController(sync: true);
12 12
13 PlatformWeb(): super.base() { 13 PlatformWeb() : super.base() {
14 window.onPopState.listen((args) => _processUrlHash()); 14 window.onPopState.listen((args) => _processUrlHash());
15 } 15 }
16 16
17 @override 17 @override
18 Future clearValues() { 18 Future clearValues() {
19 window.localStorage.clear(); 19 window.localStorage.clear();
20 return new Future.value(); 20 return new Future.value();
21 } 21 }
22 22
23 @override 23 @override
24 Future setValue(String key, String value) { 24 Future setValue(String key, String value) {
25 window.localStorage[key] = value; 25 window.localStorage[key] = value;
26 return new Future.value(); 26 return new Future.value();
27 } 27 }
28 28
29 @override 29 @override
30 Future<String> getValue(String key) => 30 Future<String> getValue(String key) =>
31 new Future.value(window.localStorage[key]); 31 new Future.value(window.localStorage[key]);
32 32
33 bool get renderBig => _urlHash == _BIG_HASH; 33 int get size {
34 _sizeAccessed = true;
35 var hash = (_urlHash == null) ? '7' : _urlHash;
36 hash = hash.replaceAll('#', '');
37 return int.parse(hash, onError: (e) => 7);
38 }
34 39
35 bool get showAbout => _urlHash == _ABOUT_HASH; 40 bool get showAbout => _urlHash == _ABOUT_HASH;
36 41
37 Stream get aboutChanged => _aboutController.stream; 42 Stream get aboutChanged => _aboutController.stream;
38 43
39 void toggleAbout([bool value]) { 44 void toggleAbout([bool value]) {
40 var loc = window.location; 45 var loc = window.location;
41 // ensure we treat empty hash like '#', which makes comparison easy later 46 // ensure we treat empty hash like '#', which makes comparison easy later
42 var hash = loc.hash.length == 0 ? '#' : loc.hash; 47 var hash = loc.hash.length == 0 ? '#' : loc.hash;
43 48
(...skipping 10 matching lines...) Expand all
54 _aboutController.add(null); 59 _aboutController.add(null);
55 } 60 }
56 61
57 String get _urlHash => window.location.hash; 62 String get _urlHash => window.location.hash;
58 63
59 void _processUrlHash() { 64 void _processUrlHash() {
60 var loc = window.location; 65 var loc = window.location;
61 var hash = loc.hash; 66 var hash = loc.hash;
62 var href = loc.href; 67 var href = loc.href;
63 68
64 final History history = window.history;
65 switch (hash) { 69 switch (hash) {
66 case "#reset": 70 case "#reset":
67 assert(href.endsWith(hash)); 71 assert(href.endsWith(hash));
68 var newLoc = href.substring(0, href.length - hash.length); 72 var newLoc = href.substring(0, href.length - hash.length);
69 73
70 window.localStorage.clear(); 74 window.localStorage.clear();
71 75
72 loc.replace(newLoc); 76 loc.replace(newLoc);
73 break; 77 break;
74 case _BIG_HASH:
75 if (!renderBig) loc.reload();
76 break;
77 case _ABOUT_HASH: 78 case _ABOUT_HASH:
78 _aboutController.add(null); 79 _aboutController.add(null);
79 break; 80 break;
81 default:
82 if (hash.isNotEmpty && _sizeAccessed) {
83 loc.reload();
84 }
85 break;
80 } 86 }
81 } 87 }
82 } 88 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/web/index.html ('k') | samples/pop_pop_win/web/resources/audio/audio.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698