@@ -4,7 +4,7 @@ import { ng as angular } from "./angular";
4
4
import { IAugmentedJQuery } from "angular" ;
5
5
import {
6
6
isArray , isDefined , isFunction , isObject , services , Obj , IInjectable , tail , kebobString , unnestR , ResolveContext ,
7
- Resolvable , RawParams , prop
7
+ Resolvable , RawParams
8
8
} from "@uirouter/core" ;
9
9
import { Ng1ViewDeclaration , TemplateFactoryProvider } from "./interface" ;
10
10
@@ -33,13 +33,13 @@ export class TemplateFactory implements TemplateFactoryProvider {
33
33
* Creates a template from a configuration object.
34
34
*
35
35
* @param config Configuration object for which to load a template.
36
- * The following properties are search in the specified order, and the first one
36
+ * The following properties are search in the specified order, and the first one
37
37
* that is defined is used to create the template:
38
38
*
39
39
* @param params Parameters to pass to the template function.
40
40
* @param context The resolve context associated with the template's view
41
41
*
42
- * @return {string|object } The template html as a string, or a promise for
42
+ * @return {string|object } The template html as a string, or a promise for
43
43
* that string,or `null` if no template is configured.
44
44
*/
45
45
fromConfig ( config : Ng1ViewDeclaration , params : any , context : ResolveContext ) {
@@ -49,12 +49,12 @@ export class TemplateFactory implements TemplateFactoryProvider {
49
49
const asComponent = ( result ) => services . $q . when ( result ) . then ( str => ( { component : str } ) ) ;
50
50
51
51
return (
52
- isDefined ( config . template ) ? asTemplate ( this . fromString ( config . template , params ) ) :
53
- isDefined ( config . templateUrl ) ? asTemplate ( this . fromUrl ( config . templateUrl , params ) ) :
54
- isDefined ( config . templateProvider ) ? asTemplate ( this . fromProvider ( config . templateProvider , params , context ) ) :
55
- isDefined ( config . component ) ? asComponent ( config . component ) :
56
- isDefined ( config . componentProvider ) ? asComponent ( this . fromComponentProvider ( config . componentProvider , params , context ) ) :
57
- asTemplate ( defaultTemplate )
52
+ isDefined ( config . template ) ? asTemplate ( this . fromString ( config . template , params ) ) :
53
+ isDefined ( config . templateUrl ) ? asTemplate ( this . fromUrl ( config . templateUrl , params ) ) :
54
+ isDefined ( config . templateProvider ) ? asTemplate ( this . fromProvider ( config . templateProvider , params , context ) ) :
55
+ isDefined ( config . component ) ? asComponent ( config . component ) :
56
+ isDefined ( config . componentProvider ) ? asComponent ( this . fromComponentProvider ( config . componentProvider , params , context ) ) :
57
+ asTemplate ( defaultTemplate )
58
58
) ;
59
59
} ;
60
60
@@ -64,29 +64,31 @@ export class TemplateFactory implements TemplateFactoryProvider {
64
64
* @param template html template as a string or function that returns an html template as a string.
65
65
* @param params Parameters to pass to the template function.
66
66
*
67
- * @return {string|object } The template html as a string, or a promise for that
67
+ * @return {string|object } The template html as a string, or a promise for that
68
68
* string.
69
69
*/
70
- fromString ( template : ( string | Function ) , params ?: RawParams ) {
70
+ fromString ( template : ( string | Function ) , params ?: RawParams ) {
71
71
return isFunction ( template ) ? ( < any > template ) ( params ) : template ;
72
72
} ;
73
73
74
74
/**
75
75
* Loads a template from the a URL via `$http` and `$templateCache`.
76
76
*
77
- * @param {string|Function } url url of the template to load, or a function
77
+ * @param {string|Function } url url of the template to load, or a function
78
78
* that returns a url.
79
79
* @param {Object } params Parameters to pass to the url function.
80
- * @return {string|Promise.<string> } The template html as a string, or a promise
80
+ * @return {string|Promise.<string> } The template html as a string, or a promise
81
81
* for that string.
82
82
*/
83
- fromUrl ( url : ( string | Function ) , params : any ) {
83
+ fromUrl ( url : ( string | Function ) , params : any ) {
84
84
if ( isFunction ( url ) ) url = ( < any > url ) ( params ) ;
85
85
if ( url == null ) return null ;
86
86
87
87
if ( this . _useHttp ) {
88
- return this . $http . get ( url , { cache : this . $templateCache , headers : { Accept : 'text/html' } } )
89
- . then ( function ( response ) { return response . data ; } ) ;
88
+ return this . $http . get ( url , { cache : this . $templateCache , headers : { Accept : 'text/html' } } )
89
+ . then ( function ( response ) {
90
+ return response . data ;
91
+ } ) ;
90
92
}
91
93
92
94
return this . $templateRequest ( url ) ;
@@ -97,7 +99,7 @@ export class TemplateFactory implements TemplateFactoryProvider {
97
99
*
98
100
* @param provider Function to invoke via `locals`
99
101
* @param {Function } injectFn a function used to invoke the template provider
100
- * @return {string|Promise.<string> } The template html as a string, or a promise
102
+ * @return {string|Promise.<string> } The template html as a string, or a promise
101
103
* for that string.
102
104
*/
103
105
fromProvider ( provider : IInjectable , params : any , context : ResolveContext ) {
@@ -140,21 +142,27 @@ export class TemplateFactory implements TemplateFactoryProvider {
140
142
141
143
// Bind once prefix
142
144
const prefix = angular . version . minor >= 3 ? "::" : "" ;
145
+ // Convert to kebob name. Add x- prefix if the string starts with `x-` or `data-`
146
+ const kebob = ( camelCase : string ) => {
147
+ const kebobed = kebobString ( camelCase ) ;
148
+ return / ^ ( x | d a t a ) - / . exec ( kebobed ) ? `x-${ kebobed } ` : kebobed ;
149
+ } ;
150
+
143
151
144
152
const attributeTpl = ( input : BindingTuple ) => {
145
- let { name, type } = input ;
146
- let attrName = kebobString ( name ) ;
153
+ let { name, type } = input ;
154
+ let attrName = kebob ( name ) ;
147
155
// If the ui-view has an attribute which matches a binding on the routed component
148
156
// then pass that attribute through to the routed component template.
149
157
// Prefer ui-view wired mappings to resolve data, unless the resolve was explicitly bound using `bindings:`
150
158
if ( uiView . attr ( attrName ) && ! bindings [ name ] )
151
- return `x- ${ attrName } ='${ uiView . attr ( attrName ) } '` ;
159
+ return `${ attrName } ='${ uiView . attr ( attrName ) } '` ;
152
160
153
161
let resolveName = bindings [ name ] || name ;
154
162
// Pre-evaluate the expression for "@" bindings by enclosing in {{ }}
155
163
// some-attr="{{ ::$resolve.someResolveName }}"
156
164
if ( type === '@' )
157
- return `x- ${ attrName } ='{{${ prefix } $resolve.${ resolveName } }}'` ;
165
+ return `${ attrName } ='{{${ prefix } $resolve.${ resolveName } }}'` ;
158
166
159
167
// Wire "&" callbacks to resolves that return a callback function
160
168
// Get the result of the resolve (should be a function) and annotate it to get its arguments.
@@ -165,18 +173,15 @@ export class TemplateFactory implements TemplateFactoryProvider {
165
173
let args = fn && services . $injector . annotate ( fn ) || [ ] ;
166
174
// account for array style injection, i.e., ['foo', function(foo) {}]
167
175
let arrayIdxStr = isArray ( fn ) ? `[${ fn . length - 1 } ]` : '' ;
168
- return `x- ${ attrName } ='$resolve.${ resolveName } ${ arrayIdxStr } (${ args . join ( "," ) } )'` ;
176
+ return `${ attrName } ='$resolve.${ resolveName } ${ arrayIdxStr } (${ args . join ( "," ) } )'` ;
169
177
}
170
178
171
179
// some-attr="::$resolve.someResolveName"
172
- return `x- ${ attrName } ='${ prefix } $resolve.${ resolveName } '` ;
180
+ return `${ attrName } ='${ prefix } $resolve.${ resolveName } '` ;
173
181
} ;
174
182
175
183
let attrs = getComponentBindings ( component ) . map ( attributeTpl ) . join ( " " ) ;
176
- let kebobName = kebobString ( component ) ;
177
- if ( / ^ ( x | d a t a ) - / . exec ( kebobName ) ) {
178
- kebobName = "x-" + kebobName ;
179
- }
184
+ let kebobName = kebob ( component ) ;
180
185
return `<${ kebobName } ${ attrs } ></${ kebobName } >` ;
181
186
} ;
182
187
}
0 commit comments