Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container" ng-app="ModalDialogSample">
  
  <div class="centered">
    
    <h1>simple modal dialogs</h1>
    
    <modal-dialog-trigger trigger-on="testone" class="btn btn-danger">modal-dialog-trigger</modal-dialog-trigger> 
    
    <span ng-controller="ModalDialogSampleController as mdsc">
      <a class="btn btn-info" ng-click="mdsc.open('testwo')">ng-click="expression"</a>
    </span>
    
    <modal-dialog-trigger trigger-on="login-form" class="btn btn-success">login form</modal-dialog-trigger>
    
  </div>
  
  <modal-dialog id="testone">
    <h1>testone</h1>
    <code>
    &lt;modal-dialog-trigger trigger-on=&quot;testone&quot; class=&quot;btn btn-danger&quot;&gt;modal-dialog-trigger&lt;/modal-dialog-trigger&gt; 
    </code>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias, quas minima nam. Architecto nobis at deleniti unde ea totam, provident magni enim velit. Quo accusantium laborum magnam, veniam veritatis sit.</p>
  </modal-dialog>
  
  <modal-dialog id="testwo">
    <h1>testtwo</h1>
    <code>
      &lt;span ng-controller=&quot;ModalDialogSampleController as mdsc&quot;&gt;
      &lt;a class=&quot;btn btn-info&quot; ng-click=&quot;mdsc.open(&#x27;testwo&#x27;)&quot;&gt;ng-click=&quot;expression&quot;&lt;/a&gt;
    &lt;/span&gt;
    </code>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae voluptas eos a. Repellendus sunt, velit vitae quibusdam possimus dignissimos. Harum possimus dolores nobis quisquam accusantium ducimus, odio asperiores nemo expedita!</p>
    <p>Blanditiis quaerat unde, minus tempore doloribus aut excepturi tempora labore dicta alias iusto error. Nesciunt et, error, blanditiis, inventore tenetur dolore mollitia sit vero ab laudantium, veritatis odio fugiat repellat!</p>
  </modal-dialog>
  
  <modal-dialog id="login-form">
    <!-- from bootstrap doc -->
    <form class="form-horizontal" role="form">
      <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
          <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
        </div>
      </div>
      <div class="form-group">
        <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
        <div class="col-sm-10">
          <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <div class="checkbox">
            <label>
              <input type="checkbox"> Remember me
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <button type="submit" class="btn btn-default">Sign in</button>
        </div>
      </div>
    </form>
  </modal-dialog>
</div>  

<!-- template --
<div class="dr-modal"> 
  <div class="modal-overlay"></div> 
  <div class="modal-dialog">
    <div class="modal-dialog-close"><i class="fa fa-times"></i></div>
    <div class="modal-dialog-content" ng-transclude></div>
  </div>
</div>
<!-- -->
              
            
!

CSS

              
                /***************
 * modal bones
 **************/
.dr-modal {
  .modal-overlay {
    position: absolute;
    z-index: 9999;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
  }
  .modal-dialog {
    box-sizing: border-box;
    z-index: 10000;
    .modal-dialog-close {
      display: inline-block;
      position: absolute;
      top: 0; right: 0;
      cursor: pointer;
    }
  }
}

modal-dialog {
  display: none;
}

/***************
 * modal themes
 * <modal-dialog theme='theme-class'></modal-dialog>
 **************/
.dr-modal-default-theme {
  .modal-overlay {
    background: #000;
    opacity: 0.7;
  }
  
  .modal-dialog {
    margin: 25px auto;
    background: white;
    padding: 25px;
    .modal-dialog-close {
      padding: 10px 15px;
      &:hover {
        color: #E9573F;
      }
    }
  }
}

/**
 * from http://www.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
 */
%abs-centered {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  margin: auto;
}

/**
 * sample styles
 */
html, body {
  width: 100%;
  height: 100%;
}

.container {
  position: relative;
  width: 100%;
  height: 100%;
}

.centered {
  @extend %abs-centered;
  display: block;
  width: 800px;  
  height: 155px;
  text-align: center;
}


              
            
!

JS

              
                // animations will be added soon
var modal = angular.module('dx.ModalDialog', []);

// I think that each dialog should have its own controller
function ModalDialogController($scope, ModalDialog) {

  this.id = $scope.id;

  this.close = function() {
    $scope.shown = false;
    $scope.$apply();
  }

  this.open = function() {
    $scope.shown = true;
    $scope.$apply();
  }

  this.toggle = function() {
    $scope.shown = !$scope.shown;
    $scope.$apply();
  }

  this.init = function(controller) {
    ModalDialog.add(controller);
  }

}

modal.controller('ModalDialogController', ModalDialogController);

// so here's a singleton service to store those dialog controllers
// and it exposes APIs to the application to control the modal dialogs
function ModalDialogService() {
  var dialogControllers = [],
    service = {};

  service.add = function(dialogController) {
    // TODO duplicated ids
    dialogControllers.push({
      id: dialogController.id,
      controller: dialogController
    });
  }

  service.open = function(dialogId) {
    handleTargetDialog(dialogId, 'open');
  }

  service.close = function(dialogId) {
    handleTargetDialog(dialogId, 'close');
  }

  service.toggle = function(dialogId) {
    handleTargetDialog(dialogId, 'toggle');
  }

  function handleTargetDialog(targetId, action) {
/*    var found = false;
    // TODO any good solutions for this iteration ?
    for (var i = 0; i < dialogControllers.length; i++) {
      if (dialogControllers[i].id !== targetId) continue;
      found = true;
      dialogControllers[i].controller[action]();
      break;
    }*/
    
    var targetDialogController = dialogControllers.filter(function(dialogCtrl) {
      return dialogCtrl.id === targetId;
    }).pop();
    
    if (!targetDialogController) console.error('dialog error : ' + dialogId + ' not found !');
    
    targetDialogController.controller[action]();
  }

  return service;
}

modal.service('ModalDialog', ModalDialogService);

// here is the directive
// create a controller and inject ModalDialog into it
// then use the ModalDialog APIs to control the modal dialogs.
function modalDialog() {
  return {
    restrict: 'E',
    replace: true,
    transclude: true,
    scope: {
      id: '@'
    },
    link: function(scope, elem, attrs, ctrl) {
      elem.addClass(attrs.theme || 'dr-modal-default-theme');
      ctrl.init(ctrl);
    },
    controller: 'ModalDialogController',
    controllerAs: 'mdctrl',
    template: '<div class="dr-modal" ng-show="shown"> \
                <div class="modal-overlay" ng-click="mdctrl.close()"></div> \
                <div class="modal-dialog">\
                  <div class="modal-dialog-close" ng-click="mdctrl.close()"><i class="fa fa-times"></i></div>\
                  <div class="modal-dialog-content" ng-transclude></div>\
                </div>\
              </div>'
  };
}

modal.directive('modalDialog', modalDialog);

// another way to use this directive
// simply write : 
// <modal-dialog-trigger trigger-on='target-id'>...</modal-dialog-trigger>
// or
// <a modal-dialog-trigger trigger-on='target-id'>...</a>
function modalDialogTrigger(ModalDialog) {
  return {
    restrict: 'EA',
    link: function(scope, elem, attrs) {
      elem.bind('click', function() {
        ModalDialog.toggle(attrs.triggerOn);
      });
    }
  }
}

modal.directive('modalDialogTrigger', modalDialogTrigger);

/*****************************
 * a sample controller
 *****************************/
var sample = angular.module('ModalDialogSample', ['dx.ModalDialog']);

function ModalDialogSampleController($scope, ModalDialog) {
  this.open = function(id) {
    ModalDialog.open(id);
  }
}

sample.controller('ModalDialogSampleController', ModalDialogSampleController);
              
            
!
999px

Console