-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
515 lines (412 loc) · 14 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
ysJQueryRevolutionsPlugin
=========================
The ysJQueryRevolutionsPlugin provides support for jquery
in your app views; Importing the jquery library and simplifies HTML document
traversing, event handling, animating, and Ajax interactions for rapid
web development. Everything from PHP code (Symfony helpers).
jQuery and Symfony write less, do more.
*Installation*
--------------
* Install the plugin (from http://plugins.symfony-project.com)
$ symfony plugin-install http://www.symfony-project.org/plugins/ysJQueryRevolutionsPlugin
* Install the plugin (from .tgz file)<br>
Download the .tgz from <br>
http://www.symfony-project.org/plugins/ysJQueryRevolutionsPlugin<br>
execute command:<br>
php symfony plugin:install path/to/ysJQueryRevolutionsPlugin-.x.x.x.tgz
* Enable modules in your `settings.yml` (optional for demos)
[yml]
all:
.settings:
enabled_modules: [default, jquery_demo]
* Enable the plugin if necessary by editing config/ProjectConfiguration.class.php:
[php]
$this->enablePlugins('ysJQueryRevolutionsPlugin');
* Publish plugin assets:
php symfony plugin:publish-assets
* Clear you cache
symfony cc
* See the app.yml to change where you load the library jquery (Optional)
[yml]
all:
.ys_jquery_revolutions_plugins:
### To load jQuery from ajax.googleapis.com:
### - jquery.min.js
#ys_jquery_path: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
### - jquery.js
#ys_jquery_path: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
### To load jQuery from localhost
### - Only available jquery.min.js
ys_jquery_path: /ysJQueryRevolutionsPlugin/js/jquery/jquery-1.3.2.min.js
### Uses structured configuration if you use plugins.
#ys_jquery_web_dir: ysJQueryRevolutionsPlugin
#ys_jquery_js_dir: jquery
#ys_jquery_core: jquery-1.3.2.min.js
#ys_jquery_plugins_folder: plugins
#ys_jquery_js_folder: js
#ys_jquery_css_folder: css
#ys_jquery_images_folder: images
#path_separattor: '/'
<br><br>
HELPERS
-------
* **ysJQueryRevolutionsHelper** (Recommended): generates the following jQuery syntax
[javascript]
jQuery('jquery-selector').event();
* **ysJQueryDollarRevolutionsHelper**: generates the following jQuery syntax
[javascript]
$('jquery-selector').event();
* **ysUtilHelper**: Add this helper in your wiews to support the php functions
json_encode() and boolean_for_javascript() php functions on Symfony 1.0.x
**IMPORTANT**: If you use these helpers very often is advisable to add in the
settings.yml
[yml]
all:
.settings:
standard_helpers: [Partial, Cache, Form, Javascript, ysJQueryRevolutions]
<br><br>
HOW TO USE
----------
*The Helper **like_function()**:*
Is a helper to represent a javascript function.
First Parameter is the body functions.
Second Parameter are the functions arguments.
[php]
<?php echo like_function(
"alert('Hello + ' myArg1); alert('Hello + ' myArg2)",
"myArg1, myArg2")?>
//javascript code generated
function(myArg1, myArg2){
alert('Hello + ' myArg1); alert('Hello + ' myArg2);
}
<br>
*The Helper **eval_function()**:*
Is a helper to represent the javascript eval() function.
First Parameter is the body functions.
[php]
<?php echo eval_function(
like_function(
"alert('Hello + ' myArg1); alert('Hello + ' myArg2)",
"myArg1, myArg2"))?>
//javascript code generated
eval("function(myArg1, myArg2){
alert('Hello + ' myArg1); alert('Hello + ' myArg2);
})"; ?>
<br>
*The New Helper **jquery_execute()**:*
To execute immediately a javascript or jquery function
[php]
<?php/* BEFORE the creation of jquery_execute function
echo add_jquery_support(
'document',
'ready' ,
like_function(
jquery_toggle_event(
'li',
array(
like_function('$(this).css({"list-style-type":"disc", "color":"blue"});'),
like_function('$(this).css({"list-style-type":"disc", "color":"red"});'),
like_function('$(this).css({"list-style-type":"", "color":"yellow"});'),
)))); */
/* Now with jquery_execute*/
echo jquery_execute(
jquery_toggle_event(
'li',
array(
like_function('$(this).css({"list-style-type":"disc", "color":"blue"});'),
like_function('$(this).css({"list-style-type":"disc", "color":"red"});'),
like_function('$(this).css({"list-style-type":"", "color":"yellow"});')))); ?>
<br>
*Adding **click** event:*
[php]
<?php echo add_jquery_support(
'#jQuerySelector', // You can use any jquery Selector '# . : < >' ...
'click' , // events 'click' , 'change' , 'dblclick' ...
like_function("alert('Hello World')")); ?>
<input type="button" id="exampleId" value="Click me" />
<br>
*Symfony Helper inside javascript code (use jquery_support() not add_jquery_support() )*
[php]
<?php echo core_init_javasacript_tag() ?> // <= <script language="javascript" type="text/javascript">
var jsVar = 'Hello world';
<?php echo jquery_support(
'#jQuerySelector',
'click' ,
like_function("alert(jsVar)"); ?>
<?php echo core_end_javasacript_tag() ?> // <= </script>
<input type="button" id="exampleId" value="Click me" />
<br><br>
**AJAX SUPPORT**
<br>
*jquery_ajax()*
Load a remote page using an HTTP request
[php]
<?php echo jquery_ajax(array(
'url' => url_for('module/action')
'data' => "'varName=value'", // See the double and simple quotes
'type' => 'POST'));
?>
<br>
*jquery_periodically_ajax()*
[php]
<?php echo core_init_javasacript_tag() ?>
<?php echo jquery_periodically_ajax(array(
'url' => url_for('module/action'),
'dataType' => 'json' ,
'success' => like_function("alert(data)" , 'data'),
'data' => "'varName=' + Math.ceil(Math.random() * 3)",
'frequency' => 5)); // <- Default value is 10 seconds
?>
<?php echo core_end_javasacript_tag() ?>
//OR
<?php echo jquery_ajax(array(
'url' => url_for('module/action')
'data' => "'varName=value'", // See the double and simple quotes
'type' => 'POST'
'frequency' => 3)); <- No default value
?>
<br>
*Ajax call on Click Event*
[php]
<?php echo add_jquery_support(
'#jQuerySelector',
'click' ,
like_function(
jquery_ajax(array(
'url' => url_for('module/action')
'data' => "'varName=value'", // See the double and simple quotes
'type' => 'POST')))); ?>
<a id="exampleId">To Remote Function</a>
<br>
*Ajax events and another way to add click event*
[php]
<?php echo jquery_ajax(array(
'listener' => array(
'selector' => '#jQuerySelector',
'event' => 'click'),
'url' => url_for('module/action'),
'dataType' => 'json' ,
'data' => "'varName'=5",
'type' => 'POST',
'complete' => like_function("alert('complete')" ),
'success' => like_function("alert(data)" , 'data'),
'async' => 'true',
'beforeSend' => like_function("alert('beforeSend')"),
'error' => like_function("alert('error')")));
?>
<br>
*jQuery Submit form with jquery_ajax_form()*
[php]
<?php echo jquery_ajax_form(
'#myForm',
array(
'url' => url_for('module/action'),
'success' => like_function("alert('Submit success')" , 'data'),
'type' => 'POST')) ?>
<br><br>
**OTHERS AJAX HELPERS:**
<br>
* **jquery_ajax_setup()**
Setup global settings for AJAX requests
<br>
[php]
<?php echo jquery_ajax_setup(
array(
'type' => 'json',)) ?>
<br>
<br>
* **jquery_ajax_get_request()**<br>
Load a remote page using an HTTP GET request
<br>
[php]
<?php echo jquery_ajax_get_request(
array(
'listener' => array(
'selector' => 'document',
'event' => 'ready'),
'url' => url_for('module/action'),
'callback' => like_function('alert("GET: Data SUCCESS: " + data);', 'data'),
//'type' => 'json',
'data' => array ('varName' => 'value'))) ?>
<br>
<br>
* **jquery_ajax_post_request()**<br>
Load a remote page using an HTTP POST request
<br>
[php]
<?php echo jquery_ajax_post_request(
array(
'listener' => array(
'selector' => 'document',
'event' => 'ready'),
'url' => url_for('module/action'),
'callback' => like_function('alert("POST: Data SUCCESS: " + data);', 'data'),
//'type' => 'json',
'data' => array ('varName' => 'value'))) ?>
<br>
<br>
* **jquery_load()**<br>
Load HTML from a remote file and inject it into the DOM
<br>
[php]
<?php echo jquery_load(
'#spnLoadResult',
array(
'listener' => array(
'selector' => '#jQuerySelector',
'event' => 'click'),
'url' => url_for('module/action'),
'callback' => like_function('alert("Data Loaded!")'),
'data' => array ('varName' => 'value'))) ?>
<br>
<br>
* **jquery_get_json():**<br>
Load JSON data using an HTTP GET request
<br>
[php]
<?php echo jquery_get_json(
array(
'listener' => array(
'selector' => '#jQuerySelector',
'event' => 'click'),
'url' => url_for('module/action'),
'callback' => like_function('alert(data)', 'data'),
'data' => array ('varName' => 'value'))) ?>
<br>
<br>
* **jquery_get_script():**<br>
Load JSON data using an HTTP GET request
<br>
[php]
<?php echo jquery_get_script(
array(
'listener' => array(
'selector' => '#jQuerySelector',
'event' => 'click'),
'url' => url_for('module/action'),
'callback' => like_function('alert(data)', 'data'))) ?>
<br>
* **jquery_ajax_event():** <br>
Attach a function to be executed whenever an AJAX request completes , fails
is sent,request begins ,requests have ended and completes successfully
<br>
[php]
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxComplete',
like_function("alert('Complete')")); ?>
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxSend',
like_function("alert('Send')", 'event,request,settings'));?>
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxStop',
like_function("alert('Stop')", 'event,request,settings'));?>
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxSuccess',
like_function("alert('Success')", 'event,request,settings'));?>
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxStart',
like_function("alert('Start')", 'event,request,settings'));?>
<?php echo jquery_ajax_event(
'#jQuerySelector',
'ajaxError',
like_function("alert('Error')", 'event,request,settings'));?>
<br><br>
**EFFECTS SUPPORT**
<br>
*jquery_execute_effect()*
[php]
jquery_execute_effect('#imageId', // jquery Selector
'fadeOut' , // event
array('speed' => 'fast',
'callback' => "alert('Event Excuted')")
*Adding effect on click event*
[php]
<?php echo add_jquery_support(
'#exampleId',
'click' ,
like_function(
jquery_execute_effect(
'#sfImg' ,
'fadeIn' ,
array('speed' => '900')))) ?>
<input type="button" id="exampleId" value="Click me" />
<img id="sfImg" alt="Debug toolbar" src="/sf/sf_web_debug/images/sf.png"/>
*Adding effect on Double Click event with callback*
[php]
<?php echo add_jquery_support(
'#exampleId',
'dblclick' ,
like_function(
jquery_execute_effect(
'#sfImg',
'fadeOut' ,
array(
'speed' => 'fast',
'callback' => "alert('Event Excuted')")))) ?>
<input type="button" id="exampleId" value="Hide Image" />
<img id="sfImg" alt="Debug toolbar" src="/sf/sf_web_debug/images/sf.png"/>
**IMPORTANT:** See the demo module for more documentation and source code.
<br><br><br>
**AVAILABLES HELPERS**
* CORE [documentation](http://docs.jquery.com "jQuery")
* core_init_javasacript_tag
* core_end_javasacript_tag
* core_get_jquery_var
* add_jquery_support
* jquery_support
* like_function
* eval_function
* jquery_serialize
* jquery_serialize_array
* jquery_get
* jquery_set
* add_css
* add_js
* AJAX [documentation](http://docs.jquery.com/Ajax "Ajax")
* jquery_ajax
* jquery_ajax_setup
* jquery_ajax_get_request
* jquery_ajax_post_request
* jquery_load
* jquery_get_json
* jquery_get_script
* jquery_ajax_event
* jquery_periodically_ajax
* jquery_ajax_form
* EFFECTS [documentation](http://docs.jquery.com/Effects "Effects")
* jquery_execute_effect
* EVENTS [documentation](http://docs.jquery.com/Events "Events")
* jquery_live_event
* jquery_die_event
* jquery_toggle_event
* jquery_hover_event
* jquery_bind_event
* jquery_one_event
* jquery_unbind_event
* jquery_trigger_event
* jquery_trigger_handler_event
* ysUtilHelper
* boolean_for_javascript
* json_encode
* set_jquery_plugins_configuration_files
* merge_plugin_defaults_options
*Todo*
-------
* Fix bugs
* Adding support for popular jquery plugins
*Changelog*
-----------
***2010-10-01 1.0.4 STABLE***
* oyepez003: added the internal functions add_css , add_js internal , set_jquery_plugins_configuration_files and merge_plugin_defaults_options
* oyepez003: added the jquery_execute function to execute immediately a javascript or jquery function
* oyepez003: added the options ['condition', 'onFailureCondition', 'confirmation', 'onNoConfirmation'] available for jquery_ajax() & jquery_ajax_form()
* oyepez003: added autocomplete support (ysJQueryAutocompleteHelper) see the documentation
***2009-15-12 1.0.3 STABLE***
* oyepez003: added the core_get_jquery_var() function
***2009-22-11 0.0.1 BETA***
* oyepez003: Initial release