|
|
/**
|
|
|
* 弹出窗口定义文件
|
|
|
* @description 窗口核心文件
|
|
|
* @version 1.0
|
|
|
*/
|
|
|
define(function (require, exports, module) {
|
|
|
|
|
|
function Window(options) {
|
|
|
this.id = generateID('window_');
|
|
|
|
|
|
_init(this, options);
|
|
|
}
|
|
|
|
|
|
var _init = function (self, options) {
|
|
|
|
|
|
$('body').append('<div id="' + self.id + '"></div>');
|
|
|
self.$container = $('#' + self.id);
|
|
|
|
|
|
self.options = {
|
|
|
title: '',
|
|
|
content: '',
|
|
|
width: 600,
|
|
|
height: 400,
|
|
|
modal: true,
|
|
|
closed: false,
|
|
|
closable: true,
|
|
|
inline: true,
|
|
|
resizable: false,
|
|
|
minimizable: false,
|
|
|
draggable: false
|
|
|
}
|
|
|
|
|
|
_.extend(self.options, options);
|
|
|
|
|
|
self.eventHandler(options);
|
|
|
}
|
|
|
|
|
|
Window.prototype.create = function () {
|
|
|
this.$container.window(this.options);
|
|
|
// avalon.scan(this.$container[0]);
|
|
|
}
|
|
|
|
|
|
Window.prototype.open = function () {
|
|
|
if (!this.initialized) {
|
|
|
if (typeof this.init === 'function') {
|
|
|
this.init();
|
|
|
} else {
|
|
|
console.warn('自定义窗口需实现init方法!');
|
|
|
}
|
|
|
|
|
|
this.create();
|
|
|
}
|
|
|
;
|
|
|
|
|
|
this.focusObj = document.activeElement;
|
|
|
this.$container.window('open');
|
|
|
}
|
|
|
|
|
|
Window.prototype.close = function () {
|
|
|
if (this.focusObj) {
|
|
|
$(this.focusObj).focus();
|
|
|
}
|
|
|
this.$container.window('close');
|
|
|
}
|
|
|
|
|
|
Window.prototype.eventHandler = function (options) {
|
|
|
var self = this;
|
|
|
this.options.onBeforeOpen = function () {
|
|
|
if (typeof options.onBeforeOpen === 'function') {
|
|
|
options.onBeforeOpen();
|
|
|
}
|
|
|
}
|
|
|
this.options.onOpen = function () {
|
|
|
if (typeof self.customerize === 'function') {
|
|
|
self.customerize(self.$container);
|
|
|
// avalon.scan(self.$container[0]);
|
|
|
}
|
|
|
|
|
|
if (typeof options.onOpen === 'function') {
|
|
|
options.onOpen();
|
|
|
}
|
|
|
|
|
|
self.initialized = true;
|
|
|
}
|
|
|
this.options.onBeforeClose = function () {
|
|
|
if (typeof options.onBeforeClose === 'function') {
|
|
|
return options.onBeforeClose();
|
|
|
}
|
|
|
;
|
|
|
}
|
|
|
this.options.onClose = function () {
|
|
|
if (typeof options.onClose === 'function') {
|
|
|
options.onClose();
|
|
|
}
|
|
|
;
|
|
|
self.destroy();
|
|
|
}
|
|
|
|
|
|
this.options.onDestroy = function () {
|
|
|
if (typeof options.onDestroy === 'function') {
|
|
|
options.onDestroy();
|
|
|
}
|
|
|
;
|
|
|
$('body').children('span.slick-columnpicker').remove();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Window.prototype.destroy = function () {
|
|
|
this.$container.window('destroy');
|
|
|
|
|
|
}
|
|
|
|
|
|
Window.prototype.getElement = function(selector) {
|
|
|
return this.$container.find(selector);
|
|
|
}
|
|
|
|
|
|
var generateID = function (prefix) {
|
|
|
prefix = prefix || "edpr-window"
|
|
|
return String(Math.random() + Math.random()).replace(/\d\.\d{4}/, prefix)
|
|
|
}
|
|
|
|
|
|
return Window;
|
|
|
}) |