cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div ng-app="app" ng-controller="Controller as ctrl">
  <script type="text/ng-template" id="modal.html">
    <div draggable=".modal-header">
      <div class="modal-header">
        <h3 class="modal-title">I'm a draggable modal!</h3>
      </div>
      <div class="modal-body">
        <p>This is my body</p>
      </div>
      <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="modal.ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="modal.cancel()">Cancel</button>
      </div>
    </div>
  </script>
  <div class="well text-center">
    <button class="btn btn-default" ng-click="ctrl.openModal()">Open modal</button>
  </div>
</div>
            
          
!
            
              const app = angular.module('app', ['ui.bootstrap']);
/**
 * Controller

 */
class Controller {
  constructor(private $uibModal: ng.ui.bootstrap.IModalService) {
    this.openModal();
  }

  openModal(): void {
    this.$uibModal.open({
      backdrop: false,
      controller: ModalController,
      controllerAs: 'modal',
      templateUrl: 'modal.html'
    });
  }
}

app.controller('Controller', Controller);

/**
 * Modal controller
 */
class ModalController {
  constructor(private $uibModalInstance: ng.ui.bootstrap.IModalServiceInstance) { }

  ok(): void {
    this.$uibModalInstance.close();
  }

  cancel(): void {
    this.$uibModalInstance.dismiss();
  }
}

/**
 * Draggable directive
 */
interface IDraggableScope extends ng.IScope {
  draggable?: string;
}

interface IPosition {
  x: number;
  y: number;
}

class DraggableDirective {
  private cursorPosition: IPosition;
  private offsetPosition: IPosition;

  private mouseMoveEventListener: JQuery;
  private mouseUpEventListener: JQuery;

  private element: JQuery;
  private handle: JQuery;

  constructor(
    $element: ng.IAugmentedJQuery,
    $scope: IDraggableScope,
    private $document: ng.IDocumentService
  ) {
    this.setCursorPosition(0, 0);
    this.setOffsetPosition(0, 0);

    this.element = $element.parent('.modal-content');

    this.element.css({
      position: 'relative'
    });

    if ($scope.draggable) {
      this.handle = angular.element($scope.draggable);
    } else {
      this.handle = this.element;
    }

    this.handle.on('mousedown', (event: JQueryEventObject) => this.beginDrag(event));
    this.handle.css({
      cursor: 'move'
    });
  }

  private beginDrag(event: JQueryEventObject): void {
    event.preventDefault();

    const x: number = event.pageX - this.offsetPosition.x;
    const y: number = event.pageY - this.offsetPosition.y;
    this.setCursorPosition(x, y);

    this.mouseMoveEventListener = this.$document.on('mousemove', (e: JQueryEventObject) => this.drag(e));
    this.mouseUpEventListener = this.$document.on('mouseup', (e: JQueryEventObject) => this.endDrag());
  }

  private drag(event: JQueryEventObject): void {
    const x: number = event.pageX - this.cursorPosition.x;
    const y: number = event.pageY - this.cursorPosition.y;

    this.setOffsetPosition(x, y);

    this.element.css({
      left: `${x}px`,
      top: `${y}px`
    });
  }

  private endDrag(): void {
    this.mouseMoveEventListener.off();
    this.mouseUpEventListener.off();
  }

  private setCursorPosition(x: number, y: number): void {
    this.cursorPosition = {
      x: x,
      y: y
    };
  }

  private setOffsetPosition(x: number, y: number): void {
    this.offsetPosition = {
      x: x,
      y: y
    };
  }
}

app
  .directive('draggable', () => {
    return {
      controller: DraggableDirective,
      restrict: 'A',
      scope: {
        'draggable': '@'
      }
    };
  });


            
          
!
999px
Loading ..................

Console