angular-modal-service
Advanced tools
Comparing version 0.6.0 to 0.6.4
{ | ||
"name": "angular-modal-service", | ||
"version": "0.6.0", | ||
"version": "0.6.4", | ||
"homepage": "https://github.com/dwmkerr/angular-modal-service", | ||
@@ -27,4 +27,3 @@ "authors": [ | ||
"*.json", | ||
"server.js", | ||
"Gruntfile.js", | ||
"gulpfile.js", | ||
"CHANGELOG.md", | ||
@@ -34,7 +33,12 @@ "*.yml" | ||
"dependencies": { | ||
"angular": "~1.3.x" | ||
"angular": "~1.3.x", | ||
"bootstrap": "~3.3.2", | ||
"jquery": "~2.1.3" | ||
}, | ||
"devDependencies": { | ||
"angular-mocks": "~1.3.x" | ||
}, | ||
"resolutions": { | ||
"angular": "~1.3.x" | ||
} | ||
} |
@@ -0,1 +1,20 @@ | ||
## v0.6.4 | ||
* Merged `scope` option field. Updated readme. | ||
## v0.6.3 | ||
* Fixed memory leak. | ||
## v0.6.2 | ||
* Tidied up logic for cleanup. | ||
* Fixed issue with vendor files. | ||
## v0.6.1 | ||
* Moved from grunt to gulp. | ||
## v0.6 | ||
## v0.5 | ||
@@ -2,0 +21,0 @@ |
@@ -13,4 +13,4 @@ // angularModalService.js | ||
module.factory('ModalService', ['$document', '$compile', '$controller', '$http', '$rootScope', '$q', '$timeout', '$templateCache', | ||
function($document, $compile, $controller, $http, $rootScope, $q, $timeout, $templateCache) { | ||
module.factory('ModalService', ['$document', '$compile', '$controller', '$http', '$rootScope', '$q', '$templateCache', | ||
function($document, $compile, $controller, $http, $rootScope, $q, $templateCache) { | ||
@@ -78,3 +78,3 @@ // Get the body of the document, we'll add the modal to this. | ||
// Create a new scope for the modal. | ||
var modalScope = $rootScope.$new(); | ||
var modalScope = options.scope || $rootScope.$new(); | ||
@@ -92,4 +92,20 @@ // Create the inputs object to the controller - this will include | ||
if(delay === undefined || delay === null) delay = 0; | ||
$timeout(function () { | ||
window.setTimeout(function() { | ||
// Resolve the 'close' promise. | ||
closeDeferred.resolve(result); | ||
// We can now clean up the scope and remove the element from the DOM. | ||
modalScope.$destroy(); | ||
modalElement.remove(); | ||
// Unless we null out all of these objects we seem to suffer | ||
// from memory leaks, if anyone can explain why then I'd | ||
// be very interested to know. | ||
inputs.close = null; | ||
deferred = null; | ||
closeDeferred = null; | ||
modal = null; | ||
inputs = null; | ||
modalElement = null; | ||
modalScope = null; | ||
}, delay); | ||
@@ -109,2 +125,5 @@ } | ||
// Create the controller, explicitly specifying the scope to use. | ||
var modalController = $controller(controllerName, inputs); | ||
// Compile then link the template element, building the actual element. | ||
@@ -116,6 +135,3 @@ // Set the $element on the inputs so that it can be injected if required. | ||
// Create the controller, explicitly specifying the scope to use. | ||
var modalController = $controller(controllerName, inputs); | ||
// Finally, append the modal to the dom. | ||
@@ -130,3 +146,3 @@ if (options.appendElement) { | ||
// We now have a modal object. | ||
// We now have a modal object... | ||
var modal = { | ||
@@ -139,10 +155,3 @@ controller: modalController, | ||
// When close is resolved, we'll clean up the scope and element. | ||
modal.close.then(function(result) { | ||
// Clean up the scope | ||
modalScope.$destroy(); | ||
// Remove the element from the dom. | ||
modalElement.remove(); | ||
}); | ||
// ...which is passed to the caller via the promise. | ||
deferred.resolve(modal); | ||
@@ -149,0 +158,0 @@ |
@@ -1,3 +0,3 @@ | ||
/*! angular-modal-service - v0.5.0 - 2015-01-23 github.com/dwmkerr/angular-modal-service */ | ||
!function(){"use strict";var a=angular.module("angularModalService",[]);a.factory("ModalService",["$document","$compile","$controller","$http","$rootScope","$q","$timeout","$templateCache",function(a,b,c,d,e,f,g,h){function i(){var a=this,i=function(a,b){var c=f.defer();if(a)c.resolve(a);else if(b){var e=h.get(b);void 0!==e?c.resolve(e):d({method:"GET",url:b,cache:!0}).then(function(a){h.put(b,a.data),c.resolve(a.data)})["catch"](function(a){c.reject(a)})}else c.reject("No template or templateUrl has been specified.");return c.promise};a.showModal=function(a){var d=f.defer(),h=a.controller;return h?(a.controllerAs&&(h=h+" as "+a.controllerAs),i(a.template,a.templateUrl).then(function(i){var k=e.$new(),l=f.defer(),m={$scope:k,close:function(a,b){(void 0===b||null===b)&&(b=0),g(function(){l.resolve(a)},b)}};if(a.inputs)for(var n in a.inputs)m[n]=a.inputs[n];var o=angular.element(i),p=b(o),q=p(k);m.$element=q;var r=c(h,m);a.appendElement?a.appendElement.append(q):j.append(q);var s={controller:r,scope:k,element:q,close:l.promise};s.close.then(function(){k.$destroy(),q.remove()}),d.resolve(s)})["catch"](function(a){d.reject(a)}),d.promise):(d.reject("No controller has been specified."),d.promise)}}var j=a.find("body");return new i}])}(); | ||
/*angular-modal-service v0.6.4 - https://github.com/dwmkerr/angular-modal-service */ | ||
!function(){"use strict";var e=angular.module("angularModalService",[]);e.factory("ModalService",["$document","$compile","$controller","$http","$rootScope","$q","$templateCache",function(e,n,t,o,l,r,c){function a(){var e=this,a=function(e,n){var t=r.defer();if(e)t.resolve(e);else if(n){var l=c.get(n);void 0!==l?t.resolve(l):o({method:"GET",url:n,cache:!0}).then(function(e){c.put(n,e.data),t.resolve(e.data)})["catch"](function(e){t.reject(e)})}else t.reject("No template or templateUrl has been specified.");return t.promise};e.showModal=function(e){var o=r.defer(),c=e.controller;return c?(e.controllerAs&&(c=c+" as "+e.controllerAs),a(e.template,e.templateUrl).then(function(a){var u=e.scope||l.$new(),s=r.defer(),p={$scope:u,close:function(e,n){(void 0===n||null===n)&&(n=0),window.setTimeout(function(){s.resolve(e),u.$destroy(),h.remove(),p.close=null,o=null,s=null,$=null,p=null,h=null,u=null},n)}};if(e.inputs)for(var d in e.inputs)p[d]=e.inputs[d];var f=angular.element(a),m=t(c,p),v=n(f),h=v(u);p.$element=h,e.appendElement?e.appendElement.append(h):i.append(h);var $={controller:m,scope:u,element:h,close:s.promise};o.resolve($)})["catch"](function(e){o.reject(e)}),o.promise):(o.reject("No controller has been specified."),o.promise)}}var i=e.find("body");return new a}])}(); | ||
//# sourceMappingURL=angular-modal-service.min.js.map |
{ | ||
"name": "angular-modal-service", | ||
"version": "0.6.0", | ||
"version": "0.6.4", | ||
"description": "AngularJS Service for showing Modals and Popups", | ||
"main": "./dst/angular-modal-service.js", | ||
"scripts": { | ||
"test": "grunt karma:silent", | ||
"test": "gulp test", | ||
"coveralls": "cp build/coverage/PhantomJS*/lcov.info lcov.info && node node_modules/coveralls/bin/coveralls.js < lcov.info" | ||
@@ -27,17 +27,23 @@ }, | ||
"devDependencies": { | ||
"express": "^4.4.0", | ||
"grunt": "~0.4", | ||
"grunt-contrib-uglify": "~0.7", | ||
"grunt-contrib-jshint": "~0.11", | ||
"grunt-contrib-watch": "~0.6", | ||
"karma": "~0.12.16", | ||
"coveralls": "^2.10.0", | ||
"express": "^4.12.0", | ||
"gulp": "^3.8.11", | ||
"gulp-jshint": "^1.9.2", | ||
"gulp-open": "^0.3.2", | ||
"jshint-stylish": "^1.0.1", | ||
"karma": "^0.12.31", | ||
"karma-chrome-launcher": "^0.1.3", | ||
"karma-chrome-launcher": "^0.1.3", | ||
"karma-coverage": "^0.2.1", | ||
"karma-jasmine": "~0.3", | ||
"karma-junit-reporter": "~0.2", | ||
"karma-phantomjs-launcher": "^0.1.4", | ||
"karma-chrome-launcher": "^0.1.3", | ||
"karma-junit-reporter": "~0.2", | ||
"grunt-karma": "~0.10", | ||
"grunt-contrib-copy": "~0.7", | ||
"coveralls": "^2.10.0" | ||
"tiny-lr": "^0.1.5", | ||
"gulp-uglify": "^1.1.0", | ||
"gulp-rename": "^1.2.0", | ||
"gulp-sourcemaps": "^1.5.0", | ||
"connect-livereload": "^0.5.3", | ||
"opn": "^1.0.1", | ||
"gulp-header": "^1.2.2" | ||
} | ||
} |
@@ -75,3 +75,3 @@ angular-modal-service | ||
$scope.close = function(result) { | ||
$scope.dismissModal = function(result) { | ||
close(result, 200); // close, but give 200ms for bootstrap to animate | ||
@@ -94,2 +94,22 @@ }; | ||
To pass data into the modal controller, use the `inputs` field of the modal options. For example: | ||
```js | ||
ModalService.showModal({ | ||
templateUrl: "exampletemplate.html", | ||
controller: "ExampleController", | ||
inputs: { | ||
name: "Fry", | ||
year: 3001 | ||
} | ||
}) | ||
``` | ||
injects the `name` and `year` values into the controller: | ||
```js | ||
app.controler('ExampleController', function($scope, name, year, close) { | ||
}); | ||
``` | ||
#### ShowModal Options | ||
@@ -100,3 +120,3 @@ | ||
* `controller`: The name of the controller to created. | ||
* `controllerAs` : The name of the variable on the scope the controller is assigned to - (optional) | ||
* `controllerAs` : The name of the variable on the scope the controller is assigned to - (optional). | ||
* `templateUrl`: The URL of the HTML template to use for the modal. | ||
@@ -107,3 +127,4 @@ * `template`: If `templateUrl` is not specified, you can specify `template` as raw | ||
is injected into the controller constructor. | ||
* `appendElement`: The custom angular element to append the modal to instead of default body. | ||
* `appendElement`: The custom angular element to append the modal to instead of default `body` element. | ||
* `scope`: Optional. If provided, a new scope will not be created for the model - this scope will be used. Be aware that the modal service will *still* destroy the scope when the modal is closed. Typically you should not need to use this field, as the generated scope will handle most use cases. | ||
@@ -152,11 +173,7 @@ #### The Modal Object | ||
bower install | ||
gulp | ||
``` | ||
and all code will be built and ready to go. To ensure the code is linted, test, minified and | ||
updated to the `dst` folder as you change it, run: | ||
The samples will be opened in the browser. All JavaScript changes will re-run the tests, all samples changes are automatically reloaded into the browser. | ||
``` | ||
grunt dev | ||
``` | ||
The easiest way to adapt the code is to play with some of the examples in the ``samples`` folder. | ||
@@ -174,10 +191,2 @@ | ||
If you are updating or debugging tests, you can run: | ||
``` | ||
grunt karma:debug | ||
``` | ||
This will open Karma in Chrome allowing you to set breakpoints and debug your suite. | ||
## FAQ | ||
@@ -232,2 +241,9 @@ | ||
**I'm using a Bootstrap Modal and the dialog doesn't show up** | ||
Code is entered exactly as shown the example but when the showAModal() function fires the modal template html is appended to the body while the console outputs TypeError: undefined is not a function (pointing to a line: modal.element.modal(); | ||
Solution: include bootstrap before angular in your script loads | ||
## Thanks | ||
@@ -239,2 +255,2 @@ | ||
* [cointilt](https://github.com/cointilt) - Allowing the modal to be added to a custom element, not just the body. | ||
* [kernowjoe](https://github.com/kernowjoe) - controllerAs | ||
* [kernowjoe](https://github.com/kernowjoe) - controllerAs |
@@ -0,0 +0,0 @@ var app = angular.module('sampleapp'); |
@@ -0,0 +0,0 @@ var app = angular.module('sampleapp'); |
@@ -0,0 +0,0 @@ // Build our app module, with a dependency on the angular modal service. |
var app = angular.module('sampleapp'); | ||
app.controller('YesNoController', ['$scope', 'close', function($scope, close) { | ||
$scope.close = function(result) { | ||
close(result, 500); // close, but give 500ms for bootstrap to animate | ||
}; | ||
$scope.close = function(result) { | ||
close(result, 500); // close, but give 500ms for bootstrap to animate | ||
}; | ||
}]); |
@@ -13,4 +13,4 @@ // angularModalService.js | ||
module.factory('ModalService', ['$document', '$compile', '$controller', '$http', '$rootScope', '$q', '$timeout', '$templateCache', | ||
function($document, $compile, $controller, $http, $rootScope, $q, $timeout, $templateCache) { | ||
module.factory('ModalService', ['$document', '$compile', '$controller', '$http', '$rootScope', '$q', '$templateCache', | ||
function($document, $compile, $controller, $http, $rootScope, $q, $templateCache) { | ||
@@ -78,3 +78,3 @@ // Get the body of the document, we'll add the modal to this. | ||
// Create a new scope for the modal. | ||
var modalScope = $rootScope.$new(); | ||
var modalScope = options.scope || $rootScope.$new(); | ||
@@ -92,4 +92,20 @@ // Create the inputs object to the controller - this will include | ||
if(delay === undefined || delay === null) delay = 0; | ||
$timeout(function () { | ||
window.setTimeout(function() { | ||
// Resolve the 'close' promise. | ||
closeDeferred.resolve(result); | ||
// We can now clean up the scope and remove the element from the DOM. | ||
modalScope.$destroy(); | ||
modalElement.remove(); | ||
// Unless we null out all of these objects we seem to suffer | ||
// from memory leaks, if anyone can explain why then I'd | ||
// be very interested to know. | ||
inputs.close = null; | ||
deferred = null; | ||
closeDeferred = null; | ||
modal = null; | ||
inputs = null; | ||
modalElement = null; | ||
modalScope = null; | ||
}, delay); | ||
@@ -109,2 +125,5 @@ } | ||
// Create the controller, explicitly specifying the scope to use. | ||
var modalController = $controller(controllerName, inputs); | ||
// Compile then link the template element, building the actual element. | ||
@@ -116,6 +135,3 @@ // Set the $element on the inputs so that it can be injected if required. | ||
// Create the controller, explicitly specifying the scope to use. | ||
var modalController = $controller(controllerName, inputs); | ||
// Finally, append the modal to the dom. | ||
@@ -130,3 +146,3 @@ if (options.appendElement) { | ||
// We now have a modal object. | ||
// We now have a modal object... | ||
var modal = { | ||
@@ -139,10 +155,3 @@ controller: modalController, | ||
// When close is resolved, we'll clean up the scope and element. | ||
modal.close.then(function(result) { | ||
// Clean up the scope | ||
modalScope.$destroy(); | ||
// Remove the element from the dom. | ||
modalElement.remove(); | ||
}); | ||
// ...which is passed to the caller via the promise. | ||
deferred.resolve(modal); | ||
@@ -149,0 +158,0 @@ |
@@ -0,0 +0,0 @@ describe('basics', function() { |
@@ -0,0 +0,0 @@ describe('controller', function() { |
@@ -0,0 +0,0 @@ describe('dom', function() { |
@@ -66,3 +66,3 @@ module.exports = function(config) { | ||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher | ||
browsers: ['PhantomJS', 'Chrome'], | ||
browsers: ['PhantomJS'], | ||
@@ -69,0 +69,0 @@ // if true, Karma captures browsers, runs the tests and exits |
@@ -0,0 +0,0 @@ describe('parameters', function() { |
@@ -0,0 +0,0 @@ describe('template', function() { |
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
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
2519127
44
41562
249
19
3
7