(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. Qt调用JS(二)

    转自:http://www.cnblogs.com/verstin/p/4908673.html <html> <script language="JavaScript&q ...

  2. python格式化日期

    #!/usr/bin/python # -*- coding: UTF-8 -*- import time import calendar """ 时间元组(年.月.日. ...

  3. Java Web(八) 事务,安全问题及隔离级别

    事务 什么是事务? 事务就是一组原子性的SQL查询,或者说是一个独立的工作单元. 事务的作用 事务在我们平常的CRUD(增删改查)操作当中也许不太常用, 但是如果我们有一种需求,一组操作中必须全部成功 ...

  4. Win10系列:VC++文件选取

    在C++/CX的Windows::Storage::Pickers命名空间中定义了一个FileOpenPicker类,使用此类可以新建一个文件打开选取器,并可以通过这个类里面包含的属性和函数选取一个或 ...

  5. python中的argparse模块(参数解析)

    import argparseparse = argparse.ArgumentParser()parse.add_argument("a", help="params ...

  6. FPGA复位的可靠性(转)

    FPGA复位的可靠性(同步复位和异步复位)  reference:http://www.eetop.cn/blog/html/17/743817-24442.html 一.特点: 同步复位:顾名思义, ...

  7. byte[]->new String(byte[]) -> getByte()引发的不一致问题

    今天接短信接口,短信接口提供了sdk,我们可以直接用sdk发送请求然后发送对应短信. 但是想使用我们平台自定义的httpUtil实现. 然而忙了1天半,才解决这个问题,还是我同事帮忙找出问题并解决的. ...

  8. Ionic2开发环境搭建、项目创建调试与Android应用的打包、优化

    Ionic2开发环境搭建.项目创建调试与Android应用的打包.优化. windows下ionic2开发环境配置步骤如下: 下载node.js环境,稳定版本:v6.9.5 下载android stu ...

  9. POJ - 2635 E - The Embarrassed Cryptographer

    The young and very promising cryptographer Odd Even has implemented the security module of a large s ...

  10. 缓存一致性协议 mesi

    m : modified e : exlusive s : shared i : invalid 四种状态的转换略过,现在讨论为什么有了这个协议,i++在多线程上还不是安全的. 两个cpu A B同时 ...