<!DOCTYPE html>
<html ng-app="example">

  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Example</title>
    <meta name="description" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>

  <body>
    <!--[if lt IE 8]>
            <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->
    <div ng-controller="MainCtrl">
      <div class="open-btn-group">
        <button class="btn btn-primary btn-main" ng-click="$quickDialog.open('login')">Log in</button>
        <button class="btn btn-primary btn-main" ng-click="$quickDialog.open('signup')">Sign up</button>
        <input id="test-focus-input" />
      </div>
      <quick-dialog id="test-dialog-login" ng-cloak="" dialog-name="login" open-focus="login-email" close-focus="test-focus-input">
        <form class="custom-form" action="GET" ng-submit="$event.preventDefault(); $quickDialog.close('login')">
          <h1>Log in</h1>
          <div class="custom-form__labels">
            <label for="login-email">Email:</label>
            <br />
            <label for="login-password">Password:</label>
          </div>
          <div class="custom-form__inputs">
            <input ng-model="auth.email" id="login-email" type="email" placeholder="Enter email address" />
            <br />
            <input ng-model="auth.password" id="login-password" type="password" placeholder="Enter password" />
          </div>
          <div class="btn-group">
            <button id="test-dialog-login-login" class="btn btn-primary" type="submit">Log in</button>
            <button id="test-dialog-login-cancel" class="btn btn-secondary" type="button" ng-click="auth.clear(); $quickDialog.close('login')">Cancel</button>
          </div>
        </form>
      </quick-dialog>
      <quick-dialog id="test-dialog-signup" ng-cloak="" dialog-name="signup">
        <form class="custom-form" action="GET" ng-submit="$event.preventDefault(); $quickDialog.close()">
          <h1>Sign up</h1>
          <div class="custom-form__labels">
            <label for="signup-email">Email:</label>
            <br />
            <label for="signup-password">Password:</label>
            <br />
            <label for="signup-password-check">Confirm password:</label>
          </div>
          <div class="custom-form__inputs">
            <input ng-model="auth.email" id="signup-email" type="email" placeholder="Enter email address" />
            <br />
            <input ng-model="auth.password" id="signup-password" type="password" placeholder="Enter password" />
            <br />
            <input ng-model="auth.passwordCheck" id="signup-password-check" type="password" placeholder="Enter password" />
          </div>
          <div class="btn-group">
            <button class="btn btn-primary" type="submit">Sign up</button>
            <button class="btn btn-secondary" type="button" ng-click="auth.clear(); $quickDialog.close()">Cancel</button>
          </div>
        </form>
        <!-- Testing stacking dialogs -->
        <button ng-click="$quickDialog.open('test')">Test</button>
        <quick-dialog ng-cloak="" dialog-name="test">
          <form class="custom-form" action="GET" ng-submit="$event.preventDefault(); $quickDialog.close()">
            <h1>Test</h1>
            <div class="custom-form__labels">
              <label for="signup-email">Email:</label>
            </div>
            <div class="custom-form__inputs">
              <input ng-model="auth.email" id="signup-email" type="email" placeholder="Enter email address" />
            </div>
            <div class="btn-group">
              <button class="btn btn-primary" type="submit">Test</button>
              <button class="btn btn-secondary" type="button" ng-click="auth.clear(); $quickDialog.close()">Cancel</button>
            </div>
          </form>
        </quick-dialog>
        <!-- Testing stacking dialogs -->
      </quick-dialog>
    </div>
    <script data-require="angular.js@1.3.0-beta.5" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
    <script src="script.js"></script>
    <script>
            angular.module('example', ['angularQuickDialog'])
               .controller('MainCtrl', function ($scope, $quickDialog) {
                       $scope.$quickDialog = $quickDialog;

                       $scope.auth = {
                           clear: function() {
                               this.email = '';
                               this.password = '';
                               this.passwordCheck = '';
                           }
                       };
                       $scope.auth.clear();
               });
        </script>
  </body>
</html>
// Code goes here

!function(t){try{t=angular.module("angularQuickDialog.template")}catch(o){t=angular.module("angularQuickDialog.template",[])}t.run(["$templateCache",function(t){t.put("template/quick-dialog.html",'<div class="quick-dialog" ng-show="dialog.isVisible"><span class="quick-dialog__close" ng-click="dialog.close()">x</span><div class="quick-dialog__content" ng-transclude></div></div>')}])}();var global=this;!function(t,o){"use strict";o.module("angularQuickDialog",["angularQuickDialog.template"]).factory("$quickDialog",function(){function t(t){this.isVisible=!1,this.name=t}function o(t){c[t].open()}function e(t){t=t||a.getTop().name,c[t].close()}function n(o){return c[o]=new t(o),c[o]}function i(){c={},a.clear()}var c={},a={stack:[],top:0,push:function(t){this.stack[this.top++]=t},pop:function(){return this.stack[--this.top]},getTop:function(){return this.stack[this.top-1]},clear:function(){this.top=0}};return t.prototype.open=function(){this.isVisible=!0,a.push(this)},t.prototype.close=function(){console.trace(),console.log("top before pop:",a.top),this.isVisible&&a.pop(),this.isVisible=!1,console.log("top after pop:",a.top)},global.d=function(){console.log("top dialog",a.getTop().name)},{open:o,close:e,create:n,reset:i}}).directive("quickDialog",["$timeout","$quickDialog",function(e,n){return{restrict:"EA",templateUrl:"template/quick-dialog.html",scope:{},transclude:!0,link:function(i,c,a){function l(){h=h||document.activeElement,g.append(d),d.bind("click",r),m.bind("keydown",s),e(function(){f.focus()})}function u(){m.unbind("keydown",s),d.unbind("click",r),d.remove(),e(function(){i.dialog.close()}),null!==h&&(h.focus(),h=k)}function s(t){t.keyCode===p&&(t.preventDefault(),u())}function r(t){t.stopPropagation(),u()}var d=o.element(document.createElement("div")).addClass("quick-dialog__backdrop"),p=27,g=o.element(document.body),m=o.element(t),f=document.getElementById(a.autoFocus)||c[0],h=document.getElementById(a.exitFocus),k=document.getElementById(a.exitFocus);try{i.dialog=n.create(a.dialogName)}catch(b){throw new Error("Dialog needs a name.")}var v=!0;i.$watch("dialog.isVisible",function(t){v||(t?l():u()),v=!1}),i.$on("$routeChangeStart",function(){n.reset()})}}}])}(window,window.angular);
/* Module styles */
.quick-dialog {
    overflow: hidden;
    min-height: 30%;
    width: 30%;

    position: fixed;
    left: 35%;
    top: 15%;

    background: white;
    border-radius: 5px;
    color: black;

    z-index: 90;
}

.quick-dialog__backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    background: black;
    opacity: .7;

    z-index: 80;
}

.quick-dialog__close {
    color: #888;
    cursor: pointer;
    font-family: sans-serif;
    position: absolute;
    top: 5px;
    right: 5px;
}
.quick-dialog__close:hover {   
    color: black;
}

@media only screen and (max-width: 767px) {
    .quick-dialog {
        left: 5%;
        width: 90%;
    }

}


/* Example styles */
* {
    box-sizing: border-box;
}

[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
    display: none !important;
}


.custom-form {
    margin-left:auto;
    margin-right:auto;
    overflow: hidden;

    max-width: 500px;
    background: #FFF;
    padding: 0 30px 20px 30px;
    font: 12px "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: #888;
    text-shadow: 1px 1px 1px #FFF;
    border:1px solid #DDD;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
}

.custom-form h1 {
    font: 25px "Helvetica Neue", Helvetica, Arial, sans-serif;
    padding: 10px 0;
    display: block;
    border-bottom: 1px solid #DADADA;
    text-align: center;
    color: #888;
}

.custom-form label {
    float: right;
    margin: 13px 0;
}

.custom-form input {
    border: 1px solid #CCC;
    color: #888;
    height: 20px;
    line-height:15px;
    margin: 10px 0;
    padding: 5px 0px 5px 5px;
    width: 80%;
    border-radius: 4px;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;    
    -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
    -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

.custom-form .button {
    background: #FFF;
    border: 1px solid #CCC;
    padding: 10px 25px 10px 25px;
    color: #333;
    border-radius: 4px;
}

.custom-form .button:hover {
    color: #333;
    background-color: #EBEBEB;
    border-color: #ADADAD;
}

.custom-form__labels {
    overflow: hidden;
    display: inline-block;
    float: left;
    padding-right: 10px;
    width: 25%;
}

.custom-form__inputs {
    overflow: hidden;
    display: inline-block;
    float: right;
    width: 75%;
}

.btn {
  -webkit-border-radius: 5;
  -moz-border-radius: 5;
  border-radius: 5px;
  cursor: pointer;
  font-family: Arial;
  color: #000;
  font-size: 14px;
  background: #fff;
  outline: 0;
  padding: 5px 10px;
  border: solid #000 1px;
  text-decoration: none;
}

.btn-primary { color: #505050; border: 1px solid #505050; }

.btn-secondary { color: #888; border: 1px solid #888; }

.btn:hover {
  border-color: #888;
  color: #888
  text-decoration: none;
}

.btn:active, .btn:focus { background: #fff; }

.open-btn-group { width: 150px; position: fixed; left: 50%; top: 33%; margin-left: -75px; }

.btn-group { margin-top: 10px; text-align: center; }

@media only screen and (max-width: 767px) {
    .custom-form__labels { width: 30%; }
    .custom-form__inputs { width: 70%; }
    .custom-form input { width: 100%; }
}