(function($){"use strict"; window.kWin = { version: '0.7.5', zindex: 6000, windows: [], dom: { win: $(window), doc: $(document), html: $('html'), body: null }, modal: { layer: null, init: function(){ if (this.layer===null) { this.layer = $('#kModal'); if (this.layer.length === 0) { this.layer = $('
').css({ zIndex: kWin.zindex, opacity: 0, display: 'none' }); kWin.dom.body = $('body'); kWin.dom.body.append(this.layer); } } }, hide: function(z){ var self = this, max = 0, i; for (i = 0; i < kWin.windows.length; i+=1) { if (kWin.windows[i].zindex !== 0) { if (kWin.windows[i].settings.modal && kWin.windows[i].isVisible && kWin.windows[i].zindex > max && kWin.windows[i].zindex !== z) { max = kWin.windows[i].zindex; } } else { kWin.windows.splice(i, 1); } } if (max > 0) { this.layer.css({ zIndex: max - 1 }); } else { this.layer.css({ 'display': 'block' }); this.layer.animate({ opacity: 0 }, { queue: false, duration: 500, complete: function(){ self.layer.css({ opacity: 1, display: 'none' }); } }); } }, show: function(z){ if (this.layer.is(':visible')) { this.layer.css({ zIndex: z || kWin.zindex }); } else { this.layer.css({ display: 'block', opacity: 0, zIndex: z || kWin.zindex }).animate({ opacity: 0.5 }, { queue: false, duration: 500 }); } } } }; kWin.window = function(settings){ this.zindex = kWin.zindex += 2; this.settings = { id: "Win" + this.zindex, title: false, buttons: false, content: "
 
", closeText: "Ablak bezárása", closeOnEsc: true, closeOnLayerClick: false, insideScroll: true, modal: true, draggable: false, resizable: false, width: 'auto', height: 'auto', minWidth: 100, minHeight: 50, maxWidth: 1920, maxHeight: 1080, fixedContainer: false, minTop: 15, left: 'center', top: 'center', dumbIE: $.browser.msie && parseInt($.browser.version, 10) <= 8, template: '
 
 
 
', beforeShow: function(){ }, afterClose: function(){ } }; $.extend(this.settings, settings); this.contentIsObject = typeof this.settings.content === 'object'; this.content = this.contentIsObject ? this.settings.content.show() : $(this.settings.content); this.isVisible = false; kWin.modal.init(); this.create(); this.buttons(); this.events(); kWin.windows.push(this); }; kWin.window.prototype = { events: function(){ var self = this; this.close.click(function(){ self.exit(); }); if (this.settings.closeOnLayerClick) { kWin.modal.layer.bind('click', function(){ self.exit(); }); } if (this.settings.closeOnEsc) { kWin.dom.doc.bind('keyup.kWindow', function(e){ if (self.isVisible && e.keyCode === 27) { self.exit(); } }); } if (this.settings.draggable) { this.object.draggable({ start: function(){ kWin.zindex += 1; self.zindex = kWin.zindex; self.object.css({ zIndex: self.zindex }); }, handle: '.kWindowHeader', distance: 5 }); } else { this.object.addClass('noDrag').css({ top: -10000, left: -10000 }); } if (this.settings.resizable) { this.contentObject.resizable({ maxHeight: this.settings.maxHeight, maxWidth: this.settings.maxWidth, minHeight: this.settings.minHeight, minWidth: this.settings.minWidth }); } }, create: function(){ this.object = $('#k' + this.id); this.openedWin = true; if (this.object.length === 0) { this.object = $(this.settings.template); this.object.attr('id', 'k' + this.settings.id); this.openedWin = false; } this.object.css({ opacity: 0, position: 'absolute' }); this.titleObject = this.object.find('.kWindowTitle'); this.contentObject = this.object.find('.kWindowContent'); this.container = this.object.find('.kWindowContentContainer'); this.toolbar = this.object.find('.kWindowToolBar'); this.cnt = this.object.find('.kWindowScroll'); this.close = this.object.find('.kWindowClose'); if (!this.settings.title) { this.object.addClass('noTitle'); this.titleObject.empty(); } else { this.titleObject.html(this.settings.title); } this.cnt.empty().append(this.content); if (this.openedWin === false) { kWin.modal.layer.after(this.object); } if (this.settings.closeText) { this.close.append('' + this.settings.closeText + ''); } if (this.settings.closeImage) { this.close.append('exit'); } if (this.settings.dumbIE) { this.object.addClass('dumbIE'); } }, buttons: function(){ if (this.settings.buttons) { this.buttonContainer = this.object.find('.kWindowButtons').empty(); if (this.buttonContainer.length === 0) { this.buttonContainer = $('
'); this.contentObject.append(this.buttonContainer); } var self = this, i, btn; if (!this.settings.buttons.length) { this.settings.buttons = [{ value: 'OK', click: function(){ self.exit(); } }]; } for (i = 0; i < this.settings.buttons.length; i+=1) { btn = $(''); btn.bind("click", this.settings.buttons[i].click); this.buttonContainer.append(btn); } } else { this.object.addClass('noButtons'); } }, positions: function(){ var pos; this.object.css({ clear: 'both', position: 'relative', display: this.settings.dumbIE?'inline':'inline-block' }); this.height = this.settings.height; this.width = this.settings.width; this.contentObject.css({ width: this.width, height: this.height }); if (this.settings.width === 'auto') { this.width = this.cnt.outerWidth(true); this.width = Math.max(this.width,this.settings.minWidth); this.width = Math.min(this.width,this.settings.maxWidth); } if (this.settings.height === 'auto') { this.height = this.cnt.outerHeight(true) + this.toolbar.outerHeight(true); this.height = Math.max(this.height,this.settings.minHeight); this.height = Math.min(this.height,this.settings.maxHeight); } this.cnt.css({ overflow: this.settings.insideScroll?'auto':'visible' }); this.object.css({ position: 'absolute' }); this.contentObject.css({ width: this.width, height: this.settings.height === 'auto'?'auto':this.height }); if (this.settings.left === 'center' || this.settings.left === '50%') { this.left = '50%'; this.object.css({ marginLeft: -Math.round(this.object[0].offsetWidth / 2) + kWin.dom.win.scrollLeft() }); } else { this.left = this.settings.left; } if (this.settings.top === 'center' || this.settings.top === '50%') { this.top = '50%'; this.object.css({ marginTop: -Math.round(this.object[0].offsetHeight / 2) + kWin.dom.win.scrollTop() }); } else { if (this.settings.top === 'auto') { this.top = $(window).scrollTop() + $(window).height() / 2 -$('body').offset().top; this.object.css({ marginTop: -Math.round(this.object[0].offsetHeight / 2) }); } else { this.top = this.settings.top; } } if (typeof this.settings.horizontal === "object") { pos = this.settings.horizontal[0].offsetLeft - this.scrollLeftSave + this.settings.horizontal[0].offsetWidth / 2; if (typeof this.left === 'number'){ this.left += pos; } else { this.left = pos; } } if (typeof this.settings.vertical === "object") { pos = this.settings.vertical[0].offsetTop - this.scrollTopSave + this.settings.vertical[0].offsetHeight / 2; if (typeof this.top === 'number'){ this.top += pos; } else { this.top = pos; } } //console.log(this.contentObject.outerWidth(true)) this.object.css({ left: this.left, top: this.top, width: this.container.outerWidth(), zIndex: this.zindex }); if (this.settings.minTop !== false && this.object.offset().top < this.settings.minTop) { this.object.css({ marginTop: 0, top: this.settings.minTop }); } if (this.settings.height !== 'auto' && this.settings.height < this.cnt.height()) { this.width += 30; this.cnt.css({ height: this.settings.height - this.toolbar.outerHeight(true) }); } }, exit: function(){ this.hide(this.settings.afterClose); if (this.settings.modal) { //this.zindex = 0; kWin.modal.hide(this.zindex); } }, show: function(){ var self = this; this.object.css({ opacity: 0 }); if (this.settings.fixedContainer) { this.scrollTopSave = kWin.dom.win.scrollTop(); this.scrollLeftSave = kWin.dom.win.scrollLeft(); this.settings.fixedContainer.css({position:'fixed',top:-this.scrollTopSave,left:-this.scrollLeftSave}); kWin.dom.win.scrollTop(0); kWin.dom.win.scrollLeft(0); } this.positions(); if (this.settings.modal) { kWin.modal.show(this.zindex - 1); } self.isVisible = true; this.object.animate({ opacity: 1 }, { queue: false, duration: 500, complete: function(){ $(this).css({ filter: '' }); } }); this.settings.beforeShow(this); }, hide: function(cb){ var self = this; self.isVisible = false; this.object.animate({ opacity: 0 }, { queue: false, duration: 300, complete: function(){ var i, opened = 0; if (self.settings.fixedContainer) { for (i = 0; i < kWin.windows.length; i+=1) { if (kWin.windows[i].isVisible && kWin.windows[i].settings.fixedContainer) { opened+=1; } } if (opened === 0){ self.settings.fixedContainer.css({ top: 'auto', position: 'static' }); } kWin.dom.win.scrollTop(self.scrollTopSave); } if (typeof cb === 'function') { cb(self); } self.object.css({ top:-10000, left:-10000 }); } }); } }; })(jq172);