phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
BaseHtmlEventsTrait.php
Go to the documentation of this file.
1<?php
7
15
16 protected $_events=array ();
17
25 public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
26 if ($stopPropagation === true) {
27 $jsCode=Javascript::$stopPropagation . $jsCode;
28 }
29 if ($preventDefault === true) {
30 $jsCode=Javascript::$preventDefault . $jsCode;
31 }
32 return $this->_addEvent($event, $jsCode);
33 }
34
35 public function trigger($event,$params="[]"){
36 $this->executeOnRun('$("#'.$this->identifier.'").trigger("'.$event.'",'.$params.');');
37 }
38
39 public function jsTrigger($event,$params="[this]"){
40 return $this->jsDoJquery("trigger",["'".$event."'",$params]);
41 }
42
48 public function _addEvent($event, $jsCode) {
49 if (array_key_exists($event, $this->_events)) {
50 if (\is_array($this->_events[$event])) {
51 if(array_search($jsCode, $this->_events[$event])===false){
52 $this->_events[$event][]=$jsCode;
53 }
54 } else {
55 $this->_events[$event]=array ($this->_events[$event],$jsCode );
56 }
57 } else {
58 $this->_events[$event]=$jsCode;
59 }
60 return $this;
61 }
62
70 public function on($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
71 return $this->_self->addEvent($event, $jsCode, $stopPropagation, $preventDefault);
72 }
73
74 public function onClick($jsCode, $stopPropagation=false, $preventDefault=true) {
75 return $this->on("click", $jsCode, $stopPropagation, $preventDefault);
76 }
77
78 public function setClick($jsCode) {
79 return $this->onClick($jsCode);
80 }
81
82 public function onCreate($jsCode){
83 if(isset($this->_events["_create"])){
84 $this->_events["_create"][]=$jsCode;
85 }else{
86 $this->_events["_create"]=[$jsCode];
87 }
88 return $this;
89 }
90
91 public function addEventsOnRun(JsUtils $js=NULL) {
92 $this->_eventsOnCreate($js);
93 if (isset($this->_bsComponent)) {
94 foreach ( $this->_events as $event => $jsCode ) {
95 $code=$jsCode;
96 if (\is_array($jsCode)) {
97 $code="";
98 foreach ( $jsCode as $jsC ) {
99 if ($jsC instanceof AjaxCall) {
100 $code.="\n" . $jsC->compile($js);
101 } else {
102 $code.="\n" . $jsC;
103 }
104 }
105 } elseif ($jsCode instanceof AjaxCall) {
106 $code=$jsCode->compile($js);
107 }
108 $this->_bsComponent->addEvent($event, $code);
109 }
110 $this->_events=array ();
111 return $this->_bsComponent->getScript();
112 }
113 return "";
114 }
115
116 protected function _eventsOnCreate(JsUtils $js=NULL){
117 if(isset($this->_events["_create"])){
118 $create=$this->_events["_create"];
119 if(\is_array($create)){
120 $create=\implode("", $create);
121 }
122 if(isset($js) && $create!=="")
123 $js->exec($create,true);
124 unset($this->_events["_create"]);
125 }
126 }
127
136 public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
137 $params=array ("url" => $url,"responseElement" => $responseElement );
138 $params=array_merge($params, $parameters);
139 $this->_addEvent($event, new AjaxCall($operation, $params));
140 return $this;
141 }
142
152 public function getOn($event, $url, $responseElement="", $parameters=array()) {
153 return $this->_ajaxOn("get", $event, $url, $responseElement, $parameters);
154 }
155
164 public function getOnClick($url, $responseElement="", $parameters=array()) {
165 return $this->getOn("click", $url, $responseElement, $parameters);
166 }
167
178 public function postOn($event, $url, $params="{}", $responseElement="", $parameters=array()) {
179 $allParameters=[];
180 if(isset($parameters["params"])){
181 $allParameters[]=JsUtils::_correctParams($parameters["params"]);
182 }
183 if(isset($params)){
184 $allParameters[]=JsUtils::_correctParams($params);
185 }
186 $parameters["params"]=\implode("+'&'+", $allParameters);
187 return $this->_ajaxOn("post", $event, $url, $responseElement, $parameters);
188 }
189
199 public function postOnClick($url, $params="{}", $responseElement="", $parameters=array()) {
200 return $this->postOn("click", $url, $params, $responseElement, $parameters);
201 }
202
212 public function postFormOn($event, $url, $form, $responseElement="", $parameters=array()) {
213 $parameters["form"]=$form;
214 return $this->_ajaxOn("postForm", $event, $url, $responseElement, $parameters);
215 }
216
225 public function postFormOnClick($url, $form, $responseElement="", $parameters=array()) {
226 return $this->postFormOn("click", $url, $form, $responseElement, $parameters);
227 }
228
229 public function jsDoJquery($jqueryCall, $param="") {
230 return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");";
231 }
232
233 public function executeOnRun($jsCode) {
234 return $this->_addEvent("execute", $jsCode);
235 }
236
237 public function jsHtml($content="") {
238 return $this->jsDoJquery("html", $content);
239 }
240
241 public function jsShow() {
242 return $this->jsDoJquery("show");
243 }
244
245 public function jsHide() {
246 return $this->jsDoJquery("hide");
247 }
248
249 public function jsToggle($value) {
250 return $this->jsDoJquery("toggle",$value);
251 }
255 public function getEvents() {
256 return $this->_events;
257 }
258
259}
JQuery PHP library.
Definition JsUtils.php:23
BaseHtml for HTML components.
Definition BaseHtml.php:17
getOn($event, $url, $responseElement="", $parameters=array())
Performs a get to $url on the event $event on $element and display it in $responseElement.
postFormOnClick($url, $form, $responseElement="", $parameters=array())
Performs a post form with ajax on click.
postOn($event, $url, $params="{}", $responseElement="", $parameters=array())
Performs a post to $url on the event $event on $element and display it in $responseElement.
onClick($jsCode, $stopPropagation=false, $preventDefault=true)
postOnClick($url, $params="{}", $responseElement="", $parameters=array())
Performs a post to $url on the click event on $element and display it in $responseElement.
addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false)
_ajaxOn($operation, $event, $url, $responseElement="", $parameters=array())
on($event, $jsCode, $stopPropagation=false, $preventDefault=false)
postFormOn($event, $url, $form, $responseElement="", $parameters=array())
Performs a post form with ajax.
getOnClick($url, $responseElement="", $parameters=array())
Performs a get to $url on the click event on $element and display it in $responseElement.
static _correctParams($params, $ajaxParameters=[])
static prep_value($value)
Puts HTML values in quotes for use in jQuery code unless the supplied value contains the Javascript '...