function Modal(element) {
	this.overlay = document.createElement("div")
	this.overlay.classList.add("modal-overlay")

	if (element instanceof HTMLElement) {
		this.element = element	
	}

	else {
		this.element = document.querySelector(element)	
		if (this.element == null) {
			throw new Error("element does not exist.")	
		}
		else if (!this.element.classList.contains("modal")) {
			throw new Error("element must have class modal")	
		}
	}


	if (this.overlay.style.zIndex === undefined || this.overlay.style.zIndex === ""){
		this.overlay.style.zIndex = 0
	}

	this.element.style.zIndex = this.overlay.style.zIndex + 1

	buttonsEl = this.element.querySelector(".modal-buttons")
	if (buttonsEl != null){
		buttons = Array.prototype.slice.call(buttonsEl.childNodes)
		var _this = this
		buttons.forEach(function(button){
			//Checks if the button is actually an element.
			if (button.nodeType == 1){
				if (button.classList.contains("positive")){
					document.addEventListener("keyup", function(event){
						if (event.keyCode == 13){ //Enter
							event.preventDefault()
							button.click()
						}
					})
				}

				button.addEventListener("click", function(event){
					var mainEvent = new Event("pressed", {cancelable: true})
					mainEvent.el = this
					if (this.classList.contains("positive")){
						var secondaryEvent = new Event("positive-pressed", {cancelable: true})
					}

					else if (this.classList.contains("negative")){
						var secondaryEvent = new Event("negative-pressed", {cancelable: true})
					}	
					
					_this.element.dispatchEvent(mainEvent)

					if (secondaryEvent != null){
						secondaryEvent.el = this
						_this.element.dispatchEvent(secondaryEvent)
					}

					if (!(mainEvent.defaultPrevented || (secondaryEvent != null && secondaryEvent.defaultPrevented))){
						_this.hide()
					}
				})
			}
		})
	}
}


Modal.prototype.show = function() {
	this.element.classList.add("active")
	document.body.appendChild(this.overlay)
	this.overlay.classList.add("active")
}

Modal.prototype.hide = function() {
	this.element.classList.remove("active")
	this.overlay.addEventListener("transitionend", function(event){
		this.remove()
	})
	this.overlay.classList.remove("active")
}

Modal.prototype.toggle = function() {
	if (this.element.classList.contains("active")) {
		this.hide()
	}
	else {
		this.show()
	}
}

Modal.prototype.addEventListener = function(){
	this.element.addEventListener.apply(this, arguments)
}


@@ -1881,32 +1881,150 @@
  = function() %7B%0A
+%09var event = new Event(%22show%22, %7Bcancelable: true%7D)%0A%09this.element.dispatchEvent(event)%0A%09if (!event.defaultPrevented)%7B%0A%09
 %09this.element.cl
@@ -2045,16 +2045,17 @@
 ctive%22)%0A
+%09
 %09documen
@@ -2087,16 +2087,17 @@
 verlay)%0A
+%09
 %09this.ov
@@ -2118,32 +2118,35 @@
 t.add(%22active%22)%0A
+%09%7D%0A
 %7D%0A%0AModal.prototy
@@ -2164,24 +2164,143 @@
 unction() %7B%0A
+%09var event = new Event(%22hide%22, %7Bcancelable: true%7D)%09%0A%09this.element.dispatchEvent(event)%0A%09if (!event.defaultPrevented)%7B%0A%09
 %09this.elemen
@@ -2328,16 +2328,17 @@
 ctive%22)%0A
+%09
 %09this.ov
@@ -2392,24 +2392,25 @@
 n(event)%7B%0A%09%09
+%09
 this.remove(
@@ -2411,20 +2411,22 @@
 emove()%0A
+%09
 %09%7D)%0A
+%09
 %09this.ov
@@ -2458,16 +2458,19 @@
 ctive%22)%0A
+%09%7D%0A
 %7D%0A%0AModal

Add show and hide events