Skip to content

Commit

Permalink
Metal-modal: adds draggable functionality
Browse files Browse the repository at this point in the history
Metal-modal-deprecate#9: make modal draggable
  • Loading branch information
antoniorhee committed Aug 1, 2017
1 parent 4a9f479 commit acbae80
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
7 changes: 4 additions & 3 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ <h1>Modal</h1>
<button type="button" class="btn btn-primary openModal">Open Modal</button>
<script type="text/javascript">
window.modal = new metal.Modal({
element: '.modal',
header: '<h4 class="modal-title">Modal header</h4>',
body: 'One fine body...',
footer: '<button type="button" class="btn btn-primary">OK</button>'
disableDrag: false,
element: '.modal',
footer: '<button type="button" class="btn btn-primary">OK</button>',
header: '<h4 class="modal-title">Modal header</h4>'
});

document.querySelector('.openModal').addEventListener('click', function() {
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
"modal"
],
"dependencies": {
"metal": "^2.0.0",
"metal-component": "^2.0.0",
"metal-dom": "^2.0.0",
"metal-events": "^2.0.0",
"metal-soy": "^2.0.0"
"metal-component": "^1.0.0-rc.11",
"metal-drag-drop": "^2.0.1",
"metal-soy": "^1.0.0-rc.11"
},
"devDependencies": {
"bootstrap": "^3.3.6",
Expand Down
17 changes: 17 additions & 0 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import core from 'metal';
import dom from 'metal-dom';
import { Drag } from 'metal-drag-drop';
import { EventHandler } from 'metal-events';
import templates from './Modal.soy.js';
import Component from 'metal-component';
Expand All @@ -18,6 +19,13 @@ class Modal extends Component {
*/
created() {
this.eventHandler_ = new EventHandler();

this.drag_ = new Drag({
disabled: this.get('disableDrag'),
handles: '.modal-header',
sources: '.modal',
useShim: false
});
}

/**
Expand Down Expand Up @@ -219,6 +227,15 @@ Modal.STATE = {
validator: core.isString
},

/**
* Boolean to determine whether modal will be draggable.
* @type {Boolean}
*/
disableDrag: {
validator: core.isBoolean,
value: false
},

/**
* Content to be placed inside modal footer. Can be either an html string or
* a function that calls incremental-dom to render the footer.
Expand Down
8 changes: 4 additions & 4 deletions src/Modal.soy
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
class="modal{$elementClasses ? ' ' + $elementClasses : ''}"
style="display: {$visible ? 'block' : 'none'}">
<div
aria-describedby="{$bodyId}"
aria-labelledby="{$headerId}"
class="modal-dialog{$dialogClasses ? ' ' + $dialogClasses : ''}"
tabindex="0"
role="{$role ? $role : 'dialog'}"
aria-labelledby="{$headerId}"
aria-describedby="{$bodyId}">
tabindex="0">
<div class="modal-content">
<header class="modal-header">
{if $header}
{if not $noCloseButton}
<button type="button" class="close" data-onclick="hide" aria-label="Close">
<button aria-label="Close" class="close" data-onclick="hide" type="button">
<span aria-hidden="true">×</span>
</button>
{/if}
Expand Down

0 comments on commit acbae80

Please sign in to comment.