MkFramework
 All Data Structures Functions
plugin_jquery.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
24 
25  private $sJs;
26  private $sName;
27  private $tParam;
28 
35  public function __construct($sName,$tParam=null){
36  $this->sName=$sName;
37  if($tParam==null){
38  $tParam=array();
39  }
40  $this->tParam=$tParam;
41 
42  }
43 
44  private function parseUrl($sUrl){
45  $sUrl=preg_replace('/&amp;/','&',$sUrl);
46 
47  foreach($this->tParam as $sParam){
48  $sUrl=preg_replace( '/\$'.$sParam.'/',"'+$sParam+'",$sUrl);
49  }
50 
51  return $sUrl;
52  }
53 
60  public function addLinkUpdateElement($sUrl,$sCible){
61 
62  $sUrl=$this->parseUrl($sUrl);
63 
64  $this->sJs.='
65  $.ajax({
66  url: \''.$sUrl.'\',
67  success: function(response) {
68  // update status element
69  $(\'#'.$sCible.'\').html(response);
70  }
71  });
72  ';
73 
74  }
81  public function addLinkCallFunction($sUrl,$sFunction){
82  $sUrl=$this->parseUrl($sUrl);
83 
84  $this->sJs.='
85  $.ajax({
86  url: \''.$sUrl.'\',
87  success: function(response) {
88  // call function
89  '.$sFunction.'(response);
90  }
91  });
92  ';
93  }
101  public function addModifyElement($sCible,$sAction,$sParam=null){
102  $this->sJs.=' $(\'#'.$sCible.'\').'.$sAction.'('.$sParam.');';
103 
104  }
111  public function addJs($sTxt){
112  $this->sJs.=$sTxt;
113  }
120  public function getJs(){
121  $sParams=implode($this->tParam,',');
122  return '<script language="Javascript">function '.$this->sName.'('.$sParams.'){'.$this->sJs.'}</script>';
123  }
124 
125 
126 
127 
128 }
__construct($sName, $tParam=null)
addLinkUpdateElement($sUrl, $sCible)