| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Projax | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * An open source set of php helper classes for prototype and script.aculo.us. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @package     Projax | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author      Vikas Patial | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright   Copyright (c) 2006, ngcoders. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @license     http://www.gnu.org/copyleft/gpl.html | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @link        http://www.ngcoders.com | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @since       Version 0.2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @filesource | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 16 |  | View Code Duplication | class Scriptaculous extends Prototype | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public $TOGGLE_EFFECTS = ['toggle_appear', 'toggle_slide', 'toggle_blind']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Scriptaculous constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param         $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * @param  null   $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function dragable_element($element_id, $options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         return $this->tag($this->_dragable_element_js($element_id, $options)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @param         $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param  null   $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     public function drop_receiving_element($element_id, $options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         return $this->tag($this->_drop_receiving_element($element_id, $options)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param         $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param  bool   $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param  null   $js_options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function visual_effect($name, $element_id = false, $js_options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $element = $element_id ? "'$element_id'" : 'element'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $js_queue = ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         if (isset($js_options) && is_array($js_options['queue'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } elseif (isset($js_options)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $js_queue = "'$js_options'"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         if (in_array($name, $this->TOGGLE_EFFECTS)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             return "Effect.toggle($element,'" . str_replace('toggle_', '', $name) . "'," . $this->_options_for_javascript($js_options) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             return 'new Effect.' . ucwords($name) . "($element," . $this->_options_for_javascript($js_options) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param         $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @param  null   $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     public function sortabe_element($element_id, $options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         return $this->tag($this->_sortabe_element($element_id, $options)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     ///////////////////////////////////////////////////////////////////////////////////// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     //                             Private functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     ///////////////////////////////////////////////////////////////////////////////////// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @param $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     public function _sortabe_element($element_id, $options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         //if (isset($options['with'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             $options['with'] = "Sortable.serialize('$element_id')"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         //if (isset($option['onUpdate'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             $options['onUpdate'] = 'function(){' . $this->remote_function($options) . '}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         foreach ($options as $var => $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             if (in_array($var, $this->AJAX_OPTIONS)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                 unset($options[$var]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $arr = ['tag', 'overlap', 'contraint', 'handle']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         foreach ($arr as $var) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             if (isset($options[$var])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 $options[$var] = "'" . $options[$var] . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         if (isset($options['containment'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $options['containment'] = $this->_array_or_string_for_javascript($options['containment']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         if (isset($options['only'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $options['only'] = $this->_array_or_string_for_javascript($options['only']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return "Sortable.create('$element_id'," . $this->_options_for_javascript($options) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      * @param $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |      * @param $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     public function _dragable_element_js($element_id, $options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         return 'new Draggable(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * @param $element_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * @param $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     public function _drop_receiving_element($element_id, $options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         //if (isset($options['with'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |             $options['with'] = '\'id=\' + encodeURIComponent(element.id)'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         //if (isset($option['onDrop'])) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |             $options['onDrop'] = 'function(element){' . $this->remote_function($options) . '}'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         if (is_array($options)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             foreach ($options as $var => $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |                 if (in_array($var, $this->AJAX_OPTIONS)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                     unset($options[$var]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         if (isset($options['accept'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |             $options['accept'] = $this->_array_or_string_for_javascript($options['accept']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         if (isset($options['hoverclass'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |             $options['hoverclass'] = "'" . $options['hoverclass'] . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         return 'Droppables.add(\'' . $element_id . '\',' . $this->_options_for_javascript($options) . ')'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |     ///////////////////////////////////////////////////////////////////////////////////// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     //                            Merged Javascript macro | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |     ///////////////////////////////////////////////////////////////////////////////////// | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * @param         $field_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * @param         $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      * @param  bool   $tag | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 183 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 184 |  |  |     public function in_place_editor($field_id, $options, $tag = true) | 
            
                                                                        
                            
            
                                    
            
            
                | 185 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 186 |  |  |         $function = 'new Ajax.InPlaceEditor('; | 
            
                                                                        
                            
            
                                    
            
            
                | 187 |  |  |         $function .= "'$field_id', "; | 
            
                                                                        
                            
            
                                    
            
            
                | 188 |  |  |         $function .= "'" . $options['url'] . "'"; | 
            
                                                                        
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 190 |  |  |         $js_options = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  |         if (isset($options['cancel_text'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  |             $js_options['cancelText'] = $options['cancel_text']; | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |         if (isset($options['save_text'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |             $js_options['okText'] = $options['save_text']; | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |         if (isset($options['loading_text'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |             $js_options['loadingText'] = $options['loading_text']; | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 200 |  |  |         if (isset($options['rows'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 201 |  |  |             $js_options['rows'] = $options['rows']; | 
            
                                                                        
                            
            
                                    
            
            
                | 202 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 203 |  |  |         if (isset($options['cols'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 204 |  |  |             $js_options['cols'] = $options['cols']; | 
            
                                                                        
                            
            
                                    
            
            
                | 205 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 206 |  |  |         if (isset($options['size'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 207 |  |  |             $js_options['size'] = $options['size']; | 
            
                                                                        
                            
            
                                    
            
            
                | 208 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 209 |  |  |         if (isset($options['external_control'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 210 |  |  |             $js_options['externalControl'] = "'" . $options['external_control'] . "'"; | 
            
                                                                        
                            
            
                                    
            
            
                | 211 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 212 |  |  |         if (isset($options['load_text_url'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 213 |  |  |             $js_options['loadTextURL'] = "'" . $options['load_text_url'] . "'"; | 
            
                                                                        
                            
            
                                    
            
            
                | 214 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 215 |  |  |         if (isset($options['options'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 216 |  |  |             $js_options['ajaxOptions'] = $options['options']; | 
            
                                                                        
                            
            
                                    
            
            
                | 217 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 218 |  |  |         if (isset($options['script'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 219 |  |  |             $js_options['evalScripts'] = $options['script']; | 
            
                                                                        
                            
            
                                    
            
            
                | 220 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 221 |  |  |         if (isset($options['with'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 222 |  |  |             $js_options['callback'] = 'function(form) { return ' . $options['with'] . ' }'; | 
            
                                                                        
                            
            
                                    
            
            
                | 223 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 224 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 225 |  |  |         $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; | 
            
                                                                        
                            
            
                                    
            
            
                | 226 |  |  |         if ($tag) { | 
            
                                                                        
                            
            
                                    
            
            
                | 227 |  |  |             return $this->tag($function); | 
            
                                                                        
                            
            
                                    
            
            
                | 228 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 229 |  |  |             return $function; | 
            
                                                                        
                            
            
                                    
            
            
                | 230 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 231 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |      * @param         $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |      * @param  null   $tag_options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |      * @param  null   $in_place_editor_options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     public function in_place_editor_field($object, $tag_options = null, $in_place_editor_options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         $ret_val = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         $ret_val .= '<span id="' . $object . '" class="in_place_editor_field">' . (isset($tag_options['value']) ? $tag_options['value'] : '') . '</span>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         $ret_val .= $this->in_place_editor($object, $in_place_editor_options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |         return $ret_val; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |      * @param $field_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |      * @param $options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     public function auto_complete_field($field_id, $options) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         $function = "var $field_id" . '_auto_completer = new Ajax.Autocompleter('; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         $function .= "'$field_id', "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         $function .= "'" . (isset($options['update']) ? $options['update'] : $field_id . '_auto_complete') . "', "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         $function .= "'" . $options['url'] . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         $js_options = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         if (isset($options['tokens'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |             $js_options['tokens'] = $this->javascript->_array_or_string_for_javascript($options['tokens']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         if (isset($options['with'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |             $js_options['callback'] = 'function(element, value) { return ' . $options['with'] . ' }'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |         if (isset($options['indicator'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |             $js_options['indicator'] = "'" . $options['indicator'] . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         if (isset($options['select'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             $js_options['select'] = "'" . $options['select'] . "'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |         foreach (['on_show' => 'onShow', 'on_hide' => 'onHide', 'min_chars' => 'min_chars'] as $var => $val) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |             if (isset($options[$var])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |                 $js_options['$val'] = $options['var']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         $function .= ', ' . $this->_options_for_javascript($js_options) . ' )'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         return $this->tag($function); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |      * @param      $entries | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |      * @param      $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |      * @param null $phrase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |     public function auto_complete_results($entries, $field, $phrase = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         if (!is_array($entries)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         $ret_val = '<ul>'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         //  Complete this function | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |      * @param         $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |      * @param  null   $tag_options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |      * @param  null   $completion_options | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |     public function text_field_with_auto_complete($object, $tag_options = null, $completion_options = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |         $ret_val = isset($completion_options['skip_style']) ? '' : $this->_auto_complete_stylesheet(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |         $ret_val .= '<input autocomplete="off" id="' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |                     . $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |                     . '" name="' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |                     . $object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |                     . '" size="' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |                     . (isset($tag_options['size']) ? $tag_options['size'] : 30) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |                     . '" type="text" value="' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |                     . (isset($tag_options['size']) ? $tag_options['value'] : '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |                     . '" ' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |                     . (isset($tag_options['class']) ? 'class = "' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |                                                       . $tag_options['class'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |                                                       . '" ' : '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |                     . '>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         $ret_val .= '<div id="' . $object . '_auto_complete" class="auto_complete"></div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |         $ret_val .= $this->auto_complete_field($object, $completion_options); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         return $ret_val; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     public function _auto_complete_stylesheet() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         return '<style> div.auto_complete { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |                   width: 350px; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |                   background: #fff; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  |                  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |                 div.auto_complete ul { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  |                    border:1px solid #888; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  |                    margin:0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |                    padding:0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  |                    width:100%; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  |                    list-style-type:none; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |                  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 |  |  |                  div.auto_complete ul li { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 |  |  |                    margin:0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 |  |  |                    padding:3px; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 |  |  |                  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 |  |  |                  div.auto_complete ul li.selected { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 |  |  |                    background-color: #ffb; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 |  |  |                  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 |  |  |                  div.auto_complete ul strong.highlight { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 |  |  |                    color: #800; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 |  |  |                    margin:0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 |  |  |                    padding:0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  |                  } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 |  |  |                  </style>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 358 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 359 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.