Skip to content

Commit

Permalink
Bootstrap Notify layer
Browse files Browse the repository at this point in the history
  • Loading branch information
loveorigami committed Oct 23, 2016
1 parent 858ff13 commit 435f01d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 16 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,23 @@ For example:

Currently supported layers are:

| Library (Layer) | Bower | Confirm | Project homepage | Docs |
| ------------------ | ------------- | ------- | ------------------------------------------------ | -------------------------------- |
| Bootstrap Alert | - | - | http://getbootstrap.com/components/#alerts | [read](docs/Alert.md) |
| Growl | jquery-growl | - | https://github.com/ksylvest/jquery-growl | [read](docs/Growl.md) |
| iGrowl | igrowl | - | https://github.com/catc/iGrowl | [read](docs/Igrowl.md) |
| Jquery Notify | jquery.notify | - | https://github.com/CreativeDream/jquery.notify | [read](docs/JqueryNotify.md) |
| jQuery Notify Bar | jqnotifybar | - | https://github.com/dknight/jQuery-Notify-bar | [read](docs/JqueryNotifyBar.md) |
| Lobibox | lobibox | + | https://github.com/arboshiki/lobibox | [read](docs/Lobibox.md) |
| Notie | notie | + | https://github.com/jaredreich/notie | [read](docs/Notie.md) |
| Notific8 | notific8 | - | https://github.com/ralivue/notific8 | [read](docs/Notific8.md) |
| NotifIt | notifit | + | https://github.com/naoxink/notifIt | [read](docs/NotifIt.md) |
| Notify.js | notifyjs | - | https://github.com/notifyjs/notifyjs | [read](docs/Notifyjs.md) |
| Noty | noty | + | https://github.com/needim/noty | [read](docs/Noty.md) |
| PNotify | pnotify | + | https://github.com/sciactive/pnotify | [read](docs/PNotify.md) |
| Sweetalert | sweetalert | + | https://github.com/t4t5/sweetalert | [read](docs/Sweetalert.md) |
| Toastr | toastr | - | https://github.com/CodeSeven/toastr | [read](docs/Toastr.md) |
| Library (Layer) | Bower | Confirm | Project homepage | Docs |
| ------------------ | --------------------------- | ------- | ------------------------------------------------ | -------------------------------- |
| Bootstrap Alert | - | - | http://getbootstrap.com/components/#alerts | [read](docs/Alert.md) |
| Bootstrap Notify | remarkable-bootstrap-notify | - | https://github.com/mouse0270/bootstrap-notify | [read](docs/BootstrapNotify.md) |
| Growl | jquery-growl | - | https://github.com/ksylvest/jquery-growl | [read](docs/Growl.md) |
| iGrowl | igrowl | - | https://github.com/catc/iGrowl | [read](docs/Igrowl.md) |
| Jquery Notify | jquery.notify | - | https://github.com/CreativeDream/jquery.notify | [read](docs/JqueryNotify.md) |
| jQuery Notify Bar | jqnotifybar | - | https://github.com/dknight/jQuery-Notify-bar | [read](docs/JqueryNotifyBar.md) |
| Lobibox | lobibox | + | https://github.com/arboshiki/lobibox | [read](docs/Lobibox.md) |
| Notie | notie | + | https://github.com/jaredreich/notie | [read](docs/Notie.md) |
| Notific8 | notific8 | - | https://github.com/ralivue/notific8 | [read](docs/Notific8.md) |
| NotifIt | notifit | + | https://github.com/naoxink/notifIt | [read](docs/NotifIt.md) |
| Notify.js | notifyjs | - | https://github.com/notifyjs/notifyjs | [read](docs/Notifyjs.md) |
| Noty | noty | + | https://github.com/needim/noty | [read](docs/Noty.md) |
| PNotify | pnotify | + | https://github.com/sciactive/pnotify | [read](docs/PNotify.md) |
| Sweetalert | sweetalert | + | https://github.com/t4t5/sweetalert | [read](docs/Sweetalert.md) |
| Toastr | toastr | - | https://github.com/CodeSeven/toastr | [read](docs/Toastr.md) |


## Full installation
Expand All @@ -232,6 +233,7 @@ Add
"bower-asset/notifyjs": "^0.4",
"bower-asset/pnotify": "^3.0",
"bower-asset/noty": "^2.3",
"bower-asset/remarkable-bootstrap-notify": "^3.1",
"bower-asset/sweetalert": "^1.1",
"bower-asset/toastr": "^2.1"
```
Expand Down
36 changes: 36 additions & 0 deletions docs/BootstrapNotify.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Bootstrap Notify
!["Bootstrap Notify"](img/bootstrap-notify.jpg)

Installation
--------

```bash
"loveorigami/yii2-notification-wrapper": "*",
"bower-asset/remarkable-bootstrap-notify": "^3.1",
```

to the ```require``` section of your `composer.json` file.


Usage
-----

```php
use lo\modules\noty\Wrapper;

echo Wrapper::widget([
'layerClass' => 'lo\modules\noty\layers\BootstrapNotify',
// default options
'options' => [
'newest_on_top' => false,
'showProgressbar' => true,
'placement' => [
'from' => 'top',
'align' => 'right'
]

// and more for this library here https://github.com/mouse0270/bootstrap-notify
],
]);

```
Binary file added docs/img/bootstrap-notify.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/assets/BootstrapNotifyAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace lo\modules\noty\assets;

use yii\web\AssetBundle;

/**
* Class BootstrapNotifyAsset
* @package lo\modules\noty\layers
*/
class BootstrapNotifyAsset extends AssetBundle
{
/** @var string */
public $sourcePath = '@bower/remarkable-bootstrap-notify';

/** @var array $js */
public $js = [
'bootstrap-notify.min.js'
];

/** @var array $depends */
public $depends = [
'yii\bootstrap\BootstrapPluginAsset',
];
}
85 changes: 85 additions & 0 deletions src/layers/BootstrapNotify.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace lo\modules\noty\layers;

use yii\helpers\Json;
use lo\modules\noty\assets\BootstrapNotifyAsset;

/**
* Class BootstrapNotify
* @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\BootstrapNotify',
* 'options' => [
* 'fixed' => true,
* 'size' => 'medium',
* 'location' => 'tr',
* 'delayOnHover' => true,
*
* // and more for this library...
* ],
* ]);
* ---------------------------------------
*/
class BootstrapNotify extends Layer implements LayerInterface
{

/**
* @var array $defaultOptions
*/
protected $defaultOptions = [
'newest_on_top' => false,
'showProgressbar' => false,
'placement' => [
'from' => 'top',
'align' => 'right'
]
];

/**
* register asset
*/
public function run()
{
$view = $this->getView();
BootstrapNotifyAsset::register($view);
parent::run();
}

/**
* @param $options
* @return string
*/
public function getNotification($options)
{
$options['type'] = $this->getType();
$options = Json::encode($options);

$data['message'] = $this->getMessageWithTitle();
//$data['title'] = $this->title;
$data = Json::encode($data);

return "$.notify($data, $options);";
}

/**
* @return string
*/
public function getType()
{
switch ($this->type) {
case self::TYPE_ERROR:
$type = 'danger';
break;
default:
$type = $this->type;
}
return $type;
}

}

0 comments on commit 435f01d

Please sign in to comment.