1- var deps = [ ] ;
1+ var deps = [ 'ObjectPath' ] ;
22try {
33 //This throws an expection if module does not exist.
44 angular . module ( 'ngSanitize' ) ;
1313
1414angular . module ( 'schemaForm' , deps ) ;
1515
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-
10816/**
10917 * @ngdoc service
11018 * @name sfSelect
@@ -125,7 +33,7 @@ angular.module('schemaForm',deps);
12533 * @returns {Any|undefined } returns the value at the end of the projection path
12634 * or undefined if there is none.
12735 */
128- angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ function ( ) {
36+ angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'ObjectPath' , function ( ObjectPath ) {
12937 var numRe = / ^ \d + $ / ;
13038
13139 return function ( projection , obj , valueToSet ) {
@@ -178,7 +86,7 @@ angular.module('schemaForm').factory('sfSelect', [function () {
17886 } ;
17987} ] ) ;
18088
181- angular . module ( 'schemaForm' ) . provider ( 'schemaFormDecorators' , [ '$compileProvider' , function ( $compileProvider ) {
89+ angular . module ( 'schemaForm' ) . provider ( 'schemaFormDecorators' , [ '$compileProvider' , 'ObjectPathProvider' , function ( $compileProvider , ObjectPathProvider ) {
18290 var defaultDecorator = '' ;
18391 var directives = { } ;
18492
@@ -231,7 +139,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
231139 //for fieldsets to recurse properly.
232140 var url = templateUrl ( name , form ) ;
233141 $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, '"' ) : '' ;
235143 var template = res . data . replace ( / \$ \$ v a l u e \$ \$ / g, 'model' + key ) ;
236144 $compile ( template ) ( scope , function ( clone ) {
237145 element . replaceWith ( clone ) ;
@@ -484,7 +392,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',['$compileProvider'
484392 * This service is not that useful outside of schema form directive
485393 * but makes the code more testable.
486394 */
487- angular . module ( 'schemaForm' ) . provider ( 'schemaForm' , [ function ( ) {
395+ angular . module ( 'schemaForm' ) . provider ( 'schemaForm' , [ 'ObjectPathProvider' , function ( ObjectPathProvider ) {
488396
489397 var defaultFormDefinition = function ( name , schema , options ) {
490398 var rules = defaults [ schema . type ] ;
@@ -526,7 +434,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
526434 var f = stdFormObj ( schema , options ) ;
527435 f . key = options . path ;
528436 f . type = 'text' ;
529- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
437+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
530438 return f ;
531439 }
532440 } ;
@@ -538,7 +446,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
538446 var f = stdFormObj ( schema , options ) ;
539447 f . key = options . path ;
540448 f . type = 'number' ;
541- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
449+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
542450 return f ;
543451 }
544452 } ;
@@ -548,7 +456,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
548456 var f = stdFormObj ( schema , options ) ;
549457 f . key = options . path ;
550458 f . type = 'number' ;
551- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
459+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
552460 return f ;
553461 }
554462 } ;
@@ -558,7 +466,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
558466 var f = stdFormObj ( schema , options ) ;
559467 f . key = options . path ;
560468 f . type = 'checkbox' ;
561- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
469+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
562470 return f ;
563471 }
564472 } ;
@@ -575,7 +483,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
575483 f . titleMap [ name ] = name ;
576484 } ) ;
577485 }
578- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
486+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
579487 return f ;
580488 }
581489 } ;
@@ -591,7 +499,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
591499 f . titleMap [ name ] = name ;
592500 } ) ;
593501 }
594- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
502+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
595503 return f ;
596504 }
597505 } ;
@@ -604,13 +512,13 @@ angular.module('schemaForm').provider('schemaForm',[function(){
604512 var f = stdFormObj ( schema , options ) ;
605513 f . type = 'fieldset' ;
606514 f . items = [ ] ;
607- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
515+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
608516
609517 //recurse down into properties
610518 angular . forEach ( schema . properties , function ( v , k ) {
611519 var path = options . path . slice ( ) ;
612520 path . push ( k ) ;
613- if ( options . ignore [ ObjectPath . stringify ( path ) ] !== true ) {
521+ if ( options . ignore [ ObjectPathProvider . stringify ( path ) ] !== true ) {
614522 var required = schema . required && schema . required . indexOf ( k ) !== - 1 ;
615523
616524 var def = defaultFormDefinition ( k , v , {
@@ -636,7 +544,7 @@ angular.module('schemaForm').provider('schemaForm',[function(){
636544 var f = stdFormObj ( schema , options ) ;
637545 f . type = 'array' ;
638546 f . key = options . path ;
639- options . lookup [ ObjectPath . stringify ( options . path ) ] = f ;
547+ options . lookup [ ObjectPathProvider . stringify ( options . path ) ] = f ;
640548
641549 var required = schema . required && schema . required . indexOf ( options . path ( options . path . length - 1 ) ) !== - 1 ;
642550
@@ -772,9 +680,9 @@ angular.module('schemaForm').provider('schemaForm',[function(){
772680 //extend with std form from schema.
773681 if ( obj . key ) {
774682 if ( typeof obj . key == 'string' ) {
775- obj . key = ObjectPath . parse ( obj . key ) ;
683+ obj . key = ObjectPathProvider . parse ( obj . key ) ;
776684 }
777- var str = ObjectPath . stringify ( obj . key ) ;
685+ var str = ObjectPathProvider . stringify ( obj . key ) ;
778686 if ( lookup [ str ] ) {
779687 return angular . extend ( lookup [ str ] , obj ) ;
780688 }
0 commit comments