Giter VIP home page Giter VIP logo

ngdialog's Introduction

ngDialog

build status npm version github tag Download Count Code Climate

Modal dialogs and popups provider for AngularJS applications.

ngDialog is ~10KB (minified), has minimalistic API, is highly customizable through themes and has only AngularJS as dependency.

Install

You can download all necessary ngDialog files manually, or install it with bower:

bower install ng-dialog

or npm:

npm install ng-dialog

Usage

You need only to include ngDialog.js, ngDialog.css and ngDialog-theme-default.css (as minimal setup) to your project and then you can start using the ngDialog provider in your directives, controllers and services. For example:

<link rel="stylesheet" href="lib/ng-dialog/css/ngDialog.min.css">
<link rel="stylesheet" href="lib/ng-dialog/css/ngDialog-theme-default.min.css">
<script src="lib/ng-dialog/js/ngDialog.min.js"></script>

Define the className to be the ngDialog-theme-default.

For example in controllers:

var app = angular.module('exampleApp', ['ngDialog']);

app.controller('MainCtrl', function ($scope, ngDialog) {
    $scope.clickToOpen = function () {
        ngDialog.open({ template: 'popupTmpl.html', className: 'ngdialog-theme-default' });
    };
});

Collaboration

Your help is appreciated! If you've found a bug or if something is not clear, please raise an issue.

Ideally, if you've found an issue, you will submit a PR that meets our contributor guidelines.

Running Tests

git clone [email protected]:likeastore/ngDialog.git
cd ngDialog
npm i
npm run test

API

ngDialog service provides easy to use and minimalistic API, but in the same time it's powerful enough. Here is the list of accessible methods that you can use:

===

.open(options)

Method allows to open dialog window, creates new dialog instance on each call. It accepts options object as the only argument.

Options:

template {String}

Dialog template can be loaded through path to external html template or <script> tag with text/ng-template:

<script type="text/ng-template" id="templateId">
    <h1>Template heading</h1>
    <p>Content goes here</p>
</script>
ngDialog.open({ template: 'templateId' });

Also it is possible to use a simple string as template together with plain option.

Pro Tip about templates

It's not always necessary to place your external html template inside <script> tag. You could put these templates into $templateCache like this:

angular.module('dialog.templates').run(['$templateCache', function($templateCache) {
    $templateCache.put('templateId', 'template content');
}]);

Then it would be possible to include the dialog.templates module into the dependencies of your main module and start using this template as templateId.

There is no need to do these actions manually. You could use one of the plugins specifically for these purposes. They are available for different build systems including most popular Gulp / Grunt:

You could find more detailed examples on each of these pages.

plain {Boolean}

If true allows to use plain string as template, default false:

ngDialog.open({
    template: '<p>my template</p>',
    plain: true
});
controller {String} | {Array} | {Object}

Controller that will be used for the dialog window if necessary. The controller can be specified either by referring it by name or directly inline.

ngDialog.open({
    template: 'externalTemplate.html',
    controller: 'SomeController'
});

or

ngDialog.open({
    template: 'externalTemplate.html',
    controller: ['$scope', 'otherService', function($scope, otherService) {
        // controller logic
    }]
});
controllerAs {String}

You could optionally specify controllerAs parameter for your controller. Then inside your template it will be possible to refer this controller by the value specified by controllerAs.

Usage of controllerAs syntax is currently recommended by the AngularJS team.

resolve {Object.<String, Function>}

An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, ngDialog will wait for them all to be resolved or one to be rejected before the controller is instantiated.

If all the promises are resolved successfully, the values of the resolved promises are injected.

The map object is:

  • key{String}: a name of a dependency to be injected into the controller.
  • factory - {String | Function}: If String then it is an alias for a service. Otherwise if Function, then it is injected using $injector.invoke and the return value is treated as the dependency. If the result is a promise, it is resolved before its value is injected into the controller.
ngDialog.open({
    controller: function Ctrl(dep) {/*...*/},
    resolve: {
        dep: function depFactory() {
            return 'dep value';
        }
    }
});
scope {Object}

Scope object that will be passed to the dialog. If you use a controller with separate $scope service this object will be passed to the $scope.$parent param:

$scope.value = true;

ngDialog.open({
    template: 'externalTemplate.html',
    className: 'ngdialog-theme-plain',
    scope: $scope
});
<script type="text/ng-template" id="externalTemplate.html">
<p>External scope: <code>{{value}}</code></p>
</script>
scope.closeThisDialog(value)

In addition .closeThisDialog(value) method gets injected to passed $scope. This allows you to close the dialog straight from the handler in a popup element, for example:

<div class="dialog-contents">
    <input type="text"/>
    <input type="button" value="OK" ng-click="checkInput() && closeThisDialog('Some value')"/>
</div>

Any value passed to this function will be attached to the object which resolves on the close promise for this dialog. For dialogs opened with the openConfirm() method the value is used as the reject reason.

data {String | Object | Array}

Any serializable data that you want to be stored in the controller's dialog scope. ($scope.ngDialogData). From version 0.3.6 $scope.ngDialogData keeps references to the objects instead of copying them.

Additionally, you will have the dialog id available as $scope.ngDialogId. If you are using $scope.ngDialogData, it'll be also available under $scope.ngDialogData.ngDialogId.

className {String}

This option allows you to control the dialog's look, you can use built-in themes or create your own styled modals.

This example enables one of the built-in ngDialog themes - ngdialog-theme-default (do not forget to include necessary css files):

ngDialog.open({
    template: 'templateId',
    className: 'ngdialog-theme-default'
});

Note: If the className is not mentioned, the dialog will not display correctly.

Check themes block to learn more.

appendClassName {String}

Unlike the className property, which overrides any default classes specified through the setDefaults() method (see docs), appendClassName allows for the addition of a class on top of any defaults.

For example, the following would add both the ngdialog-theme-default and ngdialog-custom classes to the dialog opened:

ngDialogProvider.setDefaults({
    className: 'ngdialog-theme-default'
});
ngDialog.open({
    template: 'template.html',
    appendClassName: 'ngdialog-custom'
});
disableAnimation {Boolean}

If true then animation for the dialog will be disabled, default false.

overlay {Boolean}

If false it allows to hide the overlay div behind the modals, default true.

showClose {Boolean}

If false it allows to hide the close button on modals, default true.

closeByEscape {Boolean}

It allows to close modals by clicking the Esc key, default true.

This will close all open modals if there are several of them opened at the same time.

closeByNavigation {Boolean}

It allows to close modals on state change (history.back, $state.go, etc.), default false. Compatible with ui-router and angular-router. Set this value to true if you want your modal to close when you go back or change state. Set this value to false if you want your modal to stay open when you change state within your app.

This will close all open modals if there are several of them opened at the same time.

closeByDocument {Boolean}

It allows to close modals by clicking on overlay background, default true. If Hammer.js is loaded, it will listen for tap instead of click.

appendTo {String}

Specify your element where to append dialog instance, accepts selector string (e.g. #yourId, .yourClass). If not specified appends dialog to body as default behavior.

cache {Boolean}

Pass false to disable template caching. Useful for developing purposes, default is true.

name {String} | {Number}

Give a name for a dialog instance. It is useful for identifying specific dialog if there are multiple dialog boxes opened.

onOpenCallback {String} | {Function}

Provide either the name of a function or a function to be called after the dialog is opened. This callback can be used instead of the ngdialog.opened event. It provides with a way to register a hook for when the dialog is appended to the DOM and about to be shown to the user.

preCloseCallback {String} | {Function}

Provide either the name of a function or a function to be called before the dialog is closed. If the callback function specified in the option returns false then the dialog will not be closed. Alternatively, if the callback function returns a promise that gets resolved the dialog will be closed.

The preCloseCallback function receives as a parameter value which is the same value sent to .close(id, value).

The primary use case for this feature is a dialog which contains user actions (e.g. editing data) for which you want the ability to confirm whether to discard unsaved changes upon exiting the dialog (e.g. via the escape key).

This example uses an inline function with a window.confirm call in the preCloseCallback function:

ngDialog.open({
    preCloseCallback: function(value) {
        if (confirm('Are you sure you want to close without saving your changes?')) {
            return true;
        }
        return false;
    }
});

In another example, a callback function with a nested confirm ngDialog is used:

ngDialog.open({
    preCloseCallback: function(value) {
        var nestedConfirmDialog = ngDialog.openConfirm({
            template:'\
                <p>Are you sure you want to close the parent dialog?</p>\
                <div class="ngdialog-buttons">\
                    <button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog(0)">No</button>\
                    <button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="confirm(1)">Yes</button>\
                </div>',
            plain: true
        });

        // NOTE: return the promise from openConfirm
        return nestedConfirmDialog;
    }
});
trapFocus {Boolean}

When true, ensures that the focused element remains within the dialog to conform to accessibility recommendations. Default value is true

preserveFocus {Boolean}

When true, closing the dialog restores focus to the element that launched it. Designed to improve keyboard accessibility. Default value is true

ariaAuto {Boolean}

When true, automatically selects appropriate values for any unspecified accessibility attributes. Default value is true

See Accessibility for more information.

ariaRole {String}

Specifies the value for the role attribute that should be applied to the dialog element. Default value is null (unspecified)

See Accessibility for more information.

ariaLabelledById {String}

Specifies the value for the aria-labelledby attribute that should be applied to the dialog element. Default value is null (unspecified)

If specified, the value is not validated against the DOM. See Accessibility for more information.

ariaLabelledBySelector {String}

Specifies the CSS selector for the element to be referenced by the aria-labelledby attribute on the dialog element. Default value is null (unspecified)

If specified, the first matching element is used. See Accessibility for more information.

ariaDescribedById {String}

Specifies the value for the aria-describedby attribute that should be applied to the dialog element. Default value is null (unspecified)

If specified, the value is not validated against the DOM. See Accessibility for more information.

ariaDescribedBySelector {String}

Specifies the CSS selector for the element to be referenced by the aria-describedby attribute on the dialog element. Default value is null (unspecified)

If specified, the first matching element is used. See Accessibility for more information.

width {Number | String}

This option allows you to control the dialog's width. Default value is null (unspecified)

If you provide a Number, 'px' will be appended. To use a custom metric, use a String, e.g. '40%'.

For example, the following will add width: 400px; to the dialog when opened:

ngDialog.open({
    template: 'template.html',
    width: 400
});

In another example, the following will add width: 40%;:

ngDialog.open({
    template: 'template.html',
    width: '40%'
});
height {Number | String}

This option allows you to control the dialog's height. Default value is null (unspecified)

If you provide a Number, 'px' will be appended. To use a custom metric, use a String, e.g. '40%'.

For example, the following will add height: 400px; to the dialog when opened:

ngDialog.open({
    template: 'template.html',
    height: 400
});

In another example, the following will add height: 40%;:

ngDialog.open({
    template: 'template.html',
    height: '40%'
});

Returns:

The open() method returns an object with some useful properties.

id {String}

This is the ID of the dialog which was just created. It is the ID on the dialog's DOM element.

close(value) {Function}

This is a function which will close the dialog which was opened by the current call to open(). It takes an optional value to pass to the close promise.

closePromise {Promise}

A promise which will resolve when the dialog is closed. It is resolved with an object containing: id - the ID of the closed dialog, value - the value the dialog was closed with, $dialog - the dialog element which at this point has been removed from the DOM and remainingDialogs - the number of dialogs still open.

The value property will be a special string if the dialog is dismissed by one of the built in mechanisms: '$escape', '$closeButton' or '$document'.

This allows you do to something like this:

var dialog = ngDialog.open({
    template: 'templateId'
});

dialog.closePromise.then(function (data) {
    console.log(data.id + ' has been dismissed.');
});

===

.setDefaults(options)

You're able to set default settings through ngDialogProvider:

var app = angular.module('myApp', ['ngDialog']);
app.config(['ngDialogProvider', function (ngDialogProvider) {
    ngDialogProvider.setDefaults({
        className: 'ngdialog-theme-default',
        plain: true,
        showClose: true,
        closeByDocument: true,
        closeByEscape: true
    });
}]);

===

.openConfirm(options)

Opens a dialog that by default does not close when hitting escape or clicking outside the dialog window. The function returns a promise that is either resolved or rejected depending on the way the dialog was closed.

Options:

The options are the same as the regular .open() method with an extra function added to the scope:

scope.confirm()

In addition to the .closeThisDialog() method. The method .confirm() is also injected to passed $scope. Use this method to close the dialog and resolve the promise that was returned when opening the modal.

The function accepts a single optional parameter which is used as the value of the resolved promise.

<div class="dialog-contents">
    Some message
    <button ng-click="closeThisDialog()">Cancel</button>
    <button ng-click="confirm()">Confirm</button>
</div>

Returns:

An Angular promise object that is resolved if the .confirm() function is used to close the dialog, otherwise the promise is rejected. The resolve value and the reject reason is defined by the value passed to the confirm() or closeThisDialog() call respectively.

===

.isOpen(id)

Method accepts dialog's id and returns a Boolean value indicating whether the specified dialog is open.

===

.close(id, value)

Method accepts dialog's id as string argument to close specific dialog window, if id is not specified it will close all currently active modals (same behavior as .closeAll()). Takes an optional value to resolve the dialog promise with (or all dialog promises).

===

.closeAll(value)

Method manages closing all active modals on the page. Takes an optional value to resolve all of the dialog promises with.

===

.getOpenDialogs()

Method that returns array which includes the ids of opened dialogs.

===

.setForceHtmlReload({Boolean})

Adds an additional listener on every $locationChangeSuccess event and gets update version of html into dialog. May be useful in some rare cases when you're dependant on DOM changes, defaults to false. Use it in module's config as provider instance:

var app = angular.module('exampleApp', ['ngDialog']);

app.config(function (ngDialogProvider) {
    ngDialogProvider.setForceHtmlReload(true);
});

===

.setForceBodyReload({Boolean})

Adds additional listener on every $locationChangeSuccess event and gets updated version of body into dialog. Maybe useful in some rare cases when you're dependant on DOM changes, defaults to false. Use it in module's config as provider instance:

var app = angular.module('exampleApp', ['ngDialog']);

app.config(function (ngDialogProvider) {
    ngDialogProvider.setForceBodyReload(true);
});

===

.setOpenOnePerName({Boolean})

Default value: false

Define whether or not opening a dialog with the same name more than once simultaneously is allowed. Assigning true prevents opening a second dialog.

Setting it in the ngDialogProvider:

var app = angular.module('exampleApp', ['ngDialog']);

app.config(function (ngDialogProvider) {
    ngDialogProvider.setOpenOnePerName(true);
});

Make sure to remember to add a 'name' when opening a dialog. ngDialog 'open' and 'openConfirm' functions will return undefined if the dialog was not opened.

Directive

By default the ngDialog module is served with the ngDialog directive which can be used as attribute for buttons, links, etc. Almost all .open() options are available through tag attributes as well, the only difference is that ng-template id or path of template file is required.

Some imaginary button, for example, will look like:

<button type="button"
    ng-dialog="templateId.html"
    ng-dialog-class="ngdialog-theme-flat"
    ng-dialog-controller="ModalCtrl"
    ng-dialog-close-previous>
    Open modal text
</button>

You could optionally use ng-dialog-bind-to-controller to bind scope you've defined via parameter of directive to controller. More information about bindToController is available here.

Directive contains one more additional but very useful option, it's an attribute named ng-dialog-close-previous. It allows you to close previously opened dialogs automatically.

Events

Everytime ngDialog is opened or closed we're broadcasting three events (dispatching events downwards to all child scopes):

  • ngDialog.opened

  • ngDialog.closing

  • ngDialog.closed

This allows you to register your own listeners, example:

$rootScope.$on('ngDialog.opened', function (e, $dialog) {
    console.log('ngDialog opened: ' + $dialog.attr('id'));
});

ngDialog.closing is different than ngDialog.closed in that it is fired immediately when the dialog begins closing, whereas ngDialog.closed is fired after all animations are complete. Both will be fired even when animation end support is not detected.

Additionally we trigger following 2 events related to loading of template for dialog:

  • ngDialog.templateLoading

  • ngDialog.templateLoaded

In case you are loading your templates from an external location, you could use above events to show some kind of loader.

Finally, we trigger the following event when adding padding to or removing padding from the body tag to compensate for scrollbar toggling:

  • ngDialog.setPadding

The ngDialog.setPadding event will communicate the pixel value being added to the body tag so you can add it to any other elements in your layout at the same time (often fixed-position elements will need this).

Themes

Currently ngDialog contains two default themes that show how easily you can create your own. Check example folder for demonstration purposes.

Accessibility

ngDialog supports accessible keyboard navigation via the trapFocus and preserveFocus options.

The role, aria-labelledby and aria-describedby attributes are also supported, and are rendered as follows.

Dialog role attribute:

  • options.ariaRole, if specified
  • "dialog" if options.ariaAuto is true and the dialog contains any focusable elements
  • "alertdialog" is options.ariaAuto is true and the dialog does not contain any focusable elements

Dialog aria-labelledby attribute:

  • options.ariaLabelledById, if specified
  • If options.ariaLabelledBySelector is specified, the first matching element will be found and assigned an id (if required) and that id will be used
  • If options.ariaAuto is true, the first heading element in the dialog (h1-6) will be found and processed as per ariaLabelledBySelector

Dialog aria-describedby attribute:

  • options.ariaDescribedById, if specified
  • If options.ariaDescribedBySelector is specified, the first matching element will be found and assigned an id (if required) and that id will be used
  • If options.ariaAuto is true, the first content element in the dialog (article,section,p) will be found and processed as per ariaDescribedBySelector

Dialog Content role attribute:

  • Always assigned a value of "document"

CDN

ngDialog is available for public on cdnjs. For example, please use following urls for version 0.4.0.

//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog.min.css
//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog-theme-default.min.css
//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/css/ngDialog-theme-plain.min.css
//cdnjs.cloudflare.com/ajax/libs/ng-dialog/0.4.0/js/ngDialog.min.js

References

ngDialog default styles are heavily inspired by awesome Hubspot/Vex jQuery modals.

License

MIT Licensed

Copyright (c) 2013-2015, Likeastore.com [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge

ngdialog's People

Contributors

agungsb avatar altmind avatar aseemflowingly avatar ashubham avatar bchelli avatar bgse avatar camaross avatar colinbate avatar cstickel avatar davidvuong avatar dpicode avatar egor-smirnov avatar faceleg avatar jdelibas avatar jperals avatar julianlaval avatar korzhuka avatar masimplo avatar oleksii-kachura avatar petercrona1989 avatar platdesign avatar programbo avatar radarhere avatar richardszalay avatar robbaman avatar saifmd4u avatar sjke avatar skeymeulen avatar thewrongalice avatar voronianski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ngdialog's Issues

No dialog is opened, content appears at the bottom of my page

I try a very simple example, and when I click the link that is supposed to launch my dialog, no dialog is opened and instead I get the template content at the bottom of my page.

markup:

<button ng-click="openFeedbackDialog()">Your Feedback</button>

script (in controller):

    $scope.openFeedbackDialog = function(){
            ngDialog.open({ template: 'firstDialogId' });
    };

template:

<script type="text/ng-template" id="firstDialogId">
   <h1>Template heading</h1>
    <p>Content goes here</p>
</script>

Directive should have an option to close other dialogs before opening a new one

I prefer using the directive version rather than the api, since I keep the template paths inside the actual template files and not inside the controllers. Problem is that when I want to follow a chain of dialogs say: login->reset password->success, I have to use the api version to close the previous dialog first (maybe calling close all or even better having the option to pass an id which call close and if empty calls closeAll.

Example on using data field

Sorry if this one looks like a newbie suggestion. I am a newbie to AngularJS.
Your lib is great, but it is not clear how to work with data field.

IMO you should add to README.md that variable is accessible via ngDialogData. Or have an example in examples/

Non-modal and draggable dialogs

Correct me if these features are already possible, but I need some of my dialogs to be draggable, and non-modal.

Draggable functionality doesn't need to be built into the library, but the issue I'm having is that the top element in my template is draggable, but this element is nested within the created ngdialog-content element, meaning that whilst my template is draggable, it doesn't take the dialog with it. Perhaps if there were an option to replace the element rather than nest the template within it (like Angular directives can), this would be a non-issue?

Would also be nice to have an option for dialogs to be non-modal - i.e. no click-blocker and no blackout effect.

Great library otherwise, very simple and effective!

Thoughts?

Background tabbing still works while dialog is up

Maybe I'm missing something, but if I open a dialog, I can still tab around in the background and interact with other elements; it so happens I have a view where there are multiple items, and each one of them can summon a dialog.

The real issue comes along when I tab around in the background and open up other dialogs - they start stacking up and the screen dimmer obviously gets darker and darker. I can work around this, but it'd be ideal if we could disable tabbing once a dialog crops up, or takes priority, so as to stack dialogs on top of each other and still only be able to interact with the topmost.

Any ideas?

animationEndEvent don't fire

Closing of dialogs doesn't work, because of animationEndEvent failure.
I'm using angular 1.3.0-18, and ngDialog 0.3.0.
I've set var animationEndSupport = false temporarily to fix this.

Multiple clicks => multiple opens

I have an app with a lot of ngDialog, when I click multiple times fastly on button, ngDialog opens multiple times too.

I've try preventDefault on 'ngDialog.opened' event, but that's don't work...

Have you a general solution or It's required too make it with hand and some booleans on each dialog ?

Thanks in advance !

Bootstrap?

Will this work with Bootstrap 3 modals/dialogs?

ngDialog is taking time to show ng-bind values when open

We are using ngDialog on a page with +1000 table rows. When we open ngDialog on ng-click, it takes near about 1 sec. to populate and show ng-bind values from passed scope object. The dialog has a hello/wecome message with dynamic user name value ($scope.username) but it shows this message like 'hello , welcome to our website' and after 1 sec, message changes to 'hello testuser, wecome to our website'. Is there any way to wait dialog till the template compiled completely.

How to obtain the modal ID?

We want to use a custom close button that besides closing the dialog, also triggers some other functions:

<a ng-click="closeDialog()" >Close</a>

$rootScope.closeDialog = function () {
    // Do some stuff here
    ngDialog.close(dialogID);
}

How do we get the dialogID?

Thanks!

templateCache trouble

Hi there,

in my scenario I have a login form open both as a dialog and as a full page as well. Both are using the same html template file. During some playing around I noticed that if I opened the dialog after I had visited the full page version, the dialog was not displayed (although background was filled). With some debugging I found out that although you are requesting the template from $templateCache service, you never actually put it there. After getting the template from $http I think you should store it, otherwise don't use $templateCache service at all since you are using the cached $http

Pass object using data property

I don't understand why data option is restricted to be a String? Why can't I pass arbitrary object?
My use-case:
I have list of items, each one with edit button. Modal window opens on button click and I want to pass item to this modal window.
I don't want to create additional controller for each item and I don't want to mess with JSON.stringify/JSON.parse.
Thank you.

Maybe this directive should provide a 'width' options?

When i want to create different size dialog,i have to change the source code or do something other .

In your code ,you give the 'width' to 'ngdialog' in stylesheet 'ngDialog-theme-default.css'

I change the source code

var dialogWidth;
dialogWidth = options.width + "px" || "438px";
$dialog.html('<div class="ngdialog-overlay"></div><div class="ngdialog-content" style="width:'+dialogWidth+'">' + template + '</div>');

then i can use 'width' options to resolve this problem

how do you use the data option?

I am trying to use the data option to pass some values to the modal template, but I'm not having any luck. Could you please advise the correct way to do this?

ngDialog.open({
                template: '/views/modals/template.html',
                scope: $scope,
                data : {"foo": "bar"}
            });

/views/modals/template.html:

<p>{{ngDialogData.foo}}</p>

results in:

<p class="ng-binding"></p>

Defaults don't work for directive

Defaults set with ngDialogProvider are overwritten when I use ng-dialog directive.
This is because directive's link method does not check whether or not an attribute exists.

P.S.
thanks for this awesome plugin!

Scrollable on entire page

Hi there,

do you see a good way to allow for vertical scrolling outside of the dialog-content itself, i.e. on the overlay?

My Problem is that I've got a dialog which needs to be scrolled and it is kind of confusing that this is only possible if the cursor is over the dialog. I tried to work around this problem by giving the content 100% width and making its background transparent. However, this has a negative effect on the closeByDocument behavior (as it doesn't really work any more 😏). I want both, full page scrolling and clicking outside the dialog to close.

Do you get the picture?

Thanks in advance

Get wrong $body

Issue,
Can't open ngDialog after location.path redirect to other page.

Issue analysis:
In ngDialog.js version 0.2.0.
Line 30 var $body = $document.find('body');

$body is a static variable and remain the same in open function, It is not right in some situations.

Solution:
Replace var $body = $document.find('body');
by var getBody = function () {
return $document.find('body');
}
make sure $body is up to date in each time usage.

Broadcasting?

It may be a helpful to add broadcasting to some events. For my current project I added this line at the bottom of the closeDialog function.

$rootScope.$broadcast('ngDialog.closed', $dialog);

Using KineticJS together with ngDialog

I want to use a KineticJS stage inside of the HTML Template.
It doesnt work because Kinetic is not able to find the id used in the stage ctor.
Any idea how to do this?
Thanks in advance

External templates

When opening a dialog with an external template (ex "assets/templates/template.html") it renders [object Object]. The fetched template is returned as an object with the regular { data: ..., config: ..., status: ... } etc. Where the property data contains the actual html. Is this intended? since it doesn't work with Angular (maybe I'm doing something wrong).

It could be solved with changing the dialog content html from using the template object to using template.data instead. Or perhaps just check for the attribute data on the template object.

Package ngDialog as npm module

Certain infrastructure tools(like cdnjs) assume that libraries are packaged as npm modules. Can we package ndDialog as npm module?

See #19

please use keydown event for capturing 'esc' key

When a ngDiaglog opened, if you opened a browser dialog such as 'Save image as...', then press 'esc' key to close it, the keyup event will still be sent to your listener, but the keydown won't.

How to close all modals or the active one modal via custom button?

Hey, everything works here, but i got a problem, i can't understand how to make the active dialog or directly all dialogs to close on custom link or button click

I mean equivalent to this? :
onclick="close_dialogs()"

Any clue on how to do this ?

thanks for the ngDialog!

ngDialog module not found in IE11 and on Linux

Really strange one. It works great on Windows on Chrome and Firefox, but on IE11 and on a friend's Ubuntu box (on Chrome and Firefox) I get this error: -

Error: [$injector:unpr] http://errors.angularjs.org/1.3.0-beta.14/$injector/unpr?p0=ngDialogProvider%20%3C-%20ngDialog
at Anonymous function (http://onlineracingchampionship.com/scripts/angular.min.js:37:260)
at d (http://onlineracingchampionship.com/scripts/angular.min.js:35:276)
at Anonymous function (http://onlineracingchampionship.com/scripts/angular.min.js:37:332)
at d (http://onlineracingchampionship.com/scripts/angular.min.js:35:276)
at e (http://onlineracingchampionship.com/scripts/angular.min.js:36:29)
at instantiate (http://onlineracingchampionship.com/scripts/angular.min.js:36:221)
at Anonymous function (http://onlineracingchampionship.com/scripts/angular.min.js:69:249)
at Anonymous function (http://onlineracingchampionship.com/scripts/angular.min.js:55:64)
at q (http://onlineracingchampionship.com/scripts/angular.min.js:7:396)
at B (http://onlineracingchampionship.com/scripts/angular.min.js:54:435)

I have included ngDialog.min.js after angular.min.js: -

<script src="/scripts/angular.min.js" type="text/javascript"></script> <script src="/scripts/ngDialog.min.js" type="text/javascript"></script>

Any ideas what could be going wrong?

Thanks for your help
All the best,
Ash

Flip transition is not smooth in Safari 7

If you click the green button in the demo modal dialog, left side of the modal dialog remains half-opaque until then the animation is complete, and then it abruptly turns to normal opacity. This issue does not happen in the latest version of Firefox and Google Chrome.

ngDialog.open returns undefined

I'm trying to close an open dialog using it's id. To do this I'm using

myDialog = ngDialog.open(
                    {
                        template: '../../views/factcheckmodal.html',
                        className: 'ngdialog-theme-plain',
                        showClose: false,
                        scope: scope

                    }).$result;

then later

ngDialog.close(myDialog.attr('id'));

What I'm getting is
cannot read propertly $result of undefined

Preventing body from shifting when opening/closing popup.

When triggering the popup, when it gets shown, the body content shifts around 20px (i believe it's the scrollbar width equivalent). The same happens when closing. It also happened with bootstrap, but was fixed in version 3.2.0 of it.
Does anyone have a solution for this?
It's not a blocker but it really affects ui/ux appearence.

Thanks in advance.

it 's possible to pass a variable to the template ??

I have this code:
show = (post_id) ->
ngDialog.open({
template: '<%= asset_path("angular/templates/posts/post.html.erb") %>',
data: post_id
});

i need to pass post_id to post.html.erb template, it's possible??
thanks.

How to cross scope?

There is an input in ngDialog,when i change the model "name",the {{name}} in the dialog is right,bug the outside scope can't catch the model "name",how can i get the ngDialog's scope?

$scope.name = "default value";

$scope.showCreateLayer = function(){

    ngDialog.open({
        template: '<div class="ngdialog-message"><input type="text" ng-model="name" />{{name}}</div>'+
            '<div class="ngdialog-buttons">'+
            '<button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog()">Cancel</button>'+
            '<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="create()">OK</button></div>',
        plain: true,
        scope:$scope
    });
};

$scope.create = function(){
    console.log($scope.name);//always be 'default value'

    if($scope.name == ""){
        $window.alert("The name can't be null.");
        return;
    }
};

Finally i solve this problem as:

$scope.dialogData = '{"name":"default value"}';

$scope.showCreateLayer = function(){

    ngDialog.open({
        template: '<div class="ngdialog-message"><input type="text" ng-model="ngDialogData.name" />{{ngDialogData.name}}</div>'+
            '<div class="ngdialog-buttons">'+
            '<button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="closeThisDialog()">Cancel</button>'+
            '<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="create(ngDialogData)">OK</button></div>',
        plain: true,
        data:$scope.dialogData ,
        scope:$scope
    });
};

$scope.create = function(opts){
    console.log(opts.name);//This will be right

    if(opts.name == ""){
        $window.alert("The name can't be null.");
        return;
    }
};

scope.closeThisDialog should accept data argument

What I want to do is scope.closeThisDialog(dataPassedBackToCallee) and in callee controller myModal.closePromise.then(function(dataPassedBackToCallee) { /*work with data*/ })
Just like in http://angular-ui.github.io/bootstrap/ modal.
Use-case:
I opened a modal window to edit some item. In this modal window I have two buttons "Save changes" and "Cancel". Now in callee controller I want a way to understand if changes was saved or canceled.
Thank you.

ngAnimate 1.3.x issue with ngDialog duplicate calls.

Probably an outside issue due to ngAnimate v.1.3.0-rc.0 (I hear they're having a lot of issues with this release).

When you open the same dialog twice (with a form inside), angular throws an error cannot read property 'add' of undefined in ngAnimate module.

Does not seem to happen in Angular v1.2.x

Cannot install using bower

When I run bower install ngDialog I get the following error:

bower install ngDialog
bower ngDialog#*            not-cached https://github.com/likeastore/ngDialog.git#*
bower ngDialog#*               resolve https://github.com/likeastore/ngDialog.git#*
bower ngDialog#*              download https://github.com/likeastore/ngDialog/archive/0.1.2.tar.gz
bower ngDialog#*               extract archive.tar.gz
bower ngDialog#*              resolved https://github.com/likeastore/ngDialog.git#0.1.2
bower angular#~1            not-cached https://github.com/angular/bower-angular.git#~1
bower angular#~1               resolve https://github.com/angular/bower-angular.git#~1
bower angular#~1              download https://github.com/angular/bower-angular/archive/v1.2.11-build.2186+sha.766b3d5.tar.gz
bower angular#~1               extract archive.tar.gz
bower angular#~1              resolved https://github.com/angular/bower-angular.git#1.2.11-build.2186+sha.766b3d5
bower angular#>=1           not-cached https://github.com/angular/bower-angular.git#>=1
bower angular#>=1              resolve https://github.com/angular/bower-angular.git#>=1
bower angular#1.2.11-build.2186+sha.766b3d5       not-cached https://github.com/angular/bower-angular.git#1.2.11-build.2186+sha.766b3d5
bower angular#1.2.11-build.2186+sha.766b3d5          resolve https://github.com/angular/bower-angular.git#1.2.11-build.2186+sha.766b3d5
bower angular#>=1                                   download https://github.com/angular/bower-angular/archive/v1.2.11-build.2186+sha.766b3d5
.tar.gz
bower angular#1.2.11-build.2186+sha.766b3d5         download https://github.com/angular/bower-angular/archive/v1.2.11-build.2186+sha.766b3d5
.tar.gz
bower angular#1.2.11-build.2186+sha.766b3d5          extract archive.tar.gz
bower angular#>=1                                    extract archive.tar.gz
bower angular#>=1                                   resolved https://github.com/angular/bower-angular.git#1.2.11-build.2186+sha.766b3d5
bower angular#1.2.11-build.2186+sha.766b3d5            EPERM EPERM, unlink 'C:\**censored**\**censored**\AppData\Roaming\bower\cache\packages\060a9fe0e6
0a0d3d6c9ed350cde03e61\1.2.11-build.2186%2Bsha.766b3d5\angular.min.js'

Stack trace:
Error: EPERM, unlink 'C:\**censored**\**censored**\AppData\Roaming\bower\cache\packages\060a9fe0e60a0d3d6c9ed350cde03e61\1.2.11-build.2186%2Bsha.766b3d5
\angular.min.js'

Console trace:
Trace
    at StandardRenderer.error (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\lib\renderers\StandardRenderer.js:74:17)
    at Logger.updateNotifier.packageName (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\bin\bower:109:18)
    at Logger.EventEmitter.emit (events.js:95:17)
    at Logger.emit (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\bower-logger\lib\Logger.js:29:39)
    at C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\lib\commands\install.js:27:16
    at _rejected (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:808:24)
    at C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:834:30
    at Promise.when (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:1079:31)
    at Promise.promise.promiseDispatch (C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:752:41)
    at C:\**censored**\**censored**\AppData\Roaming\npm\node_modules\bower\node_modules\q\q.js:574:44

System info:
Bower version: 1.2.8
Node version: 0.10.22
OS: Windows_NT 6.1.7601 x64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.