Skip to content

Commit 74df65b

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents bb79452 + 97137d1 commit 74df65b

35 files changed

+1229
-365
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The following widgets are currently available:
7373
* Breadcrumbs
7474
* Button
7575
* Carousel
76-
* Chip
76+
* ChipInput
7777
* Collapsible
7878
* DatePicker
7979
* DetailView
@@ -93,6 +93,7 @@ The following widgets are currently available:
9393
* SideNav
9494
* Slider
9595
* Spinner
96+
* StaticChip
9697
* SubmitButton
9798
* SwitchButton
9899
* TimePicker

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
],
1616
"version": "3.0.0",
1717
"require": {
18-
"php": ">=7.0.0",
19-
"yiisoft/yii2": "~2.0.14",
18+
"php": ">=5.6.0",
19+
"yiisoft/yii2": "~2.0.0",
2020

21-
"bower-asset/materialize": "1.0.0-beta"
21+
"bower-asset/materialize": "1.0.*@beta"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/assets/MaterializeAsset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* MaterializeAsset provides the required Materialize CSS files.
14-
*
14+
*
1515
* @author Christoph Erdmann <[email protected]>
1616
* @package assets
1717
*/
@@ -33,6 +33,6 @@ class MaterializeAsset extends AssetBundle
3333
* @var array list of bundle class names that this bundle depends on.
3434
*/
3535
public $depends = [
36-
'macgyer\yii2materializecss\assets\MaterializeFontAsset',
36+
MaterializeFontAsset::class,
3737
];
3838
}

src/assets/MaterializePluginAsset.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
/**
1313
* MaterializePluginAsset provides the Materialize JS files.
14-
*
14+
*
1515
* @author Christoph Erdmann <[email protected]>
1616
* @package assets
1717
*/
@@ -21,18 +21,11 @@ class MaterializePluginAsset extends AssetBundle
2121
* @var string the directory that contains the source asset files for this asset bundle.
2222
*/
2323
public $sourcePath = '@bower/materialize/dist';
24-
24+
2525
/**
2626
* @var array list of JS files that this bundle contains.
2727
*/
2828
public $js = [
2929
'js/materialize.min.js'
3030
];
31-
32-
/**
33-
* @var array list of bundle class names that this bundle depends on.
34-
*/
35-
public $depends = [
36-
'yii\web\JqueryAsset'
37-
];
3831
}

src/lib/Html.php

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.

src/lib/MaterializeWidgetTrait.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use macgyer\yii2materializecss\assets\MaterializePluginAsset;
1111
use Yii;
1212
use yii\helpers\Json;
13+
use yii\web\View;
1314

1415
/**
1516
* MaterializeWidgetTrait provides the basics for all Materialize widgets features.
@@ -72,6 +73,7 @@ public function init()
7273
*/
7374
protected function registerPlugin($name, $selector = null)
7475
{
76+
/** @var View $view */
7577
$view = $this->getView();
7678

7779
MaterializePluginAsset::register($view);
@@ -83,9 +85,10 @@ protected function registerPlugin($name, $selector = null)
8385
}
8486

8587
if ($this->clientOptions !== false) {
86-
$options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
87-
$js = "jQuery('$selector').$name($options);";
88-
$view->registerJs($js);
88+
$options = empty($this->clientOptions) ? '{}' : Json::htmlEncode($this->clientOptions);
89+
90+
$js = "document.addEventListener('DOMContentLoaded', function() {M.$name.init(document.querySelectorAll('$selector'), $options);});";
91+
$view->registerJs($js, View::POS_END);
8992
}
9093

9194
$this->registerClientEvents();
@@ -97,12 +100,23 @@ protected function registerPlugin($name, $selector = null)
97100
protected function registerClientEvents()
98101
{
99102
if (!empty($this->clientEvents)) {
103+
/** @var View $view */
104+
$view = $this->getView();
100105
$id = $this->options['id'];
101-
$js = [];
106+
$js[] = "var elem_$id = document.getElementById('$id');";
102107
foreach ($this->clientEvents as $event => $handler) {
103-
$js[] = "jQuery('#$id').on('$event', $handler);";
108+
$js[] = "elem_$id.addEventListener('$event', $handler);";
104109
}
105-
$this->getView()->registerJs(implode("\n", $js));
110+
$view->registerJs(implode("\n", $js), View::POS_END);
106111
}
107112
}
108-
}
113+
114+
/**
115+
* @return string
116+
*/
117+
protected function getUniqueId($prefix = 'u_')
118+
{
119+
$uniqid = sha1(uniqid($prefix, true));
120+
return "{$prefix}{$uniqid}";
121+
}
122+
}

src/widgets/Alert.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
use yii\helpers\ArrayHelper;
1414

1515
/**
16-
* Alert renders Yii's session flash messages.
17-
*
18-
* All flash messages are displayed in the sequence they were assigned using
19-
* [yii\web\Session::setFlash()](http://www.yiiframework.com/doc-2.0/yii-web-session.html#setFlash()-detail).
20-
*
16+
* Alert renders Yii's session flash messages.
17+
*
18+
* All flash messages are displayed in the sequence they were assigned using
19+
* [yii\web\Session::setFlash()](http://www.yiiframework.com/doc-2.0/yii-web-session.html#setFlash()-detail).
20+
*
2121
* You can set messages as follows:
2222
*
2323
* ```php
@@ -62,7 +62,7 @@ class Alert extends BaseWidget
6262

6363
/**
6464
* @var array the HTML attributes for the widget container tag.
65-
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail) for details on
65+
* @see [yii\helpers\BaseHtml::renderTagAttributes()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#renderTagAttributes()-detail) for details on
6666
* how attributes are being rendered.
6767
*/
6868
public $options = [];
@@ -81,8 +81,7 @@ public function init()
8181

8282
/**
8383
* Executes the widget.
84-
* @return string the result of widget execution to be outputted.
85-
*
84+
*
8685
* @uses [yii\web\Session](http://www.yiiframework.com/doc-2.0/yii-web-session.html)
8786
*/
8887
public function run()

src/widgets/Button.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* The button can be displayed with an optional icon. This class uses the [[Icon|Icon]] widget to show icons.
2323
*
24-
* @see http://materializecss.com/buttons.html
24+
* @see https://materializecss.com/buttons.html
2525
* @author Christoph Erdmann <[email protected]>
2626
* @package widgets
2727
*/
@@ -42,6 +42,21 @@ class Button extends BaseWidget
4242
*/
4343
const TYPE_FLAT = 'flat';
4444

45+
/**
46+
* Sets the [[size]] of the button to the default size.
47+
*/
48+
const SIZE_DEFAULT = 'default';
49+
50+
/**
51+
* Sets the [[size]] of the button to "small".
52+
*/
53+
const SIZE_SMALL = 'small';
54+
55+
/**
56+
* Sets the [[size]] of the button to "large".
57+
*/
58+
const SIZE_LARGE = 'large';
59+
4560
/**
4661
* @var string the tag used to render the button.
4762
*/
@@ -88,9 +103,17 @@ class Button extends BaseWidget
88103
public $type = self::TYPE_RAISED;
89104

90105
/**
91-
* @var boolean whether the button shall be of larger size.
106+
* @var string the size of button to be rendered.
107+
*
108+
* The following options are supported:
109+
* - default
110+
* - small
111+
* - large
112+
*
113+
* This property defaults to "default". To set the type, use the corresponding `TYPE_*` constant of this class.
114+
* If no type from this range is given, the button will be of the "default" type.
92115
*/
93-
public $large = false;
116+
public $size = self::SIZE_DEFAULT;
94117

95118
/**
96119
* @var boolean whether the button shall be disabled.
@@ -113,10 +136,17 @@ public function init()
113136
break;
114137
}
115138

116-
if ($this->large) {
117-
Html::addCssClass($this->options, ['btn_size' => 'btn-large']);
139+
switch ($this->size) {
140+
case self::SIZE_SMALL:
141+
case self::SIZE_LARGE:
142+
Html::addCssClass($this->options, ['btn_size' => "btn-$this->size"]);
143+
break;
118144
}
119145

146+
// if ($this->large) {
147+
// Html::addCssClass($this->options, ['btn_size' => 'btn-large']);
148+
// }
149+
120150
if ($this->disabled) {
121151
Html::addCssClass($this->options, ['btn_disabled' => 'disabled']);
122152
}

src/widgets/Collapsible.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
* 'tag' => 'p',
4545
* 'data-body-category' => 'example',
4646
* ],
47+
* 'options' => ['class' => 'active'], // to make this item pre-selected
4748
* ],
4849
* ]
4950
* ```
5051
* @author Christoph Erdmann <[email protected]>
5152
* @package widgets
5253
*
53-
* @see http://materializecss.com/collapsible.html
54+
* @see https://materializecss.com/collapsible.html
5455
*/
5556
class Collapsible extends BaseWidget
5657
{
@@ -91,7 +92,12 @@ public function init()
9192
if ($this->isPopoutStyle) {
9293
Html::addCssClass($this->options, ['popout' => 'popout']);
9394
}
94-
$this->options['data-collapsible'] = $this->type;
95+
96+
if ($this->type == self::TYPE_EXPANDABLE) {
97+
$this->clientOptions['accordion'] = false;
98+
}
99+
100+
$this->registerPlugin('Collapsible');
95101
}
96102

97103
/**

src/widgets/Icon.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
* Please note that the Materialize icons are shipped in a separate font file. This font file is automatically registered
1919
* by the [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]].
2020
*
21-
* If you do not load the default [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]] make sure to at least load
22-
* [[\macgyer\yii2materializecss\assets\MaterializeFontAsset|MaterializeFontAsset]] (or another source providing the font file) to correctly
21+
* If you do not load the default [[\macgyer\yii2materializecss\assets\MaterializeAsset|MaterializeAsset]] make sure to at least load
22+
* [[\macgyer\yii2materializecss\assets\MaterializeFontAsset|MaterializeFontAsset]] (or another source providing the font file) to correctly
2323
* display the icons.
2424
*
2525
* @author Christoph Erdmann <[email protected]>
2626
* @package widgets
27-
* @see http://materializecss.com/icons.html
27+
* @see https://materializecss.com/icons.html
2828
*/
2929
class Icon extends BaseWidget
3030
{
3131
/**
3232
* @var string the name of the icon.
3333
*
34-
* @see http://materializecss.com/icons.html
34+
* @see https://materializecss.com/icons.html
3535
*/
3636
public $name;
3737

0 commit comments

Comments
 (0)