Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit c644d6a

Browse files
committed
docs(icon): documentation refinement and cleanup
- remove reference to whitelist - fix typos and formatting - fix syntax issues with examples - fix invalid Closure types
1 parent b88e637 commit c644d6a

File tree

1 file changed

+101
-118
lines changed

1 file changed

+101
-118
lines changed

src/components/icon/js/iconService.js

+101-118
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*
1919
* @description
2020
* `$mdIconProvider` is used only to register icon IDs with URLs. These configuration features allow
21-
* icons and icon sets to be pre-registered and associated with source URLs **before** the `<md-icon />`
22-
* directives are compiled.
21+
* icons and icon sets to be pre-registered and associated with source URLs **before** the
22+
* `<md-icon />` directives are compiled.
2323
*
2424
* If using font-icons, the developer is responsible for loading the fonts.
2525
*
@@ -29,23 +29,24 @@
2929
* that URL is used to on-demand load and parse the SVG dynamically.
3030
*
3131
* The `$templateRequest` service expects the icons source to be loaded over trusted URLs.<br/>
32-
* This means, when loading icons from an external URL, you have to trust the URL in the `$sceDelegateProvider`.
32+
* This means, when loading icons from an external URL, you have to trust the URL in the
33+
* `$sceDelegateProvider`.
3334
*
3435
* <hljs lang="js">
3536
* app.config(function($sceDelegateProvider) {
3637
* $sceDelegateProvider.resourceUrlWhitelist([
37-
* // Adding 'self' to the whitelist, will allow requests from the current origin.
38+
* // Adding 'self' to the allow-list, will allow requests from the current origin.
3839
* 'self',
3940
* // Using double asterisks here, will allow all URLs to load.
40-
* // We recommend to only specify the given domain you want to allow.
41+
* // However, we recommend only specifying the given domain you want to allow.
4142
* '**'
4243
* ]);
4344
* });
4445
* </hljs>
4546
*
4647
* Read more about the [$sceDelegateProvider](https://docs.angularjs.org/api/ng/provider/$sceDelegateProvider).
4748
*
48-
* **Notice:** Most font-icons libraries do not support ligatures (for example `fontawesome`).<br/>
49+
* **Notice:** Most font-icon libraries do not support ligatures (for example `fontawesome`).<br/>
4950
* In such cases you are not able to use the icon's ligature name - Like so:
5051
*
5152
* <hljs lang="html">
@@ -64,77 +65,71 @@
6465
* @usage
6566
* <hljs lang="js">
6667
* app.config(function($mdIconProvider) {
67-
*
68-
* // Configure URLs for icons specified by [set:]id.
69-
*
70-
* $mdIconProvider
71-
* .defaultFontSet( 'fa' ) // This sets our default fontset className.
72-
* .defaultIconSet('my/app/icons.svg') // Register a default set of SVG icons
73-
* .iconSet('social', 'my/app/social.svg') // Register a named icon set of SVGs
74-
* .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
75-
* .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
76-
* });
68+
*
69+
* // Configure URLs for icons specified by [set:]id.
70+
* $mdIconProvider
71+
* .defaultFontSet( 'fa' ) // This sets our default fontset className.
72+
* .defaultIconSet('my/app/icons.svg') // Register a default set of SVG icons
73+
* .iconSet('social', 'my/app/social.svg') // Register a named icon set of SVGs
74+
* .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
75+
* .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
76+
* });
7777
* </hljs>
7878
*
79-
* SVG icons and icon sets can be easily pre-loaded and cached using either (a) a build process or (b) a runtime
80-
* **startup** process (shown below):
79+
* SVG icons and icon sets can be easily pre-loaded and cached using either (a) a build process or
80+
* (b) a runtime **startup** process (shown below):
8181
*
8282
* <hljs lang="js">
8383
* app.config(function($mdIconProvider) {
84-
*
85-
* // Register a default set of SVG icon definitions
86-
* $mdIconProvider.defaultIconSet('my/app/icons.svg')
87-
*
88-
* })
89-
* .run(function($templateRequest){
90-
*
91-
* // Pre-fetch icons sources by URL and cache in the $templateCache...
92-
* // subsequent $templateRequest calls will look there first.
93-
*
94-
* var urls = [ 'imy/app/icons.svg', 'img/icons/android.svg'];
95-
*
96-
* angular.forEach(urls, function(url) {
97-
* $templateRequest(url);
98-
* });
99-
*
100-
* });
84+
*
85+
* // Register a default set of SVG icon definitions
86+
* $mdIconProvider.defaultIconSet('my/app/icons.svg')
87+
* })
88+
* .run(function($templateRequest) {
89+
*
90+
* // Pre-fetch icons sources by URL and cache in the $templateCache...
91+
* // subsequent $templateRequest calls will look there first.
92+
* var urls = [ 'imy/app/icons.svg', 'img/icons/android.svg'];
93+
*
94+
* angular.forEach(urls, function(url) {
95+
* $templateRequest(url);
96+
* });
97+
* });
10198
*
10299
* </hljs>
103100
*
104101
* > <b>Note:</b> The loaded SVG data is subsequently cached internally for future requests.
105-
*
106102
*/
107103

108104
/**
109105
* @ngdoc method
110106
* @name $mdIconProvider#icon
111107
*
112108
* @description
113-
* Register a source URL for a specific icon name; the name may include optional 'icon set' name prefix.
114-
* These icons will later be retrieved from the cache using `$mdIcon( <icon name> )`
109+
* Register a source URL for a specific icon name; the name may include optional 'icon set' name
110+
* prefix. These icons will later be retrieved from the cache using `$mdIcon(<icon name>)`.
115111
*
116112
* @param {string} id Icon name/id used to register the icon
117113
* @param {string} url specifies the external location for the data file. Used internally by
118-
* `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
119-
* was configured.
114+
* `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
115+
* was configured.
120116
* @param {number=} viewBoxSize Sets the width and height the icon's viewBox.
121-
* It is ignored for icons with an existing viewBox. Default size is 24.
117+
* It is ignored for icons with an existing viewBox. Default size is 24.
122118
*
123119
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
124120
*
125121
* @usage
126122
* <hljs lang="js">
127123
* app.config(function($mdIconProvider) {
128-
*
129-
* // Configure URLs for icons specified by [set:]id.
130-
*
131-
* $mdIconProvider
132-
* .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
133-
* .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
134-
* });
135-
* </hljs>
136124
*
125+
* // Configure URLs for icons specified by [set:]id.
126+
* $mdIconProvider
127+
* .icon('android', 'my/app/android.svg') // Register a specific icon (by name)
128+
* .icon('work:chair', 'my/app/chair.svg'); // Register icon in a specific set
129+
* });
130+
* </hljs>
137131
*/
132+
138133
/**
139134
* @ngdoc method
140135
* @name $mdIconProvider#iconSet
@@ -154,127 +149,118 @@
154149
*
155150
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
156151
*
157-
*
158152
* @usage
159153
* <hljs lang="js">
160154
* app.config(function($mdIconProvider) {
161-
*
162-
* // Configure URLs for icons specified by [set:]id.
163-
*
164-
* $mdIconProvider
165-
* .iconSet('social', 'my/app/social.svg') // Register a named icon set
166-
* });
167-
* </hljs>
168155
*
156+
* // Configure URLs for icons specified by [set:]id.
157+
* $mdIconProvider
158+
* .iconSet('social', 'my/app/social.svg'); // Register a named icon set
159+
* });
160+
* </hljs>
169161
*/
162+
170163
/**
171164
* @ngdoc method
172165
* @name $mdIconProvider#defaultIconSet
173166
*
174167
* @description
175168
* Register a source URL for the default 'named' set of icons. Unless explicitly registered,
176-
* subsequent lookups of icons will failover to search this 'default' icon set.
169+
* subsequent lookups of icons will fail over to search this 'default' icon set.
177170
* Icon can be retrieved from this cached, default set using `$mdIcon(<name>)`
178171
*
179172
* @param {string} url specifies the external location for the data file. Used internally by
180173
* `$templateRequest` to load the data or as part of the lookup in `$templateCache` if pre-loading
181174
* was configured.
182175
* @param {number=} viewBoxSize Sets the width and height of the viewBox of all icons in the set.
183-
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same size.
184-
* Default value is 24.
176+
* It is ignored for icons with an existing viewBox. All icons in the icon set should be the same
177+
* size. Default value is 24.
185178
*
186-
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
179+
* @returns {Object} an `$mdIconProvider` reference; used to support method call chains for the API
187180
*
188181
* @usage
189182
* <hljs lang="js">
190183
* app.config(function($mdIconProvider) {
191-
*
192-
* // Configure URLs for icons specified by [set:]id.
193-
*
194-
* $mdIconProvider
195-
* .defaultIconSet( 'my/app/social.svg' ) // Register a default icon set
196-
* });
197-
* </hljs>
198184
*
185+
* // Configure URLs for icons specified by [set:]id.
186+
* $mdIconProvider
187+
* .defaultIconSet('my/app/social.svg'); // Register a default icon set
188+
* });
189+
* </hljs>
199190
*/
191+
200192
/**
201193
* @ngdoc method
202194
* @name $mdIconProvider#defaultFontSet
203195
*
204196
* @description
205-
* When using Font-Icons, AngularJS Material assumes the the Material Design icons will be used and automatically
206-
* configures the default font-set == 'material-icons'. Note that the font-set references the font-icon library
207-
* class style that should be applied to the `<md-icon>`.
197+
* When using Font-Icons, AngularJS Material assumes the the Material Design icons will be used and
198+
* automatically configures the default `font-set == 'material-icons'`. Note that the font-set
199+
* references the font-icon library class style that should be applied to the `<md-icon>`.
208200
*
209201
* Configuring the default means that the attributes
210-
* `md-font-set="material-icons"` or `class="material-icons"` do not need to be explicitly declared on the
211-
* `<md-icon>` markup. For example:
212-
*
213-
* `<md-icon> face </md-icon>`
214-
* will render as
215-
* `<span class="material-icons"> face </span>`, and
202+
* `md-font-set="material-icons"` or `class="material-icons"` do not need to be explicitly declared
203+
* on the `<md-icon>` markup.
216204
*
217-
* `<md-icon md-font-set="fa"> face </md-icon>`
218-
* will render as
219-
* `<span class="fa"> face </span>`
205+
* For example:<br/>
206+
* `<md-icon>face</md-icon>` will render as `<span class="material-icons">face</span>`,<br/>
207+
* and<br/>
208+
* `<md-icon md-font-set="fa">face</md-icon>` will render as `<span class="fa">face</span>`
220209
*
221-
* @param {string} name of the font-library style that should be applied to the md-icon DOM element
210+
* @param {string} name Name of the font-library style that should be applied to the md-icon DOM
211+
* element.
222212
*
223213
* @usage
224214
* <hljs lang="js">
225215
* app.config(function($mdIconProvider) {
226-
* $mdIconProvider.defaultFontSet( 'fa' );
227-
* });
216+
* $mdIconProvider.defaultFontSet('fa');
217+
* });
228218
* </hljs>
229-
*
230219
*/
231220

232221
/**
233222
* @ngdoc method
234223
* @name $mdIconProvider#fontSet
235224
*
236225
* @description
237-
* When using a font set for `<md-icon>` you must specify the correct font classname in the `md-font-set`
238-
* attribute. If the fonset className is really long, your markup may become cluttered... an easy
239-
* solution is to define an `alias` for your fontset:
226+
* When using a font-set for `<md-icon>` you must specify the correct font classname in the
227+
* `md-font-set` attribute. If the font-set className is really long, your markup may become
228+
* cluttered... an easy solution is to define an `alias` for your font-set:
240229
*
241-
* @param {string} alias of the specified fontset.
242-
* @param {string} className of the fontset.
230+
* @param {string} alias Alias name of the specified font-set.
231+
* @param {string} className Name of the class for the font-set.
243232
*
244233
* @usage
245234
* <hljs lang="js">
246235
* app.config(function($mdIconProvider) {
247-
* // In this case, we set an alias for the `material-icons` fontset.
248-
* $mdIconProvider.fontSet('md', 'material-icons');
249-
* });
236+
* // In this case, we set an alias for the `material-icons` font-set.
237+
* $mdIconProvider.fontSet('md', 'material-icons');
238+
* });
250239
* </hljs>
251-
*
252240
*/
253241

254242
/**
255243
* @ngdoc method
256244
* @name $mdIconProvider#defaultViewBoxSize
257245
*
258246
* @description
259-
* While `<md-icon />` markup can also be style with sizing CSS, this method configures
247+
* While `<md-icon>` markup can also be styled with sizing CSS, this method configures
260248
* the default width **and** height used for all icons; unless overridden by specific CSS.
261-
* The default sizing is (24px, 24px).
249+
* The default sizing is (`24px`, `24px`).
262250
* @param {number=} viewBoxSize Sets the width and height of the viewBox for an icon or an icon set.
263251
* All icons in a set should be the same size. The default value is 24.
264252
*
265-
* @returns {obj} an `$mdIconProvider` reference; used to support method call chains for the API
253+
* @returns {Object} an `$mdIconProvider` reference; used to support method call chains for the API
266254
*
267255
* @usage
268256
* <hljs lang="js">
269257
* app.config(function($mdIconProvider) {
270-
*
271-
* // Configure URLs for icons specified by [set:]id.
272-
*
273-
* $mdIconProvider
274-
* .defaultViewBoxSize(36) // Register a default icon size (width == height)
275-
* });
276-
* </hljs>
277258
*
259+
* // Configure URLs for icons specified by [set:]id.
260+
* $mdIconProvider
261+
* .defaultViewBoxSize(36); // Register a default icon size (width == height)
262+
* });
263+
* </hljs>
278264
*/
279265

280266
var config = {
@@ -381,21 +367,18 @@ MdIconProvider.prototype = {
381367
* @usage
382368
* <hljs lang="js">
383369
* function SomeDirective($mdIcon) {
384-
*
385-
* // See if the icon has already been loaded, if not
386-
* // then lookup the icon from the registry cache, load and cache
387-
* // it for future requests.
388-
* // NOTE: ID queries require configuration with $mdIconProvider
389-
*
390-
* $mdIcon('android').then(function(iconEl) { element.append(iconEl); });
391-
* $mdIcon('work:chair').then(function(iconEl) { element.append(iconEl); });
392-
*
393-
* // Load and cache the external SVG using a URL
394-
*
395-
* $mdIcon('img/icons/android.svg').then(function(iconEl) {
396-
* element.append(iconEl);
397-
* });
398-
* };
370+
*
371+
* // See if the icon has already been loaded, if not then lookup the icon from the
372+
* // registry cache, load and cache it for future requests.
373+
* // NOTE: Non-URL queries require configuration with $mdIconProvider.
374+
* $mdIcon('android').then(function(iconEl) { element.append(iconEl); });
375+
* $mdIcon('work:chair').then(function(iconEl) { element.append(iconEl); });
376+
*
377+
* // Load and cache the external SVG using a URL.
378+
* $mdIcon('img/icons/android.svg').then(function(iconEl) {
379+
* element.append(iconEl);
380+
* });
381+
* };
399382
* </hljs>
400383
*
401384
* > <b>Note:</b> The `<md-icon>` directive internally uses the `$mdIcon` service to query, load,

0 commit comments

Comments
 (0)