Skip to content

Commit

Permalink
Added option to set width and height of widget with percentages
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanderburg committed Feb 8, 2019
1 parent 20fd1a5 commit aed75a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions MapPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class MapPicker extends Widget
/**
* @var bool|int Width for the map widget, optional
*/
public $width = 200;
public $width = "200px";
/**
* @var int Height for the map widget, optional
*/
public $height = 100;
public $height = "100px";
/**
* @var string Input field where to update matching latitude
*/
Expand Down Expand Up @@ -76,8 +76,10 @@ public function init()
}
$this->mapId = $this->mapId ?: 'map_' . substr(md5(time() . rand(0, 999)), 0, 8);
$styles = [];
$styles[] = $this->width ? "width: {$this->width}px;" : '';
$styles[] = $this->height ? "height: {$this->height}px;" : '';
$width = strpos($this->width, "px")||strpos($this->width, "%")?$this->width:$this->width."px";
$height = strpos($this->height, "px")||strpos($this->height, "%")?$this->height:$this->height."px";
$styles[] = $this->width ? "width: {$width};" : '';
$styles[] = $this->height ? "height: {$height};" : '';
$style = implode(" ", $styles);
$this->options = ArrayHelper::merge(['style' => $style], $this->options);
}
Expand Down

0 comments on commit aed75a2

Please sign in to comment.