Skip to content

Commit

Permalink
do not output default parameters if not needed to
Browse files Browse the repository at this point in the history
  • Loading branch information
marekgach committed Oct 6, 2015
1 parent 7729835 commit aa9bf94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
25 changes: 15 additions & 10 deletions src/Smartsupp/ChatGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,27 @@ class ChatGenerator
/**
* @var string Chat X align.
*/
protected $align_x = 'right';
protected $align_x = null;

/**
* @var string Chat Y align.
*/
protected $align_y = 'bottom';
protected $align_y = null;

/**
* @var int Chat X offset.
*/
protected $offset_x = 10;
protected $offset_x = null;

/**
* @var int Chat Y offset.
*/
protected $offset_y = 100;
protected $offset_y = null;

/**
* @var string Widget type.
*/
protected $widget = 'widget';
protected $widget = null;

/**
* @var null|string Google analytics key value.
Expand Down Expand Up @@ -377,11 +377,16 @@ public function render($print_out = false)
$params[] = "_smartsupp.ratingComment = " . ($this->rating_comment? 'true':'false') . "; // default false";
}

$params[] = "_smartsupp.alignX = '" . $this->align_x . "'; // or 'left'";
$params[] = "_smartsupp.alignY = '" . $this->align_y . "'; // by default 'bottom'";
$params[] = "_smartsupp.offsetX = " . (int) $this->offset_x . "; // offset from left or right, default 10";
$params[] = "_smartsupp.offsetY = " . (int) $this->offset_y . "; // offset from top, default 100";
$params[] = "_smartsupp.widget = '" . $this->widget . "'; // by default 'widget'";
if ($this->align_x && $this->align_y && $this->widget) {
$params[] = "_smartsupp.alignX = '" . $this->align_x . "'; // or 'left'";
$params[] = "_smartsupp.alignY = '" . $this->align_y . "'; // by default 'bottom'";
$params[] = "_smartsupp.widget = '" . $this->widget . "'; // by default 'widget'";
}

if ($this->offset_x && $this->offset_y) {
$params[] = "_smartsupp.offsetX = " . (int)$this->offset_x . "; // offset from left / right, default 10";
$params[] = "_smartsupp.offsetY = " . (int)$this->offset_y . "; // offset from top, default 100";
}

// set detailed visitor's info
// basic info
Expand Down
10 changes: 3 additions & 7 deletions tests/ChatGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ public function test_render_simple()
$expected = "<script type=\"text/javascript\">
var _smartsupp = _smartsupp || {};
_smartsupp.key = 'XYZ123456';
_smartsupp.alignX = 'right'; // or 'left'
_smartsupp.alignY = 'bottom'; // by default 'bottom'
_smartsupp.offsetX = 10; // offset from left or right, default 10
_smartsupp.offsetY = 100; // offset from top, default 100
_smartsupp.widget = 'widget'; // by default 'widget'
window.smartsupp||(function(d) {
var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
Expand Down Expand Up @@ -246,9 +242,9 @@ public function test_render_allParams()
_smartsupp.ratingComment = true; // default false
_smartsupp.alignX = 'left'; // or 'left'
_smartsupp.alignY = 'side'; // by default 'bottom'
_smartsupp.offsetX = 20; // offset from left or right, default 10
_smartsupp.offsetY = 120; // offset from top, default 100
_smartsupp.widget = 'button'; // by default 'widget'
_smartsupp.offsetX = 20; // offset from left / right, default 10
_smartsupp.offsetY = 120; // offset from top, default 100
_smartsupp.gaKey = 'UA\\x2d123456';
_smartsupp.gaOptions = {'cookieDomain': '\\x2efoo\\x2ebar'};
_smartsupp.hideWidget = true;
Expand Down

0 comments on commit aa9bf94

Please sign in to comment.