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