[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/projax/classes/ -> Scriptaculous.php (source)

   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  
  17  class Scriptaculous extends Prototype   {
  18      
  19      var $TOGGLE_EFFECTS = array('toggle_appear', 'toggle_slide','toggle_blind');
  20  
  21  	function Scriptaculous(){
  22      }
  23  
  24  	function dragable_element($element_id,$options=null)
  25      {
  26          return $this->tag($this->_dragable_element_js($element_id,$options));
  27      }
  28  
  29  	function drop_receiving_element($element_id,$options=null)
  30      {
  31          return $this->tag($this->_drop_receiving_element($element_id,$options));
  32      }
  33  
  34  	function visual_effect($name,$element_id=false,$js_options=null) {
  35  
  36          $element=($element_id)?"'$element_id'":'element';
  37  
  38          $js_queue ='';
  39          if(isset($js_options) && is_array($js_options['queue'])){
  40  
  41          } elseif (isset($js_options)) {
  42              $js_queue="'$js_options'";
  43          }
  44  
  45          if(in_array($name,$this->TOGGLE_EFFECTS)){
  46              return  "Effect.toggle($element,'".str_replace('toggle_','',$name)."',".$this->_options_for_javascript($js_options).')';
  47          }else {
  48              return  "new Effect.".ucwords($name)."($element,".$this->_options_for_javascript($js_options).')';
  49          }
  50  
  51      }
  52  
  53  	function sortabe_element($element_id,$options=null)
  54      {
  55          return $this->tag($this->_sortabe_element($element_id,$options));
  56      }
  57  
  58      /////////////////////////////////////////////////////////////////////////////////////
  59      //                             Private functions
  60      /////////////////////////////////////////////////////////////////////////////////////
  61  
  62  	function _sortabe_element($element_id,$options)
  63      {
  64          //if(isset($options['with']))
  65          {
  66              $options['with'] ="Sortable.serialize('$element_id')";
  67          }
  68  
  69          //if (isset($option['onUpdate']))
  70          {
  71              $options['onUpdate'] ="function(){". $this->remote_function($options) ."}";
  72          }
  73  
  74          foreach ($options as $var=>$val)if(in_array($var,$this->AJAX_OPTIONS))unset($options[$var]);
  75  
  76          $arr = array('tag','overlap','contraint','handle');
  77  
  78          foreach ($arr as $var){
  79              if (isset($options[$var])) {
  80                  $options[$var]    = "'".$options[$var]."'";
  81              }
  82          }
  83  
  84          if (isset($options['containment'])) {
  85              $options['containment'] =$this->_array_or_string_for_javascript($options['containment']);
  86          }
  87  
  88          if (isset($options['only'])) {
  89              $options['only'] =$this->_array_or_string_for_javascript($options['only']);
  90          }
  91  
  92          return "Sortable.create('$element_id',".$this->_options_for_javascript($options).')';
  93  
  94      }
  95  
  96  	function  _dragable_element_js($element_id,$options)
  97      {
  98          return 'new Draggable(\''.$element_id.'\','.$this->_options_for_javascript($options).')';
  99      }
 100  
 101  
 102  	function _drop_receiving_element($element_id,$options)
 103      {
 104  
 105  
 106          //if(isset($options['with']))
 107          {
 108              $options['with'] = '\'id=\' + encodeURIComponent(element.id)';
 109          }
 110          //if (isset($option['onDrop']))
 111  
 112          {
 113              $options['onDrop'] ="function(element){". $this->remote_function($options) ."}";
 114          }
 115  
 116          if (is_array($options)) {
 117              foreach ($options as $var=>$val)if(in_array($var,$this->AJAX_OPTIONS))unset($options[$var]);
 118          }
 119  
 120  
 121          if (isset($options['accept'])) {
 122              $options['accept'] =$this->_array_or_string_for_javascript($options['accept']);
 123          }
 124  
 125          if (isset($options['hoverclass'])) {
 126              $options['hoverclass'] ="'".$options['hoverclass']."'";
 127          }
 128  
 129          return  'Droppables.add(\''.$element_id.'\','. $this->_options_for_javascript($options).')';
 130      }
 131  
 132      /////////////////////////////////////////////////////////////////////////////////////
 133      //                            Merged Javascript macro 
 134      /////////////////////////////////////////////////////////////////////////////////////
 135  
 136  function in_place_editor($field_id,$options,$tag=true) {
 137           $function  =  "new Ajax.InPlaceEditor(";
 138           $function .= "'$field_id', ";
 139           $function .= "'".$options['url']."'";
 140           
 141            $js_options=array();
 142           if (isset($options['cancel_text']))$js_options['cancelText']=$options['cancel_text'];
 143           if (isset($options['save_text']))$js_options['okText']=$options['save_text'];
 144           if (isset($options['loading_text']))$js_options['loadingText']=$options['loading_text'];
 145           if (isset($options['rows']))$js_options['rows']=$options['rows'];
 146           if (isset($options['cols']))$js_options['cols']=$options['cols'];
 147           if (isset($options['size']))$js_options['size']=$options['size'];
 148           if (isset($options['external_control']))$js_options['externalControl']="'".$options['external_control']."'";
 149           if (isset($options['load_text_url']))$js_options['loadTextURL']="'".$options['load_text_url']."'";
 150           if (isset($options['options']))$js_options['ajaxOptions']=$options['options'];
 151           if (isset($options['script']))$js_options['evalScripts']=$options['script'];
 152           if (isset($options['with']))$js_options['callback']="function(form) { return ".$options['with']." }";
 153  
 154           $function.= ', '.$this->_options_for_javascript($js_options).' )';
 155            if($tag)return $this->tag($function);    else 
 156            return  $function;
 157      }
 158      
 159  	function in_place_editor_field($object,$tag_options=null,$in_place_editor_options=null)
 160      {
 161          $ret_val='';
 162          $ret_val.='<span id="'.$object.'" class="in_place_editor_field">'.(isset($tag_options['value'])?$tag_options['value']:'').'</span>';
 163          $ret_val.=$this->in_place_editor($object,$in_place_editor_options);
 164          return $ret_val;
 165      }
 166      
 167  	function auto_complete_field($field_id,$options){
 168          $function = "var $field_id"."_auto_completer = new Ajax.Autocompleter(";
 169          $function.= "'$field_id', ";
 170          $function.= "'".(isset($options['update'])?$options['update']:$field_id.'_auto_complete')."', ";
 171          $function.= "'".$options['url']."'";
 172          
 173          $js_options=array();
 174          if (isset($options['tokens']))$js_options['tokens']=$this->javascript->_array_or_string_for_javascript($options['tokens']);
 175          if (isset($options['with']))$js_options['callback']="function(element, value) { return ".$options['with']." }";
 176          if (isset($options['indicator']))$js_options['indicator']="'".$options['indicator']."'";
 177          if (isset($options['select']))$js_options['select']="'".$options['select']."'";
 178          
 179          foreach (array('on_show'=>'onShow','on_hide'=>'onHide','min_chars'=>'min_chars') as $var=>$val) {
 180              if (isset($options[$var])) $js_options['$val']=$options['var'];
 181          }
 182          
 183          $function.= ', '.$this->_options_for_javascript($js_options).' )';
 184          return $this->tag($function);
 185      }
 186      
 187  	function auto_complete_results($entries,$field,$phrase=null){
 188          if(!is_array($entries))return;
 189          $ret_val='<ul>';
 190      //    Complete this function
 191      }
 192      
 193  	function text_field_with_auto_complete($object,$tag_options=null,$completion_options=null)
 194      {
 195          $ret_val=(isset($completion_options['skip_style']))?'':$this->_auto_complete_stylesheet();
 196          
 197          # @@@ Fixed a bug in the next like where the dumping of the value tag used to check if size is set!
 198          # @@@ Added maxlength and tabindex attributes
 199          $t_tabindex = isset( $tag_options['tabindex'] ) ? ( ' tabindex="' . $tag_options['tabindex'] . '"' ) : '';
 200          $t_maxlength = isset( $tag_options['maxlength'] ) ?( ' maxlength="' . $tag_options['maxlength'] . '"' ) : '';
 201          $ret_val.='<input autocomplete="off" id="'.$object.'" name="'.$object.'"'. $t_tabindex . $t_maxlength . ' size="'.(isset($tag_options['size'])?$tag_options['size']:30).'" type="text" value="'.(isset($tag_options['value'])?$tag_options['value']:'').'" '.(isset($tag_options['class'])?'class = "'.$tag_options['class'].'" ':'').'/>';
 202          
 203          $ret_val.='<div id="'.$object.'_auto_complete" class="auto_complete"></div>';
 204          $ret_val.=$this->auto_complete_field($object,$completion_options);
 205          return $ret_val;
 206      }
 207      
 208  	function _auto_complete_stylesheet()
 209      {
 210          return '<style> div.auto_complete {
 211                    width: 350px;
 212                    background: #fff;
 213                   }
 214                  div.auto_complete ul {
 215                     border:1px solid #888;
 216                     margin:0;
 217                     padding:0;
 218                     width:100%;
 219                     list-style-type:none;
 220                   }
 221                   div.auto_complete ul li {
 222                     margin:0;
 223                     padding:3px;
 224                   }
 225                   div.auto_complete ul li.selected {
 226                     background-color: #ffb;
 227                   }
 228                   div.auto_complete ul strong.highlight {
 229                     color: #800;
 230                     margin:0;
 231                     padding:0;
 232                   }
 233                   </style>';
 234      }
 235  
 236  }


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics