Comparing version 0.2.10 to 0.2.11
{ | ||
"name": "ngDialog", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"homepage": "https://github.com/likeastore/ngDialog", | ||
@@ -5,0 +5,0 @@ "description": "Modal dialogs and popups provider for Angular.js applications", |
@@ -39,4 +39,4 @@ /* | ||
this.$get = ['$document', '$templateCache', '$compile', '$q', '$http', '$rootScope', '$timeout', '$window', | ||
function ($document, $templateCache, $compile, $q, $http, $rootScope, $timeout, $window) { | ||
this.$get = ['$document', '$templateCache', '$compile', '$q', '$http', '$rootScope', '$timeout', '$window', '$controller', | ||
function ($document, $templateCache, $compile, $q, $http, $rootScope, $timeout, $window, $controller) { | ||
var $body = $document.find('body'); | ||
@@ -52,3 +52,3 @@ if (forceBodyReload) { | ||
if (event.keyCode === 27) { | ||
publicMethods.close(); | ||
publicMethods.close('$escape'); | ||
} | ||
@@ -72,3 +72,3 @@ }, | ||
closeDialog: function ($dialog) { | ||
closeDialog: function ($dialog, value) { | ||
var id = $dialog.attr('id'); | ||
@@ -97,2 +97,3 @@ if (typeof window.Hammer !== 'undefined') { | ||
} | ||
$rootScope.$broadcast('ngDialog.closed', $dialog); | ||
}).addClass('ngdialog-closing'); | ||
@@ -106,2 +107,3 @@ } else { | ||
} | ||
$rootScope.$broadcast('ngDialog.closed', $dialog); | ||
} | ||
@@ -111,2 +113,3 @@ if (defers[id]) { | ||
id: id, | ||
value: value, | ||
$dialog: $dialog, | ||
@@ -117,3 +120,2 @@ remainingDialogs: dialogsCount | ||
} | ||
$rootScope.$broadcast('ngDialog.closed', $dialog); | ||
} | ||
@@ -170,4 +172,8 @@ }; | ||
if (options.controller && angular.isString(options.controller)) { | ||
$dialog.attr('ng-controller', options.controller); | ||
if (options.controller && (angular.isString(options.controller) || angular.isArray(options.controller) || angular.isFunction(options.controller))) { | ||
var controllerInstance = $controller(options.controller, { | ||
$scope: scope, | ||
$element: $dialog | ||
}); | ||
$dialog.data('$ngDialogControllerController', controllerInstance); | ||
} | ||
@@ -180,3 +186,6 @@ | ||
if (options.data && angular.isString(options.data)) { | ||
scope.ngDialogData = options.data.replace(/^\s*/, '')[0] === '{' ? angular.fromJson(options.data) : options.data; | ||
var firstLetter = options.data.replace(/^\s*/, '')[0]; | ||
scope.ngDialogData = (firstLetter === '{' || firstLetter === '[') ? angular.fromJson(options.data) : options.data; | ||
} else if (options.data && angular.isObject(options.data)) { | ||
scope.ngDialogData = angular.fromJson(angular.toJson(options.data)); | ||
} | ||
@@ -190,4 +199,4 @@ | ||
scope.closeThisDialog = function() { | ||
privateMethods.closeDialog($dialog); | ||
scope.closeThisDialog = function (value) { | ||
privateMethods.closeDialog($dialog, value); | ||
}; | ||
@@ -205,3 +214,2 @@ | ||
$dialogParent.append($dialog); | ||
$rootScope.$broadcast('ngDialog.opened', $dialog); | ||
@@ -219,3 +227,3 @@ }); | ||
if (isOverlay || isCloseBtn) { | ||
publicMethods.close($dialog.attr('id')); | ||
publicMethods.close($dialog.attr('id'), isCloseBtn ? '$closeButton' : '$document'); | ||
} | ||
@@ -238,4 +246,4 @@ }; | ||
closePromise: defer.promise, | ||
close: function() { | ||
privateMethods.closeDialog($dialog); | ||
close: function(value) { | ||
privateMethods.closeDialog($dialog, value); | ||
} | ||
@@ -282,8 +290,11 @@ }; | ||
defer.resolve(value); | ||
openResult.close(); | ||
openResult.close(value); | ||
}; | ||
var openResult = publicMethods.open(options); | ||
openResult.closePromise.then(function () { | ||
defer.reject(); | ||
openResult.closePromise.then(function (data) { | ||
if (data) { | ||
return defer.reject(data.value); | ||
} | ||
return defer.reject(); | ||
}); | ||
@@ -298,9 +309,9 @@ | ||
*/ | ||
close: function (id) { | ||
close: function (id, value) { | ||
var $dialog = $el(document.getElementById(id)); | ||
if ($dialog.length) { | ||
privateMethods.closeDialog($dialog); | ||
privateMethods.closeDialog($dialog, value); | ||
} else { | ||
publicMethods.closeAll(); | ||
publicMethods.closeAll(value); | ||
} | ||
@@ -311,7 +322,7 @@ | ||
closeAll: function () { | ||
closeAll: function (value) { | ||
var $all = document.querySelectorAll('.ngdialog'); | ||
angular.forEach($all, function (dialog) { | ||
privateMethods.closeDialog($el(dialog)); | ||
privateMethods.closeDialog($el(dialog), value); | ||
}); | ||
@@ -318,0 +329,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/*! ng-dialog - v0.2.10 (https://github.com/likeastore/ngDialog) */ | ||
!function(a,b){"use strict";var c=b.module("ngDialog",[]),d=b.element,e=b.isDefined,f=(document.body||document.documentElement).style,g=e(f.animation)||e(f.WebkitAnimation)||e(f.MozAnimation)||e(f.MsAnimation)||e(f.OAnimation),h="animationend webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend",i=!1;c.provider("ngDialog",function(){var c=this.defaults={className:"ngdialog-theme-default",plain:!1,showClose:!0,closeByDocument:!0,closeByEscape:!0,appendTo:!1};this.setForceBodyReload=function(a){i=a||!1},this.setDefaults=function(a){b.extend(c,a)};var e,f=0,j=0,k={};this.$get=["$document","$templateCache","$compile","$q","$http","$rootScope","$timeout","$window",function(l,m,n,o,p,q,r,s){var t=l.find("body");i&&q.$on("$locationChangeSuccess",function(){t=l.find("body")});var u={onDocumentKeydown:function(a){27===a.keyCode&&v.close()},setBodyPadding:function(a){var b=parseInt(t.css("padding-right")||0,10);t.css("padding-right",b+a+"px"),t.data("ng-dialog-original-padding",b)},resetBodyPadding:function(){var a=t.data("ng-dialog-original-padding");a?t.css("padding-right",a+"px"):t.css("padding-right","")},closeDialog:function(b){var c=b.attr("id");"undefined"!=typeof a.Hammer?a.Hammer(b[0]).off("tap",e):b.unbind("click"),1===j&&t.unbind("keydown"),b.hasClass("ngdialog-closing")||(j-=1),g?b.unbind(h).bind(h,function(){b.scope().$destroy(),b.remove(),0===j&&(t.removeClass("ngdialog-open"),u.resetBodyPadding())}).addClass("ngdialog-closing"):(b.scope().$destroy(),b.remove(),0===j&&(t.removeClass("ngdialog-open"),u.resetBodyPadding())),k[c]&&(k[c].resolve({id:c,$dialog:b,remainingDialogs:j}),delete k[c]),q.$broadcast("ngDialog.closed",b)}},v={open:function(g){function h(a){return a?b.isString(a)&&l.plain?a:m.get(a)||p.get(a,{cache:!0}):"Empty template"}var i=this,l=b.copy(c);g=g||{},b.extend(l,g),f+=1,i.latestID="ngdialog"+f;var w;k[i.latestID]=w=o.defer();var x,y,z=b.isObject(l.scope)?l.scope.$new():q.$new();return o.when(h(l.template)).then(function(c){return c=b.isString(c)?c:c.data&&b.isString(c.data)?c.data:"",m.put(l.template,c),l.showClose&&(c+='<div class="ngdialog-close"></div>'),i.$result=x=d('<div id="ngdialog'+f+'" class="ngdialog"></div>'),x.html('<div class="ngdialog-overlay"></div><div class="ngdialog-content">'+c+"</div>"),l.controller&&b.isString(l.controller)&&x.attr("ng-controller",l.controller),l.className&&x.addClass(l.className),l.data&&b.isString(l.data)&&(z.ngDialogData="{"===l.data.replace(/^\s*/,"")[0]?b.fromJson(l.data):l.data),y=l.appendTo&&b.isString(l.appendTo)?b.element(document.querySelector(l.appendTo)):t,z.closeThisDialog=function(){u.closeDialog(x)},r(function(){n(x)(z);var a=s.innerWidth-t.prop("clientWidth");t.addClass("ngdialog-open");var b=a-(s.innerWidth-t.prop("clientWidth"));b>0&&u.setBodyPadding(b),y.append(x),q.$broadcast("ngDialog.opened",x)}),l.closeByEscape&&t.bind("keydown",u.onDocumentKeydown),e=function(a){var b=l.closeByDocument?d(a.target).hasClass("ngdialog-overlay"):!1,c=d(a.target).hasClass("ngdialog-close");(b||c)&&v.close(x.attr("id"))},"undefined"!=typeof a.Hammer?a.Hammer(x[0]).on("tap",e):x.bind("click",e),j+=1,v}),{id:"ngdialog"+f,closePromise:w.promise,close:function(){u.closeDialog(x)}}},openConfirm:function(a){var c=o.defer(),d={closeByEscape:!1,closeByDocument:!1};b.extend(d,a),d.scope=b.isObject(d.scope)?d.scope.$new():q.$new(),d.scope.confirm=function(a){c.resolve(a),e.close()};var e=v.open(d);return e.closePromise.then(function(){c.reject()}),c.promise},close:function(a){var b=d(document.getElementById(a));return b.length?u.closeDialog(b):v.closeAll(),v},closeAll:function(){var a=document.querySelectorAll(".ngdialog");b.forEach(a,function(a){u.closeDialog(d(a))})}};return v}]}),c.directive("ngDialog",["ngDialog",function(a){return{restrict:"A",scope:{ngDialogScope:"="},link:function(c,d,e){d.on("click",function(d){d.preventDefault();var f=b.isDefined(c.ngDialogScope)?c.ngDialogScope:"noScope";b.isDefined(e.ngDialogClosePrevious)&&a.close(e.ngDialogClosePrevious),a.open({template:e.ngDialog,className:e.ngDialogClass,controller:e.ngDialogController,scope:f,data:e.ngDialogData,showClose:"false"===e.ngDialogShowClose?!1:!0,closeByDocument:"false"===e.ngDialogCloseByDocument?!1:!0,closeByEscape:"false"===e.ngDialogCloseByEscape?!1:!0})})}}}])}(window,window.angular); | ||
/*! ng-dialog - v0.2.11 (https://github.com/likeastore/ngDialog) */ | ||
!function(a,b){"use strict";var c=b.module("ngDialog",[]),d=b.element,e=b.isDefined,f=(document.body||document.documentElement).style,g=e(f.animation)||e(f.WebkitAnimation)||e(f.MozAnimation)||e(f.MsAnimation)||e(f.OAnimation),h="animationend webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend",i=!1;c.provider("ngDialog",function(){var c=this.defaults={className:"ngdialog-theme-default",plain:!1,showClose:!0,closeByDocument:!0,closeByEscape:!0,appendTo:!1};this.setForceBodyReload=function(a){i=a||!1},this.setDefaults=function(a){b.extend(c,a)};var e,f=0,j=0,k={};this.$get=["$document","$templateCache","$compile","$q","$http","$rootScope","$timeout","$window","$controller",function(l,m,n,o,p,q,r,s,t){var u=l.find("body");i&&q.$on("$locationChangeSuccess",function(){u=l.find("body")});var v={onDocumentKeydown:function(a){27===a.keyCode&&w.close("$escape")},setBodyPadding:function(a){var b=parseInt(u.css("padding-right")||0,10);u.css("padding-right",b+a+"px"),u.data("ng-dialog-original-padding",b)},resetBodyPadding:function(){var a=u.data("ng-dialog-original-padding");a?u.css("padding-right",a+"px"):u.css("padding-right","")},closeDialog:function(b,c){var d=b.attr("id");"undefined"!=typeof a.Hammer?a.Hammer(b[0]).off("tap",e):b.unbind("click"),1===j&&u.unbind("keydown"),b.hasClass("ngdialog-closing")||(j-=1),g?b.unbind(h).bind(h,function(){b.scope().$destroy(),b.remove(),0===j&&(u.removeClass("ngdialog-open"),v.resetBodyPadding()),q.$broadcast("ngDialog.closed",b)}).addClass("ngdialog-closing"):(b.scope().$destroy(),b.remove(),0===j&&(u.removeClass("ngdialog-open"),v.resetBodyPadding()),q.$broadcast("ngDialog.closed",b)),k[d]&&(k[d].resolve({id:d,value:c,$dialog:b,remainingDialogs:j}),delete k[d])}},w={open:function(g){function h(a){return a?b.isString(a)&&l.plain?a:m.get(a)||p.get(a,{cache:!0}):"Empty template"}var i=this,l=b.copy(c);g=g||{},b.extend(l,g),f+=1,i.latestID="ngdialog"+f;var x;k[i.latestID]=x=o.defer();var y,z,A=b.isObject(l.scope)?l.scope.$new():q.$new();return o.when(h(l.template)).then(function(c){if(c=b.isString(c)?c:c.data&&b.isString(c.data)?c.data:"",m.put(l.template,c),l.showClose&&(c+='<div class="ngdialog-close"></div>'),i.$result=y=d('<div id="ngdialog'+f+'" class="ngdialog"></div>'),y.html('<div class="ngdialog-overlay"></div><div class="ngdialog-content">'+c+"</div>"),l.controller&&(b.isString(l.controller)||b.isArray(l.controller)||b.isFunction(l.controller))){var g=t(l.controller,{$scope:A,$element:y});y.data("$ngDialogControllerController",g)}if(l.className&&y.addClass(l.className),l.data&&b.isString(l.data)){var h=l.data.replace(/^\s*/,"")[0];A.ngDialogData="{"===h||"["===h?b.fromJson(l.data):l.data}else l.data&&b.isObject(l.data)&&(A.ngDialogData=b.fromJson(b.toJson(l.data)));return z=l.appendTo&&b.isString(l.appendTo)?b.element(document.querySelector(l.appendTo)):u,A.closeThisDialog=function(a){v.closeDialog(y,a)},r(function(){n(y)(A);var a=s.innerWidth-u.prop("clientWidth");u.addClass("ngdialog-open");var b=a-(s.innerWidth-u.prop("clientWidth"));b>0&&v.setBodyPadding(b),z.append(y),q.$broadcast("ngDialog.opened",y)}),l.closeByEscape&&u.bind("keydown",v.onDocumentKeydown),e=function(a){var b=l.closeByDocument?d(a.target).hasClass("ngdialog-overlay"):!1,c=d(a.target).hasClass("ngdialog-close");(b||c)&&w.close(y.attr("id"),c?"$closeButton":"$document")},"undefined"!=typeof a.Hammer?a.Hammer(y[0]).on("tap",e):y.bind("click",e),j+=1,w}),{id:"ngdialog"+f,closePromise:x.promise,close:function(a){v.closeDialog(y,a)}}},openConfirm:function(a){var c=o.defer(),d={closeByEscape:!1,closeByDocument:!1};b.extend(d,a),d.scope=b.isObject(d.scope)?d.scope.$new():q.$new(),d.scope.confirm=function(a){c.resolve(a),e.close(a)};var e=w.open(d);return e.closePromise.then(function(a){return a?c.reject(a.value):c.reject()}),c.promise},close:function(a,b){var c=d(document.getElementById(a));return c.length?v.closeDialog(c,b):w.closeAll(b),w},closeAll:function(a){var c=document.querySelectorAll(".ngdialog");b.forEach(c,function(b){v.closeDialog(d(b),a)})}};return w}]}),c.directive("ngDialog",["ngDialog",function(a){return{restrict:"A",scope:{ngDialogScope:"="},link:function(c,d,e){d.on("click",function(d){d.preventDefault();var f=b.isDefined(c.ngDialogScope)?c.ngDialogScope:"noScope";b.isDefined(e.ngDialogClosePrevious)&&a.close(e.ngDialogClosePrevious),a.open({template:e.ngDialog,className:e.ngDialogClass,controller:e.ngDialogController,scope:f,data:e.ngDialogData,showClose:"false"===e.ngDialogShowClose?!1:!0,closeByDocument:"false"===e.ngDialogCloseByDocument?!1:!0,closeByEscape:"false"===e.ngDialogCloseByEscape?!1:!0})})}}}])}(window,window.angular); |
{ | ||
"name": "ng-dialog", | ||
"version": "0.2.10", | ||
"version": "0.2.11", | ||
"homepage": "https://github.com/likeastore/ngDialog", | ||
@@ -5,0 +5,0 @@ "description": "Modal dialogs and popups provider for Angular.js applications", |
@@ -71,6 +71,24 @@ # ngDialog | ||
##### ``controller {String}`` | ||
##### ``controller {String} | {Array} | {Object}`` | ||
Name of controller that will be used for dialog window if necessary. | ||
Controller that will be used for dialog window if necessary. The controller can be specified either by referring it by name or directly inline. | ||
```javascript | ||
ngDialog.open({ | ||
template: 'externalTemplate.html', | ||
controller: 'SomeController' | ||
}); | ||
``` | ||
or | ||
```javascript | ||
ngDialog.open({ | ||
template: 'externalTemplate.html', | ||
controller: ['$scope', 'otherService', function($scope, otherService) { | ||
// controller logic | ||
}] | ||
}); | ||
``` | ||
##### ``scope {Object}`` | ||
@@ -96,5 +114,5 @@ | ||
##### ``scope.closeThisDialog()`` | ||
##### ``scope.closeThisDialog(value)`` | ||
In addition ``.closeThisDialog()`` method get injected to passed ``$scope``. This allows you to close dialog straight from handler in a popup element, for example: | ||
In addition ``.closeThisDialog(value)`` method gets injected to passed ``$scope``. This allows you to close dialog straight from handler in a popup element, for example: | ||
@@ -104,8 +122,10 @@ ```html | ||
<input type="text"/> | ||
<input type="button" value="OK" ng-click="checkInput() && closeThisDialog()"/> | ||
<input type="button" value="OK" ng-click="checkInput() && closeThisDialog('Some value')"/> | ||
</div> | ||
``` | ||
##### ``data {String}`` | ||
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 data that you want to be stored in controller's ``$parent`` scope, it could be stringified JSON as well. | ||
@@ -146,3 +166,3 @@ | ||
### Defaults: | ||
### Defaults | ||
@@ -174,10 +194,12 @@ ##### ``setDefaults(options)`` | ||
##### ``close() {Function}`` | ||
##### ``close(value) {Function}`` | ||
This is a function which will close the dialog which was opened by the current call to ``open()``. | ||
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, ``$dialog`` - the dialog element which at this point has been removed from the DOM and ``remainingDialogs`` - the number of dialogs still open. | ||
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: | ||
@@ -221,15 +243,15 @@ | ||
An Angular promise object that is resolved if the ``.confirm()`` function is used to close the dialog, otherwise the promise is rejected. | ||
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. | ||
=== | ||
### ``.close(id)`` | ||
### ``.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()``). | ||
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()`` | ||
### ``.closeAll(value)`` | ||
Method manages closing all active modals on the page. | ||
Method manages closing all active modals on the page. Takes an optional value to resolve all of the dialog promises with. | ||
@@ -236,0 +258,0 @@ === |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64585
1047
327