中医药大学课题数据库系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2 KiB

4 years ago
;(function(window) {
var _instance = null;
window.TallPlugin = function(config) {
this.config = config;
this.props = null;
}
// 初始化并保证是单例
TallPlugin.init = function (config) {
if (!_instance) {
_instance = new TallPlugin(config);
}
return _instance;
}
TallPlugin.prototype.created = function (callback) {
var _this = this;
window.postMessage('created');
window.addEventListener('message', function ({ data, origin }) {
try {
var target = JSON.parse(data);
if (target.success) {
_this.props = JSON.parse(data);
callback && typeof callback === 'function' && callback.call(_this, _this.props);
} else {
_this.props = null;
}
} catch (e) {
_this.props = null;
}
}, false);
// DOM加载完成
window.addEventListener('DOMContentLoaded', this.mounted, false);
// window onload
window.addEventListener('load', this.loaded, false);
// destroy
window.addEventListener('unload', this.destroy, false);
// error
window.addEventListener('error', this.error, false);
return this;
}
TallPlugin.prototype.mounted = function(callback) {
console.log('mounted');
window.postMessage('mounted');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
TallPlugin.prototype.loaded = function(callback) {
console.log('loaded');
window.postMessage('loaded');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
TallPlugin.prototype.destroy = function(callback) {
console.log('destroy');
window.postMessage('destroy');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
TallPlugin.prototype.error = function(callback) {
console.log('error');
window.postMessage('error');
callback && typeof callback === 'function' && callback.call(this);
return this;
}
})(window)