Navigation Menu

Skip to content

Commit

Permalink
jquery toaster plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
loveorigami committed Jan 3, 2017
1 parent f16a239 commit 313dd70
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
35 changes: 35 additions & 0 deletions docs/JqueryToastPlugin.md
@@ -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
],
]);

```
4 changes: 2 additions & 2 deletions docs/JqueryToaster.md
@@ -1,5 +1,5 @@
# Jquery Toaster
!["Jquery Notify"](img/jquery_toaster.jpg)
!["JqueryToaster"](img/jquery_toaster.jpg)

Installation
--------
Expand All @@ -19,7 +19,7 @@ Usage
use lo\modules\noty\Wrapper;

echo Wrapper::widget([
'layerClass' => 'lo\modules\noty\layers\JqueryNotify',
'layerClass' => 'lo\modules\noty\layers\JqueryToaster',
// default options
'options' => [
'settings' => [
Expand Down
Binary file added docs/img/jquery-toast-plugin.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/assets/JqueryToastPluginAsset.php
@@ -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'
];
}
63 changes: 63 additions & 0 deletions src/layers/JqueryToastPlugin.php
@@ -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);";
}
}

0 comments on commit 313dd70

Please sign in to comment.