1
- var deps = [ ] ;
1
+ var deps = [ 'ObjectPath' ] ;
2
2
try {
3
3
//This throws an expection if module does not exist.
4
4
angular . module ( 'ngSanitize' ) ;
13
13
14
14
angular . module ( 'schemaForm' , deps ) ;
15
15
16
-
17
- 'use strict' ;
18
-
19
- ; ! function ( undefined ) {
20
-
21
- var ObjectPath = {
22
- parse : function ( str ) {
23
- if ( typeof str !== 'string' ) {
24
- throw new TypeError ( 'ObjectPath.parse must be passed a string' ) ;
25
- }
26
-
27
- var i = 0 ;
28
- var parts = [ ] ;
29
- var d , b , q , c ;
30
- while ( i < str . length ) {
31
- d = str . indexOf ( '.' , i ) ;
32
- b = str . indexOf ( '[' , i ) ;
33
-
34
- // we've reached the end
35
- if ( d === - 1 && b === - 1 ) {
36
- parts . push ( str . slice ( i , str . length ) ) ;
37
- i = str . length ;
38
- }
39
-
40
- // dots
41
- else if ( b === - 1 || ( d !== - 1 && d < b ) ) {
42
- parts . push ( str . slice ( i , d ) ) ;
43
- i = d + 1 ;
44
- }
45
-
46
- // brackets
47
- else {
48
- if ( b > i ) {
49
- parts . push ( str . slice ( i , b ) ) ;
50
- i = b ;
51
- }
52
- q = str . slice ( b + 1 , b + 2 ) ;
53
- if ( q !== '"' && q !== '\'' ) {
54
- c = str . indexOf ( ']' , b ) ;
55
- if ( c === - 1 ) c = str . length ;
56
- parts . push ( str . slice ( i + 1 , c ) ) ;
57
- i = ( str . slice ( c + 1 , c + 2 ) === '.' ) ? c + 2 : c + 1 ;
58
- } else {
59
- c = str . indexOf ( q + ']' , b ) ;
60
- if ( c === - 1 ) c = str . length ;
61
- while ( str . slice ( c - 1 , c ) === '\\' && b < str . length ) {
62
- b ++ ;
63
- c = str . indexOf ( q + ']' , b ) ;
64
- }
65
- parts . push ( str . slice ( i + 2 , c ) . replace ( new RegExp ( '\\' + q , 'g' ) , q ) ) ;
66
- i = ( str . slice ( c + 2 , c + 3 ) === '.' ) ? c + 3 : c + 2 ;
67
- }
68
- }
69
- }
70
- return parts ;
71
- } ,
72
-
73
- // root === true : auto calculate root; must be dot-notation friendly
74
- // root String : the string to use as root
75
- stringify : function ( arr , quote ) {
76
-
77
- if ( Array . isArray ( arr ) !== true )
78
- arr = [ arr . toString ( ) ] ;
79
-
80
- quote = quote === '"' ? '"' : '\'' ;
81
-
82
- return arr . slice ( ) . map ( function ( n ) { return '[' + quote + ( n . toString ( ) ) . replace ( new RegExp ( quote , 'g' ) , '\\' + quote ) + quote + ']' ; } ) . join ( '' ) ;
83
- } ,
84
-
85
- normalize : function ( str ) {
86
- return this . stringify ( this . parse ( str ) ) ;
87
- }
88
- } ;
89
-
90
- // AMD
91
- if ( typeof define === 'function' && define . amd ) {
92
- define ( function ( ) {
93
- return ObjectPath ;
94
- } ) ;
95
- }
96
-
97
- // CommonJS
98
- else if ( typeof exports === 'object' ) {
99
- exports . ObjectPath = ObjectPath ;
100
- }
101
-
102
- // Browser global.
103
- else {
104
- window . ObjectPath = ObjectPath ;
105
- }
106
- } ( ) ;
107
-
108
16
/**
109
17
* @ngdoc service
110
18
* @name sfSelect
@@ -125,7 +33,7 @@ angular.module('schemaForm',deps);
125
33
* @returns {Any|undefined } returns the value at the end of the projection path
126
34
* or undefined if there is none.
127
35
*/
128
- angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ function ( ) {
36
+ angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'ObjectPath' , function ( ObjectPath ) {
129
37
var numRe = / ^ \d + $ / ;
130
38
131
39
return function ( projection , obj , valueToSet ) {
@@ -178,7 +86,7 @@ angular.module('schemaForm').factory('sfSelect', [function () {
178
86
} ;
179
87
} ] ) ;
180
88
181
- angular . module ( 'schemaForm' ) . provider ( 'schemaFormDecorators' , [ '$compileProvider' , function ( $compileProvider ) {
89
+ angular . module ( 'schemaForm' ) . provider ( 'schemaFormDecorators' , [ '$compileProvider' , 'ObjectPathProvider' , function ( $compileProvider , ObjectPathProvider ) {
182
90
var defaultDecorator = '' ;
183
91
var directives = { } ;
184
92
@@ -231,7 +139,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
231
139
//for fieldsets to recurse properly.
232
140
var url = templateUrl ( name , form ) ;
233
141
$http . get ( url , { cache : $templateCache } ) . then ( function ( res ) {
234
- var key = form . key ? ObjectPath . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
142
+ var key = form . key ? ObjectPathProvider . stringify ( form . key ) . replace ( / " / g, '"' ) : '' ;
235
143
var template = res . data . replace ( / \$ \$ v a l u e \$ \$ / g, 'model' + key ) ;
236
144
$compile ( template ) ( scope , function ( clone ) {
237
145
element . replaceWith ( clone ) ;
@@ -484,7 +392,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
484
392
* This service is not that useful outside of schema form directive
485
393
* but makes the code more testable.
486
394
*/
487
- angular . module ( 'schemaForm' ) . provider ( 'schemaForm' , [ function ( ) {
395
+ angular . module ( 'schemaForm' ) . provider ( 'schemaForm' , [ 'ObjectPathProvider' , function ( ObjectPathProvider ) {
488
396
489
397
var defaultFormDefinition = function ( name , schema , options ) {
490
398
var rules = defaults [ schema . type ] ;
@@ -526,7 +434,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
526
434
var f = stdFormObj ( schema , options ) ;
527
435
f . key = options . path ;
528
436
f . type = 'text' ;
529
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
437
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
530
438
return f ;
531
439
}
532
440
} ;
@@ -538,7 +446,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
538
446
var f = stdFormObj ( schema , options ) ;
539
447
f . key = options . path ;
540
448
f . type = 'number' ;
541
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
449
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
542
450
return f ;
543
451
}
544
452
} ;
@@ -548,7 +456,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
548
456
var f = stdFormObj ( schema , options ) ;
549
457
f . key = options . path ;
550
458
f . type = 'number' ;
551
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
459
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
552
460
return f ;
553
461
}
554
462
} ;
@@ -558,7 +466,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
558
466
var f = stdFormObj ( schema , options ) ;
559
467
f . key = options . path ;
560
468
f . type = 'checkbox' ;
561
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
469
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
562
470
return f ;
563
471
}
564
472
} ;
@@ -575,7 +483,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
575
483
f . titleMap [ name ] = name ;
576
484
} ) ;
577
485
}
578
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
486
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
579
487
return f ;
580
488
}
581
489
} ;
@@ -591,7 +499,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
591
499
f . titleMap [ name ] = name ;
592
500
} ) ;
593
501
}
594
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
502
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
595
503
return f ;
596
504
}
597
505
} ;
@@ -604,13 +512,13 @@ angular.module('schemaForm').provider('schemaForm',[function(){
604
512
var f = stdFormObj ( schema , options ) ;
605
513
f . type = 'fieldset' ;
606
514
f . items = [ ] ;
607
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
515
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
608
516
609
517
//recurse down into properties
610
518
angular . forEach ( schema . properties , function ( v , k ) {
611
519
var path = options . path . slice ( ) ;
612
520
path . push ( k ) ;
613
- if ( options . ignore [ ObjectPath . stringify ( path ) ] !== true ) {
521
+ if ( options . ignore [ ObjectPathProvider . stringify ( path ) ] !== true ) {
614
522
var required = schema . required && schema . required . indexOf ( k ) !== - 1 ;
615
523
616
524
var def = defaultFormDefinition ( k , v , {
@@ -636,7 +544,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
636
544
var f = stdFormObj ( schema , options ) ;
637
545
f . type = 'array' ;
638
546
f . key = options . path ;
639
- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
547
+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
640
548
641
549
var required = schema . required && schema . required . indexOf ( options . path ( options . path . length - 1 ) ) !== - 1 ;
642
550
@@ -772,9 +680,9 @@ angular.module('schemaForm').provider('schemaForm',[function(){
772
680
//extend with std form from schema.
773
681
if ( obj . key ) {
774
682
if ( typeof obj . key == 'string' ) {
775
- obj . key = ObjectPath . parse ( obj . key ) ;
683
+ obj . key = ObjectPathProvider . parse ( obj . key ) ;
776
684
}
777
- var str = ObjectPath . stringify ( obj . key ) ;
685
+ var str = ObjectPathProvider . stringify ( obj . key ) ;
778
686
if ( lookup [ str ] ) {
779
687
return angular . extend ( lookup [ str ] , obj ) ;
780
688
}
0 commit comments