├── .gitignore ├── LICENSE ├── README.md ├── bower.json └── src ├── app.js ├── complexModal.html ├── createDialog.js ├── index.html └── simpleModal.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Webstorm 2 | \.idea 3 | 4 | 5 | # OS droppings 6 | .DS_Store 7 | .DS_Store? 8 | .Spotlight-V100 9 | .Trashes 10 | Icon? 11 | ehthumbs.db 12 | Thumbs.db 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | 3 | Copyright (C) 2011-2013 Vojta Jína. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation files 7 | (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 20 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 21 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | angularjs-modal-service 2 | ======================= 3 | 4 | An AngularJS service that creates a Modal Popup with a given HTML template and controller. 5 | 6 | The Service createDialog can be used to create a modal using Twitter's Bootstrap on the fly. 7 | 8 | ## Requirements 9 | 10 | 1. Twitter Bootstrap CSS 11 | 2. the createDialog.js file 12 | 13 | ## Using it: 14 | 15 | ### Getting it via Bower 16 | 17 | 1. bower install angularjs-modal-service 18 | 19 | ### Getting it otherwise 20 | 21 | 1. Download createDialog.js and include it as part of your library 22 | 23 | ### Using it 24 | 25 | 1. Include the createDialog.js file in your index.html file. 26 | 2. Include the 'fundoo.services' as a module dependency when you define your app 27 | 3. Import the createDialog Service in your App Controller. 28 | 4. Call the createDialog() function from your controller, using the following syntax : 29 | 30 | ``` 31 | createDialog([template_url],{ 32 | id : [modal_id], 33 | title: [modal_title], 34 | backdrop: [backdrop_visible], 35 | success: [modal_success_button], 36 | cancel: [modal_cancel_button], 37 | controller: [modal_controller], 38 | backdropClass: [modal_backdrop_class], 39 | footerTemplate: [modal_footer_template], 40 | modalClass: [modal_class], 41 | css: { 42 | [css properties key: value] 43 | } 44 | }, {modal_custom_data}); 45 | ``` 46 | where, 47 | 48 | * **template_url** *[string]* : the url of the template of the body of the template. 49 | * **modal_id** *[string]* : the unique html id attr of the template. 50 | * **modal_title** *[string]* : is the title of the modal to be displayed in its header section. 51 | * **backdrop_visible(optional)** *[boolean]*: whether to hide the html page behind the modal under an overlay 52 | * **modal_success_button(optional)** *[object]*: the object add a submit button to the modal with its functionality 53 | 54 | *Syntax* 55 | ``` 56 | {label: '[label_of_button]', fn: '[function_on_click]'} 57 | ``` 58 | 59 | * **modal_cancel_button(optional)** *[object]*: the object add a cancel button to the modal with its functionality. For configuration options see modal_success_button 60 | * **modal_controller(optional)** *[string]* : is the controller attached to the modal. 61 | * **modal_backdrop_class(optional)** *[string]* : the css class for the backdrop of the modal. 62 | * **modal_footer_template(optional)** *[string]* : the footer template of the modal. 63 | * **modal_class(optional)** *[string]* : the css class for the modal. 64 | * **modal_custom_data(optional)** *[object]* : is an object where each key becomes an argument to the controller of the modal. 65 | 66 | ## Where can I see a demo? 67 | 68 | Glad you asked. Go check out our GitHub page for the [AngularJS-Modal-Service] 69 | 70 | ## Who are you? 71 | 72 | We are Fundoo Solutions, an awesome company based out of India who just love AngularJS. Check out our [website] or our [LinkedIn] page. 73 | 74 | ## License 75 | 76 | The code above is open sourced, and licensed under the MIT License, which is the simplest and easiest to understand, and most open. 77 | Basically, feel free to use this code or modify it as per your needs. The actual license can be found in the `LICENSE` file. 78 | 79 | 80 | [AngularJS-Modal-Service]: http://fundoo-solutions.github.io/angularjs-modal-service/ 81 | [website]: http://www.befundoo.com 82 | [LinkedIn]: http://www.linkedin.com/company/fundoo-solutions 83 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angularjs-modal-service", 3 | "version": "0.0.1", 4 | "main": "src/createDialog.js", 5 | "ignore": [ 6 | "**/.*", 7 | ".DS_Store", 8 | "node_modules", 9 | "components" 10 | ], 11 | "description": "An AngularJS service that creates a Modal Popup with a given HTML template and controller", 12 | "repository": { 13 | "type": "git", 14 | "url": "git@github.com:Fundoo-Solutions/angularjs-modal-service.git" 15 | }, 16 | 17 | "license": "MIT" 18 | } 19 | -------------------------------------------------------------------------------- /src/app.js: -------------------------------------------------------------------------------- 1 | var app = angular.module('FundooModalApp', ['fundoo.services']) 2 | .controller('MainCtrl', ['$scope', 'createDialog', function($scope, createDialogService) { 3 | $scope.launchInlineModal = function() { 4 | createDialogService({ 5 | id: 'simpleDialog', 6 | template: 7 | '
' + 8 | '

This is how the Simple Modal was launched

' + 9 | '
' + 10 | '
' + 11 | '
' +
 12 |                 'createDialog({\n' +
 13 |                 '    id: "inlineDialog",\n' +
 14 |                 '    template: "<div><!--template HTML here...--></div>"\n' +
 15 |                 '    title: "A Inline Modal Dialog",\n' +
 16 |                 '    backdrop: true,\n' +
 17 |                 '    success: {\n' +
 18 |                 '        label: "Yay",\n' +
 19 |                 '        fn: function(){\n' +
 20 |                 '            console.log("Inline modal closed");\n' +
 21 |                 '        }\n' +
 22 |                 '    }\n' +
 23 |                 '});\n' +
 24 |                 '
\n' + 25 | '
\n' + 26 | '
\n' + 27 | '
', 28 | title: 'A Inline Modal Dialog', 29 | backdrop: true, 30 | success: {label: 'Success', fn: function() {console.log('Inline modal closed');}} 31 | }); 32 | }; 33 | $scope.launchObjectModal = function() { 34 | createDialogService({ 35 | id: 'simpleDialog', 36 | template: angular.element( 37 | '
' + 38 | '

This is how the Simple Modal was launched

' + 39 | '
' + 40 | '
' + 41 | '
' +
 42 |                 'createDialog({\n' +
 43 |                 '    id: "objectDialog",\n' +
 44 |                 '    template: angular.element("...")\n' +
 45 |                 '    title: "A Object Modal Dialog",\n' +
 46 |                 '    backdrop: true,\n' +
 47 |                 '    success: {\n' +
 48 |                 '        label: "Yay",\n' +
 49 |                 '        fn: function(){\n' +
 50 |                 '            console.log("Object modal closed");\n' +
 51 |                 '        }\n' +
 52 |                 '    }\n' +
 53 |                 '});\n' +
 54 |                 '
\n' + 55 | '
\n' + 56 | '
\n' + 57 | '
'), 58 | title: 'A Object Modal Dialog', 59 | backdrop: true, 60 | success: {label: 'Success', fn: function() {console.log('Object modal closed');}} 61 | }); 62 | }; 63 | $scope.launchSimpleModal = function() { 64 | createDialogService('simpleModal.html', { 65 | id: 'simpleDialog', 66 | title: 'A Simple Modal Dialog', 67 | backdrop: true, 68 | success: {label: 'Success', fn: function() {console.log('Simple modal closed');}} 69 | }); 70 | }; 71 | $scope.launchComplexModal = function() { 72 | createDialogService('complexModal.html', { 73 | id: 'complexDialog', 74 | title: 'A Complex Modal Dialog', 75 | backdrop: true, 76 | controller: 'ComplexModalController', 77 | success: {label: 'Success', fn: function() {console.log('Complex modal closed');}} 78 | }, { 79 | myVal: 15, 80 | assetDetails: { 81 | name: 'My Asset', 82 | description: 'A Very Nice Asset' 83 | } 84 | }); 85 | }; 86 | }]) 87 | .factory('SampleFactory', function() { 88 | return { 89 | sample: function() { 90 | console.log('This is a sample'); 91 | } 92 | }; 93 | }) 94 | .controller('ComplexModalController', ['$scope', 'SampleFactory', 'myVal', 'assetDetails', 95 | function($scope, SampleFactory, myVal, assetDetails) { 96 | $scope.myVal = myVal; 97 | $scope.asset = assetDetails; 98 | SampleFactory.sample(); 99 | }]); 100 | -------------------------------------------------------------------------------- /src/complexModal.html: -------------------------------------------------------------------------------- 1 |
2 |

This is how the Complex Modal was launched

3 |
4 |
5 |
 6 | createDialog('complexModal.html',{
 7 |     id : 'complexDialog',
 8 |     title: 'A Complex Modal Dialog',
 9 |     backdrop: true,
10 |     success: {
11 |         label: 'Yay',
12 |         fn: function() {
13 |             console.log('Complex modal closed');
14 |         }
15 |     },
16 |     controller: 'ComplexModalController'
17 | },{
18 |     myVal: 15,
19 |     assetDetails: {
20 |         name: 'My Asset',
21 |         description: 'A Very Nice Asset'
22 |     }
23 | });
24 | 
25 |
26 |
27 |
The Values on the scope are:
28 |
    29 |
  • Value of Asset :
  • 30 |
  • Name of Asset :
  • 31 |
  • Asset Description :
  • 32 |
33 |
34 |
35 |
36 | -------------------------------------------------------------------------------- /src/createDialog.js: -------------------------------------------------------------------------------- 1 | angular.module('fundoo.services', []).factory('createDialog', ["$document", "$compile", "$rootScope", "$controller", "$timeout", 2 | function ($document, $compile, $rootScope, $controller, $timeout) { 3 | var defaults = { 4 | id: null, 5 | template: null, 6 | templateUrl: null, 7 | title: 'Default Title', 8 | backdrop: true, 9 | success: {label: 'OK', fn: null}, 10 | cancel: {label: 'Close', fn: null}, 11 | controller: null, //just like route controller declaration 12 | backdropClass: "modal-backdrop", 13 | backdropCancel: true, 14 | footerTemplate: null, 15 | modalClass: "modal", 16 | css: { 17 | top: '100px', 18 | left: '30%', 19 | margin: '0 auto' 20 | } 21 | }; 22 | var body = $document.find('body'); 23 | 24 | return function Dialog(templateUrl/*optional*/, options, passedInLocals) { 25 | 26 | // Handle arguments if optional template isn't provided. 27 | if(angular.isObject(templateUrl)){ 28 | passedInLocals = options; 29 | options = templateUrl; 30 | } else { 31 | options.templateUrl = templateUrl; 32 | } 33 | 34 | options = angular.extend({}, defaults, options); //options defined in constructor 35 | 36 | var key; 37 | var idAttr = options.id ? ' id="' + options.id + '" ' : ''; 38 | var defaultFooter = '' + 39 | ''; 40 | var footerTemplate = ''; 43 | var modalBody = (function(){ 44 | if(options.template){ 45 | if(angular.isString(options.template)){ 46 | // Simple string template 47 | return ''; 48 | } else { 49 | // jQuery/JQlite wrapped object 50 | return ''; 51 | } 52 | } else { 53 | // Template url 54 | return '' 55 | } 56 | })(); 57 | //We don't have the scope we're gonna use yet, so just get a compile function for modal 58 | var modalEl = angular.element( 59 | '
' + 60 | ' ' + 70 | '
'); 71 | 72 | for(key in options.css) { 73 | modalEl.css(key, options.css[key]); 74 | } 75 | var divHTML = "
2 | 3 | 4 | AngularJS Modal Services Demo 5 | 6 | 23 | 32 | 33 | 34 |
35 |
36 |

AngularJS Modal Service

37 |
38 | 39 | 40 | 41 | 42 |
43 |
44 |
45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/simpleModal.html: -------------------------------------------------------------------------------- 1 |
2 |

This is how the Simple Modal was launched

3 |
4 |
5 |
 6 | createDialog('simpleModal.html', {
 7 |     id : 'simpleDialog',
 8 |     title: 'A Simple Modal Dialog',
 9 |     backdrop: true,
10 |     success: {
11 |         label: 'Yay',
12 |         fn: function(){
13 |             console.log('Simple modal closed');
14 |         }
15 |     }
16 | });
17 | 
18 |
19 |
20 |
21 | --------------------------------------------------------------------------------