24
24
*/
25
25
26
26
/**
27
- * Plugin extension subscribers, adding support for jQuery UI
28
- * and the Validation Plugin.
29
- * Initializes element type subscribers and subscriber functions
27
+ * Plugin extension subscribers, to support external jQuery plugins,
28
+ * adding support for jQuery UI and the Validation Plugin.
29
+ * Initializes element types and subscriber functions
30
30
* provided by the jQuery UI framework.
31
31
* Only subscribes if the elements (like tabs, slider, progressbar etc.)
32
32
* are actually available (in case you are using a custom jQuery UI build).
35
35
*/
36
36
( function ( $ )
37
37
{
38
- if ( $ . isFunction ( $ . fn . validate ) ) // Check if the validation plugin is available
38
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . validate ) , // Subscribe if validation plugin is available
39
39
{
40
- $ . dform . subscribe (
40
+ /**
41
+ * Add a preprocessing subscriber that calls .validate() on the form,
42
+ * so that we can add rules to the input elements.
43
+ *
44
+ * @param options mixed All options that have been used for
45
+ * creating the current element.
46
+ * @param type string The type of the <strong>this</strong> element
47
+ */
48
+ "[pre]" : function ( options , type )
41
49
{
42
- /**
43
- * Add a preprocessing subscriber that calls .validate() on the form,
44
- * so that we can add rules to the input elements.
45
- *
46
- * @param options mixed All options that have been used for
47
- * creating the current element.
48
- * @param type string The type of the <strong>this</strong> element
49
- */
50
- "[pre]" : function ( options , type )
50
+ if ( type == "form" )
51
51
{
52
- if ( type == "form" )
53
- {
54
- var defaults = { } ;
55
- if ( $ ( this ) . hasClass ( "ui-widget" ) )
56
- defaults = {
57
- highlight : function ( input )
58
- {
59
- $ ( input ) . addClass ( "ui-state-highlight" ) ;
60
- } ,
61
- unhighlight : function ( input )
62
- {
63
- $ ( input ) . removeClass ( "ui-state-highlight" ) ;
64
- }
65
- } ;
66
- $ ( this ) . validate ( defaults ) ;
67
- }
68
- } ,
69
- /**
70
- * Adds support for the jQuery validation rulesets.
71
- *
72
- * @param options object Options as specified in the rules parameter
73
- * @param type string The type of the <strong>this</strong> element
74
- */
75
- "validate" : function ( options , type )
76
- {
77
- $ ( this ) . rules ( "add" , options ) ;
52
+ var defaults = { } ;
53
+ if ( $ ( this ) . hasClass ( "ui-widget" ) )
54
+ defaults = {
55
+ highlight : function ( input )
56
+ {
57
+ $ ( input ) . addClass ( "ui-state-highlight" ) ;
58
+ } ,
59
+ unhighlight : function ( input )
60
+ {
61
+ $ ( input ) . removeClass ( "ui-state-highlight" ) ;
62
+ }
63
+ } ;
64
+ $ ( this ) . validate ( defaults ) ;
78
65
}
79
- } ) ;
80
- }
66
+ } ,
67
+ /**
68
+ * Adds support for the jQuery validation rulesets.
69
+ *
70
+ * @param options object Options as specified in the rules parameter
71
+ * @param type string The type of the <strong>this</strong> element
72
+ */
73
+ "validate" : function ( options , type )
74
+ {
75
+ $ ( this ) . rules ( "add" , options ) ;
76
+ }
77
+ } ) ;
81
78
82
79
function _getOptions ( type , options )
83
80
{
89
86
return result ;
90
87
}
91
88
92
- if ( $ . isFunction ( $ . fn . progressbar ) )
93
- {
94
- $ . dform . subscribe ( "[type=progressbar]" ,
89
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . progressbar ) , "[type=progressbar]" ,
95
90
/**
96
91
* Returns a progressbar jQuery UI progressbar.
97
92
* @param options object All parameters for this type
101
96
var ops = _getOptions ( "progressbar" , options ) ;
102
97
return $ ( "<div>" ) . attr ( ops . attributes ) . progressbar ( ops . options ) ;
103
98
} ) ;
104
- }
105
99
106
- if ( $ . isFunction ( $ . fn . slider ) )
107
- {
108
- $ . dform . subscribe ( "[type=slider]" ,
100
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . slider ) , "[type=slider]" ,
109
101
/**
110
102
* Returns a slider.
111
103
* @param options object All parameters for this type
115
107
var ops = _getOptions ( "slider" , options ) ;
116
108
return $ ( "<div>" ) . attr ( ops . attributes ) . slider ( ops . options ) ;
117
109
} ) ;
118
- }
119
110
120
- if ( $ . isFunction ( $ . fn . tabs ) )
111
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . tabs ) ,
121
112
{
122
- $ . dform . subscribe (
113
+ /**
114
+ * Creates a container for jQuery UI tabs.
115
+ * @param options object All parameters for this type
116
+ */
117
+ "[type=tabs]" : function ( options )
123
118
{
124
- /**
125
- * Creates a container for jQuery UI tabs.
126
- * @param options object All parameters for this type
127
- */
128
- "[type=tabs]" : function ( options )
129
- {
130
- var ops = _getOptions ( "tabs" , options ) ;
131
- return $ ( "<div>" ) . attr ( ops . attributes ) ;
132
- } ,
133
- /**
134
- * Adds tabs to a tab element.
135
- *
136
- * @param options object An object containing a tab with its unique id as a key
137
- * and the tab options including an "elements" with all
138
- * subelements as a value.
139
- * @param type string The type of the <strong>this</strong> element
140
- */
141
- "tabs" : function ( options , type )
119
+ var ops = _getOptions ( "tabs" , options ) ;
120
+ return $ ( "<div>" ) . attr ( ops . attributes ) ;
121
+ } ,
122
+ /**
123
+ * Adds tabs to a tab element.
124
+ *
125
+ * @param options object An object containing a tab with its unique id as a key
126
+ * and the tab options including an "elements" with all
127
+ * subelements as a value.
128
+ * @param type string The type of the <strong>this</strong> element
129
+ */
130
+ "tabs" : function ( options , type )
131
+ {
132
+ if ( type == "tabs" )
142
133
{
143
- if ( type == "tabs" )
134
+ $ ( this ) . append ( "<ul>" ) ;
135
+ var scoper = $ ( this ) ;
136
+ $ . each ( options , function ( tabname , ops )
144
137
{
145
- $ ( this ) . append ( "<ul>" ) ;
146
- var scoper = $ ( this ) ;
147
- $ . each ( options , function ( tabname , ops )
138
+ var tablink = $ ( "<a>" ) . attr (
148
139
{
149
- var tablink = $ ( "<a>" ) . attr (
150
- {
151
- "href" : "#" + tabname
152
- } ) . html ( ops . title ) ;
153
- var li = $ ( "<li>" ) . append ( tablink ) ;
154
- var tabdiv = $ ( "<div>" ) . attr ( "id" , tabname ) ;
155
- $ ( scoper ) . children ( "ul" ) . first ( ) . append ( li ) ;
156
- $ ( scoper ) . append ( tabdiv ) ;
157
-
158
- $ ( tabdiv ) . runAll ( ops ) ;
159
- } ) ;
160
- }
161
- $ ( this ) . tabs ( ) ;
140
+ "href" : "#" + tabname
141
+ } ) . html ( ops . title ) ;
142
+ var li = $ ( "<li>" ) . append ( tablink ) ;
143
+ var tabdiv = $ ( "<div>" ) . attr ( "id" , tabname ) ;
144
+ $ ( scoper ) . children ( "ul" ) . first ( ) . append ( li ) ;
145
+ $ ( scoper ) . append ( tabdiv ) ;
146
+
147
+ $ ( tabdiv ) . runAll ( ops ) ;
148
+ } ) ;
162
149
}
163
- } ) ;
164
- }
150
+ $ ( this ) . tabs ( ) ;
151
+ }
152
+ } ) ;
165
153
166
- if ( $ . isFunction ( $ . fn . accordion ) )
167
- {
168
- $ . dform . subscribe ( "[type=accordion]" ,
154
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . accordion ) , "[type=accordion]" ,
169
155
/**
170
156
* Creates a container for the jQuery UI accordion.
171
157
* @param options object All parameters for this type
176
162
var ops = _getOptions ( "accordion" , options ) ;
177
163
return $ ( "<div>" ) . attr ( ops . attributes ) ;
178
164
} ) ;
179
- }
180
165
181
- if ( $ . isFunction ( $ . fn . dialog ) )
182
- {
183
- $ . dform . subscribe ( "dialog" ,
166
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . dialog ) , "dialog" ,
184
167
/**
185
168
* Creates a dialog on form or fieldset elements.
186
169
*
192
175
if ( type == "form" || type == "fieldset" )
193
176
$ ( this ) . dialog ( options ) ;
194
177
} ) ;
195
- }
196
178
197
- if ( $ . isFunction ( $ . fn . resizable ) )
198
- {
199
- $ . dform . subscribe ( "resizable" ,
179
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . resizable ) , "resizable" ,
200
180
/**
201
181
* Makes the current element resizeable.
202
182
*
207
187
{
208
188
$ ( this ) . resizable ( options ) ;
209
189
} ) ;
210
- }
211
190
212
- if ( $ . isFunction ( $ . fn . datepicker ) )
213
- {
214
- $ . dform . subscribe ( "datepicker" ,
191
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . datepicker ) , "datepicker" ,
215
192
/**
216
193
* Turns a text element into a datepicker
217
194
*
223
200
if ( type == "text" )
224
201
$ ( this ) . datepicker ( options ) ;
225
202
} ) ;
226
- }
227
-
228
- if ( $ . isFunction ( $ . fn . autocomplete ) )
229
- {
230
- $ . dform . subscribe ( "autocomplete" ,
203
+
204
+ $ . dform . subscribeIf ( $ . isFunction ( $ . fn . autocomplete ) , "autocomplete" ,
231
205
/**
232
206
* Adds an autocomplete feature to a text element.
233
207
*
239
213
if ( type == "text" )
240
214
$ ( this ) . autocomplete ( options ) ;
241
215
} ) ;
242
- }
243
216
244
217
$ . dform . subscribe ( "[post]" ,
245
- /**
246
- * Post processing subscriber that adds jQuery UI styling classes to
247
- * "text", "textarea", "password" and "fieldset" elements as well
248
- * as calling .button() on submit buttons.
249
- *
250
- * @param options mixed All options that have been used for
251
- * creating the current element.
252
- * @param type string The type of the <strong>this</strong> element
253
- */
254
- function ( options , type )
255
- {
256
- if ( $ ( this ) . parents ( "form" ) . hasClass ( "ui-widget" ) )
218
+ /**
219
+ * Post processing subscriber that adds jQuery UI styling classes to
220
+ * "text", "textarea", "password" and "fieldset" elements as well
221
+ * as calling .button() on submit buttons.
222
+ *
223
+ * @param options mixed All options that have been used for
224
+ * creating the current element.
225
+ * @param type string The type of the <strong>this</strong> element
226
+ */
227
+ function ( options , type )
257
228
{
258
- if ( ( type == "button" || type == "submit" ) && $ . isFunction ( $ . fn . button ) )
259
- $ ( this ) . button ( ) ;
260
- if ( $ . inArray ( type , [ "text" , "textarea" , "password" ,
261
- "fieldset" ] ) != - 1 )
262
- $ ( this ) . addClass ( "ui-widget-content ui-corner-all" ) ;
263
- }
264
- } ) ;
229
+ if ( $ ( this ) . parents ( "form" ) . hasClass ( "ui-widget" ) )
230
+ {
231
+ if ( ( type == "button" || type == "submit" ) && $ . isFunction ( $ . fn . button ) )
232
+ $ ( this ) . button ( ) ;
233
+ if ( $ . inArray ( type , [ "text" , "textarea" , "password" ,
234
+ "fieldset" ] ) != - 1 )
235
+ $ ( this ) . addClass ( "ui-widget-content ui-corner-all" ) ;
236
+ }
237
+ } ) ;
265
238
} ) ( jQuery ) ;
0 commit comments