src/toastify.js
function() {
      // Validating if the options are defined
      if (!this.options) {
        throw "Toastify is not initialized";
      }

      // Creating the DOM object
      var divElement = document.createElement("div");
      divElement.className = "toastify on " + this.options.className;

      // Positioning toast to left or right
      if (this.options.positionLeft === true) {
        divElement.className += " toastify-left";
      } else {
        divElement.className += " toastify-right";
      }

      // Assigning gravity of element
      divElement.className += " " + this.options.gravity;

      if (this.options.backgroundColor) {
        divElement.style.background = this.options.backgroundColor;
      }

      // Adding the toast message
      divElement.innerHTML = this.options.text;

      if (this.options.avatar !== "") {
        var avatarElement = document.createElement("img");
        avatarElement.src = this.options.avatar;

        avatarElement.className = "toastify-avatar";

        if (this.options.positionLeft === true) {
          // Adding close icon on the left of content
          divElement.appendChild(avatarElement);
        } else {
          // Adding close icon on the right of content
          divElement.insertAdjacentElement("beforeend", avatarElement);
        }
      }

      // Adding a close icon to the toast
      if (this.options.close === true) {
        // Create a span for close element
        var closeElement = document.createElement("span");
        closeElement.innerHTML = "&#10006;";

        closeElement.className = "toast-close";

        // Triggering the removal of toast from DOM on close click
        closeElement.addEventListener(
          "click",
          function(event) {
            event.stopPropagation();
            this.removeElement(event.target.parentElement);
            window.clearTimeout(event.target.parentElement.timeOutValue);
          }.bind(this)
        );

        //Calculating screen width
        var width = window.innerWidth > 0 ? window.innerWidth : screen.width;

        // Adding the close icon to the toast element
        // Display on the right if screen width is less than or equal to 360px
        if (this.options.positionLeft === true && width > 360) {
          // Adding close icon on the left of content
          divElement.insertAdjacentElement("afterbegin", closeElement);
        } else {
          // Adding close icon on the right of content
          divElement.appendChild(closeElement);
        }
      }

      // Adding an on-click destination path
      if (typeof this.options.destination !== "undefined") {
        divElement.addEventListener(
          "click",
          function(event) {
            event.stopPropagation();
            if (this.options.newWindow === true) {
              window.open(this.options.destination, "_blank");
            } else {
              window.location = this.options.destination;
            }
          }.bind(this)
        );
      }

      // Returning the generated element
      return divElement;
    }
function() {
      // Validating if the options are defined
      if (!this.options) {
        throw "Toastify is not initialized";
      }

      // Creating the DOM object
      var divElement = document.createElement("div");
      divElement.className = "toastify on " + this.options.className;

      // Positioning toast to left or right
      if (this.options.positionLeft === true) {
        divElement.className += " toastify-left";
      } else {
        divElement.className += " toastify-right";
      }

      // Assigning gravity of element
      divElement.className += " " + this.options.gravity;

      if (this.options.backgroundColor) {
        divElement.style.background = this.options.backgroundColor;
      }

      // Adding the toast message
      divElement.innerHTML = this.options.text;

      if (this.options.avatar !== "") {
        var avatarElement = document.createElement("img");
        avatarElement.src = this.options.avatar;

        avatarElement.className = "toastify-avatar";

        if (this.options.positionLeft === true) {
          // Adding close icon on the left of content
          divElement.appendChild(avatarElement);
        } else {
          // Adding close icon on the right of content
          divElement.insertAdjacentElement("beforeend", avatarElement);
        }
      }

      // Adding a close icon to the toast
      if (this.options.close === true) {
        // Create a span for close element
        var closeElement = document.createElement("span");
        closeElement.innerHTML = "&#10006;";

        closeElement.className = "toast-close";

        // Triggering the removal of toast from DOM on close click
        closeElement.addEventListener(
          "click",
          function(event) {
            event.stopPropagation();
            this.removeElement(event.target.parentElement);
            window.clearTimeout(event.target.parentElement.timeOutValue);
          }.bind(this)
        );

        //Calculating screen width
        var width = window.innerWidth > 0 ? window.innerWidth : screen.width;

        // Adding the close icon to the toast element
        // Display on the right if screen width is less than or equal to 360px
        if (this.options.positionLeft === true && width > 360) {
          // Adding close icon on the left of content
          divElement.insertAdjacentElement("afterbegin", closeElement);
        } else {
          // Adding close icon on the right of content
          divElement.appendChild(closeElement);
        }
      }

      // Adding an on-click destination path
      if (typeof this.options.destination !== "undefined") {
        divElement.addEventListener(
          "click",
          function(event) {
            event.stopPropagation();
            if (this.options.newWindow === true) {
              window.open(this.options.destination, "_blank");
            } else {
              window.location = this.options.destination;
            }
          }.bind(this)
        );
      }

      // Returning the generated element
      return divElement;
    }
function ( ) { // Validating if the options are defined if ( ! this . options ) { throw "Toastify is not initialized" ; } // Creating the DOM object var divElement = document . createElement ( "div" ) ; divElement . className = "toastify on " + this . options . className ; // Positioning toast to left or right if ( this . options . positionLeft === true ) { divElement . className += " toastify-left" ; } else { divElement . className += " toastify-right" ; } // Assigning gravity of element divElement . className += " " + this . options . gravity ; if ( this . options . backgroundColor ) { divElement . style . background = this . options . backgroundColor ; } // Adding the toast message divElement . innerHTML = this . options . text ; if ( this . options . avatar !== "" ) { var avatarElement = document . createElement ( "img" ) ; avatarElement . src = this . options . avatar ; avatarElement . className = "toastify-avatar" ; if ( this . options . positionLeft === true ) { // Adding close icon on the left of content divElement . appendChild ( avatarElement ) ; } else { // Adding close icon on the right of content divElement . insertAdjacentElement ( "beforeend" , avatarElement ) ; } } // Adding a close icon to the toast if ( this . options . close === true ) { // Create a span for close element var closeElement = document . createElement ( "span" ) ; closeElement . innerHTML = "&#10006;" ; closeElement . className = "toast-close" ; // Triggering the removal of toast from DOM on close click closeElement . addEventListener ( "click" , function ( event ) { event . stopPropagation ( ) ; this . removeElement ( event . target . parentElement ) ; window . clearTimeout ( event . target . parentElement . timeOutValue ) ; } . bind ( this ) ) ; //Calculating screen width var width = window . innerWidth > 0 ? window . innerWidth : screen . width ; // Adding the close icon to the toast element // Display on the right if screen width is less than or equal to 360px if ( this . options . positionLeft === true && width > 360 ) { // Adding close icon on the left of content divElement . insertAdjacentElement ( "afterbegin" , closeElement ) ; } else { // Adding close icon on the right of content divElement . appendChild ( closeElement ) ; } } // Adding an on-click destination path if ( typeof this . options . destination !== "undefined" ) { divElement . addEventListener ( "click" , function ( event ) { event . stopPropagation ( ) ; if ( this . options . newWindow === true ) { window . open ( this . options . destination , "_blank" ) ; } else { window . location = this . options . destination ; } } . bind ( this ) ) ; } // Returning the generated element return divElement ; }
Building the DOM element
Building the DOM element