AlertifyJS icon indicating copy to clipboard operation
AlertifyJS copied to clipboard

alertify global enable disable option

Open darkworks opened this issue 7 years ago • 1 comments

i do not know if there is global enable disable alertify flag option currently available or not . so it will be good to have global flag where we could enable disable alertify globally. like in development we use alerts but in product we do not want to show alerts of success errors etc.

darkworks avatar Jun 19 '18 11:06 darkworks

Easiest method to solve it in your production code, is to prevent the script from loading by adding it dynamically if some conditions are met:

<script>
if (development) {
  let alertify = document.createElement('script'), attr = {
    type: 'text/javascript',
    src: 'path/to/alertify.js',
    crossorigin: 'anonymous'
  };
  for (let n in attr) {
    if (attr.hasOwnProperty(n)) {
      alertify.setAttribute(n, attr[n]);
    }
  }
  document.head.appendChild(alertify);
}
</script>

Your request doesn't require any modification of alertify or how to implement it.

Another solution would be on every usage where it is not needed in production make use of a simple check:

if (development) { alertify.alert(title, text); }
// or a wrapper
function printError() {
  if (development) {
    alertify.alert.apply(alertify, arguments);
  }
}
printError(title, text);

Greetings :)

anotherCoward avatar Jun 27 '19 19:06 anotherCoward