Skip to content

Commit 48f8d5c

Browse files
committed
Bugfix: lowerThan property would fire the widget for any browser
1 parent 0c8ac5f commit 48f8d5c

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

OutdatedBrowser.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@
33
namespace biller\outdatedBrowser;
44

55
use yii\base\Widget;
6+
use yii\helpers\ArrayHelper;
67
use yii\helpers\Html;
78

89
class Outdatedbrowser extends Widget {
910

1011
public $bgColor = '#f25648';
1112
public $color = '#ffffff';
12-
public $lowerThan = null;
13+
public $lowerThan = 'transform';
1314
public $language = 'en';
1415
public $onlyIe7 = false;
16+
private $bundle;
1517

1618
public function run() {
17-
$bundle = OutDatedBrowserAsset::register($this->view);
18-
$js = $this->render('widget', [
19-
'widget' => $this,
20-
'bundle' => $bundle,
19+
$this->bundle = OutDatedBrowserAsset::register($this->view);
20+
21+
$data = ArrayHelper::toArray($this, [
22+
Outdatedbrowser::class => ['bgColor', 'color', 'lowerThan', 'languagePath']
2123
]);
24+
25+
$js = $this->render('widget', ['data' => $data, 'onlyIe7' => $this->onlyIe7]);
2226
$this->view->registerJs($js);
27+
2328
$div = Html::tag('div', '', ['id' => 'outdated']);
2429
return $this->onlyIe7 ? "<!--[if lt IE 8]>$div<![endif]-->" : $div;
2530
}
2631

2732
public function getLanguagePath() {
28-
return "$this->baseUrl/outdatedbrowser/lang/$this->language.html";
33+
return "{$this->bundle->baseUrl}/lang/es.html";
2934
}
3035

3136
}

OutdatedBrowserAsset.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
class OutDatedBrowserAsset extends AssetBundle {
99

10-
public $sourcePath = '@bower/outdated-browser';
10+
public $sourcePath = '@bower/outdated-browser/outdatedbrowser';
1111
public $js = [
12-
'outdatedbrowser/outdatedbrowser.js',
12+
'outdatedbrowser.min.js',
1313
];
1414
public $css = [
15-
'outdatedbrowser/outdatedbrowser.css',
15+
'outdatedbrowser.min.css',
1616
];
1717
public $depends = [
1818
JqueryAsset::class,

views/widget.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php
22

3-
use biller\outdatedBrowser\Outdatedbrowser;
43
use yii\helpers\Json;
54
use yii\web\View;
65

76
/* @var $this View */
8-
/* @var $widget Outdatedbrowser */
7+
/* @var $onlyIe7 bool */
8+
/* @var $data array */
99
?>
1010
<?php if (false) { ?>
1111
<script>
1212
<?php } ?>
1313
$(function () {
14-
<?= $widget->onlyIe7 ? "if ($('#outdated').length > 0) {" : '' ?>
15-
outdatedBrowser(<?= Json::encode($widget) ?>);
16-
<?= $widget->onlyIe7 ? '}' : '' ?>
14+
<?= $onlyIe7 ? "if ($('#outdated').length > 0) {" : '' ?>
15+
outdatedBrowser(<?= Json::encode($data) ?>);
16+
<?= $onlyIe7 ? '}' : '' ?>
1717
});
1818
<?php if (false) { ?>
1919
</script>

0 commit comments

Comments
 (0)