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

Side by Side Diff: src/site/docs/tutorials/polymer-intro/index.markdown

Issue 51473002: update polymer related info to 0.8.7 (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: tweaks as per KW's comment Created 7 years, 1 month 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
« no previous file with comments | « src/site/docs/tutorials/polymer-intro/images/template-code.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 --- 1 ---
2 layout: default 2 layout: default
3 title: "Define a Custom Element" 3 title: "Define a Custom Element"
4 description: "Create a custom HTML element using Polymer." 4 description: "Create a custom HTML element using Polymer."
5 has-permalinks: true 5 has-permalinks: true
6 tutorial: 6 tutorial:
7 id: polymer-intro 7 id: polymer-intro
8 next: fetchdata 8 next: fetchdata
9 next-title: "Fetch Data Dynamically" 9 next-title: "Fetch Data Dynamically"
10 prev: shared-pkgs 10 prev: shared-pkgs
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 <h3>Create a custom HTML element using Polymer</h3> 42 <h3>Create a custom HTML element using Polymer</h3>
43 </div> 43 </div>
44 44
45 A custom element is an HTML element you can define yourself, 45 A custom element is an HTML element you can define yourself,
46 encapsulating appearance and/or behavior 46 encapsulating appearance and/or behavior
47 within semantically meaningful HTML. 47 within semantically meaningful HTML.
48 48
49 <aside class="alert"> 49 <aside class="alert">
50 <strong>Version Note:</strong> The code sample and the content 50 <strong>Version Note:</strong> The code sample and the content
51 of this tutorial are compatible with 51 of this tutorial are compatible with
52 <a href="https://pub.dartlang.org/packages/polymer#versions">polymer.dart 0.8.1< /a>. 52 <a href="https://pub.dartlang.org/packages/polymer#versions">polymer.dart 0.8.7< /a>.
53 </aside> 53 </aside>
54 54
55 <aside class="alert alert-info"> 55 <aside class="alert alert-info">
56 Custom elements are one feature of 56 Custom elements are one feature of
57 <a href="http://www.polymer-project.org/" 57 <a href="http://www.polymer-project.org/"
58 target="_blank">Polymer</a>, 58 target="_blank">Polymer</a>,
59 a new type of library for the web based on Web Components. 59 a new type of library for the web based on Web Components.
60 <a href="http://www.dartlang.org/polymer-dart/" 60 <a href="http://www.dartlang.org/polymer-dart/"
61 target="_blank">Polymer.dart</a> 61 target="_blank">Polymer.dart</a>
62 is the Dart implementation of Polymer. 62 is the Dart implementation of Polymer.
63 (Note: Polymer supersedes Web UI.) 63 (Note: Polymer supersedes Web UI.)
64 </aside> 64 </aside>
65 65
66 * [An example](#an-example) 66 * [An example](#an-example)
67 * [Installing Polymer.dart](#getting-polymer-dart) 67 * [Installing Polymer.dart](#getting-polymer-dart)
68 * [Including Polymer.dart in your application](#bootstrap) 68 * [Including Polymer.dart in your application](#bootstrap)
69 * [Initializing Polymer](#initializing-polymer)
69 * [Instantiating a custom element](#instantiating) 70 * [Instantiating a custom element](#instantiating)
70 * [Defining a custom element](#define-element) 71 * [Defining a custom element](#define-element)
71 * [Providing a template for the custom element](#providing-a-template) 72 * [Providing a template for the custom element](#providing-a-template)
72 * [Providing a script for the custom element](#providing-a-script) 73 * [Providing a script for the custom element](#providing-a-script)
73 * [Overiding life-cycle methods](#life-cycle-methods) 74 * [Overiding life-cycle methods](#life-cycle-methods)
74 * [Using data binding](#data-binding) 75 * [Using data binding](#data-binding)
75 * [Setting up event handlers declaratively](#event-handlers) 76 * [Setting up event handlers declaratively](#event-handlers)
76 * [Styling a custom element](#scoped-css) 77 * [Styling a custom element](#scoped-css)
77 * [Other resources](#other-resources) 78 * [Other resources](#other-resources)
78 * [What next?](#what-next) 79 * [What next?](#what-next)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 If you are using command line tools, 177 If you are using command line tools,
177 you can run it with the command `pub install`. 178 you can run it with the command `pub install`.
178 179
179 ##Including Polymer.dart in your application {#bootstrap} 180 ##Including Polymer.dart in your application {#bootstrap}
180 181
181 To use Polymer.dart features such as custom elements, 182 To use Polymer.dart features such as custom elements,
182 you need to include Polymer in both 183 you need to include Polymer in both
183 the HTML side and the Dart side of your app. 184 the HTML side and the Dart side of your app.
184 185
185 * In the primary HTML file for your app, 186 * In the primary HTML file for your app,
186 include `packages/polymer/boot.js` 187 include the `packages/browser/dart.js` bootstrap script
187 in the &lt;head&gt; section. 188 in the &lt;head&gt; section.
188 When using this script,
189 you do not need to define a top-level `main()` function,
190 although you can.
191 **Note:** Use this script instead of `packages/browser/dart.js`.
192 189
193 ![Include the Polymer bootstrap script](images/bootstrap-script.png) 190 ![Include the Polymer bootstrap script](images/bootstrap-script.png)
194 191
195 * In your Dart code, import the Polymer library: 192 * In your Dart code, import the Polymer library:
196 193
197 ![Import the Polymer library](images/polymer-library.png) 194 ![Import the Polymer library](images/polymer-library.png)
198 195
196 ##Initializing Polymer {#initializing-polymer}
197
198 The `main()` function for the stopwatch example, defined
199 in `index.dart`, calls `initPolymer()` to initialize Polymer.
Kathy Walrath 2013/10/30 17:00:50 index.dart or index.html? This is the only mention
200
201 {% prettify html %}
202 import 'package:polymer/polymer.dart';
203
204 void main() {
205 initPolymer();
sethladd 2013/10/30 17:02:14 According to Messerly, this isn't the best practic
206 }
207 {% endprettify %}
208
209 You can initialize Polymer using other techniques,
210 but this is the most straightforward.
Kathy Walrath 2013/10/30 17:00:50 what is "this"? calling initPolymer()? having the
211
199 ##Instantiating a custom element {#instantiating} 212 ##Instantiating a custom element {#instantiating}
200 213
201 To create an instance of a custom element, 214 To create an instance of a custom element,
202 use the name of the custom element just as you would any normal HTML tag. 215 use the name of the custom element just as you would any normal HTML tag.
203 In this example, the tag name is `tute-stopwatch`. 216 In this example, the tag name is `tute-stopwatch`.
204 217
205 ![Instantiate a custom element with a custom tag](images/polymer-element-instant iation.png) 218 ![Instantiate a custom element with a custom tag](images/polymer-element-instant iation.png)
206 219
207 Using best practices, 220 Using best practices,
208 the custom element definition is in a separate file. 221 the custom element definition is in a separate file.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ![The script code for the tute-stopwatch element](images/dart-script-code.png) 320 ![The script code for the tute-stopwatch element](images/dart-script-code.png)
308 321
309 Any Dart class that backs a Polymer element must subclass PolymerElement. 322 Any Dart class that backs a Polymer element must subclass PolymerElement.
310 323
311 {% comment %} 324 {% comment %}
312 [xx: more about PolymerElement] 325 [xx: more about PolymerElement]
313 {% endcomment %} 326 {% endcomment %}
314 327
315 The class can respond to life-cycle milestones 328 The class can respond to life-cycle milestones
316 by overriding [life-cycle methods](#life-cycle-methods). 329 by overriding [life-cycle methods](#life-cycle-methods).
317 For example, the TuteStopwatch class overrides the `inserted()` 330 For example, the TuteStopwatch class overrides the `enteredView()`
318 method&mdash;which is called when the element is inserted 331 method&mdash;which is called when the element is inserted
319 into the DOM&mdash;to initialize the app. 332 into the DOM&mdash;to initialize the app.
320 333
321 The `start()` method is an event handler for the **Start** button. 334 The `start()` method is an event handler for the **Start** button.
322 The event handler is declaratively connected to the button. 335 The event handler is declaratively connected to the button.
323 Refer to [Setting up event handlers declaratively](#event-handlers) to see how. 336 Refer to [Setting up event handlers declaratively](#event-handlers) to see how.
324 337
325 ##Overriding life-cycle methods {#life-cycle-methods} 338 ##Overriding life-cycle methods {#life-cycle-methods}
326 339
327 A custom element has four life-cycle methods 340 A custom element has four life-cycle methods
328 that it can override: 341 that it can override:
329 342
330 |---|---| 343 |---|---|
331 | `created()` | Called when an instance of a custom element is created. | 344 | `created()` | Called when an instance of a custom element is created. |
332 | `inserted()` | Called when an instance of a custom element is inserted into th e DOM. | 345 | `enteredView()` | Called when an instance of a custom element is inserted into the DOM. |
333 | `removed()` | Called when an instance of a custom element is removed from the DOM. | 346 | `leftView()` | Called when an instance of a custom element is removed from the DOM. |
334 | `attributeChanged()` | Called when an attribute, such as `class`, of an instan ce of the custom element is added, changed, or removed. | 347 | `attributeChanged()` | Called when an attribute, such as `class`, of an instan ce of the custom element is added, changed, or removed. |
335 {: .table} 348 {: .table}
336 349
337 You can override any of these life-cycle methods. 350 You can override any of these life-cycle methods.
338 The overriding method 351 The overriding method
339 *must* call the super class method first. 352 *must* call the super class method first.
340 353
341 The Stopwatch app overrides the `inserted()` method because it 354 The Stopwatch app overrides the `enteredView()` method because it
342 needs a reference to each of the three buttons 355 needs a reference to each of the three buttons
343 so that it can enable and disable them. 356 so that it can enable and disable them.
344 When a tute-stopwatch custom element is inserted into the DOM 357 When a tute-stopwatch custom element is inserted into the DOM
345 the buttons have been created, so the references to them 358 the buttons have been created, so the references to them
346 will be available when the inserted() method is called. 359 will be available when the enteredView() method is called.
347 360
348 {% prettify dart %} 361 {% prettify dart %}
349 void inserted() { 362 void enteredView() {
350 super.inserted(); 363 super.enteredView();
351 startButton = $['startButton']; 364 startButton = $['startButton'];
352 stopButton = $['stopButton']; 365 stopButton = $['stopButton'];
353 resetButton = $['resetButton']; 366 resetButton = $['resetButton'];
354 367
355 stopButton.disabled = true; 368 stopButton.disabled = true;
356 resetButton.disabled = true; 369 resetButton.disabled = true;
357 } 370 }
358 {% endprettify %} 371 {% endprettify %}
359 372
360 The code uses _automatic node finding_, a Polymer feature, 373 The code uses _automatic node finding_, a Polymer feature,
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 525
513 The next tutorial, 526 The next tutorial,
514 [Fetch Data Dynamically](/docs/tutorials/fetchdata/), 527 [Fetch Data Dynamically](/docs/tutorials/fetchdata/),
515 shows you how to fetch data 528 shows you how to fetch data
516 and use JSON to encode and decode 529 and use JSON to encode and decode
517 that data. 530 that data.
518 531
519 {% endcapture %} 532 {% endcapture %}
520 533
521 {% include tutorial.html %} 534 {% include tutorial.html %}
OLDNEW
« no previous file with comments | « src/site/docs/tutorials/polymer-intro/images/template-code.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698