Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Ajax/CssCommand.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Ajax; | |
4 | |
5 /** | |
6 * An AJAX command for calling the jQuery css() method. | |
7 * | |
8 * The 'css' command will instruct the client to use the jQuery css() method to | |
9 * apply the CSS arguments to elements matched by the given selector. | |
10 * | |
11 * This command is implemented by Drupal.AjaxCommands.prototype.css() defined | |
12 * in misc/ajax.js. | |
13 * | |
14 * @see http://docs.jquery.com/CSS/css#properties | |
15 * | |
16 * @ingroup ajax | |
17 */ | |
18 class CssCommand implements CommandInterface { | |
19 | |
20 /** | |
21 * A CSS selector string. | |
22 * | |
23 * If the command is a response to a request from an #ajax form element then | |
24 * this value can be NULL. | |
25 * | |
26 * @var string | |
27 */ | |
28 protected $selector; | |
29 | |
30 /** | |
31 * An array of property/value pairs to set in the CSS for the selector. | |
32 * | |
33 * @var array | |
34 */ | |
35 protected $css = []; | |
36 | |
37 /** | |
38 * Constructs a CssCommand object. | |
39 * | |
40 * @param string $selector | |
41 * A CSS selector for elements to which the CSS will be applied. | |
42 * @param array $css | |
43 * An array of CSS property/value pairs to set. | |
44 */ | |
45 public function __construct($selector, array $css = []) { | |
46 $this->selector = $selector; | |
47 $this->css = $css; | |
48 } | |
49 | |
50 /** | |
51 * Adds a property/value pair to the CSS to be added to this element. | |
52 * | |
53 * @param $property | |
54 * The CSS property to be changed. | |
55 * @param $value | |
56 * The new value of the CSS property. | |
57 * | |
58 * @return $this | |
59 */ | |
60 public function setProperty($property, $value) { | |
61 $this->css[$property] = $value; | |
62 return $this; | |
63 } | |
64 | |
65 /** | |
66 * Implements Drupal\Core\Ajax\CommandInterface:render(). | |
67 */ | |
68 public function render() { | |
69 | |
70 return [ | |
71 'command' => 'css', | |
72 'selector' => $this->selector, | |
73 'argument' => $this->css, | |
74 ]; | |
75 } | |
76 | |
77 } |