-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f16a239
commit 313dd70
Showing
5 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Jquery Toast Plugin | ||
!["Jquery Toast Plugin"](img/jquery-toast-plugin.jpg) | ||
|
||
Installation | ||
-------- | ||
|
||
```bash | ||
"loveorigami/yii2-notification-wrapper": "*", | ||
"bower-asset/jquery-toast-plugin": "*" | ||
``` | ||
|
||
to the ```require``` section of your `composer.json` file. | ||
|
||
|
||
Usage | ||
----- | ||
|
||
```php | ||
use lo\modules\noty\Wrapper; | ||
|
||
echo Wrapper::widget([ | ||
'layerClass' => 'lo\modules\noty\layers\JqueryToastPlugin', | ||
// default options | ||
'options' => [ | ||
'showHideTransition' => 'slide', // It can be plain, fade or slide | ||
'allowToastClose' => 'true', // Show the close button or not | ||
'hideAfter' => 3000, // `false` to make it sticky or time in miliseconds to hide after | ||
'stack' => 5, // `false` to show one stack at a time count showing the number of toasts that can be shown at once | ||
'position' => 'top-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values to position the toast on page | ||
|
||
// and more for this library here https://github.com/kamranahmedse/jquery-toast-plugin | ||
], | ||
]); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace lo\modules\noty\assets; | ||
|
||
use yii\web\AssetBundle; | ||
|
||
/** | ||
* Class JqueryToastPlugin | ||
* @package lo\modules\noty\layers | ||
*/ | ||
class JqueryToastPluginAsset extends AssetBundle | ||
{ | ||
/** @var string */ | ||
public $sourcePath = '@bower/jquery-toast-plugin/dist'; | ||
|
||
/** @var array $css */ | ||
public $css = [ | ||
'jquery.toast.min.css' | ||
]; | ||
|
||
/** @var array $js */ | ||
public $js = [ | ||
'jquery.toast.min.js' | ||
]; | ||
|
||
/** @var array $depends */ | ||
public $depends = [ | ||
'yii\web\JqueryAsset' | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace lo\modules\noty\layers; | ||
|
||
use lo\modules\noty\assets\JqueryToastPluginAsset; | ||
use yii\helpers\Json; | ||
|
||
/** | ||
* Class JqueryToastPlugin | ||
* @package lo\modules\noty\layers | ||
* | ||
* This widget should be used in your main layout file as follows: | ||
* --------------------------------------- | ||
* use lo\modules\noty\Wrapper; | ||
* | ||
* echo Wrapper::widget([ | ||
* 'layerClass' => 'lo\modules\noty\layers\JqueryToastPlugin', | ||
* 'options' => [ | ||
* 'position' => 'top-right', | ||
* 'hideAfter' => 3000, | ||
* 'allowToastClose' => true, | ||
* | ||
* // and more for this library... | ||
* ], | ||
* ]); | ||
* --------------------------------------- | ||
*/ | ||
class JqueryToastPlugin extends Layer implements LayerInterface | ||
{ | ||
/** | ||
* @var array $defaultOptions | ||
*/ | ||
protected $defaultOptions = [ | ||
'showHideTransition' => 'slide', // It can be plain, fade or slide | ||
'allowToastClose' => 'true', // Show the close button or not | ||
'hideAfter' => 3000, // `false` to make it sticky or time in miliseconds to hide after | ||
'stack' => 5, // `false` to show one stack at a time count showing the number of toasts that can be shown at once | ||
'position' => 'top-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values to position the toast on page | ||
]; | ||
|
||
/** | ||
* register asset | ||
*/ | ||
public function run() | ||
{ | ||
$view = $this->getView(); | ||
JqueryToastPluginAsset::register($view); | ||
parent::run(); | ||
} | ||
|
||
/** | ||
* @param $options | ||
* @return string | ||
*/ | ||
public function getNotification($options) | ||
{ | ||
$options['icon'] = $this->type; | ||
$options['text'] = $this->getMessageWithTitle(); | ||
$options = Json::encode($options); | ||
|
||
return "$.toast($options);"; | ||
} | ||
} |