forked from wyntau/angular-ios-alertview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-ios-alertview.min.js
8 lines (8 loc) · 3.16 KB
/
angular-ios-alertview.min.js
1
2
3
4
5
6
7
8
/*!
* angular-ios-alertview 1.4.2
* iOS7+ style alertview service for angular
* License: MIT
* Author: Treri
* build: Thu Feb 04 2016 14:20:21 GMT+0100 (CET)
**/
angular.module("angular-ios-alertview",[]).directive("iosAlertView",function(){return{restrict:"AE",replace:!0,template:['<div class="ios-alertview-overlay" ng-cloak>','<div class="ios-alertview">','<div class="ios-alertview-inner" ng-class="{\'ios-alertview-inner-remind\': !buttons || !buttons.length}">','<div class="ios-alertview-title" ng-if="title">{{ title }}</div>','<div class="ios-alertview-text" ng-bind-html="renderHtml(text)" ng-if="text"></div>','<input autofocus class="ios-alertview-text-input" type="{{ inputType }}" placeholder="{{ inputPlaceholder }}" ng-model="form.inputValue" ng-if="input" />',"</div>",'<div class="ios-alertview-buttons" ng-if="buttons.length" ng-class="{\'ios-alertview-buttons-horizontal\': buttons.length <= 2}">','<span class="ios-alertview-button" ng-class="{\'ios-alertview-button-bold\': button.bold}" ng-repeat="button in buttons" ng-click="onClick($event, button, $index)">{{ button.text }}</span>',"</div>","</div>","</div>"].join(""),controller:["$scope","$sce",function(e,t){e.renderHtml=function(e){return t.trustAsHtml(e)}}]}}).provider("iosAlertView",function(){var e={title:null,text:null,input:!1,inputType:"text",inputPlaceholder:"",cancelText:"Cancel",okText:"OK",remindTime:250,defaultOption:"text"},t=Object.keys(e),n=this;n.set=function(i,r){if(angular.isObject(i))for(var o in i)n.set(o,i[o]);else i&&t.indexOf(i)>-1&&r&&(e[i]=r)},this.$get=["$rootScope","$compile","$animate","$q","$document","$timeout","$log",function(t,n,i,r,o,l,a){function u(u){if(!angular.isObject(u))return a.error("iosAlertView expect object option"),r.when();var s=r.defer(),c=t.$new(!0);angular.extend(c,e,u,{form:{}});var d=n("<div ios-alert-view></div>")(c);return c.onClick=function(e,t,n){e.preventDefault(),e.stopPropagation();var r=c.form.inputValue,o={index:n,button:t,inputValue:r};angular.isFunction(t.onClick)&&t.onClick(o),i.leave(d).then(function(){s.resolve(o)})},i.enter(d,o[0].body,o[0].body.lastChild),c.buttons&&c.buttons.length||l(function(){i.leave(d).then(function(){s.resolve()})},450+1*c.remindTime),s.promise}function s(t){if(angular.isObject(t))return t;var n={};return angular.isString(t)?n[e.defaultOption]=t:a.error("expect a string or an object"),n}function c(t){var n=r.defer();return t=s(t),t=angular.extend({},e,t),t=angular.extend(t,{buttons:[{text:t.okText,onClick:n.resolve,bold:!0}]}),u(t).then(n.resolve,n.reject),n.promise}function d(t){var n=r.defer();return t=s(t),t=angular.extend({},e,t),t=angular.extend(t,{buttons:[{text:t.cancelText,onClick:n.reject},{text:t.okText,onClick:n.resolve,bold:!0}]}),u(t).then(n.resolve,n.reject),n.promise}function v(t){var n=r.defer();return t=s(t),t=angular.extend({},e,t),t=angular.extend(t,{input:!0,buttons:[{text:t.cancelText,onClick:n.reject},{text:t.okText,onClick:function(e){n.resolve(e.inputValue)},bold:!0}]}),u(t).then(function(e){n.resolve(e.inputValue)},n.reject),n.promise}function p(t){var n=r.defer();return t=s(t),t=angular.extend({},e,t),u(t).then(n.resolve,n.reject),n.promise}return u.alert=c,u.confirm=d,u.prompt=v,u.remind=p,u}]});