5
5
use Ajax \common \traits \JqueryEventsTrait ;
6
6
use Ajax \common \traits \JqueryAjaxTrait ;
7
7
use Ajax \common \traits \JqueryActionsTrait ;
8
+ use Ajax \service \Javascript ;
8
9
9
10
/**
10
- * JQuery Phalcon library
11
+ * jQuery Class
11
12
*
12
13
* @author jcheron
13
14
* @version 1.002
14
15
* @license Apache 2 http://www.apache.org/licenses/
15
- */
16
- /**
17
- * jQuery Class
18
- */
16
+ **/
19
17
class Jquery {
20
18
use JqueryEventsTrait,JqueryAjaxTrait,JqueryActionsTrait;
21
19
protected $ _ui ;
22
20
protected $ _bootstrap ;
23
21
protected $ _semantic ;
24
- protected $ libraryFile ;
25
- protected $ _javascript_folder ='js ' ;
26
- protected $ jquery_code_for_load =array ();
27
22
protected $ jquery_code_for_compile =array ();
28
- protected $ jquery_corner_active =FALSE ;
29
- protected $ jquery_table_sorter_active =FALSE ;
30
- protected $ jquery_table_sorter_pager_active =FALSE ;
31
23
protected $ jsUtils ;
32
24
protected $ params ;
33
25
@@ -109,10 +101,6 @@ private function _close_script($extra="\n") {
109
101
return "</script> {$ extra }" ;
110
102
}
111
103
112
- public function setLibraryFile ($ name ) {
113
- $ this ->libraryFile =$ name ;
114
- }
115
-
116
104
public function _setAjaxLoader ($ loader ) {
117
105
$ this ->ajaxLoader =$ loader ;
118
106
}
@@ -144,9 +132,9 @@ public function _output($array_js='') {
144
132
* @param boolean $immediatly delayed if false
145
133
*/
146
134
public function _genericCallValue ($ jQueryCall ,$ element ='this ' , $ param ="" , $ immediatly =false ) {
147
- $ element =$ this -> _prep_element ($ element );
135
+ $ element =Javascript:: prep_element ($ element );
148
136
if (isset ($ param )) {
149
- $ param =$ this -> _prep_value ($ param );
137
+ $ param =Javascript:: prep_value ($ param );
150
138
$ str ="$( {$ element }). {$ jQueryCall }( {$ param }); " ;
151
139
} else
152
140
$ str ="$( {$ element }). {$ jQueryCall }(); " ;
@@ -163,8 +151,8 @@ public function _genericCallValue($jQueryCall,$element='this', $param="", $immed
163
151
* @return string
164
152
*/
165
153
public function _genericCallElement ($ jQueryCall ,$ to ='this ' , $ element , $ immediatly =false ) {
166
- $ to =$ this -> _prep_element ($ to );
167
- $ element =$ this -> _prep_element ($ element );
154
+ $ to =Javascript:: prep_element ($ to );
155
+ $ element =Javascript:: prep_element ($ element );
168
156
$ str ="$( {$ to }). {$ jQueryCall }( {$ element }); " ;
169
157
if ($ immediatly )
170
158
$ this ->jquery_code_for_compile []=$ str ;
@@ -189,7 +177,7 @@ public function sortable($element, $options=array()) {
189
177
$ sort_options ='' ;
190
178
}
191
179
192
- return "$( " .$ this -> _prep_element ($ element ).").sortable({ " .$ sort_options ."\n\t}); " ;
180
+ return "$( " .Javascript:: prep_element ($ element ).").sortable({ " .$ sort_options ."\n\t}); " ;
193
181
}
194
182
195
183
/**
@@ -200,7 +188,7 @@ public function sortable($element, $options=array()) {
200
188
* @return string
201
189
*/
202
190
public function tablesorter ($ table ='' , $ options ='' ) {
203
- $ this ->jquery_code_for_compile []="\t$( " .$ this -> _prep_element ($ table ).").tablesorter( $ options); \n" ;
191
+ $ this ->jquery_code_for_compile []="\t$( " .Javascript:: prep_element ($ table ).").tablesorter( $ options); \n" ;
204
192
}
205
193
206
194
/**
@@ -224,9 +212,9 @@ public function _add_event($element, $js, $event, $preventDefault=false, $stopPr
224
212
$ js ="event.stopPropagation(); \n" .$ js ;
225
213
}
226
214
if (array_search ($ event , $ this ->jquery_events )===false )
227
- $ event ="\n\t$( " .$ this -> _prep_element ($ element ).").bind(' {$ event }',function(event){ \n\t\t{$ js }\n\t}); \n" ;
215
+ $ event ="\n\t$( " .Javascript:: prep_element ($ element ).").bind(' {$ event }',function(event){ \n\t\t{$ js }\n\t}); \n" ;
228
216
else
229
- $ event ="\n\t$( " .$ this -> _prep_element ($ element )."). {$ event }(function(event){ \n\t\t{$ js }\n\t}); \n" ;
217
+ $ event ="\n\t$( " .Javascript:: prep_element ($ element )."). {$ event }(function(event){ \n\t\t{$ js }\n\t}); \n" ;
230
218
if ($ immediatly )
231
219
$ this ->jquery_code_for_compile []=$ event ;
232
220
return $ event ;
@@ -242,36 +230,13 @@ public function _add_event($element, $js, $event, $preventDefault=false, $stopPr
242
230
*/
243
231
public function _compile (&$ view =NULL , $ view_var ='script_foot ' , $ script_tags =TRUE ) {
244
232
// Components UI
245
- $ ui =$ this ->ui ();
246
- if ($ this ->ui ()!=NULL ) {
247
- if ($ ui ->isAutoCompile ()) {
248
- $ ui ->compile (true );
249
- }
250
- }
251
-
233
+ $ this ->_compileLibrary ($ this ->ui ());
252
234
// Components BS
253
- $ bootstrap =$ this ->bootstrap ();
254
- if ($ this ->bootstrap ()!=NULL ) {
255
- if ($ bootstrap ->isAutoCompile ()) {
256
- $ bootstrap ->compile (true );
257
- }
258
- }
259
-
235
+ $ this ->_compileLibrary ($ this ->bootstrap ());
260
236
// Components Semantic
261
- $ semantic =$ this ->semantic ();
262
- if ($ semantic !=NULL ) {
263
- if ($ semantic ->isAutoCompile ()) {
264
- $ semantic ->compile (true );
265
- }
266
- }
237
+ $ this ->_compileLibrary ($ this ->semantic ());
267
238
268
- // External references
269
- $ external_scripts =implode ('' , $ this ->jquery_code_for_load );
270
- extract (array (
271
- 'library_src ' => $ external_scripts
272
- ));
273
-
274
- if (count ($ this ->jquery_code_for_compile )==0 ) {
239
+ if (\sizeof ($ this ->jquery_code_for_compile )==0 ) {
275
240
// no inline references, let's just return
276
241
return ;
277
242
}
@@ -293,6 +258,14 @@ public function _compile(&$view=NULL, $view_var='script_foot', $script_tags=TRUE
293
258
return $ output ;
294
259
}
295
260
261
+ private function _compileLibrary ($ library ){
262
+ if ($ library !=NULL ) {
263
+ if ($ library ->isAutoCompile ()) {
264
+ $ library ->compile (true );
265
+ }
266
+ }
267
+ }
268
+
296
269
public function _addToCompile ($ jsScript ) {
297
270
$ this ->jquery_code_for_compile []=$ jsScript ;
298
271
}
@@ -322,39 +295,6 @@ public function _document_ready($js) {
322
295
}
323
296
}
324
297
325
- /**
326
- * Puts HTML element in quotes for use in jQuery code
327
- * unless the supplied element is the Javascript 'this'
328
- * object, in which case no quotes are added
329
- *
330
- * @param string $element
331
- * @return string
332
- */
333
- public function _prep_element ($ element ) {
334
- if (strrpos ($ element , 'this ' )===false &&strrpos ($ element , 'event ' )===false &&strrpos ($ element , 'self ' )===false ) {
335
- $ element ='" ' .addslashes ($ element ).'" ' ;
336
- }
337
- return $ element ;
338
- }
339
-
340
- /**
341
- * Puts HTML values in quotes for use in jQuery code
342
- * unless the supplied value contains the Javascript 'this' or 'event'
343
- * object, in which case no quotes are added
344
- *
345
- * @param string $value
346
- * @return string
347
- */
348
- public function _prep_value ($ value ) {
349
- if (is_array ($ value )) {
350
- $ value =implode (", " , $ value );
351
- }
352
- if (strrpos ($ value , 'this ' )===false &&strrpos ($ value , 'event ' )===false &&strrpos ($ value , 'self ' )===false ) {
353
- $ value ='" ' .$ value .'" ' ;
354
- }
355
- return $ value ;
356
- }
357
-
358
298
private function minify ($ input ) {
359
299
if (trim ($ input ) === "" ) return $ input ;
360
300
return preg_replace (
0 commit comments