diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 923deb4..0000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -protected/runtime/* -!protected/runtime/.gitignore -protected/data/*.db -themes/classic/views/ diff --git a/AnimateAsset.php b/AnimateAsset.php new file mode 100755 index 0000000..c487d02 --- /dev/null +++ b/AnimateAsset.php @@ -0,0 +1,14 @@ +css[] = YII_DEBUG ? 'animate.css' : 'animate.min.js'; + parent::init(); + } +} diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Noty.php b/Noty.php old mode 100644 new mode 100755 index 29e4407..1fb8a5f --- a/Noty.php +++ b/Noty.php @@ -2,45 +2,68 @@ namespace eleiva\noty; -use yii\helpers\Html; use yii\helpers\Json; use yii\base\Widget; -class Noty extends Widget -{ - /* Html options for the enclosing element */ - public $options = []; +/** + * Noty Notification Wrapper @see http://ned.im/ + * + * @author Eduardo Leiva + * @author Victor Demin + */ +class Noty extends Widget { - /* Client options for noty.js */ + /** + * Notification message + * @var string + */ + public $text; + + /** + * Notification type + * @var string + */ + public $type = self::ALERT; + + /** + * Other Noty options. + * @var array + */ public $clientOptions = [ - 'timeout' => 1000, - 'layout' => 'topRight', - 'dismissQueue' => true, - 'theme' => 'defaultTheme' , - ]; + 'timeout' => 1000, + 'layout' => 'topRight', + 'dismissQueue' => true, + 'theme' => 'defaultTheme', + ]; - /* Tag of the surrounding element */ - public $tag = 'div'; + /** + * If to register Animate.css @see https://github.com/daneden/animate.css + * @var boolean + */ + public $useAnimateCss = false; - public $text = ''; - public $type = 'information'; + const ALERT = 'alert'; + const SUCCESS = 'success'; + const ERROR = 'error'; + const WARNING = 'warning'; + const INFORMATION = 'information'; - public function init(){ + /** + * Init widget + */ + public function init() { $view = $this->getView(); - $asset = new NotyAsset([ - 'publishOptions' => [ - 'forceCopy' => true - ] - ]); + $asset = new NotyAsset(); $asset->register($view); + if ($this->useAnimateCss) { + $cssAsset = new AnimateAsset(); + $cssAsset->register($view); + } + $this->clientOptions['text'] = $this->text; $this->clientOptions['type'] = $this->type; - $opts = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : "{}"; $view->registerJs("noty($opts);"); } - public function run() - { - } } diff --git a/NotyAsset.php b/NotyAsset.php old mode 100644 new mode 100755 index 3230bdb..0c29608 --- a/NotyAsset.php +++ b/NotyAsset.php @@ -1,19 +1,18 @@ -js[] = YII_DEBUG ? 'jquery.noty.packaged.js' : 'jquery.noty.packaged.min.js'; parent::init(); - - $this->sourcePath = __DIR__. DIRECTORY_SEPARATOR . 'assets'; - $this->js[] = YII_DEBUG ? 'jquery.noty.js' : 'jquery.noty.min.js'; - $this->js[] = 'noty.bootstrap.js'; } } diff --git a/README.md b/README.md old mode 100644 new mode 100755 index fb8b043..4c62f6b --- a/README.md +++ b/README.md @@ -29,16 +29,23 @@ Once the extension is installed, simply use it in your code by : ```php use eleiva\noty\Noty; - echo Noty::widget([ - 'text' => 'Hellooooooooo', - 'type' => 'error', - 'clientOptions' => [ - 'timeout' => 1000, - 'layout' => 'topRight', - 'dismissQueue' => true, - 'theme' => 'defaultTheme' , - ] - ]); + echo Noty::widget([ + 'text' => 'Hi! Looks good!', + 'type' => Noty::INFORMATION, + 'useAnimateCss' => true, + 'clientOptions' => [ + 'timeout' => 5000, + 'layout' => 'top', + 'dismissQueue' => true, + 'theme' => 'relax', + 'animation' => [ + 'open' => 'animated bounceInLeft', + 'close' => 'animated bounceOutLeft', + 'easing' => 'swing', + 'speed' => 500 + ] + ] + ]); ``` Or simply ```php diff --git a/assets/jquery.noty.js b/assets/jquery.noty.js deleted file mode 100644 index 56da41e..0000000 --- a/assets/jquery.noty.js +++ /dev/null @@ -1,1222 +0,0 @@ -/*! - @package noty - jQuery Notification Plugin - @version version: 2.2.5 - @contributors https://github.com/needim/noty/graphs/contributors - - @documentation Examples and Documentation - http://needim.github.com/noty/ - - @license Licensed under the MIT licenses: http://www.opensource.org/licenses/mit-license.php - */ - -if(typeof Object.create !== 'function') { - Object.create = function(o) { - function F() { - } - - F.prototype = o; - return new F(); - }; -} - -(function($) { - - var NotyObject = { - - init: function(options) { - - // Mix in the passed in options with the default options - this.options = $.extend({}, $.noty.defaults, options); - - this.options.layout = (this.options.custom) ? $.noty.layouts['inline'] : $.noty.layouts[this.options.layout]; - - if($.noty.themes[this.options.theme]) - this.options.theme = $.noty.themes[this.options.theme]; - else - options.themeClassName = this.options.theme; - - delete options.layout; - delete options.theme; - - this.options = $.extend({}, this.options, this.options.layout.options); - this.options.id = 'noty_' + (new Date().getTime() * Math.floor(Math.random() * 1000000)); - - this.options = $.extend({}, this.options, options); - - // Build the noty dom initial structure - this._build(); - - // return this so we can chain/use the bridge with less code. - return this; - }, // end init - - _build: function() { - - // Generating noty bar - var $bar = $('
').attr('id', this.options.id); - $bar.append(this.options.template).find('.noty_text').html(this.options.text); - - this.$bar = (this.options.layout.parent.object !== null) ? $(this.options.layout.parent.object).css(this.options.layout.parent.css).append($bar) : $bar; - - if(this.options.themeClassName) - this.$bar.addClass(this.options.themeClassName).addClass('noty_container_type_' + this.options.type); - - // Set buttons if available - if(this.options.buttons) { - - // If we have button disable closeWith & timeout options - this.options.closeWith = []; - this.options.timeout = false; - - var $buttons = $('
').addClass('noty_buttons'); - - (this.options.layout.parent.object !== null) ? this.$bar.find('.noty_bar').append($buttons) : this.$bar.append($buttons); - - var self = this; - - $.each(this.options.buttons, function(i, button) { - var $button = $('