forked from dart-lang/site-www
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DartPad to the front page (dart-lang#1805)
* add DartPad to the bottom of the front page * add use select element to select the example * move copyright headers * add pi computation sample * Hide DartPad on front page if there is no mobile browser * Change try dart link, update copy on front page * move period outside of <a> tag * remove no-automatic-external * remove site url check for try dart nav item * add border to iframe * update front page samples * compile new front page samples * fix triple-quoted strings
- Loading branch information
Showing
11 changed files
with
2,978 additions
and
2 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
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,11 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
# Remove the following pattern if you wish to check in your lock file | ||
pubspec.lock | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ |
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,4 @@ | ||
If you modify the Dart code, don't forget to regenerate the JavaScript: | ||
|
||
cd src/_packages/dartpad_picker | ||
./compile.sh |
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,14 @@ | ||
# Defines a default set of lint rules enforced for | ||
# projects at Google. For details and rationale, | ||
# see https://github.com/dart-lang/pedantic#enabled-lints. | ||
include: package:pedantic/analysis_options.yaml | ||
|
||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. | ||
# Uncomment to specify additional rules. | ||
# linter: | ||
# rules: | ||
# - camel_case_types | ||
|
||
analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** |
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,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
pub get | ||
pub run build_runner build --release --output out | ||
cp out/web/dartpad_picker_main.dart.js ../../assets/dash/js | ||
rm -rf out/ |
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,67 @@ | ||
// Copyright 2019 the Dart project authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file. | ||
|
||
import 'dart:html'; | ||
|
||
class Snippet { | ||
final String name; | ||
final String sourceCode; | ||
|
||
Snippet(this.name, this.sourceCode); | ||
} | ||
|
||
class DartPadPicker { | ||
final String dartPadUrl; | ||
final Element iFrameHost; | ||
final SelectElement selectElement; | ||
final List<Snippet> snippets; | ||
IFrameElement _iFrameElement; | ||
int _selected = 0; | ||
|
||
DartPadPicker(this.iFrameHost, this.selectElement, this.snippets, | ||
{this.dartPadUrl = 'https://dartpad.dev/experimental/'}) { | ||
_initSelectElement(); | ||
_initDartPad(); | ||
} | ||
|
||
Snippet get _selectedSnippet => snippets[_selected]; | ||
|
||
Map<String, dynamic> get _sourceCodeMessage => { | ||
'sourceCode': { | ||
'main.dart': _selectedSnippet.sourceCode, | ||
}, | ||
'type': 'sourceCode' | ||
}; | ||
|
||
void _initSelectElement() { | ||
for (var i = 0; i < snippets.length; i++) { | ||
var snippet = snippets[i]; | ||
var option = OptionElement(value: '$i')..text = snippet.name; | ||
selectElement.children.add(option); | ||
} | ||
selectElement.onChange.listen((Event e) { | ||
_selected = selectElement.selectedIndex; | ||
_sendSourceCode(); | ||
}); | ||
} | ||
|
||
void _initDartPad() { | ||
_iFrameElement = IFrameElement() | ||
..src = iFrameSrc(theme: 'dark', mode: 'dart'); | ||
iFrameHost.children.add(_iFrameElement); | ||
window.addEventListener('message', (dynamic e) { | ||
if (e.data['type'] == 'ready') { | ||
_sendSourceCode(); | ||
} | ||
}); | ||
} | ||
|
||
void _sendSourceCode() { | ||
_iFrameElement.contentWindow.postMessage(_sourceCodeMessage, '*'); | ||
} | ||
|
||
String iFrameSrc({String theme, String mode}) { | ||
return '${dartPadUrl}embed-new-$mode.html?theme=$theme'; | ||
} | ||
} |
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,8 @@ | ||
name: dartpad_picker | ||
environment: | ||
sdk: '>=2.4.0 <3.0.0' | ||
|
||
dev_dependencies: | ||
build_runner: ^1.5.0 | ||
build_web_compilers: ^2.1.0 | ||
pedantic: ^1.7.0 |
Oops, something went wrong.