Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit 21a1092

Browse files
committed
Remove trailing spaces #174
1 parent 74a66d2 commit 21a1092

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

Diff for: .editorconfig

-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ end_of_line = lf
1414
charset = utf-8
1515
trim_trailing_whitespace = true
1616
insert_final_newline = true
17-
18-
[*.md]
19-
trim_trailing_whitespace = false

Diff for: src/documents/articles/introduction-to-custom-elements.html.md

+47-47
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ level features to structure sites and apps. But it also is easy to end up with
1313
div soup once you start implementing a complex component using native HTML tags.
1414
What if the web platform could allow you to create your original component?
1515
What if you can give it an arbitrary tag name? What if you can extend features
16-
of an existing HTML tag?
16+
of an existing HTML tag?
1717
Custom Elements allow you to do those things.
1818

1919
<!-- Excerpt -->
@@ -38,12 +38,12 @@ its tag name as the first argument.
3838
var XComponent = document.registerElement('x-component');
3939
```
4040

41-
Now you can use `<x-component>`  wherever you want in the document.
41+
Now you can use `<x-component>`  wherever you want in the document.
4242

4343
```
4444
<x-component></x-component>
4545
```
46-
46+
4747
Note: `<x-component>` can appear in the document before the definition of the
4848
custom element execution. See
4949
[HTML5Rocks article](http://www.html5rocks.com/en/tutorials/webcomponents/customelements/)
@@ -62,13 +62,13 @@ polyfill it.
6262

6363
You need to have at least one '`-`' inside the name of a custom element. Any tag
6464
names without '`-`' will result in an error.
65-
66-
Good
65+
66+
Good
6767

6868
* x-component
6969
* x-web-component
7070

71-
Bad
71+
Bad
7272

7373
* web_component
7474
* xelement
@@ -84,30 +84,30 @@ var XComponent = document.registerElement('x-component');
8484
var dom = new XComponent();
8585
document.body.appendChild(dom);
8686
```
87-
88-
The above example is using `new` to instantiate a custom element.
87+
88+
The above example is using `new` to instantiate a custom element.
8989

9090
```
9191
document.registerElement('x-component');
9292
var dom = document.createElement('x-component');
9393
document.body.appendChild(dom);
9494
```
95-
96-
This example uses `document.createElement()` to instantiate a custom element.
95+
96+
This example uses `document.createElement()` to instantiate a custom element.
9797

9898
# Adding features to a custom element
9999

100100
Being able to use a custom tag name itself is fine, but it doesn't do much.
101101
Let's add some features to the element.
102-
102+
103103
In order to add features to a custom element, you first need to create a basic
104104
prototype object by calling `Object.create()` with `HTMLElement.prototype` as an
105105
argument. This gives you an empty prototype object with the basic HTML element
106106
feature set in its prototype chain. Add any functions and properties you want to
107107
the prototype object, then pass your prototype to document.registerElement as
108108
shown below:
109109

110-
```
110+
```
111111
var proto = Object.create(HTMLElement.prototype);
112112
proto.name = 'Custom Element';
113113
proto.alert = function() {
@@ -124,7 +124,7 @@ Let's see what's going on in a custom element using Chrome DevTools. Use the
124124
"Elements" panel to inspect the `x-component` tag we just created. You can see
125125
the `x-component` is an instance of a `x-component` prototype which is an
126126
instance of the `HTMLElement` prototype.
127-
127+
128128
![Custom Element Structure](/img/stories/customelements-inherit.png)
129129

130130
# Type Extension Custom Element
@@ -133,17 +133,17 @@ You can create a custom element that extends a native HTML element's features.
133133
This is called a Type Extension Custom Element. To use the element, use the
134134
original tag and specify the custom tag name using the '`is`' attribute.
135135

136-
```
136+
```
137137
<div is="x-component"></div>
138138
```
139-
139+
140140
To define a type extension:
141141

142-
- Create the base prototype object using the prototype of the extended element,
142+
- Create the base prototype object using the prototype of the extended element,
143143
instead of HTMLElement.
144-
- Add an `extends` key in the second argument to `document.registerElement()`,
144+
- Add an `extends` key in the second argument to `document.registerElement()`,
145145
specifying the *tag name* of the extended element.
146-
146+
147147
Following is an example code when extending the `input` element:
148148

149149
```
@@ -152,12 +152,12 @@ var XComponent = document.registerElement('x-component', {
152152
 prototype: Object.create(HTMLInputElement.prototype)
153153
});
154154
```
155-
155+
156156
Notice that it `extends: 'input'` and its prototype is based on
157157
`HTMLInputElement` instead of `HTMLElement`. Now you can use
158158
`<input is="x-component">` inside your document. By doing so, you can have
159159
extended APIs on top of basic `input` element's features.
160-
160+
161161
Note: You may wonder what happens if you set different elements for `'extends`'
162162
and '`prototype`'. Yes, it is possible and may cause unexpected results. But as
163163
far as I have experimented, you won't get any valuable outcome.
@@ -166,60 +166,60 @@ far as I have experimented, you won't get any valuable outcome.
166166

167167
So what's the point of Type Extension Custom Element? Let's look at a great
168168
existing example at the GitHub website.
169-
170-
![relative-time type extension](/img/stories/customelements-relativetime.png)
171-
169+
170+
![relative-time type extension](/img/stories/customelements-relativetime.png)
171+
172172
GitHub has a many components that displays date and time. Notice they are not
173173
absolute dates/times but relative to the browser's current time.
174174
You should be able to imagine how to calculate that but GitHub is doing that
175175
using Type Extension Custom Element with [`time-
176176
elements`](https://github.com/github/time-elements).
177-
178-
Let's look into how it works.
179-
180-
![time element](/img/stories/customelements-time.png)
181-
182-
There are four things you should notice:
177+
178+
Let's look into how it works.
179+
180+
![time element](/img/stories/customelements-time.png)
181+
182+
There are four things you should notice:
183183

184184
* `time` tag is used as a base element
185185
* `datetime` attribute indicates an absolute date/time
186186
* `relative-time` is specified as a type extension
187187
* `TextContent` indicates a relative date/time
188-
188+
189189
This is done by calculating a relative date/time out from an absolute date/time
190190
(`datetime`) attribute on the fly as a type extension.
191-
191+
192192
The benefit of using Type Extension Custom Element is that even if JavaScript is
193193
turned off or the browser doesn't support Custom Elements (including polyfill),
194194
the `time` element will still show the date/time information as a fallback
195195
keeping its semantics. Try using DevTools and turning off JavaScript; you'll
196196
notice it shows absolute dates and times.
197-
197+
198198
Read webcomponents.org's
199199
[How GitHub is using Web Components in production](http://webcomponents.org/articles/interview-with-joshua-peek/)
200-
for more details about `time-elements`.
200+
for more details about `time-elements`.
201201

202202
# Lifecycle callbacks
203203

204204
I mentioned the `relative-time` custom element inserts a relative date/time into
205205
`TextContent` on the fly. But when does that happen? You can define functions to
206206
be called when certain events happened on Custom Elements, which are called
207207
"lifecycle callbacks".
208-
209-
Here's the list of lifecycle callbacks:
210-
211-
**.createdCallback()**
208+
209+
Here's the list of lifecycle callbacks:
210+
211+
**.createdCallback()**
212212
Called after the element is created.
213213

214-
**.attachedCallback()**
214+
**.attachedCallback()**
215215
Called when the element is attached to the document
216216

217-
**.detachedCallback()**
217+
**.detachedCallback()**
218218
Called when the element is detached from the document.
219219

220-
**.attributeChangedCallback()**
220+
**.attributeChangedCallback()**
221221
Called when one of attributes of the element is changed.
222-
222+
223223
In case of `relative-time`, `.createdCallback()` and
224224
`.attributeChangedCallback()` are hooked up to insert a relative date/time to
225225
`TextContent`.
@@ -229,7 +229,7 @@ In case of `relative-time`, `.createdCallback()` and
229229
To use lifecycle callbacks, just define the functions as properties of a
230230
prototype object when registering a custom element.
231231

232-
```
232+
```
233233
var proto = Object.create(HTMLElement.prototype);
234234
proto.createdCallback = function() {
235235
 var div = document.createElement('div');
@@ -254,7 +254,7 @@ read the respective articles
254254
([Template](http://webcomponents.org/articles/introduction-to-template-element),
255255
[Shadow DOM](http://webcomponents.org/articles/introduction-to-shadow-dom))
256256
written previously.
257-
257+
258258
**HTML**
259259
```
260260
<!-- Template Definition -->
@@ -291,7 +291,7 @@ var XComponent = document.registerElement('x-component', {
291291
 prototype: proto
292292
});
293293
```
294-
294+
295295
[Here's a live example.](http://jsbin.com/yugoka/3/edit?html,js,output)
296296

297297
# Supported browsers
@@ -309,9 +309,9 @@ from [platform.js](https://github.com/Polymer/platform)).
309309
So that's the Custom Elements.
310310
[As you may have noticed](http://webcomponents.org/articles/interview-with-joshua-peek/)
311311
, Custom Elements are used in the production of GitHub supporting IE9 by using
312-
polyfill. Now is your time to try this feature.
313-
314-
If you are interested in learning more about the Custom Elements, head over to:
312+
polyfill. Now is your time to try this feature.
313+
314+
If you are interested in learning more about the Custom Elements, head over to:
315315

316316
* [Custom Elements: defining new elements in HTML - HTML5Rocks](http://goo.gl/ozdC4Q)
317317
* [Custom Elements spec](http://w3c.github.io/webcomponents/spec/custom/)

0 commit comments

Comments
 (0)