@@ -50,3 +50,65 @@ QueryBuilder.define = function(name, fct, def) {
5050QueryBuilder . extend = function ( methods ) {
5151 $ . extend ( QueryBuilder . prototype , methods ) ;
5252} ;
53+
54+ /**
55+ * Initializes plugins for an instance
56+ * @throws ConfigError
57+ * @private
58+ */
59+ QueryBuilder . prototype . initPlugins = function ( ) {
60+ if ( ! this . plugins ) {
61+ return ;
62+ }
63+
64+ if ( $ . isArray ( this . plugins ) ) {
65+ var tmp = { } ;
66+ this . plugins . forEach ( function ( plugin ) {
67+ tmp [ plugin ] = null ;
68+ } ) ;
69+ this . plugins = tmp ;
70+ }
71+
72+ Object . keys ( this . plugins ) . forEach ( function ( plugin ) {
73+ if ( plugin in QueryBuilder . plugins ) {
74+ this . plugins [ plugin ] = $ . extend ( true , { } ,
75+ QueryBuilder . plugins [ plugin ] . def ,
76+ this . plugins [ plugin ] || { }
77+ ) ;
78+
79+ QueryBuilder . plugins [ plugin ] . fct . call ( this , this . plugins [ plugin ] ) ;
80+ }
81+ else {
82+ Utils . error ( 'Config' , 'Unable to find plugin "{0}"' , plugin ) ;
83+ }
84+ } , this ) ;
85+ } ;
86+
87+ /**
88+ * Returns the config of a plugin, if the plugin is not loaded, returns the default config.
89+ * @param {string } name
90+ * @param {string } [property]
91+ * @throws ConfigError
92+ * @returns {* }
93+ */
94+ QueryBuilder . prototype . getPluginOptions = function ( name , property ) {
95+ var plugin ;
96+ if ( this . plugins && this . plugins [ name ] ) {
97+ plugin = this . plugins [ name ] ;
98+ }
99+ else if ( QueryBuilder . plugins [ name ] ) {
100+ plugin = QueryBuilder . plugins [ name ] . def ;
101+ }
102+
103+ if ( plugin ) {
104+ if ( property ) {
105+ return plugin [ property ] ;
106+ }
107+ else {
108+ return plugin ;
109+ }
110+ }
111+ else {
112+ Utils . error ( 'Config' , 'Unable to find plugin "{0}"' , name ) ;
113+ }
114+ } ;
0 commit comments