Изменение положения класса для toastr Уведомление

Я пытаюсь изменить positionclass для моего тоста на нажатие div.

positionclass: не изменяется на нижний. что мне здесь не хватает?

и как использовать

toastr.optionsOverride = 'positionclass: toast-bottom-full-width';

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<head>
    <title></title>
    <script type ="text/javascript" src ="@Url.Content("~/Scripts/jquery-1.6.4.js")"></script>
    <script type ="text/javascript" src ="@Url.Content("~/Scripts/toastr.js")"></script>
    <link rel="stylesheet" type="text/css" href="~/content/toastr.css" />
</head>
<script type="text/javascript">
    $(document).ready(function () {

        // show when page load
        toastr.info('Page Loaded!');

        $('#linkButton').click(function () {
            toastr.optionsOverride = 'positionclass:toast-bottom-full-width';
            // show when the button is clicked
            toastr.success('Click Button', 'ButtonClick', 'positionclass:toast-bottom-full-width');
        });

    });

</script>

<body>
    <div id ="linkButton" > click here</div>
</body>

обновление 1

после отладки я заметил, что ниже метод getOptions из toastr.js является переопределяющим 'positionclass: toast-bottom-full-width' to 'toast-top-right'

    function getOptions() {
        return $.extend({}, defaults, toastr.options);
    }

update 2 Строка 140 в toastr.js не успешно , расширяющая m optionsOverride in to options.

        if (typeof (map.optionsOverride) !== 'undefined') {
            options = $.extend(options, map.optionsOverride);
            iconClass = map.optionsOverride.iconClass || iconClass;
        }

обновление 3 Вопрос о выпуске исправлен, но я должен указать класс позиции 3 раза, как показано ниже. Я уверен, что есть менее шумный способ достичь этого.

$('#linkButton').click(function () {

    toastr.optionsOverride = 'positionclass = "toast-bottom-full-width"';
    toastr.options.positionClass = 'toast-bottom-full-width';
     //show when the button is clicked
    toastr.success('Click Button', 'ButtonClick', 'positionclass = "toast-bottom-full-width"');
});

Ответы

Ответ 1

Вы можете просто установить его так, как показано в демонстрации toastr: http://codeseven.github.io/toastr/ или эта демонстрация: http://plnkr.co/edit/6W9URNyyp2ItO4aUWzBB

toastr.options = {
  "debug": false,
  "positionClass": "toast-bottom-full-width",
  "onclick": null,
  "fadeIn": 300,
  "fadeOut": 1000,
  "timeOut": 5000,
  "extendedTimeOut": 1000
}

Ответ 2

Я там определенно ошибка здесь...

Например. Настройка параметров немного липкая. Я установил их динамически прямо перед вызовом типа тоста, который я хочу. В первый раз варианты не имеют значения. Следующий тост, похоже, подбирает варианты, а затем тост после этого не изменится.

Например

var logger = app.mainModule.factory('logger', ['$log', function ($log) {

var error = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "positionClass": "toast-bottom-full-width",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "300000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.error(msg);
    }
    $log.error(msg, data);
};
var info = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": true,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "300000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.info(msg);
    }
    $log.info(msg, data);
};
var warning = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
        toastr.warning(msg);
    }
    $log.warning(msg, data);
};

var success = function (msg, data, showtoast) {

    if (showtoast) {
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-bottom-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };

        toastr.success(msg);
    }
    $log.info(msg, data);
};


var logger = {
    success: success,
    error: error,
    info: info,
    warning: warning

};
return logger;
}]);

Ответ 3

Я не могу найти версию 2.0.3! Последняя версия 1.4.1 см. Это

В итоге я изменил значение hardcoded для positionClass в 'angular -toastr.tpls.js'

Теперь он центрируется правильно!

Ответ 4

это простые простые шаги, чтобы изменить положение...... см. ниже..

сначала объявите класс позиции перед показом сообщения.

EX: toastr.options.positionClass = 'toast-bottom-right';

Затем покажите свое сообщение, как показано ниже:

Command: toastr "успех"

Надеюсь, что это хорошо работает.... Спасибо

Я просто использовал его в своем проекте Laravel.... Я поставлю свой код здесь, если вы его поймете....

<script src="{{ asset('js/toastr.min.js') }}" type="text/javascript"></script>
<script type="text/javascript">


    @if (Session::has('success'))

        toastr.options.positionClass = 'toast-bottom-right';
        toastr.success("{{ Session::get('success') }}");

    @endif


</script>

уведомления о toastr