(function() {
angular.module('app.widgets')
.directive('bsModalPlus', function($window, $sce, $modal) {
return {
restrict: 'A',
scope: true,
link: function(scope, element, attr, transclusion) {
// Directive options
var options = { scope: scope, element: element, show: false };
angular.forEach(['template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation', 'backdropAnimation', 'id', 'prefixEvent', 'prefixClass'], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
}); // Default template url
if (!options['templateUrl'] || options['templateUrl'].length == 0)
options['templateUrl'] = 'widgets/modal/modal.template.html' // use string regex match boolean attr falsy values, leave truthy values be
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach(['backdrop', 'keyboard', 'html', 'container'], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key]))
options[key] = false;
}); // Support scope as data-attrs
angular.forEach(['title', 'content'], function(key) {
attr[key] && attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
});
}); //default container and placement
if (!options['container'])
options['container'] = 'body'; if (!options['backdrop'])
options['backdrop'] = 'static'; if (!options['placement'])
options['placement'] = 'center'; options['animation'] = 'am-fade-and-slide-top' // Support scope as an object
scope.$data = {};
attr.bsModalPlus && scope.$watch(attr.bsModalPlus, function(newValue, oldValue) {
if (angular.isObject(newValue)) {
angular.extend(scope.$data, newValue);
} else {
scope.content = newValue;
}
}, true); scope.showOkButton = !attr.showOkButton || attr.showOkButton == "true";
scope.showCloseButton = !attr.showCloseButton || attr.showCloseButton == "true"; // Initialize modal
var modal = $modal(options);
scope.$ok = function() {
if (scope.$broadcast("ok").defaultPrevented)
modal.hide();
};
scope.$close = function() {
scope.$broadcast("close");
modal.hide();
}; // Trigger
element.on(attr.trigger || 'click', modal.toggle); // Garbage collection
scope.$on('$destroy', function() {
if (modal) modal.destroy();
options = null;
modal = null;
}); }
}; });
})();

directive例子2的更多相关文章

  1. directive例子1

    (function() { 'use strict'; angular.module('app.widgets') .directive('confirm', ['confirm2', 'toastr ...

  2. vuejs心法和技法

    原文地址:http://www.cnblogs.com/kidsitcn/p/5409994.html 所有的vuejs组件都是被扩展的vue实例: var MyComponent = Vue.ext ...

  3. AngularJS directive入门例子

    这是<AngularJS>这本书里面提供的一个例子: JS代码: var expanderModule=angular.module('expanderModule', []) expan ...

  4. Directive间的通信

    Directive间的通信 源自大漠的<AngularJS>5个实例详解Directive(指令)机制 这个例子主要的难点在于如何在子Expander里面访问外层Accordion的sco ...

  5. AngularJS之Directive(三)

    前言 angular核心部分如下图几大块,最重要的莫过于指令这一部分,本文将重点讲解指令这一部分,后续笔者将通过陆续的学习来叙述其他如:factory.service等,若有叙述错误之处,欢迎各位指正 ...

  6. Angular自定义指令directive:scope属性

    在AngularJS中,除了内置指令如ng-click等,我们还可以自定义指令.自定义指令,是为了扩展DOM元素的功能.代码中,通过指定directive中的restrict属性,来决定这个指令是作为 ...

  7. angular.js 例子

    angular.js是一个前端的MVC框架,12年的时候曾近在一个portal平台的项目中使用过. 下面给出一个angular.js的典型例子,涵盖一些基础的知识点,用以复习备忘: <html ...

  8. AngularJS中Directive指令系列 - scope属性的使用

    文章是转的,我做下补充.原文地址:https://segmentfault.com/a/1190000002773689 每当一个指令被创建的时候,都会有这样一个选择,是继承自己的父作用域(一般是外部 ...

  9. [译]Exploring Angular 1.3: Binding to Directive Controllers

    原文: http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html Angul ...

随机推荐

  1. maven聚合工程使用如何debug

    maven聚合工程在正常情况下,使用debug时会出错,因为没有源码,就不会显示代码和断点行数条. 进行如下操作: 默认情况下source下只有默认的default文件夹,点击remove进行删除(这 ...

  2. Python3各种进制之间的转换方法

    一.2/8/10/16进制互转 1.1 2/8/10/16进制赋值 # 二进制赋值以0b打头 a = 0b1000 # 八进制赋值以0o打头,第一个是数字0第二个是字母o b = 0o1100 # 十 ...

  3. ffmpeg+libmp3lame库源码安装教程(CentOS)

    lame--libmp3lame的安装包,支持MP3编码:yasm--NASM的重写,用于编译ffmpeg. 1.下载 ffmpeg下载链接:http://ffmpeg.org/download.ht ...

  4. ProtoBuf 常用序列化/反序列化API 转

    http://blog.csdn.net/sealyao/article/details/6940245 1.C数组的序列化和反序列化API //C数组的序列化和序列化API bool ParseFr ...

  5. nyoj-0469-擅长排列的小明 II(找规律)

    nyoj-0469-擅长排列的小明 II 思路:递推分析:为了简便起见,我们用Ai代表第i个数字 , 由于A1一直是1,所以A2只能是2或3.假设dp[n]表示1->n这个序列的方案数      ...

  6. learning hdmi edid protocol

    referenc: https://en.wikipedia.org/wiki/Extended_Display_Identification_Data

  7. lodash 学习资料

    lodash.js 是什么不多说,工作时间长了就基本绕不过去他,工作项目中也很好的弥补angular ,jquery 的不足,由中文bootstrap 退出的中文版学习资料 http://lodash ...

  8. NOIP2018复赛获奖名单

    根据<CCF NOIP2018复赛获奖分数线及名额分配办法>,现将NOIP2018复赛获奖名单公告如下: 复赛提高组一等奖获奖名单 复赛提高组二等奖获奖名单 复赛提高组三等奖获奖名单 复赛 ...

  9. [Linux]Linux下开启snmp支持IPV4和IPV6

    SNMP简介 简单网络管理协议(SNMP),由一组网络管理的标准组成,包含一个应用层协议(application layer protocol).数据库模型(database schema)和一组资源 ...

  10. 十九. Python基础(19)--异常

    十九. Python基础(19)--异常 1 ● 捕获异常 if VS异常处理: if是预防异常出现, 异常处理是处理异常出现 异常处理一般格式: try:     <............. ...