Passed
Push — master ( 853516...f09da5 )
by Thierry
09:47 queued 07:04
created

JsCommands::confirm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
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
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
10
11
namespace Jaxon\Response\Features;
12
13
use Jaxon\Response\Response;
14
15
trait JsCommands
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait JsCommands
Loading history...
16
{
17
    /**
18
     * Add a response command to the array of commands that will be sent to the browser
19
     *
20
     * @param array         $aAttributes        Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
21
     * @param mixed            $mData                The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 12 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 16 found
Loading history...
22
     *
23
     * @return Response
24
     */
25
    abstract public function addCommand(array $aAttributes, $mData);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
26
27
    /**
28
     * Add a response command to the array of commands that will be sent to the browser
29
     *
30
     * @param string        $sName              The command name
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
31
     * @param array         $aAttributes        Associative array of attributes that will describe the command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 8 found
Loading history...
32
     * @param mixed         $mData              The data to be associated with this command
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 9 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 14 found
Loading history...
33
     * @param boolean       $bRemoveEmpty       If true, remove empty attributes
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
34
     *
35
     * @return Response
36
     */
37
    abstract protected function _addCommand($sName, array $aAttributes, $mData, $bRemoveEmpty = false);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39
    /**
40
     * Merge the response commands from the specified <Response> object with
41
     * the response commands in this <Response> object
42
     *
43
     * @param Response|array    $mCommands          The <Response> object
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 4 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 10 found
Loading history...
44
     * @param boolean           $bBefore            Add the new commands to the beginning of the list
0 ignored issues
show
Coding Style introduced by
Expected 8 spaces after parameter type; 11 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
45
     *
46
     * @return void
47
     */
48
    abstract public function appendResponse($mCommands, $bBefore = false);
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
49
50
    /**
51
     * Response command that prompts user with [ok] [cancel] style message box
52
     *
53
     * If the user clicks cancel, the specified number of response commands
54
     * following this one, will be skipped.
55
     *
56
     * @param integer       $iCommandCount      The number of commands to skip upon cancel
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 6 found
Loading history...
57
     * @param string        $sMessage           The message to display to the user
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter name; 11 found
Loading history...
58
     *
59
     * @return Response
60
     */
61
    public function confirmCommands($iCommandCount, $sMessage)
62
    {
63
        $aAttributes = ['count' => $iCommandCount];
64
        return $this->_addCommand('cc', $aAttributes, $sMessage);
65
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
66
67
    /**
68
     * Response command that prompts user with [ok] [cancel] style message box
69
     *
70
     * If the user clicks cancel, the specified number of response commands
71
     * following this one, will be skipped.
72
     *
73
     * @param string        $sMessage           The message to display to the user
0 ignored issues
show
Coding Style introduced by
Expected 3 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 11 found
Loading history...
74
     * @param callable      $xCallable          The function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 6 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 10 found
Loading history...
75
     *
76
     * @return Response
0 ignored issues
show
Documentation introduced by
Should the return type not be JsCommands?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
77
     */
78
    public function confirm($sMessage, $xCallable)
79
    {
80
        $xResponse = jaxon()->newResponse();
81
        \call_user_func($xCallable, $xResponse);
82
        $iCommandCount = $xResponse->getCommandCount();
83
        if($iCommandCount > 0)
84
        {
85
            $this->confirmCommands($iCommandCount, $sMessage);
86
            $this->appendResponse($xResponse);
87
        }
88
        return $this;
89
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
90
91
    /**
92
     * Add a command to display an alert message to the user
93
     *
94
     * @param string        $sMessage            The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
95
     *
96
     * @return Response
97
     */
98
    public function alert($sMessage)
99
    {
100
        return $this->_addCommand('al', [], $sMessage);
101
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
102
103
    /**
104
     * Add a command to display a debug message to the user
105
     *
106
     * @param string        $sMessage            The message to be displayed
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
107
     *
108
     * @return Response
109
     */
110
    public function debug($sMessage)
111
    {
112
        return $this->_addCommand('dbg', [], $sMessage);
113
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
114
115
    /**
116
     * Add a command to ask the browser to navigate to the specified URL
117
     *
118
     * @param string        $sURL                The relative or fully qualified URL
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 16 found
Loading history...
119
     * @param integer        $iDelay                Number of seconds to delay before the redirect occurs
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
120
     *
121
     * @return Response
122
     */
123
    public function redirect($sURL, $iDelay = 0)
124
    {
125
        // we need to parse the query part so that the values are rawurlencode()'ed
126
        // can't just use parse_url() cos we could be dealing with a relative URL which
127
        // parse_url() can't deal with.
128
        $queryStart = strpos($sURL, '?', strrpos($sURL, '/'));
129
        if($queryStart !== false)
130
        {
131
            $queryStart++;
132
            $queryEnd = strpos($sURL, '#', $queryStart);
133
            if($queryEnd === false)
134
            {
135
                $queryEnd = strlen($sURL);
136
            }
137
            $queryPart = substr($sURL, $queryStart, $queryEnd - $queryStart);
138
            parse_str($queryPart, $queryParts);
139
            $newQueryPart = "";
140
            if($queryParts)
141
            {
142
                $first = true;
143
                foreach($queryParts as $key => $value)
144
                {
145
                    if($first)
146
                    {
147
                        $first = false;
148
                    }
149
                    else
150
                    {
151
                        $newQueryPart .= '&';
152
                    }
153
                    $newQueryPart .= rawurlencode($key) . '=' . rawurlencode($value);
154
                }
155
            }
156
            elseif($_SERVER['QUERY_STRING'])
157
            {
158
                //couldn't break up the query, but there's one there
159
                //possibly "http://url/page.html?query1234" type of query?
160
                //just encode it and hope it works
161
                $newQueryPart = rawurlencode($_SERVER['QUERY_STRING']);
162
            }
163
            $sURL = str_replace($queryPart, $newQueryPart, $sURL);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $sURL. This often makes code more readable.
Loading history...
164
        }
165
166
        if($iDelay > 0)
167
        {
168
            return $this->script('window.setTimeout("window.location = \'' . $sURL . '\';",' . ($iDelay * 1000) . ');');
169
        }
170
        return $this->script('window.location = "' . $sURL . '";');
171
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
172
173
    /**
174
     * Add a command to execute a portion of javascript on the browser
175
     *
176
     * The script runs in it's own context, so variables declared locally, using the 'var' keyword,
177
     * will no longer be available after the call.
178
     * To construct a variable that will be accessable globally, even after the script has executed,
179
     * leave off the 'var' keyword.
180
     *
181
     * @param string        $sJS                The script to execute
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
182
     *
183
     * @return Response
184
     */
185
    public function script($sJS)
186
    {
187
        return $this->_addCommand('js', [], $sJS);
188
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
189
190
    /**
191
     * Add a command to call the specified javascript function with the given (optional) parameters
192
     *
193
     * @param string        $sFunc                The name of the function to call
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
194
     *
195
     * @return Response
196
     */
197
    public function call($sFunc)
198
    {
199
        $aArgs = func_get_args();
200
        array_shift($aArgs);
201
        $aAttributes = ['cmd' => 'jc', 'func' => $sFunc];
202
        return $this->addCommand($aAttributes, $aArgs);
203
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
204
205
    /**
206
     * Add a command to set an event handler on the browser
207
     *
208
     * @param string        $sTarget            The id of the element that contains the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
209
     * @param string        $sEvent             The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
210
     * @param string        $sScript            The javascript to execute when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
211
     *
212
     * @return Response
213
     */
214
    public function setEvent($sTarget, $sEvent, $sScript)
215
    {
216
        $aAttributes = [
217
            'id' => $sTarget,
218
            'prop' => $sEvent
219
        ];
220
        return $this->_addCommand('ev', $aAttributes, $sScript);
221
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
222
223
    /**
224
     * Add a command to set a click handler on the browser
225
     *
226
     * @param string        $sTarget            The id of the element that contains the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
227
     * @param string        $sScript            The javascript to execute when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
228
     *
229
     * @return Response
230
     */
231
    public function onClick($sTarget, $sScript)
232
    {
233
        return $this->setEvent($sTarget, 'onclick', $sScript);
234
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
235
236
    /**
237
     * Add a command to install an event handler on the specified element
238
     *
239
     * You can add more than one event handler to an element's event using this method.
240
     *
241
     * @param string        $sTarget             The id of the element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
242
     * @param string        $sEvent              The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 14 found
Loading history...
243
     * @param string        $sHandler            The name of the javascript function to call when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
244
     *
245
     * @return Response
246
     */
247
    public function addHandler($sTarget, $sEvent, $sHandler)
248
    {
249
        $aAttributes = [
250
            'id' => $sTarget,
251
            'prop' => $sEvent
252
        ];
253
        return $this->_addCommand('ah', $aAttributes, $sHandler);
254
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
255
256
    /**
257
     * Add a command to remove an event handler from an element
258
     *
259
     * @param string        $sTarget             The id of the element
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter name; 13 found
Loading history...
260
     * @param string        $sEvent              The name of the event
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 14 found
Loading history...
261
     * @param string        $sHandler            The name of the javascript function called when the event is fired
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
262
     *
263
     * @return Response
264
     */
265
    public function removeHandler($sTarget, $sEvent, $sHandler)
266
    {
267
        $aAttributes = [
268
            'id' => $sTarget,
269
            'prop' => $sEvent
270
        ];
271
        return $this->_addCommand('rh', $aAttributes, $sHandler);
272
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
273
274
    /**
275
     * Add a command to construct a javascript function on the browser
276
     *
277
     * @param string        $sFunction            The name of the function to construct
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
278
     * @param string        $sArgs                Comma separated list of parameter names
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
279
     * @param string        $sScript            The javascript code that will become the body of the function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
280
     *
281
     * @return Response
282
     */
283
    public function setFunction($sFunction, $sArgs, $sScript)
284
    {
285
        $aAttributes = [
286
            'func' => $sFunction,
287
            'prop' => $sArgs
288
        ];
289
        return $this->_addCommand('sf', $aAttributes, $sScript);
290
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
291
292
    /**
293
     * Add a command to construct a wrapper function around an existing javascript function on the browser
294
     *
295
     * @param string        $sFunction            The name of the existing function to wrap
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 12 found
Loading history...
296
     * @param string        $sArgs                The comma separated list of parameters for the function
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 11 spaces after parameter name; 16 found
Loading history...
297
     * @param array            $aScripts            An array of javascript code snippets that will be used to build
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 12 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 12 found
Loading history...
298
     *                                             the body of the function
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
299
     *                                             The first piece of code specified in the array will occur before
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
300
     *                                             the call to the original function, the second will occur after
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
301
     *                                             the original function is called.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
302
     * @param string        $sReturnValueVar    The name of the variable that will retain the return value
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
303
     *                                             from the call to the original function
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 42 spaces but found 45
Loading history...
304
     *
305
     * @return Response
306
     */
307
    public function wrapFunction($sFunction, $sArgs, $aScripts, $sReturnValueVar)
308
    {
309
        $aAttributes = [
310
            'cmd' => 'wpf',
311
            'func' => $sFunction,
312
            'prop' => $sArgs,
313
            'type' => $sReturnValueVar
314
        ];
315
        return $this->addCommand($aAttributes, $aScripts);
316
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
317
318
    /**
319
     * Add a command to load a javascript file on the browser
320
     *
321
     * @param boolean       $bIncludeOnce         Include once or not
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 7 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 9 found
Loading history...
322
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 12 found
Loading history...
323
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 8 spaces after parameter name; 16 found
Loading history...
324
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter name; 18 found
Loading history...
325
     *
326
     * @return Response
327
     */
328
    private function _includeScript($bIncludeOnce, $sFileName, $sType, $sId)
329
    {
330
        $aAttributes = [
331
            'type' => $sType,
332
            'elm_id' => $sId
333
        ];
334
        return $this->_addCommand(($bIncludeOnce ? 'ino' : 'in'), $aAttributes, $sFileName, true);
335
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
336
337
    /**
338
     * Add a command to load a javascript file on the browser
339
     *
340
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
341
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
342
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 18 found
Loading history...
343
     *
344
     * @return Response
345
     */
346
    public function includeScript($sFileName, $sType = '', $sId = '')
347
    {
348
        return $this->_includeScript(false, $sFileName, $sType, $sId);
349
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
350
351
    /**
352
     * Add a command to include a javascript file on the browser if it has not already been loaded
353
     *
354
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
355
     * @param string        $sType                Determines the script type. Defaults to 'text/javascript'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter name; 16 found
Loading history...
356
     * @param string        $sId                  The wrapper id
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter name; 18 found
Loading history...
357
     *
358
     * @return Response
359
     */
360
    public function includeScriptOnce($sFileName, $sType = '', $sId = '')
361
    {
362
        return $this->_includeScript(true, $sFileName, $sType, $sId);
363
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
364
365
    /**
366
     * Add a command to remove a SCRIPT reference to a javascript file on the browser
367
     *
368
     * Optionally, you can call a javascript function just prior to the file being unloaded (for cleanup).
369
     *
370
     * @param string        $sFileName            The relative or fully qualified URI of the javascript file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
371
     * @param string        $sUnload            Name of a javascript function to call prior to unlaoding the file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter name; 12 found
Loading history...
372
     *
373
     * @return Response
374
     */
375
    public function removeScript($sFileName, $sUnload = '')
376
    {
377
        $aAttributes = ['unld' => $sUnload];
378
        return $this->_addCommand('rjs', $aAttributes, $sFileName, true);
379
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
380
381
    /**
382
     * Add a command to include a LINK reference to the specified CSS file on the browser.
383
     *
384
     * This will cause the browser to load and apply the style sheet.
385
     *
386
     * @param string        $sFileName            The relative or fully qualified URI of the css file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
387
     * @param string        $sMedia                The media type of the CSS file. Defaults to 'screen'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter name; 16 found
Loading history...
388
     *
389
     * @return Response
390
     */
391
    public function includeCSS($sFileName, $sMedia = '')
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
392
    {
393
        $aAttributes = ['media' => $sMedia];
394
        return $this->_addCommand('css', $aAttributes, $sFileName, true);
395
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
396
397
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $sMedia should have a doc-comment as per coding-style.
Loading history...
398
     * Add a command to remove a LINK reference to a CSS file on the browser
399
     *
400
     * This causes the browser to unload the style sheet, effectively removing the style changes it caused.
401
     *
402
     * @param string        $sFileName            The relative or fully qualified URI of the css file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
403
     *
404
     * @return Response
405
     */
406
    public function removeCSS($sFileName, $sMedia = '')
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
407
    {
408
        $aAttributes = ['media' => $sMedia];
409
        return $this->_addCommand('rcss', $aAttributes, $sFileName, true);
410
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
411
412
    /**
413
     * Add a command to make Jaxon pause while the CSS files are loaded
414
     *
415
     * The browser is not typically a multi-threading application, with regards to javascript code.
416
     * Therefore, the CSS files included or removed with <Response->includeCSS> and
417
     * <Response->removeCSS> respectively, will not be loaded or removed until the browser regains
418
     * control from the script.
419
     * This command returns control back to the browser and pauses the execution of the response
420
     * until the CSS files, included previously, are loaded.
421
     *
422
     * @param integer        $iTimeout            The number of 1/10ths of a second to pause before timing out
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 12 found
Loading history...
423
     *                                             and continuing with the execution of the response commands
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 44 spaces but found 45
Loading history...
424
     *
425
     * @return Response
426
     */
427
    public function waitForCSS($iTimeout = 600)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
428
    {
429
        $aAttributes = ['cmd' => 'wcss', 'prop' => $iTimeout];
430
        return $this->addCommand($aAttributes, '');
431
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
432
433
    /**
434
     * Add a command to make Jaxon to delay execution of the response commands until a specified condition is met
435
     *
436
     * Note, this returns control to the browser, so that other script operations can execute.
437
     * Jaxon will continue to monitor the specified condition and, when it evaluates to true,
438
     * will continue processing response commands.
439
     *
440
     * @param string        $script                A piece of javascript code that evaulates to true or false
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
441
     * @param integer        $tenths                The number of 1/10ths of a second to wait before timing out
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
442
     *                                             and continuing with the execution of the response commands.
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 46 spaces but found 45
Loading history...
443
     *
444
     * @return Response
445
     */
446
    public function waitFor($script, $tenths)
447
    {
448
        $aAttributes = ['cmd' => 'wf', 'prop' => $tenths];
449
        return $this->addCommand($aAttributes, $script);
450
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
451
452
    /**
453
     * Add a command to make Jaxon to pause execution of the response commands,
454
     * returning control to the browser so it can perform other commands asynchronously.
455
     *
456
     * After the specified delay, Jaxon will continue execution of the response commands.
457
     *
458
     * @param integer        $tenths                The number of 1/10ths of a second to sleep
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 16 found
Loading history...
459
     *
460
     * @return Response
461
     */
462
    public function sleep($tenths)
463
    {
464
        $aAttributes = ['cmd' =>'s', 'prop' => $tenths];
0 ignored issues
show
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
465
        return $this->addCommand($aAttributes, '');
466
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
467
}
468