/* * ngDialog - easy modals and popup windows * http://github.com/likeastore/ngDialog * (c) 2013 MIT License, https://likeastore.com */ (function (window, angular, undefined) { 'use strict'; var module = angular.module('ngDialog', []); var $el = angular.element; var isDef = angular.isDefined; var style = (document.body || document.documentElement).style; var animationEndSupport = isDef(style.animation) || isDef(style.WebkitAnimation) || isDef(style.MozAnimation) || isDef(style.MsAnimation) || isDef(style.OAnimation); var animationEndEvent = 'animationend webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend'; module.provider('ngDialog', function () { var defaults = this.defaults = { className: 'ngdialog-theme-default', plain: false, showClose: true, closeByDocument: true, closeByEscape: true }; var globalID = 0, dialogsCount = 0, closeByDocumentHandler; this.$get = ['$document', '$templateCache', '$compile', '$q', '$http', '$rootScope', '$timeout', function ($document, $templateCache, $compile, $q, $http, $rootScope, $timeout) { var $body = $document.find('body'); var privateMethods = { onDocumentKeydown: function (event) { if (event.keyCode === 27) { publicMethods.close(); } }, closeDialog: function ($dialog) { if (typeof window.Hammer !== 'undefined') { window.Hammer($dialog[0]).off('tap', closeByDocumentHandler); } else { $dialog.unbind('click'); } if (dialogsCount === 1) { $body.unbind('keydown'); } if (!$dialog.hasClass("ngdialog-closing")) { dialogsCount -= 1; } if (animationEndSupport) { $dialog.unbind(animationEndEvent).bind(animationEndEvent, function () { $dialog.scope().$destroy(); $dialog.remove(); if (dialogsCount === 0) { $body.removeClass('ngdialog-open'); } }).addClass('ngdialog-closing'); } else { $dialog.scope().$destroy(); $dialog.remove(); if (dialogsCount === 0) { $body.removeClass('ngdialog-open'); } } $rootScope.$broadcast('ngDialog.closed', $dialog); } }; var publicMethods = { /* * @param {Object} options: * - template {String} - id of ng-template, url for partial, plain string (if enabled) * - plain {Boolean} - enable plain string templates, default false * - scope {Object} * - controller {String} * - className {String} - dialog theme class * - showClose {Boolean} - show close button, default true * - closeByEscape {Boolean} - default true * - closeByDocument {Boolean} - default true * * @return {Object} dialog */ open: function (opts) { var self = this; var options = angular.copy(defaults); opts = opts || {}; angular.extend(options, opts); globalID += 1; self.latestID = 'ngdialog' + globalID; var scope = angular.isObject(options.scope) ? options.scope.$new() : $rootScope.$new(); var $dialog; $q.when(loadTemplate(options.template)).then(function (template) { template = angular.isString(template) ? template : template.data && angular.isString(template.data) ? template.data : ''; $templateCache.put(options.template, template); if (options.showClose) { template += '
'; } self.$result = $dialog = $el(''); $dialog.html('