/* カスタマイズ用のJavaScriptコードをここに記述してください */ function modalLib (title, content, options) { this.opts = $.extend({ modal: $('#modal'), overlay: $('#modal-overlay'), delay : 0, btnOpen: null, btnClose: $('#modal .btn_close_modal'), onClose: function () {return false}, onOpen: function () {return false}, }, options); this.title = title || ''; this.content = content || ''; this.isOpening = false; this.modal = this.opts.modal; this.overlay = this.opts.overlay this.btnOpen = this.opts.btnOpen; this.btnClose = this.opts.btnClose; var _this = this; if (this.btnOpen && this.btnOpen.length > 0) { this.btnOpen.unbind(); this.btnOpen.on('click', function () { _this.open(); }); } if (this.btnClose && this.btnClose.length > 0) { this.btnClose.unbind(); this.btnClose.on('click', function () { _this.close(); }); } } modalLib.prototype.open = function (title, content) { $('input').blur(); // add blur when click show model this.title = title || this.title; this.content = content || this.content; if (typeof this.opts.onOpen == "function") { this.opts.onOpen(); } this.setTitle(this.title); this.setContent(this.content); this.overlay.fadeIn(this.opts.delay); this.modal.fadeIn(this.opts.delay); this.isOpening = true; } modalLib.prototype.close = function () { if (typeof this.opts.onClose == "function") { this.opts.onClose(); } this.reset(); this.modal.fadeOut(this.opts.delay); this.overlay.fadeOut(this.opts.delay); } modalLib.prototype.setTitle = function (title) { title = title || ''; var titleElm = this.modal.find('.title'); if (titleElm.length >0) { titleElm.html(title); } } modalLib.prototype.setContent = function (content) { content = content || ''; var contentElm = this.modal.find('.content-box'); if (contentElm.length >0) { contentElm.html(content); } } modalLib.prototype.reset = function () { this.isOpening = false; this.setTitle(''); this.setContent(''); }