Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Jquery often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Jquery, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class Jquery { |
||
| 19 | protected $_di; |
||
| 20 | protected $_ui; |
||
| 21 | protected $_bootstrap; |
||
| 22 | protected $libraryFile; |
||
| 23 | protected $_javascript_folder='js'; |
||
| 24 | protected $jquery_code_for_load=array (); |
||
| 25 | protected $jquery_code_for_compile=array (); |
||
| 26 | protected $jquery_corner_active=FALSE; |
||
| 27 | protected $jquery_table_sorter_active=FALSE; |
||
| 28 | protected $jquery_table_sorter_pager_active=FALSE; |
||
| 29 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
||
| 30 | protected $jquery_events=array ( |
||
| 31 | "bind","blur","change","click","dblclick","delegate","die","error","focus","focusin","focusout","hover","keydown","keypress","keyup","live","load","mousedown","mousseenter","mouseleave","mousemove","mouseout","mouseover","mouseup","off","on","one","ready","resize","scroll","select","submit","toggle","trigger","triggerHandler","undind","undelegate","unload" |
||
| 32 | ); |
||
| 33 | |||
| 34 | public function setDi($di) { |
||
| 37 | |||
| 38 | public function ui($ui=NULL) { |
||
| 44 | |||
| 45 | public function bootstrap($bootstrap=NULL) { |
||
| 51 | |||
| 52 | public function __construct($params) { |
||
| 58 | |||
| 59 | // -------------------------------------------------------------------- |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Inline |
||
| 63 | * |
||
| 64 | * Outputs a <script> tag |
||
| 65 | * |
||
| 66 | * @access public |
||
| 67 | * @param string $script |
||
| 68 | * @param boolean $cdata a CDATA section should be added |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function inline($script, $cdata=TRUE) { |
|
| 78 | |||
| 79 | // -------------------------------------------------------------------- |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Open Script |
||
| 83 | * |
||
| 84 | * Outputs an opening <script> |
||
| 85 | * |
||
| 86 | * @access private |
||
| 87 | * @param string $src |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | private function _open_script($src='') { |
||
| 95 | |||
| 96 | // -------------------------------------------------------------------- |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Close Script |
||
| 100 | * |
||
| 101 | * Outputs an closing </script> |
||
| 102 | * |
||
| 103 | * @param string |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | private function _close_script($extra="\n") { |
||
| 109 | |||
| 110 | public function getLibraryScript() { |
||
| 115 | |||
| 116 | public function setLibraryFile($name) { |
||
| 119 | |||
| 120 | public function _setAjaxLoader($loader) { |
||
| 123 | |||
| 124 | // -------------------------------------------------------------------- |
||
| 125 | // Event Code |
||
| 126 | // -------------------------------------------------------------------- |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Blur |
||
| 130 | * |
||
| 131 | * Outputs a jQuery blur event |
||
| 132 | * |
||
| 133 | * @param string The element to attach the event to |
||
| 134 | * @param string The code to execute |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | public function _blur($element='this', $js='') { |
||
| 140 | |||
| 141 | // -------------------------------------------------------------------- |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Change |
||
| 145 | * |
||
| 146 | * Outputs a jQuery change event |
||
| 147 | * |
||
| 148 | * @param string The element to attach the event to |
||
| 149 | * @param string The code to execute |
||
| 150 | * @return string |
||
| 151 | */ |
||
| 152 | public function _change($element='this', $js='') { |
||
| 155 | |||
| 156 | // -------------------------------------------------------------------- |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Outputs a jQuery click event |
||
| 160 | * |
||
| 161 | * @param string $element The element to attach the event to |
||
| 162 | * @param mixed $js The code to execute |
||
| 163 | * @param boolean $ret_false whether or not to return false |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function _click($element='this', $js=array(), $ret_false=TRUE) { |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Outputs a jQuery contextmenu event |
||
| 182 | * |
||
| 183 | * @param string The element to attach the event to |
||
| 184 | * @param string The code to execute |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function _contextmenu($element='this', $js='') { |
||
| 190 | |||
| 191 | // -------------------------------------------------------------------- |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Outputs a jQuery dblclick event |
||
| 195 | * |
||
| 196 | * @param string The element to attach the event to |
||
| 197 | * @param string The code to execute |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function _dblclick($element='this', $js='') { |
||
| 203 | |||
| 204 | // -------------------------------------------------------------------- |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Outputs a jQuery error event |
||
| 208 | * |
||
| 209 | * @param string The element to attach the event to |
||
| 210 | * @param string The code to execute |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | public function _error($element='this', $js='') { |
||
| 216 | |||
| 217 | // -------------------------------------------------------------------- |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Outputs a jQuery focus event |
||
| 221 | * |
||
| 222 | * @param string The element to attach the event to |
||
| 223 | * @param string The code to execute |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function _focus($element='this', $js='') { |
||
| 229 | |||
| 230 | // -------------------------------------------------------------------- |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Outputs a jQuery hover event |
||
| 234 | * |
||
| 235 | * @param string - element |
||
| 236 | * @param string - Javascript code for mouse over |
||
| 237 | * @param string - Javascript code for mouse out |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function _hover($element='this', $over, $out) { |
||
| 247 | |||
| 248 | // -------------------------------------------------------------------- |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Outputs a jQuery keydown event |
||
| 252 | * |
||
| 253 | * @param string The element to attach the event to |
||
| 254 | * @param string The code to execute |
||
| 255 | * @return string |
||
| 256 | */ |
||
| 257 | public function _keydown($element='this', $js='') { |
||
| 260 | |||
| 261 | // -------------------------------------------------------------------- |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Outputs a jQuery keypress event |
||
| 265 | * |
||
| 266 | * @param string The element to attach the event to |
||
| 267 | * @param string The code to execute |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function _keypress($element='this', $js='') { |
||
| 273 | |||
| 274 | // -------------------------------------------------------------------- |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Outputs a jQuery keydown event |
||
| 278 | * |
||
| 279 | * @param string The element to attach the event to |
||
| 280 | * @param string The code to execute |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function _keyup($element='this', $js='') { |
||
| 286 | |||
| 287 | // -------------------------------------------------------------------- |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Outputs a jQuery load event |
||
| 291 | * |
||
| 292 | * @param string The element to attach the event to |
||
| 293 | * @param string The code to execute |
||
| 294 | * @return string |
||
| 295 | */ |
||
| 296 | public function _load($element='this', $js='') { |
||
| 299 | |||
| 300 | // -------------------------------------------------------------------- |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Outputs a jQuery mousedown event |
||
| 304 | * |
||
| 305 | * @param string The element to attach the event to |
||
| 306 | * @param string The code to execute |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public function _mousedown($element='this', $js='') { |
||
| 312 | |||
| 313 | // -------------------------------------------------------------------- |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Outputs a jQuery mouseout event |
||
| 317 | * |
||
| 318 | * @param string The element to attach the event to |
||
| 319 | * @param string The code to execute |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | public function _mouseout($element='this', $js='') { |
||
| 325 | |||
| 326 | // -------------------------------------------------------------------- |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Outputs a jQuery mouseover event |
||
| 330 | * |
||
| 331 | * @param string The element to attach the event to |
||
| 332 | * @param string The code to execute |
||
| 333 | * @return string |
||
| 334 | */ |
||
| 335 | public function _mouseover($element='this', $js='') { |
||
| 338 | |||
| 339 | // -------------------------------------------------------------------- |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Outputs a jQuery mouseup event |
||
| 343 | * |
||
| 344 | * @param string The element to attach the event to |
||
| 345 | * @param string The code to execute |
||
| 346 | * @return string |
||
| 347 | */ |
||
| 348 | public function _mouseup($element='this', $js='') { |
||
| 351 | |||
| 352 | // -------------------------------------------------------------------- |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Outputs script directly |
||
| 356 | * |
||
| 357 | * @param string The element to attach the event to |
||
| 358 | * @param string The code to execute |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | public function _output($array_js='') { |
||
| 372 | |||
| 373 | // -------------------------------------------------------------------- |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Outputs a jQuery resize event |
||
| 377 | * |
||
| 378 | * @param string The element to attach the event to |
||
| 379 | * @param string The code to execute |
||
| 380 | * @return string |
||
| 381 | */ |
||
| 382 | public function _resize($element='this', $js='') { |
||
| 385 | |||
| 386 | // -------------------------------------------------------------------- |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Outputs a jQuery scroll event |
||
| 390 | * |
||
| 391 | * @param string The element to attach the event to |
||
| 392 | * @param string The code to execute |
||
| 393 | * @return string |
||
| 394 | */ |
||
| 395 | public function _scroll($element='this', $js='') { |
||
| 398 | |||
| 399 | // -------------------------------------------------------------------- |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Outputs a jQuery unload event |
||
| 403 | * |
||
| 404 | * @param string The element to attach the event to |
||
| 405 | * @param string The code to execute |
||
| 406 | * @return string |
||
| 407 | */ |
||
| 408 | public function _unload($element='this', $js='') { |
||
| 411 | |||
| 412 | // -------------------------------------------------------------------- |
||
| 413 | // Effects |
||
| 414 | // -------------------------------------------------------------------- |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Insert content, specified by the parameter, after each element in the set of matched elements |
||
| 418 | * @param string $element |
||
| 419 | * @param string $value |
||
| 420 | * @param boolean $immediatly defers the execution if set to false |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | public function after($element='this', $value='', $immediatly=false){ |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Get or set the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element. |
||
| 434 | * @param string $element |
||
| 435 | * @param string $attributeName |
||
| 436 | * @param string $value |
||
| 437 | * @param boolean $immediatly delayed if false |
||
| 438 | */ |
||
| 439 | View Code Duplication | public function _attr($element='this', $attributeName, $value="", $immediatly=false) { |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Execute a generic jQuery call with a value. |
||
| 453 | * @param string $jQueryCall |
||
| 454 | * @param string $element |
||
| 455 | * @param string $param |
||
| 456 | * @param boolean $immediatly delayed if false |
||
| 457 | */ |
||
| 458 | View Code Duplication | public function _genericCallValue($jQueryCall,$element='this', $param="", $immediatly=false) { |
|
| 469 | /** |
||
| 470 | * Execute a generic jQuery call with 2 elements. |
||
| 471 | * @param string $jQueryCall |
||
| 472 | * @param string $to |
||
| 473 | * @param string $element |
||
| 474 | * @param boolean $immediatly delayed if false |
||
| 475 | * @return string |
||
| 476 | */ |
||
| 477 | public function _genericCallElement($jQueryCall,$to='this', $element, $immediatly=false) { |
||
| 485 | // -------------------------------------------------------------------- |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Outputs a jQuery animate event |
||
| 489 | * |
||
| 490 | * @param string $element element |
||
| 491 | * @param string|array $params One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 492 | * @param string $speed |
||
| 493 | * @param string $extra |
||
| 494 | * @param boolean $immediatly delayed if false |
||
| 495 | * @return string |
||
| 496 | */ |
||
| 497 | public function _animate($element='this', $params=array(), $speed='', $extra='', $immediatly=false) { |
||
| 523 | |||
| 524 | // -------------------------------------------------------------------- |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Outputs a jQuery hide event |
||
| 528 | * |
||
| 529 | * @param string $element element |
||
| 530 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 531 | * @param string $callback Javascript callback function |
||
| 532 | * @param boolean $immediatly delayed if false |
||
| 533 | * @return string |
||
| 534 | */ |
||
| 535 | View Code Duplication | public function _fadeIn($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 549 | |||
| 550 | // -------------------------------------------------------------------- |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Outputs a jQuery hide event |
||
| 554 | * |
||
| 555 | * @param string $element element |
||
| 556 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 557 | * @param string $callback Javascript callback function |
||
| 558 | * @param boolean $immediatly delayed if false |
||
| 559 | * @return string |
||
| 560 | */ |
||
| 561 | View Code Duplication | public function _fadeOut($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 575 | |||
| 576 | // -------------------------------------------------------------------- |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Outputs a jQuery hide action |
||
| 580 | * |
||
| 581 | * @param string $element element |
||
| 582 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 583 | * @param string $callback Javascript callback function |
||
| 584 | * @param boolean $immediatly delayed if false |
||
| 585 | * @return string |
||
| 586 | */ |
||
| 587 | View Code Duplication | public function _hide($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 601 | |||
| 602 | // -------------------------------------------------------------------- |
||
| 603 | |||
| 604 | // -------------------------------------------------------------------- |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Outputs a jQuery slideUp event |
||
| 608 | * |
||
| 609 | * @param string $element element |
||
| 610 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 611 | * @param string $callback Javascript callback function |
||
| 612 | * @param boolean $immediatly delayed if false |
||
| 613 | * @return string |
||
| 614 | */ |
||
| 615 | View Code Duplication | public function _slideUp($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 629 | |||
| 630 | // -------------------------------------------------------------------- |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Outputs a jQuery slideDown event |
||
| 634 | * |
||
| 635 | * @param string $element element |
||
| 636 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 637 | * @param string $callback Javascript callback function |
||
| 638 | * @param boolean $immediatly delayed if false |
||
| 639 | * @return string |
||
| 640 | */ |
||
| 641 | View Code Duplication | public function _slideDown($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 655 | |||
| 656 | // -------------------------------------------------------------------- |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Outputs a jQuery slideToggle event |
||
| 660 | * |
||
| 661 | * @param string $element element |
||
| 662 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 663 | * @param string $callback Javascript callback function |
||
| 664 | * @param boolean $immediatly delayed if false |
||
| 665 | * @return string |
||
| 666 | */ |
||
| 667 | View Code Duplication | public function _slideToggle($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 681 | |||
| 682 | // -------------------------------------------------------------------- |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Outputs a jQuery toggle event |
||
| 686 | * |
||
| 687 | * @param string $element element |
||
| 688 | * @param boolean $immediatly delayed if false |
||
| 689 | * @return string |
||
| 690 | */ |
||
| 691 | View Code Duplication | public function _toggle($element='this', $immediatly=false) { |
|
| 699 | |||
| 700 | // -------------------------------------------------------------------- |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Execute all handlers and behaviors attached to the matched elements for the given event. |
||
| 704 | * @param string $element |
||
| 705 | * @param string $event |
||
| 706 | * @param boolean $immediatly delayed if false |
||
| 707 | */ |
||
| 708 | View Code Duplication | public function _trigger($element='this', $event='click', $immediatly=false) { |
|
| 716 | |||
| 717 | // -------------------------------------------------------------------- |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Outputs a jQuery show event |
||
| 721 | * |
||
| 722 | * @param string $element element |
||
| 723 | * @param string $speed One of 'slow', 'normal', 'fast', or time in milliseconds |
||
| 724 | * @param string $callback Javascript callback function |
||
| 725 | * @param boolean $immediatly delayed if false |
||
| 726 | * @return string |
||
| 727 | */ |
||
| 728 | View Code Duplication | public function _show($element='this', $speed='', $callback='', $immediatly=false) { |
|
| 742 | |||
| 743 | /** |
||
| 744 | * Places a condition |
||
| 745 | * @param string $condition |
||
| 746 | * @param string $jsCodeIfTrue |
||
| 747 | * @param string $jsCodeIfFalse |
||
| 748 | * @param boolean $immediatly delayed if false |
||
| 749 | * @return string |
||
| 750 | */ |
||
| 751 | public function _condition($condition, $jsCodeIfTrue, $jsCodeIfFalse=null, $immediatly=false) { |
||
| 761 | |||
| 762 | // -------------------------------------------------------------------- |
||
| 763 | // Plugins |
||
| 764 | // -------------------------------------------------------------------- |
||
| 765 | |||
| 766 | /** |
||
| 767 | * Creates a jQuery sortable |
||
| 768 | * |
||
| 769 | * @param string $element |
||
| 770 | * @param array $options |
||
| 771 | * @return void |
||
| 772 | */ |
||
| 773 | public function sortable($element, $options=array()) { |
||
| 786 | |||
| 787 | // -------------------------------------------------------------------- |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Table Sorter Plugin |
||
| 791 | * |
||
| 792 | * @param string $table table name |
||
| 793 | * @param string $options plugin location |
||
| 794 | * @return string |
||
| 795 | */ |
||
| 796 | public function tablesorter($table='', $options='') { |
||
| 799 | |||
| 800 | // -------------------------------------------------------------------- |
||
| 801 | // Class functions |
||
| 802 | // -------------------------------------------------------------------- |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Constructs the syntax for an event, and adds to into the array for compilation |
||
| 806 | * |
||
| 807 | * @param string $element The element to attach the event to |
||
| 808 | * @param string $js The code to execute |
||
| 809 | * @param string $event The event to pass |
||
| 810 | * @param boolean $preventDefault If set to true, the default action of the event will not be triggered. |
||
| 811 | * @param boolean $stopPropagation Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. |
||
| 812 | * @return string |
||
| 813 | */ |
||
| 814 | public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
||
| 832 | |||
| 833 | // -------------------------------------------------------------------- |
||
| 834 | |||
| 835 | /** |
||
| 836 | * As events are specified, they are stored in an array |
||
| 837 | * This function compiles them all for output on a page |
||
| 838 | * @param view $view |
||
| 839 | * @param string $view_var |
||
| 840 | * @param boolean $script_tags |
||
| 841 | * @return string |
||
| 842 | */ |
||
| 843 | public function _compile($view=NULL, $view_var='script_foot', $script_tags=TRUE) { |
||
| 886 | |||
| 887 | public function _addToCompile($jsScript) { |
||
| 890 | |||
| 891 | // -------------------------------------------------------------------- |
||
| 892 | |||
| 893 | /** |
||
| 894 | * Clears the array of script events collected for output |
||
| 895 | * |
||
| 896 | * @return void |
||
| 897 | */ |
||
| 898 | public function _clear_compile() { |
||
| 901 | |||
| 902 | // -------------------------------------------------------------------- |
||
| 903 | |||
| 904 | /** |
||
| 905 | * A wrapper for writing document.ready() |
||
| 906 | * |
||
| 907 | * @return string |
||
| 908 | */ |
||
| 909 | public function _document_ready($js) { |
||
| 920 | |||
| 921 | // -------------------------------------------------------------------- |
||
| 922 | |||
| 923 | /** |
||
| 924 | * Puts HTML element in quotes for use in jQuery code |
||
| 925 | * unless the supplied element is the Javascript 'this' |
||
| 926 | * object, in which case no quotes are added |
||
| 927 | * |
||
| 928 | * @param string $element |
||
| 929 | * @return string |
||
| 930 | */ |
||
| 931 | public function _prep_element($element) { |
||
| 937 | |||
| 938 | /** |
||
| 939 | * Puts HTML values in quotes for use in jQuery code |
||
| 940 | * unless the supplied value contains the Javascript 'this' or 'event' |
||
| 941 | * object, in which case no quotes are added |
||
| 942 | * |
||
| 943 | * @param string $value |
||
| 944 | * @return string |
||
| 945 | */ |
||
| 946 | public function _prep_value($value) { |
||
| 955 | |||
| 956 | // -------------------------------------------------------------------- |
||
| 957 | |||
| 958 | /** |
||
| 959 | * Ensures the speed parameter is valid for jQuery |
||
| 960 | * |
||
| 961 | * @param string|int $speed |
||
| 962 | * @return string |
||
| 963 | */ |
||
| 964 | private function _validate_speed($speed) { |
||
| 975 | // ------------------------------------------------------------------------ |
||
| 976 | protected function addLoading(&$retour, $responseElement) { |
||
| 987 | |||
| 988 | public function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
||
| 994 | |||
| 995 | protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
||
| 1010 | |||
| 1011 | protected function _getAjaxUrl($url,$attr){ |
||
| 1025 | |||
| 1026 | protected function _getOnAjaxDone($responseElement,$jsCallback){ |
||
| 1034 | |||
| 1035 | protected function _getResponseElement($responseElement){ |
||
| 1041 | |||
| 1042 | protected function _correctAjaxUrl($url) { |
||
| 1050 | |||
| 1051 | /** |
||
| 1052 | * Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name |
||
| 1053 | * @param string $url the request address |
||
| 1054 | * @param string $params Paramètres passés au format JSON |
||
| 1055 | * @param string $method Method use |
||
| 1056 | * @param string $jsCallback javascript code to execute after the request |
||
| 1057 | * @param boolean $immediatly |
||
| 1058 | */ |
||
| 1059 | public function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
||
| 1072 | |||
| 1073 | /** |
||
| 1074 | * Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name when $event fired on $element |
||
| 1075 | * @param string $element |
||
| 1076 | * @param string $event |
||
| 1077 | * @param string $url the request address |
||
| 1078 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
||
| 1079 | */ |
||
| 1080 | View Code Duplication | public function _jsonOn($event,$element, $url,$parameters=array()) { |
|
| 1092 | |||
| 1093 | /** |
||
| 1094 | * Makes an ajax request and receives a JSON array data types by copying and assigning them to the DOM elements with the same name |
||
| 1095 | * @param string $url the request address |
||
| 1096 | * @param string $params Paramètres passés au format JSON |
||
| 1097 | * @param string $method Method use |
||
| 1098 | * @param string $jsCallback javascript code to execute after the request |
||
| 1099 | * @param string $context jquery DOM element, array container. |
||
| 1100 | * @param boolean $immediatly |
||
| 1101 | */ |
||
| 1102 | public function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context=null,$immediatly=false) { |
||
| 1122 | /** |
||
| 1123 | * Makes an ajax request and receives the JSON data types by assigning DOM elements with the same name when $event fired on $element |
||
| 1124 | * @param string $element |
||
| 1125 | * @param string $event |
||
| 1126 | * @param string $url the request address |
||
| 1127 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get", "context"=>null) |
||
| 1128 | */ |
||
| 1129 | View Code Duplication | public function _jsonArrayOn($event,$element, $maskSelector,$url,$parameters=array()) { |
|
| 1141 | |||
| 1142 | public function _postForm($url, $form, $responseElement, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$immediatly=false) { |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Effectue un get vers $url sur l'évènement $event de $element en passant les paramètres $params |
||
| 1167 | * puis affiche le résultat dans $responseElement |
||
| 1168 | * @param string $element |
||
| 1169 | * @param string $event |
||
| 1170 | * @param string $url |
||
| 1171 | * @param string $params queryString parameters (JSON format). default : {} |
||
| 1172 | * @param string $responseElement |
||
| 1173 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
||
| 1174 | */ |
||
| 1175 | View Code Duplication | public function _getOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Effectue un post vers $url sur l'évènement $event de $element en passant les paramètres $params |
||
| 1188 | * puis affiche le résultat dans $responseElement |
||
| 1189 | * @param string $element |
||
| 1190 | * @param string $event |
||
| 1191 | * @param string $url |
||
| 1192 | * @param string $params queryString parameters (JSON format). default : {} |
||
| 1193 | * @param string $responseElement |
||
| 1194 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true) |
||
| 1195 | */ |
||
| 1196 | View Code Duplication | public function _postOn($event,$element, $url, $params="{}", $responseElement="", $parameters=array()) { |
|
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Effectue un post vers $url sur l'évènement $event de $element en passant les paramètres du formulaire $form |
||
| 1209 | * puis affiche le résultat dans $responseElement |
||
| 1210 | * @param string $element |
||
| 1211 | * @param string $event |
||
| 1212 | * @param string $url |
||
| 1213 | * @param string $form |
||
| 1214 | * @param string $responseElement |
||
| 1215 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"validation"=>false,"jsCallback"=>NULL,"attr"=>"id","hasLoader"=>true,"immediatly"=>true) |
||
| 1216 | */ |
||
| 1217 | View Code Duplication | public function _postFormOn($event,$element, $url, $form, $responseElement="", $parameters=array()) { |
|
| 1228 | |||
| 1229 | /** |
||
| 1230 | * Call the JQuery method $jqueryCall on $element with parameters $param |
||
| 1231 | * @param string $element |
||
| 1232 | * @param string $jqueryCall |
||
| 1233 | * @param mixed $param |
||
| 1234 | * @param string $jsCallback javascript code to execute after the jquery call |
||
| 1235 | * @param boolean $immediatly |
||
| 1236 | * @return string |
||
| 1237 | */ |
||
| 1238 | public function _doJQuery($element, $jqueryCall, $param="", $jsCallback="", $immediatly=false) { |
||
| 1248 | |||
| 1249 | /** |
||
| 1250 | * |
||
| 1251 | * @param string $event |
||
| 1252 | * @param string $element |
||
| 1253 | * @param string $elementToModify |
||
| 1254 | * @param string $jqueryCall |
||
| 1255 | * @param string|array $param |
||
| 1256 | * @param boolean $preventDefault |
||
| 1257 | * @param boolean $stopPropagation |
||
| 1258 | * @param string $jsCallback javascript code to execute after the jquery call |
||
| 1259 | * @param boolean $immediatly |
||
| 1260 | * @return string |
||
| 1261 | */ |
||
| 1262 | public function _doJQueryOn($event, $element, $elementToModify, $jqueryCall, $param="", $preventDefault=false, $stopPropagation=false, $jsCallback="",$immediatly=true) { |
||
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Execute the code $js |
||
| 1268 | * @param string $js Code to execute |
||
| 1269 | * @param boolean $immediatly diffère l'exécution si false |
||
| 1270 | * @return String |
||
| 1271 | */ |
||
| 1272 | public function _exec($js, $immediatly=false) { |
||
| 1278 | |||
| 1279 | /** |
||
| 1280 | * |
||
| 1281 | * @param string $element |
||
| 1282 | * @param string $event |
||
| 1283 | * @param string $js Code to execute |
||
| 1284 | * @param boolean $preventDefault |
||
| 1285 | * @param boolean $stopPropagation |
||
| 1286 | * @param boolean $immediatly |
||
| 1287 | * @return String |
||
| 1288 | */ |
||
| 1289 | public function _execOn($element, $event, $js, $preventDefault=false, $stopPropagation=false,$immediatly=true) { |
||
| 1292 | |||
| 1293 | private function minify($input) { |
||
| 1317 | } |
||
| 1318 | /* End of file Jquery.php */ |
||
| 1319 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: