Skip to content

Commit

Permalink
widget
Browse files Browse the repository at this point in the history
  • Loading branch information
stronglab committed Jul 10, 2016
1 parent 5332a57 commit 4a17f14
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 21 deletions.
26 changes: 26 additions & 0 deletions AlertAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace stronglab\alert;

use yii\web\AssetBundle;

class AlertAsset extends AssetBundle
{
public $sourcePath = '@stronglab/alert/web';
public $css = [
'alert.css',
];
public $js = [
'alert.js',
];

public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
];
}
8 changes: 6 additions & 2 deletions FlashMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

class FlashMessage extends \yii\base\Widget
{
public function run()
public function init()
{

$view = $this->getView();
AlertAsset::register($view);
if (Yii::$app->session->getAllFlashes()) {
$this->registerJs('showMessage("' . implode('<br/>', Yii::$app->session->getAllFlashes()) . '")');
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Usage
Once the extension is installed, simply use it in your code by :

```php
<?= \stronglab\alert\FlashMessage::widget(); ?>```
<?= \stronglab\alert\FlashMessage::widget(); ?>
```
40 changes: 22 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{
"name": "stronglab/yii2-alert",
"description": "Yii2 Alert Message",
"type": "yii2-extension",
"keywords": ["yii2","extension"],
"license": "BSD-3-Clause",
"authors": [
{
"name": "strong",
"email": "[email protected]"
}
],
"require": {
"yiisoft/yii2": "*"
},
"autoload": {
"psr-4": {
"stronglab\\alert\\": ""
}
"name": "stronglab/yii2-alert",
"description": "Yii2 Alert Message",
"type": "yii2-extension",
"keywords": [
"yii2",
"extension"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "strong",
"email": "[email protected]"
}
],
"require": {
"yiisoft/yii2": "*",
"yiisoft/yii2-bootstrap": "*"
},
"autoload": {
"psr-4": {
"stronglab\\alert\\": ""
}
}
}
13 changes: 13 additions & 0 deletions web/alert.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.flash-modal {
position: fixed;
top: 20px;
right: 30px;
z-index: 9999;
display: none;
width: 350px;
padding: 30px;
text-align: center;
border-radius: 4px;
border: 1px #9acfea solid;
font-size: 1.1em;
}
33 changes: 33 additions & 0 deletions web/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
$(".flash-modal").bind("contextmenu", function (e) {
e.preventDefault();
$(this).fadeOut(420);
});

function showMessage(message, fade, type) {
fade = typeof fade !== "undefined" ? fade : 1;
type = typeof type !== "undefined" ? type : "alert-info";
var obj = $(".flash-modal");
obj.html("<b>" + message + "</b>");
obj.addClass(type);
obj.stop().animate({opacity: "100"});
obj.show();
if (fade) {
messageBoxFadeOut();
obj.mouseover(
function () {
if ($(this).is(":animated")) {
$(this).stop().animate({opacity: "100"});
}
}
);
obj.mouseleave(messageBoxFadeOut);

}
}

function messageBoxFadeOut() {
var obj = $(".flash-modal");
obj.fadeOut(7000, function () {
obj.removeClass("alert-danger alert-success alert-info");
});
}

0 comments on commit 4a17f14

Please sign in to comment.