/*! artdialog v6.0.5 | https://github.com/aui/artdialog */ !(function () { var __modules__ = {}; function require (id) { var mod = __modules__[id]; var exports = 'exports'; if (typeof mod === 'object') { return mod; } if (!mod[exports]) { mod[exports] = {}; mod[exports] = mod.call(mod[exports], require, mod[exports], mod) || mod[exports]; } return mod[exports]; } function define (path, fn) { __modules__[path] = fn; } define("jquery", function () { return jquery; }); /*! * popupjs * date: 2014-11-09 * https://github.com/aui/popupjs * (c) 2009-2014 tangbin, http://www.planeart.cn * * this is licensed under the gnu lgpl, version 2.1 or later. * for details, see: http://www.gnu.org/licenses/lgpl-2.1.html */ define("popup", function (require) { var $ = require("jquery"); var _count = 0; var _isie6 = !('minwidth' in $('html')[0].style); var _isfixed = !_isie6; function popup () { this.destroyed = false; this.__popup = $('
') /*使用 元素可能导致 z-index 永远置顶的问题(chrome)*/ .css({ display: 'none', position: 'absolute', /* left: 0, top: 0, bottom: 'auto', right: 'auto', margin: 0, padding: 0, border: '0 none', background: 'transparent' */ outline: 0 }) .attr('tabindex', '-1') .html(this.innerhtml) .appendto('body'); this.__backdrop = this.__mask = $('
') .css({ opacity: .7, background: '#000' }); // 使用 htmlelement 作为外部接口使用,而不是 jquery 对象 // 统一的接口利于未来 popup 移植到其他 dom 库中 this.node = this.__popup[0]; this.backdrop = this.__backdrop[0]; _count ++; } $.extend(popup.prototype, { /** * 初始化完毕事件,在 show()、showmodal() 执行 * @name popup.prototype.onshow * @event */ /** * 关闭事件,在 close() 执行 * @name popup.prototype.onclose * @event */ /** * 销毁前事件,在 remove() 前执行 * @name popup.prototype.onbeforeremove * @event */ /** * 销毁事件,在 remove() 执行 * @name popup.prototype.onremove * @event */ /** * 重置事件,在 reset() 执行 * @name popup.prototype.onreset * @event */ /** * 焦点事件,在 foucs() 执行 * @name popup.prototype.onfocus * @event */ /** * 失焦事件,在 blur() 执行 * @name popup.prototype.onblur * @event */ /** 浮层 dom 素节点[*] */ node: null, /** 遮罩 dom 节点[*] */ backdrop: null, /** 是否开启固定定位[*] */ fixed: false, /** 判断对话框是否删除[*] */ destroyed: true, /** 判断对话框是否显示 */ open: false, /** close 返回值 */ returnvalue: '', /** 是否自动聚焦 */ autofocus: true, /** 对齐方式[*] */ align: 'bottom left', /** 内部的 html 字符串 */ innerhtml: '', /** css 类名 */ classname: 'ui-popup', /** * 显示浮层 * @param {htmlelement, event} 指定位置(可选) */ show: function (anchor) { if (this.destroyed) { return this; } var that = this; var popup = this.__popup; var backdrop = this.__backdrop; this.__activeelement = this.__getactive(); this.open = true; this.follow = anchor || this.follow; // 初始化 show 方法 if (!this.__ready) { popup .addclass(this.classname) .attr('role', this.modal ? 'alertdialog' : 'dialog') .css('position', this.fixed ? 'fixed' : 'absolute'); if (!_isie6) { $(window).on('resize', $.proxy(this.reset, this)); } // 模态浮层的遮罩 if (this.modal) { var backdropcss = { position: 'fixed', left: 0, top: 0, width: '100%', height: '100%', overflow: 'hidden', userselect: 'none', zindex: this.zindex || popup.zindex }; popup.addclass(this.classname + '-modal'); if (!_isfixed) { $.extend(backdropcss, { position: 'absolute', width: $(window).width() + 'px', height: $(document).height() + 'px' }); } backdrop .css(backdropcss) .attr({tabindex: '0'}) .on('focus', $.proxy(this.focus, this)); // 锁定 tab 的焦点操作 this.__mask = backdrop .clone(true) .attr('style', '') .insertafter(popup); backdrop .addclass(this.classname + '-backdrop') .insertbefore(popup); this.__ready = true; } if (!popup.html()) { popup.html(this.innerhtml); } } popup .addclass(this.classname + '-show') .show(); backdrop.show(); this.reset().focus(); this.__dispatchevent('show'); return this; }, /** 显示模态浮层。参数参见 show() */ showmodal: function () { this.modal = true; return this.show.apply(this, arguments); }, /** 关闭浮层 */ close: function (result) { if (!this.destroyed && this.open) { if (result !== undefined) { this.returnvalue = result; } this.__popup.hide().removeclass(this.classname + '-show'); this.__backdrop.hide(); this.open = false; this.blur();// 恢复焦点,照顾键盘操作的用户 this.__dispatchevent('close'); } return this; }, /** 销毁浮层 */ remove: function () { if (this.destroyed) { return this; } this.__dispatchevent('beforeremove'); if (popup.current === this) { popup.current = null; } // 从 dom 中移除节点 this.__popup.remove(); this.__backdrop.remove(); this.__mask.remove(); if (!_isie6) { $(window).off('resize', this.reset); } this.__dispatchevent('remove'); for (var i in this) { delete this[i]; } return this; }, /** 重置位置 */ reset: function () { var elem = this.follow; if (elem) { this.__follow(elem); } else { this.__center(); } this.__dispatchevent('reset'); return this; }, /** 让浮层获取焦点 */ focus: function () { var node = this.node; var popup = this.__popup; var current = popup.current; var index = this.zindex = popup.zindex ++; if (current && current !== this) { current.blur(false); } // 检查焦点是否在浮层里面 if (!$.contains(node, this.__getactive())) { var autofocus = popup.find('[autofocus]')[0]; if (!this._autofocus && autofocus) { this._autofocus = true; } else { autofocus = node; } this.__focus(autofocus); } // 设置叠加高度 popup.css('zindex', index); //this.__backdrop.css('zindex', index); popup.current = this; popup.addclass(this.classname + '-focus'); this.__dispatchevent('focus'); return this; }, /** 让浮层失去焦点。将焦点退还给之前的元素,照顾视力障碍用户 */ blur: function () { var activeelement = this.__activeelement; var isblur = arguments[0]; if (isblur !== false) { this.__focus(activeelement); } this._autofocus = false; this.__popup.removeclass(this.classname + '-focus'); this.__dispatchevent('blur'); return this; }, /** * 添加事件 * @param {string} 事件类型 * @param {function} 监听函数 */ addeventlistener: function (type, callback) { this.__geteventlistener(type).push(callback); return this; }, /** * 删除事件 * @param {string} 事件类型 * @param {function} 监听函数 */ removeeventlistener: function (type, callback) { var listeners = this.__geteventlistener(type); for (var i = 0; i < listeners.length; i ++) { if (callback === listeners[i]) { listeners.splice(i--, 1); } } return this; }, // 获取事件缓存 __geteventlistener: function (type) { var listener = this.__listener; if (!listener) { listener = this.__listener = {}; } if (!listener[type]) { listener[type] = []; } return listener[type]; }, // 派发事件 __dispatchevent: function (type) { var listeners = this.__geteventlistener(type); if (this['on' + type]) { this['on' + type](); } for (var i = 0; i < listeners.length; i ++) { listeners[i].call(this); } }, // 对元素安全聚焦 __focus: function (elem) { // 防止 iframe 跨域无权限报错 // 防止 ie 不可见元素报错 try { // ie11 bug: iframe 页面点击会跳到顶部 if (this.autofocus && !/^iframe$/i.test(elem.nodename)) { elem.focus(); } } catch (e) {} }, // 获取当前焦点的元素 __getactive: function () { try {// try: ie8~9, iframe #26 var activeelement = document.activeelement; var contentdocument = activeelement.contentdocument; var elem = contentdocument && contentdocument.activeelement || activeelement; return elem; } catch (e) {} }, // 居中浮层 __center: function () { var popup = this.__popup; var $window = $(window); var $document = $(document); var fixed = this.fixed; var dl = fixed ? 0 : $document.scrollleft(); var dt = fixed ? 0 : $document.scrolltop(); var ww = $window.width(); var wh = $window.height(); var ow = popup.width(); var oh = popup.height(); var left = (ww - ow) / 2 + dl; var top = (wh - oh) * 382 / 1000 + dt;// 黄金比例 var style = popup[0].style; style.left = math.max(parseint(left), dl) + 'px'; style.top = math.max(parseint(top), dt) + 'px'; }, // 指定位置 @param {htmlelement, event} anchor __follow: function (anchor) { var $elem = anchor.parentnode && $(anchor); var popup = this.__popup; if (this.__followskin) { popup.removeclass(this.__followskin); } // 隐藏元素不可用 if ($elem) { var o = $elem.offset(); if (o.left * o.top < 0) { return this.__center(); } } var that = this; var fixed = this.fixed; var $window = $(window); var $document = $(document); var winwidth = $window.width(); var winheight = $window.height(); var docleft = $document.scrollleft(); var doctop = $document.scrolltop(); var popupwidth = popup.width(); var popupheight = popup.height(); var width = $elem ? $elem.outerwidth() : 0; var height = $elem ? $elem.outerheight() : 0; var offset = this.__offset(anchor); var x = offset.left; var y = offset.top; var left = fixed ? x - docleft : x; var top = fixed ? y - doctop : y; var minleft = fixed ? 0 : docleft; var mintop = fixed ? 0 : doctop; var maxleft = minleft + winwidth - popupwidth; var maxtop = mintop + winheight - popupheight; var css = {}; var align = this.align.split(' '); var classname = this.classname + '-'; var reverse = {top: 'bottom', bottom: 'top', left: 'right', right: 'left'}; var name = {top: 'top', bottom: 'top', left: 'left', right: 'left'}; var temp = [{ top: top - popupheight, bottom: top + height, left: left - popupwidth, right: left + width }, { top: top, bottom: top - popupheight + height, left: left, right: left - popupwidth + width }]; var center = { left: left + width / 2 - popupwidth / 2, top: top + height / 2 - popupheight / 2 }; var range = { left: [minleft, maxleft], top: [mintop, maxtop] }; // 超出可视区域重新适应位置 $.each(align, function (i, val) { // 超出右或下边界:使用左或者上边对齐 if (temp[i][val] > range[name[val]][1]) { val = align[i] = reverse[val]; } // 超出左或右边界:使用右或者下边对齐 if (temp[i][val] < range[name[val]][0]) { align[i] = reverse[val]; } }); // 一个参数的情况 if (!align[1]) { name[align[1]] = name[align[0]] === 'left' ? 'top' : 'left'; temp[1][align[1]] = center[name[align[1]]]; } //添加follow的css, 为了给css使用 classname += align.join('-') + ' '+ this.classname+ '-follow'; that.__followskin = classname; if ($elem) { popup.addclass(classname); } css[name[align[0]]] = parseint(temp[0][align[0]]); css[name[align[1]]] = parseint(temp[1][align[1]]); popup.css(css); }, // 获取元素相对于页面的位置(包括iframe内的元素) // 暂时不支持两层以上的 iframe 套嵌 __offset: function (anchor) { var isnode = anchor.parentnode; var offset = isnode ? $(anchor).offset() : { left: anchor.pagex, top: anchor.pagey }; anchor = isnode ? anchor : anchor.target; var ownerdocument = anchor.ownerdocument; var defaultview = ownerdocument.defaultview || ownerdocument.parentwindow; if (defaultview == window) {// ie <= 8 只能使用两个等于号 return offset; } // {element: ifarme} var frameelement = defaultview.frameelement; var $ownerdocument = $(ownerdocument); var docleft = $ownerdocument.scrollleft(); var doctop = $ownerdocument.scrolltop(); var frameoffset = $(frameelement).offset(); var frameleft = frameoffset.left; var frametop = frameoffset.top; return { left: offset.left + frameleft - docleft, top: offset.top + frametop - doctop }; } }); /** 当前叠加高度 */ popup.zindex = 1024; /** 顶层浮层的实例 */ popup.current = null; return popup; }); // artdialog - 默认配置 define("dialog-config", { /* -----已注释的配置继承自 popup.js,仍可以再这里重新定义它----- */ // 对齐方式 //align: 'bottom left', // 是否固定定位 //fixed: false, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制) //zindex: 1024, // 设置遮罩背景颜色 backdropbackground: '#000', // 设置遮罩透明度 backdropopacity: 0.7, // 消息内容 content: 'loading..', // 标题 title: '', // 对话框状态栏区域 html 代码 statusbar: '', // 自定义按钮 button: null, // 确定按钮回调函数 ok: null, // 取消按钮回调函数 cancel: null, // 确定按钮文本 okvalue: 'ok', // 取消按钮文本 cancelvalue: 'cancel', canceldisplay: true, // 内容宽度 width: '', // 内容高度 height: '', // 内容与边界填充距离 padding: '', // 对话框自定义 classname skin: '', // 是否支持快捷关闭(点击遮罩层自动关闭) quickclose: false, // css 文件路径,留空则不会使用 js 自动加载样式 // 注意:css 只允许加载一个 cssuri: '../css/ui-dialog.css', // 模板(使用 table 解决 ie7 宽度自适应的 bug) // js 使用 i="***" 属性识别结构,其余的均可自定义 innerhtml: '
' + '
' + '
' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
' + '' + '
' + '
' + '
' + '
' +'
' }); /*! * artdialog * date: 2014-11-09 * https://github.com/aui/artdialog * (c) 2009-2014 tangbin, http://www.planeart.cn * * this is licensed under the gnu lgpl, version 2.1 or later. * for details, see: http://www.gnu.org/licenses/lgpl-2.1.html */ define("dialog", function (require) { var $ = require("jquery"); var popup = require("popup"); var defaults = require("dialog-config"); var css = defaults.cssuri; // css loader: requirejs & seajs if (css) { var fn = require[require.tourl ? 'tourl' : 'resolve']; if (fn) { css = fn(css); css = ''; if ($('base')[0]) { $('base').before(css); } else { $('head').append(css); } } } var _count = 0; var _expando = new date() - 0; // date.now() var _isie6 = !('minwidth' in $('html')[0].style); var _ismobile = 'createtouch' in document && !('onmousemove' in document) || /(iphone|ipad|ipod)/i.test(navigator.useragent); var _isfixed = !_isie6 && !_ismobile; var artdialog = function (options, ok, cancel) { var originaloptions = options = options || {}; if (typeof options === 'string' || options.nodetype === 1) { options = {content: options, fixed: !_ismobile}; } options = $.extend(true, {}, artdialog.defaults, options); options.original = originaloptions; var id = options.id = options.id || _expando + _count; var api = artdialog.get(id); // 如果存在同名的对话框对象,则直接返回 if (api) { return api.focus(); } // 目前主流移动设备对fixed支持不好,禁用此特性 if (!_isfixed) { options.fixed = false; } // 快捷关闭支持:点击对话框外快速关闭对话框 if (options.quickclose) { options.modal = true; options.backdropopacity = 0; } // 按钮组 if (!$.isarray(options.button)) { options.button = []; } // 取消按钮 if (cancel !== undefined) { options.cancel = cancel; } if (options.cancel) { options.button.push({ id: 'cancel', value: options.cancelvalue, callback: options.cancel, display: options.canceldisplay }); } // 确定按钮 if (ok !== undefined) { options.ok = ok; } if (options.ok) { options.button.push({ id: 'ok', value: options.okvalue, callback: options.ok, autofocus: true }); } return artdialog.list[id] = new artdialog.create(options); }; var popup = function () {}; popup.prototype = popup.prototype; var prototype = artdialog.prototype = new popup(); artdialog.create = function (options) { var that = this; $.extend(this, new popup()); var originaloptions = options.original; var $popup = $(this.node).html(options.innerhtml); var $backdrop = $(this.backdrop); this.options = options; this._popup = $popup; $.each(options, function (name, value) { if (typeof that[name] === 'function') { that[name](value); } else { that[name] = value; } }); // 更新 zindex 全局配置 if (options.zindex) { popup.zindex = options.zindex; } // 设置 aria 信息 $popup.attr({ 'aria-labelledby': this._$('title') .attr('id', 'title:' + this.id).attr('id'), 'aria-describedby': this._$('content') .attr('id', 'content:' + this.id).attr('id') }); // 关闭按钮 this._$('close') .css('display', this.cancel === false ? 'none' : '') .attr('title', this.cancelvalue) .on('click', function (event) { that._trigger('cancel'); event.preventdefault(); }); // 添加视觉参数 this._$('dialog').addclass(this.skin); this._$('body').css('padding', this.padding); // 点击任意空白处关闭对话框 if (options.quickclose) { $backdrop .on( 'onmousedown' in document ? 'mousedown' : 'click', function () { that._trigger('cancel'); return false;// 阻止抢夺焦点 }); } // 遮罩设置 this.addeventlistener('show', function () { $backdrop.css({ opacity: 0, background: options.backdropbackground }).animate( {opacity: options.backdropopacity} , 150); }); // esc 快捷键关闭对话框 this._esc = function (event) { var target = event.target; var nodename = target.nodename; var rinput = /^input|textarea$/i; var istop = popup.current === that; var keycode = event.keycode; // 避免输入状态中 esc 误操作关闭 if (!istop || rinput.test(nodename) && target.type !== 'button') { return; } if (keycode === 27) { that._trigger('cancel'); } }; $(document).on('keydown', this._esc); this.addeventlistener('remove', function () { $(document).off('keydown', this._esc); delete artdialog.list[this.id]; }); _count ++; artdialog.oncreate(this); return this; }; artdialog.create.prototype = prototype; $.extend(prototype, { /** * 显示对话框 * @name artdialog.prototype.show * @param {htmlelement object, event object} 指定位置(可选) */ /** * 显示对话框(模态) * @name artdialog.prototype.showmodal * @param {htmlelement object, event object} 指定位置(可选) */ /** * 关闭对话框 * @name artdialog.prototype.close * @param {string, number} 返回值,可被 onclose 事件收取(可选) */ /** * 销毁对话框 * @name artdialog.prototype.remove */ /** * 重置对话框位置 * @name artdialog.prototype.reset */ /** * 让对话框聚焦(同时置顶) * @name artdialog.prototype.focus */ /** * 让对话框失焦(同时置顶) * @name artdialog.prototype.blur */ /** * 添加事件 * @param {string} 事件类型 * @param {function} 监听函数 * @name artdialog.prototype.addeventlistener */ /** * 删除事件 * @param {string} 事件类型 * @param {function} 监听函数 * @name artdialog.prototype.removeeventlistener */ /** * 对话框显示事件,在 show()、showmodal() 执行 * @name artdialog.prototype.onshow * @event */ /** * 关闭事件,在 close() 执行 * @name artdialog.prototype.onclose * @event */ /** * 销毁前事件,在 remove() 前执行 * @name artdialog.prototype.onbeforeremove * @event */ /** * 销毁事件,在 remove() 执行 * @name artdialog.prototype.onremove * @event */ /** * 重置事件,在 reset() 执行 * @name artdialog.prototype.onreset * @event */ /** * 焦点事件,在 foucs() 执行 * @name artdialog.prototype.onfocus * @event */ /** * 失焦事件,在 blur() 执行 * @name artdialog.prototype.onblur * @event */ /** * 设置内容 * @param {string, htmlelement} 内容 */ content: function (html) { var $content = this._$('content'); // htmlelement if (typeof html === 'object') { html = $(html); $content.empty('').append(html.show()); this.addeventlistener('beforeremove', function () { $('body').append(html.hide()); }); // string } else { $content.html(html); } return this.reset(); }, /** * 设置标题 * @param {string} 标题内容 */ title: function (text) { this._$('title').text(text); this._$('header')[text ? 'show' : 'hide'](); return this; }, /** 设置宽度 */ width: function (value) { this._$('content').css('width', value); return this.reset(); }, /** 设置高度 */ height: function (value) { this._$('content').css('height', value); return this.reset(); }, /** * 设置按钮组 * @param {array, string} * options: value, callback, autofocus, disabled */ button: function (args) { args = args || []; var that = this; var html = ''; var number = 0; this.callbacks = {}; if (typeof args === 'string') { html = args; number ++; } else { $.each(args, function (i, val) { var id = val.id = val.id || val.value; var style = ''; that.callbacks[id] = val.callback; if (val.display === false) { style = ' style="display:none"'; } else { number ++; } html += '' + val.value + ''; that._$('button') .on('click', '[i-id=' + id +']', function (event) { var $this = $(this); if (!$this.attr('disabled')) {// ie bug that._trigger(id); } event.preventdefault(); }); }); } this._$('button').html(html); this._$('footer')[number ? 'show' : 'hide'](); return this; }, statusbar: function (html) { this._$('statusbar') .html(html)[html ? 'show' : 'hide'](); return this; }, _$: function (i) { return this._popup.find('[i=' + i + ']'); }, // 触发按钮回调函数 _trigger: function (id) { var fn = this.callbacks[id]; return typeof fn !== 'function' || fn.call(this) !== false ? this.close().remove() : this; } }); artdialog.oncreate = $.noop; /** 获取最顶层的对话框api */ artdialog.getcurrent = function () { return popup.current; }; /** * 根据 id 获取某对话框 api * @param {string} 对话框 id * @return {object} 对话框 api (实例) */ artdialog.get = function (id) { return id === undefined ? artdialog.list : artdialog.list[id]; }; artdialog.list = {}; /** * 默认配置 */ artdialog.defaults = defaults; return artdialog; }); window.dialog = require("dialog"); })();