|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Js.php - Provides javascript related commands for the Response |
|
5
|
|
|
* |
|
6
|
|
|
* @author Thierry Feuzeu <[email protected]> |
|
7
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
|
8
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
|
9
|
|
|
*/ |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Jaxon\Response\Features; |
|
12
|
|
|
|
|
13
|
|
|
trait JsCommands |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Add a response command to the array of commands that will be sent to the browser |
|
17
|
|
|
* |
|
18
|
|
|
* @param array $aAttributes Associative array of attributes that will describe the command |
|
|
|
|
|
|
19
|
|
|
* @param mixed $mData The data to be associated with this command |
|
|
|
|
|
|
20
|
|
|
* |
|
21
|
|
|
* @return Response |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract public function addCommand(array $aAttributes, $mData); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Add a response command to the array of commands that will be sent to the browser |
|
27
|
|
|
* |
|
28
|
|
|
* @param string $sName The command name |
|
|
|
|
|
|
29
|
|
|
* @param array $aAttributes Associative array of attributes that will describe the command |
|
|
|
|
|
|
30
|
|
|
* @param mixed $mData The data to be associated with this command |
|
|
|
|
|
|
31
|
|
|
* @param boolean $bRemoveEmpty If true, remove empty attributes |
|
|
|
|
|
|
32
|
|
|
* |
|
33
|
|
|
* @return Response |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Merge the response commands from the specified <Response> object with |
|
39
|
|
|
* the response commands in this <Response> object |
|
40
|
|
|
* |
|
41
|
|
|
* @param Response|array $mCommands The <Response> object |
|
|
|
|
|
|
42
|
|
|
* @param boolean $bBefore Add the new commands to the beginning of the list |
|
|
|
|
|
|
43
|
|
|
* |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
abstract public function appendResponse($mCommands, $bBefore = false); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Response command that prompts user with [ok] [cancel] style message box |
|
50
|
|
|
* |
|
51
|
|
|
* If the user clicks cancel, the specified number of response commands |
|
52
|
|
|
* following this one, will be skipped. |
|
53
|
|
|
* |
|
54
|
|
|
* @param integer $iCommandCount The number of commands to skip upon cancel |
|
|
|
|
|
|
55
|
|
|
* @param string $sMessage The message to display to the user |
|
|
|
|
|
|
56
|
|
|
* |
|
57
|
|
|
* @return Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function confirmCommands($iCommandCount, $sMessage) |
|
60
|
|
|
{ |
|
61
|
|
|
$aAttributes = ['count' => $iCommandCount]; |
|
62
|
|
|
return $this->_addCommand('cc', $aAttributes, $sMessage); |
|
63
|
|
|
} |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Response command that prompts user with [ok] [cancel] style message box |
|
67
|
|
|
* |
|
68
|
|
|
* If the user clicks cancel, the specified number of response commands |
|
69
|
|
|
* following this one, will be skipped. |
|
70
|
|
|
* |
|
71
|
|
|
* @param string $sMessage The message to display to the user |
|
|
|
|
|
|
72
|
|
|
* @param callable $xCallable The function |
|
|
|
|
|
|
73
|
|
|
* |
|
74
|
|
|
* @return Response |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
|
public function confirm($sMessage, $xCallable) |
|
77
|
|
|
{ |
|
78
|
|
|
$xResponse = jaxon()->newResponse(); |
|
79
|
|
|
\call_user_func($xCallable, $xResponse); |
|
80
|
|
|
$iCommandCount = $xResponse->getCommandCount(); |
|
81
|
|
|
if($iCommandCount > 0) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->confirmCommands($iCommandCount, $sMessage); |
|
84
|
|
|
$this->appendResponse($xResponse); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
return $this; |
|
87
|
|
|
} |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Add a command to display an alert message to the user |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $sMessage The message to be displayed |
|
|
|
|
|
|
93
|
|
|
* |
|
94
|
|
|
* @return Response |
|
95
|
|
|
*/ |
|
96
|
|
|
public function alert($sMessage) |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->_addCommand('al', [], $sMessage); |
|
99
|
|
|
} |
|
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Add a command to display a debug message to the user |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $sMessage The message to be displayed |
|
|
|
|
|
|
105
|
|
|
* |
|
106
|
|
|
* @return Response |
|
107
|
|
|
*/ |
|
108
|
|
|
public function debug($sMessage) |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->_addCommand('dbg', [], $sMessage); |
|
111
|
|
|
} |
|
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Add a command to ask the browser to navigate to the specified URL |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $sURL The relative or fully qualified URL |
|
|
|
|
|
|
117
|
|
|
* @param integer $iDelay Number of seconds to delay before the redirect occurs |
|
|
|
|
|
|
118
|
|
|
* |
|
119
|
|
|
* @return Response |
|
120
|
|
|
*/ |
|
121
|
|
|
public function redirect($sURL, $iDelay = 0) |
|
122
|
|
|
{ |
|
123
|
|
|
// we need to parse the query part so that the values are rawurlencode()'ed |
|
124
|
|
|
// can't just use parse_url() cos we could be dealing with a relative URL which |
|
125
|
|
|
// parse_url() can't deal with. |
|
126
|
|
|
$queryStart = strpos($sURL, '?', strrpos($sURL, '/')); |
|
127
|
|
|
if($queryStart !== false) |
|
128
|
|
|
{ |
|
129
|
|
|
$queryStart++; |
|
130
|
|
|
$queryEnd = strpos($sURL, '#', $queryStart); |
|
131
|
|
|
if($queryEnd === false) |
|
132
|
|
|
{ |
|
133
|
|
|
$queryEnd = strlen($sURL); |
|
134
|
|
|
} |
|
135
|
|
|
$queryPart = substr($sURL, $queryStart, $queryEnd - $queryStart); |
|
136
|
|
|
parse_str($queryPart, $queryParts); |
|
137
|
|
|
$newQueryPart = ""; |
|
138
|
|
|
if($queryParts) |
|
139
|
|
|
{ |
|
140
|
|
|
$first = true; |
|
141
|
|
|
foreach($queryParts as $key => $value) |
|
142
|
|
|
{ |
|
143
|
|
|
if($first) |
|
144
|
|
|
{ |
|
145
|
|
|
$first = false; |
|
146
|
|
|
} |
|
147
|
|
|
else |
|
148
|
|
|
{ |
|
149
|
|
|
$newQueryPart .= '&'; |
|
150
|
|
|
} |
|
151
|
|
|
$newQueryPart .= rawurlencode($key) . '=' . rawurlencode($value); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
elseif($_SERVER['QUERY_STRING']) |
|
155
|
|
|
{ |
|
156
|
|
|
//couldn't break up the query, but there's one there |
|
157
|
|
|
//possibly "http://url/page.html?query1234" type of query? |
|
158
|
|
|
//just encode it and hope it works |
|
159
|
|
|
$newQueryPart = rawurlencode($_SERVER['QUERY_STRING']); |
|
160
|
|
|
} |
|
161
|
|
|
$sURL = str_replace($queryPart, $newQueryPart, $sURL); |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if($iDelay > 0) |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->script('window.setTimeout("window.location = \'' . $sURL . '\';",' . ($iDelay * 1000) . ');'); |
|
167
|
|
|
} |
|
168
|
|
|
return $this->script('window.location = "' . $sURL . '";'); |
|
169
|
|
|
} |
|
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Add a command to execute a portion of javascript on the browser |
|
173
|
|
|
* |
|
174
|
|
|
* The script runs in it's own context, so variables declared locally, using the 'var' keyword, |
|
175
|
|
|
* will no longer be available after the call. |
|
176
|
|
|
* To construct a variable that will be accessable globally, even after the script has executed, |
|
177
|
|
|
* leave off the 'var' keyword. |
|
178
|
|
|
* |
|
179
|
|
|
* @param string $sJS The script to execute |
|
|
|
|
|
|
180
|
|
|
* |
|
181
|
|
|
* @return Response |
|
182
|
|
|
*/ |
|
183
|
|
|
public function script($sJS) |
|
184
|
|
|
{ |
|
185
|
|
|
return $this->_addCommand('js', [], $sJS); |
|
186
|
|
|
} |
|
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Add a command to call the specified javascript function with the given (optional) parameters |
|
190
|
|
|
* |
|
191
|
|
|
* @param string $sFunc The name of the function to call |
|
|
|
|
|
|
192
|
|
|
* |
|
193
|
|
|
* @return Response |
|
194
|
|
|
*/ |
|
195
|
|
|
public function call($sFunc) |
|
196
|
|
|
{ |
|
197
|
|
|
$aArgs = func_get_args(); |
|
198
|
|
|
array_shift($aArgs); |
|
199
|
|
|
$aAttributes = ['cmd' => 'jc', 'func' => $sFunc]; |
|
200
|
|
|
return $this->addCommand($aAttributes, $aArgs); |
|
201
|
|
|
} |
|
|
|
|
|
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Add a command to set an event handler on the browser |
|
205
|
|
|
* |
|
206
|
|
|
* @param string $sTarget The id of the element that contains the event |
|
|
|
|
|
|
207
|
|
|
* @param string $sEvent The name of the event |
|
|
|
|
|
|
208
|
|
|
* @param string $sScript The javascript to execute when the event is fired |
|
|
|
|
|
|
209
|
|
|
* |
|
210
|
|
|
* @return Response |
|
211
|
|
|
*/ |
|
212
|
|
|
public function setEvent($sTarget, $sEvent, $sScript) |
|
213
|
|
|
{ |
|
214
|
|
|
$aAttributes = [ |
|
215
|
|
|
'id' => $sTarget, |
|
216
|
|
|
'prop' => $sEvent |
|
217
|
|
|
]; |
|
218
|
|
|
return $this->_addCommand('ev', $aAttributes, $sScript); |
|
219
|
|
|
} |
|
|
|
|
|
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Add a command to set a click handler on the browser |
|
223
|
|
|
* |
|
224
|
|
|
* @param string $sTarget The id of the element that contains the event |
|
|
|
|
|
|
225
|
|
|
* @param string $sScript The javascript to execute when the event is fired |
|
|
|
|
|
|
226
|
|
|
* |
|
227
|
|
|
* @return Response |
|
228
|
|
|
*/ |
|
229
|
|
|
public function onClick($sTarget, $sScript) |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->setEvent($sTarget, 'onclick', $sScript); |
|
232
|
|
|
} |
|
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Add a command to install an event handler on the specified element |
|
236
|
|
|
* |
|
237
|
|
|
* You can add more than one event handler to an element's event using this method. |
|
238
|
|
|
* |
|
239
|
|
|
* @param string $sTarget The id of the element |
|
|
|
|
|
|
240
|
|
|
* @param string $sEvent The name of the event |
|
|
|
|
|
|
241
|
|
|
* @param string $sHandler The name of the javascript function to call when the event is fired |
|
|
|
|
|
|
242
|
|
|
* |
|
243
|
|
|
* @return Response |
|
244
|
|
|
*/ |
|
245
|
|
|
public function addHandler($sTarget, $sEvent, $sHandler) |
|
246
|
|
|
{ |
|
247
|
|
|
$aAttributes = [ |
|
248
|
|
|
'id' => $sTarget, |
|
249
|
|
|
'prop' => $sEvent |
|
250
|
|
|
]; |
|
251
|
|
|
return $this->_addCommand('ah', $aAttributes, $sHandler); |
|
252
|
|
|
} |
|
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* Add a command to remove an event handler from an element |
|
256
|
|
|
* |
|
257
|
|
|
* @param string $sTarget The id of the element |
|
|
|
|
|
|
258
|
|
|
* @param string $sEvent The name of the event |
|
|
|
|
|
|
259
|
|
|
* @param string $sHandler The name of the javascript function called when the event is fired |
|
|
|
|
|
|
260
|
|
|
* |
|
261
|
|
|
* @return Response |
|
262
|
|
|
*/ |
|
263
|
|
|
public function removeHandler($sTarget, $sEvent, $sHandler) |
|
264
|
|
|
{ |
|
265
|
|
|
$aAttributes = [ |
|
266
|
|
|
'id' => $sTarget, |
|
267
|
|
|
'prop' => $sEvent |
|
268
|
|
|
]; |
|
269
|
|
|
return $this->_addCommand('rh', $aAttributes, $sHandler); |
|
270
|
|
|
} |
|
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Add a command to construct a javascript function on the browser |
|
274
|
|
|
* |
|
275
|
|
|
* @param string $sFunction The name of the function to construct |
|
|
|
|
|
|
276
|
|
|
* @param string $sArgs Comma separated list of parameter names |
|
|
|
|
|
|
277
|
|
|
* @param string $sScript The javascript code that will become the body of the function |
|
|
|
|
|
|
278
|
|
|
* |
|
279
|
|
|
* @return Response |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setFunction($sFunction, $sArgs, $sScript) |
|
282
|
|
|
{ |
|
283
|
|
|
$aAttributes = [ |
|
284
|
|
|
'func' => $sFunction, |
|
285
|
|
|
'prop' => $sArgs |
|
286
|
|
|
]; |
|
287
|
|
|
return $this->_addCommand('sf', $aAttributes, $sScript); |
|
288
|
|
|
} |
|
|
|
|
|
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Add a command to construct a wrapper function around an existing javascript function on the browser |
|
292
|
|
|
* |
|
293
|
|
|
* @param string $sFunction The name of the existing function to wrap |
|
|
|
|
|
|
294
|
|
|
* @param string $sArgs The comma separated list of parameters for the function |
|
|
|
|
|
|
295
|
|
|
* @param array $aScripts An array of javascript code snippets that will be used to build |
|
|
|
|
|
|
296
|
|
|
* the body of the function |
|
|
|
|
|
|
297
|
|
|
* The first piece of code specified in the array will occur before |
|
|
|
|
|
|
298
|
|
|
* the call to the original function, the second will occur after |
|
|
|
|
|
|
299
|
|
|
* the original function is called. |
|
|
|
|
|
|
300
|
|
|
* @param string $sReturnValueVar The name of the variable that will retain the return value |
|
|
|
|
|
|
301
|
|
|
* from the call to the original function |
|
|
|
|
|
|
302
|
|
|
* |
|
303
|
|
|
* @return Response |
|
304
|
|
|
*/ |
|
305
|
|
|
public function wrapFunction($sFunction, $sArgs, $aScripts, $sReturnValueVar) |
|
306
|
|
|
{ |
|
307
|
|
|
$aAttributes = [ |
|
308
|
|
|
'cmd' => 'wpf', |
|
309
|
|
|
'func' => $sFunction, |
|
310
|
|
|
'prop' => $sArgs, |
|
311
|
|
|
'type' => $sReturnValueVar |
|
312
|
|
|
]; |
|
313
|
|
|
return $this->addCommand($aAttributes, $aScripts); |
|
314
|
|
|
} |
|
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Add a command to load a javascript file on the browser |
|
318
|
|
|
* |
|
319
|
|
|
* @param boolean $bIncludeOnce Include once or not |
|
|
|
|
|
|
320
|
|
|
* @param string $sFileName The relative or fully qualified URI of the javascript file |
|
|
|
|
|
|
321
|
|
|
* @param string $sType Determines the script type. Defaults to 'text/javascript' |
|
|
|
|
|
|
322
|
|
|
* @param string $sId The wrapper id |
|
|
|
|
|
|
323
|
|
|
* |
|
324
|
|
|
* @return Response |
|
325
|
|
|
*/ |
|
326
|
|
|
private function _includeScript($bIncludeOnce, $sFileName, $sType, $sId) |
|
327
|
|
|
{ |
|
328
|
|
|
$aAttributes = [ |
|
329
|
|
|
'type' => $sType, |
|
330
|
|
|
'elm_id' => $sId |
|
331
|
|
|
]; |
|
332
|
|
|
return $this->_addCommand(($bIncludeOnce ? 'ino' : 'in'), $aAttributes, $sFileName, true); |
|
333
|
|
|
} |
|
|
|
|
|
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* Add a command to load a javascript file on the browser |
|
337
|
|
|
* |
|
338
|
|
|
* @param string $sFileName The relative or fully qualified URI of the javascript file |
|
|
|
|
|
|
339
|
|
|
* @param string $sType Determines the script type. Defaults to 'text/javascript' |
|
|
|
|
|
|
340
|
|
|
* @param string $sId The wrapper id |
|
|
|
|
|
|
341
|
|
|
* |
|
342
|
|
|
* @return Response |
|
343
|
|
|
*/ |
|
344
|
|
|
public function includeScript($sFileName, $sType = '', $sId = '') |
|
345
|
|
|
{ |
|
346
|
|
|
return $this->_includeScript(false, $sFileName, $sType, $sId); |
|
347
|
|
|
} |
|
|
|
|
|
|
348
|
|
|
|
|
349
|
|
|
/** |
|
350
|
|
|
* Add a command to include a javascript file on the browser if it has not already been loaded |
|
351
|
|
|
* |
|
352
|
|
|
* @param string $sFileName The relative or fully qualified URI of the javascript file |
|
|
|
|
|
|
353
|
|
|
* @param string $sType Determines the script type. Defaults to 'text/javascript' |
|
|
|
|
|
|
354
|
|
|
* @param string $sId The wrapper id |
|
|
|
|
|
|
355
|
|
|
* |
|
356
|
|
|
* @return Response |
|
357
|
|
|
*/ |
|
358
|
|
|
public function includeScriptOnce($sFileName, $sType = '', $sId = '') |
|
359
|
|
|
{ |
|
360
|
|
|
return $this->_includeScript(true, $sFileName, $sType, $sId); |
|
361
|
|
|
} |
|
|
|
|
|
|
362
|
|
|
|
|
363
|
|
|
/** |
|
364
|
|
|
* Add a command to remove a SCRIPT reference to a javascript file on the browser |
|
365
|
|
|
* |
|
366
|
|
|
* Optionally, you can call a javascript function just prior to the file being unloaded (for cleanup). |
|
367
|
|
|
* |
|
368
|
|
|
* @param string $sFileName The relative or fully qualified URI of the javascript file |
|
|
|
|
|
|
369
|
|
|
* @param string $sUnload Name of a javascript function to call prior to unlaoding the file |
|
|
|
|
|
|
370
|
|
|
* |
|
371
|
|
|
* @return Response |
|
372
|
|
|
*/ |
|
373
|
|
|
public function removeScript($sFileName, $sUnload = '') |
|
374
|
|
|
{ |
|
375
|
|
|
$aAttributes = ['unld' => $sUnload]; |
|
376
|
|
|
return $this->_addCommand('rjs', $aAttributes, $sFileName, true); |
|
377
|
|
|
} |
|
|
|
|
|
|
378
|
|
|
|
|
379
|
|
|
/** |
|
380
|
|
|
* Add a command to include a LINK reference to the specified CSS file on the browser. |
|
381
|
|
|
* |
|
382
|
|
|
* This will cause the browser to load and apply the style sheet. |
|
383
|
|
|
* |
|
384
|
|
|
* @param string $sFileName The relative or fully qualified URI of the css file |
|
|
|
|
|
|
385
|
|
|
* @param string $sMedia The media type of the CSS file. Defaults to 'screen' |
|
|
|
|
|
|
386
|
|
|
* |
|
387
|
|
|
* @return Response |
|
388
|
|
|
*/ |
|
389
|
|
|
public function includeCSS($sFileName, $sMedia = '') |
|
|
|
|
|
|
390
|
|
|
{ |
|
391
|
|
|
$aAttributes = ['media' => $sMedia]; |
|
392
|
|
|
return $this->_addCommand('css', $aAttributes, $sFileName, true); |
|
393
|
|
|
} |
|
|
|
|
|
|
394
|
|
|
|
|
395
|
|
|
/** |
|
|
|
|
|
|
396
|
|
|
* Add a command to remove a LINK reference to a CSS file on the browser |
|
397
|
|
|
* |
|
398
|
|
|
* This causes the browser to unload the style sheet, effectively removing the style changes it caused. |
|
399
|
|
|
* |
|
400
|
|
|
* @param string $sFileName The relative or fully qualified URI of the css file |
|
|
|
|
|
|
401
|
|
|
* |
|
402
|
|
|
* @return Response |
|
403
|
|
|
*/ |
|
404
|
|
|
public function removeCSS($sFileName, $sMedia = '') |
|
|
|
|
|
|
405
|
|
|
{ |
|
406
|
|
|
$aAttributes = ['media' => $sMedia]; |
|
407
|
|
|
return $this->_addCommand('rcss', $aAttributes, $sFileName, true); |
|
408
|
|
|
} |
|
|
|
|
|
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* Add a command to make Jaxon pause while the CSS files are loaded |
|
412
|
|
|
* |
|
413
|
|
|
* The browser is not typically a multi-threading application, with regards to javascript code. |
|
414
|
|
|
* Therefore, the CSS files included or removed with <Response->includeCSS> and |
|
415
|
|
|
* <Response->removeCSS> respectively, will not be loaded or removed until the browser regains |
|
416
|
|
|
* control from the script. |
|
417
|
|
|
* This command returns control back to the browser and pauses the execution of the response |
|
418
|
|
|
* until the CSS files, included previously, are loaded. |
|
419
|
|
|
* |
|
420
|
|
|
* @param integer $iTimeout The number of 1/10ths of a second to pause before timing out |
|
|
|
|
|
|
421
|
|
|
* and continuing with the execution of the response commands |
|
|
|
|
|
|
422
|
|
|
* |
|
423
|
|
|
* @return Response |
|
424
|
|
|
*/ |
|
425
|
|
|
public function waitForCSS($iTimeout = 600) |
|
|
|
|
|
|
426
|
|
|
{ |
|
427
|
|
|
$aAttributes = ['cmd' => 'wcss', 'prop' => $iTimeout]; |
|
428
|
|
|
return $this->addCommand($aAttributes, ''); |
|
429
|
|
|
} |
|
|
|
|
|
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* Add a command to make Jaxon to delay execution of the response commands until a specified condition is met |
|
433
|
|
|
* |
|
434
|
|
|
* Note, this returns control to the browser, so that other script operations can execute. |
|
435
|
|
|
* Jaxon will continue to monitor the specified condition and, when it evaluates to true, |
|
436
|
|
|
* will continue processing response commands. |
|
437
|
|
|
* |
|
438
|
|
|
* @param string $script A piece of javascript code that evaulates to true or false |
|
|
|
|
|
|
439
|
|
|
* @param integer $tenths The number of 1/10ths of a second to wait before timing out |
|
|
|
|
|
|
440
|
|
|
* and continuing with the execution of the response commands. |
|
|
|
|
|
|
441
|
|
|
* |
|
442
|
|
|
* @return Response |
|
443
|
|
|
*/ |
|
444
|
|
|
public function waitFor($script, $tenths) |
|
445
|
|
|
{ |
|
446
|
|
|
$aAttributes = ['cmd' => 'wf', 'prop' => $tenths]; |
|
447
|
|
|
return $this->addCommand($aAttributes, $script); |
|
448
|
|
|
} |
|
|
|
|
|
|
449
|
|
|
|
|
450
|
|
|
/** |
|
451
|
|
|
* Add a command to make Jaxon to pause execution of the response commands, |
|
452
|
|
|
* returning control to the browser so it can perform other commands asynchronously. |
|
453
|
|
|
* |
|
454
|
|
|
* After the specified delay, Jaxon will continue execution of the response commands. |
|
455
|
|
|
* |
|
456
|
|
|
* @param integer $tenths The number of 1/10ths of a second to sleep |
|
|
|
|
|
|
457
|
|
|
* |
|
458
|
|
|
* @return Response |
|
459
|
|
|
*/ |
|
460
|
|
|
public function sleep($tenths) |
|
461
|
|
|
{ |
|
462
|
|
|
$aAttributes = ['cmd' =>'s', 'prop' => $tenths]; |
|
|
|
|
|
|
463
|
|
|
return $this->addCommand($aAttributes, ''); |
|
464
|
|
|
} |
|
|
|
|
|
|
465
|
|
|
} |
|
466
|
|
|
|