Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD mantain-position option #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ The directive itself is called *modal-dialog*. The only required attribute is `s

There are a few options that be configured inline with attributes.

| Option | Default | Description |
| -------------- | ------- | ----------------------------------------------------------------- |
| dialog-title | null | Title placed in the header of the modal dialog. |
| width | 50% | Width of the dialog. Can be specified in px or %. |
| height | 50% | Height of the dialog. Can be specified in px or %. |
| on-close | null | Call a function when the dialog is closed. Ex: `on-close='foo()'` |
| Option | Default | Description |
| ---------------- | ------- | ----------------------------------------------------------------- |
| dialog-title | null | Title placed in the header of the modal dialog. |
| width | 50% | Width of the dialog. Can be specified in px or %. |
| height | 50% | Height of the dialog. Can be specified in px or %. |
| on-close | null | Call a function when the dialog is closed. Ex: `on-close='foo()'` |
| mantain-position | false | It keeps dialog current position |

**Example:**

```html
<modal-dialog show='dialogShown' dialog-title='My Dialog' height='400px' width='75%'>
<modal-dialog show='dialogShown' dialog-title='My Dialog' height='400px' width='75%' mantain-position='true'>
<p>Dialog content goes in here</p>
</modal-dialog>
```
Expand Down
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>
<body>
<div ng-controller='DemoController'>
<modal-dialog show='myData.modalShown' width='500px' dialog-title='Modal Dialog Title' on-close='logClose()'>
<modal-dialog show='myData.modalShown' width='500px' dialog-title='Modal Dialog Title' mantain-position='true' on-close='logClose()'>
<p>This is some html content</p>
<p>
<label for='hello'>Hello:</label>
Expand Down
13 changes: 8 additions & 5 deletions dist/ng-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
scope: {
show: '=',
dialogTitle: '@',
onClose: '&?'
onClose: '&?',
mantainPosition: '='
},
replace: true,
transclude: true,
Expand All @@ -56,10 +57,12 @@
return scope.show = false;
};
scope.$watch('show', function(newVal, oldVal) {
if (newVal && !oldVal) {
document.getElementsByTagName("body")[0].style.overflow = "hidden";
} else {
document.getElementsByTagName("body")[0].style.overflow = "";
if (!scope.mantainPosition || scope.mantainPosition === '') {
if (newVal && !oldVal) {
document.getElementsByTagName("body")[0].style.overflow = "hidden";
} else {
document.getElementsByTagName("body")[0].style.overflow = "";
}
}
if ((!newVal && oldVal) && (scope.onClose != null)) {
return scope.onClose();
Expand Down
2 changes: 1 addition & 1 deletion dist/ng-modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngModal",
"version": "1.2.2"
"version": "1.2.2",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-coffee": "~0.7",
Expand Down
10 changes: 6 additions & 4 deletions src/ng-modal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ app.directive 'modalDialog', ['ngModalDefaults', '$sce', (ngModalDefaults, $sce)
show: '='
dialogTitle: '@'
onClose: '&?'
mantainPosition: '='
replace: true
transclude: true
link: (scope, element, attrs) ->
Expand All @@ -45,10 +46,11 @@ app.directive 'modalDialog', ['ngModalDefaults', '$sce', (ngModalDefaults, $sce)
scope.show = false

scope.$watch('show', (newVal, oldVal) ->
if newVal && !oldVal
document.getElementsByTagName("body")[0].style.overflow = "hidden";
else
document.getElementsByTagName("body")[0].style.overflow = "";
if !scope.mantainPosition || scope.mantainPosition == ''
if newVal && !oldVal
document.getElementsByTagName("body")[0].style.overflow = "hidden";
else
document.getElementsByTagName("body")[0].style.overflow = "";
if (!newVal && oldVal) && scope.onClose?
scope.onClose()
)
Expand Down