UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1,292 lines (1,055 loc) 86.1 kB
import './kendo.draganddrop.js'; import './kendo.popup.js'; import './kendo.icons.js'; import './kendo.html.button.js'; import './kendo.core.js'; import './kendo.licensing.js'; import '@progress/kendo-licensing'; import './kendo.userevents.js'; import './kendo.html.icon.js'; import './kendo.html.base.js'; import '@progress/kendo-svg-icons'; const __meta__ = { id: "window", name: "Window", category: "web", description: "The Window widget displays content in a modal or non-modal HTML window.", depends: [ "draganddrop", "popup", "icons" ], features: [ { id: "window-fx", name: "Animation", description: "Support for animation", depends: [ "fx" ] } ] }; (function($, undefined$1) { var kendo = window.kendo, Widget = kendo.ui.Widget, TabKeyTrap = kendo.ui.Popup.TabKeyTrap, Draggable = kendo.ui.Draggable, isPlainObject = $.isPlainObject, activeElement = kendo._activeElement, outerWidth = kendo._outerWidth, outerHeight = kendo._outerHeight, extend = $.extend, each = $.each, template = kendo.template, BODY = "body", templates, NS = ".kendoWindow", MODAL_NS = ".kendoWindowModal", // classNames KWINDOW = ".k-window", KWINDOWTITLE = ".k-window-title", KWINDOWTITLEBAR = KWINDOWTITLE + "bar", KWINDOWCONTENT = ".k-window-content", KDIALOGCONTENT = ".k-dialog-content", KWINDOWRESIZEHANDLES = ".k-resize-handle", KOVERLAY = ".k-overlay", KWINDOWMINIMIZED = "k-window-minimized", KCONTENTFRAME = "k-content-frame", LOADINGICONCLASS = "k-i-loading", KHOVERSTATE = "k-hover", KFOCUSEDSTATE = "k-focus", MAXIMIZEDSTATE = "k-window-maximized", INLINE_FLEX = "k-display-inline-flex", // constants VISIBLE = ":visible", KHIDDEN = "k-hidden", HIDDEN = "hidden", CURSOR = "cursor", // events OPEN = "open", ACTIVATE = "activate", DEACTIVATE = "deactivate", CLOSE = "close", REFRESH = "refresh", MINIMIZE = "minimize", MAXIMIZE = "maximize", RESIZESTART = "resizeStart", RESIZE = "resize", RESIZEEND = "resizeEnd", DRAGSTART = "dragstart", DRAGEND = "dragend", RESTORE = "restore", KENDOKEYDOWN = "kendoKeydown", ERROR = "error", OVERFLOW = "overflow", DATADOCOVERFLOWRULE = "original-overflow-rule", ZINDEX = "zIndex", MINIMIZE_MAXIMIZEICONSELECTORS = ".k-window-titlebar-actions .k-i-window-minimize,.k-window-titlebar-actions .k-i-window,.k-window-titlebar-actions .k-svg-i-window-minimize,.k-window-titlebar-actions .k-svg-i-window", KPINICONCLASSSELECTOR = ".k-i-pin,.k-svg-i-pin", KUNPINICONCLASSSELECTOR = ".k-i-unpin,.k-svg-i-unpin", PIN_UNPINICONCLASSSELECTOR = KPINICONCLASSSELECTOR + "," + KUNPINICONCLASSSELECTOR, TITLEBAR_BUTTONSSELECTOR = ".k-window-titlebar .k-window-titlebar-action", REFRESHICONSELECTOR = ".k-window-titlebar .k-i-arrow-rotate-cw,.k-window-titlebar .k-svg-i-arrow-rotate-cw", WINDOWEVENTSHANDLED = "WindowEventsHandled", zero = /^0[a-z]*$/i, isLocalUrl = kendo.isLocalUrl, SIZE = { small: "k-window-sm", medium: "k-window-md", large: "k-window-lg" }; function defined(x) { return (typeof x != "undefined"); } function toInt(element, property) { return parseInt(element.css(property), 10) || 0; } function constrain(value, low, high) { var normalizedValue; if (value && isNaN(value) && value.toString().indexOf("px") < 0) { normalizedValue = value; } else { normalizedValue = Math.max( Math.min(parseInt(value, 10), high === Infinity ? high : parseInt(high, 10)), low === -Infinity ? low : parseInt(low, 10) ); } return normalizedValue; } function executableScript() { return !this.type || this.type.toLowerCase().indexOf("script") >= 0; } function getPosition(elem) { var result = { top: elem.offsetTop, left: elem.offsetLeft }, parent = elem.offsetParent; while (parent) { result.top += parent.offsetTop; result.left += parent.offsetLeft; var parentOverflowX = $(parent).css("overflowX"); var parentOverflowY = $(parent).css("overflowY"); if (parentOverflowY === "auto" || parentOverflowY === "scroll") { result.top -= parent.scrollTop; } if (parentOverflowX === "auto" || parentOverflowX === "scroll") { result.left -= parent.scrollLeft; } parent = parent.offsetParent; } return result; } var Window = Widget.extend({ init: function(element, options) { var that = this, wrapper, offset = {}, visibility, display, position, content, windowContent, windowFrame, globalWindow, suppressActions = options && options.actions && !options.actions.length, id; Widget.fn.init.call(that, element, options); options = that.options; position = options.position; element = that.element; content = options.content; globalWindow = $(window); if (suppressActions) { options.actions = []; } that.appendTo = $(options.appendTo); that.containment = options.draggable.containment ? $(options.draggable.containment).first() : null; if (content && !isPlainObject(content)) { content = options.content = { url: content }; } // remove script blocks to prevent double-execution element.find("script").filter(executableScript).remove(); if (!element.parent().is(that.appendTo) && !that.containment && (position.top === undefined$1 || position.left === undefined$1)) { if (element.is(VISIBLE)) { offset = element.offset(); } else { visibility = element.css("visibility"); display = element.css("display"); element.css({ visibility: HIDDEN, display: "" }); if (document.body.contains(element[0])) { offset = element.offset(); } else { offset = { top: 0, left: 0 }; } element.css({ visibility: visibility, display: display }); } if (position.top === undefined$1) { position.top = offset.top; } if (position.left === undefined$1) { position.left = offset.left; } } if (!defined(options.visible) || options.visible === null) { options.visible = element.is(VISIBLE); } wrapper = that.wrapper = element.closest(KWINDOW); if (!element.is(".k-window-content") || !wrapper[0]) { element.addClass("k-window-content"); element.attr("tabindex", 0); that._createWindow(element, options); wrapper = that.wrapper = element.closest(KWINDOW); that.title(that.options.title); that._dimensions(); if (options._footerTemplate) { that.wrapper.append(kendo.template(options._footerTemplate)(options._footerMessages)); } } if (options.themeColor && options.themeColor !== "none") { wrapper.addClass(kendo.getValidCssClass("k-window-", "themeColor", options.themeColor)); } that.minTop = that.minLeft = -Infinity; that.maxTop = that.maxLeft = Infinity; that._position(); if (content) { that.refresh(content); } if (options.visible) { that.toFront(null, !options.modal); } windowContent = wrapper.children(KWINDOWCONTENT); if (options.visible && options.modal) { that._overlay(wrapper.is(VISIBLE)).css({ opacity: 0.5 }); } wrapper .on("mouseenter" + NS, TITLEBAR_BUTTONSSELECTOR, that._buttonEnter.bind(that)) .on("mouseleave" + NS, TITLEBAR_BUTTONSSELECTOR, that._buttonLeave.bind(that)) .on("click" + NS, "> " + TITLEBAR_BUTTONSSELECTOR, that._windowActionHandler.bind(that)) .on("keydown" + NS, that, that._keydown.bind(that)) .on("focus" + NS, that._focus.bind(that)) .on("blur" + NS, that._blur.bind(that)); windowContent .on("keydown" + NS, that, that._keydownContent.bind(that)); windowFrame = windowContent.find("." + KCONTENTFRAME)[0]; if (windowFrame && !globalWindow.data(WINDOWEVENTSHANDLED)) { globalWindow.on("blur" + NS, function() { var element = $(document.activeElement).parent(KWINDOWCONTENT); if (element.length) { var windowInstance = kendo.widgetInstance(element); windowInstance._focus(); } }); globalWindow.on("focus" + NS, function() { $(KWINDOWCONTENT).not(KDIALOGCONTENT).each(function(i, element) { kendo.widgetInstance($(element))._blur(); }); }); globalWindow.data(WINDOWEVENTSHANDLED, true); } this._resizable(); this._draggable(); if (options.pinned && this.wrapper.is(":visible")) { that.pin(); } id = element.attr("id"); if (id) { id = id + "_wnd_title"; wrapper.attr({ "role": "dialog", "aria-labelledby": id }).children(KWINDOWTITLEBAR) .children(KWINDOWTITLE) .attr("id", id); } wrapper.add(wrapper.children(".k-resize-handle," + KWINDOWTITLEBAR)) .on(kendo.support.mousedown + NS, that.toFront.bind(that)); that.touchScroller = kendo.touchScroller(element); that._resizeHandler = that._onDocumentResize.bind(that); that._marker = kendo.guid().substring(0, 8); $(window).on("resize" + NS + that._marker, that._resizeHandler); if (options.visible) { that.trigger(OPEN); that.trigger(ACTIVATE); } kendo.notify(that); if (this.options.modal) { this._tabKeyTrap = new TabKeyTrap(wrapper); this._tabKeyTrap.trap(); this._tabKeyTrap.shouldTrap = function() { return wrapper.data("isFront"); }; } if (that._showWatermarkOverlay) { that._showWatermarkOverlay(that.wrapper[0]); } }, _buttonEnter: function(e) { $(e.currentTarget).addClass(KHOVERSTATE); }, _buttonLeave: function(e) { $(e.currentTarget).removeClass(KHOVERSTATE); }, _focus: function() { this.wrapper.addClass(KFOCUSEDSTATE); }, _blur: function() { this.wrapper.removeClass(KFOCUSEDSTATE); }, _dimensions: function() { var wrapper = this.wrapper; var options = this.options; var width = options.width; var height = options.height; var maxHeight = options.maxHeight; var sizeClass = options.size; var dimensions = ["minWidth","minHeight","maxWidth","maxHeight"]; var contentBoxSizing = wrapper.css("box-sizing") == "content-box"; var lrBorderWidth = contentBoxSizing ? toInt(wrapper, "border-left-width") + toInt(wrapper, "border-right-width") : 0; var tbBorderWidth = contentBoxSizing ? toInt(wrapper, "border-top-width") + toInt(wrapper, "border-bottom-width") : 0; var paddingTop = contentBoxSizing ? toInt(wrapper, "padding-top") : 0; if (this.containment && !this._isPinned) { this._updateBoundaries(); options.maxHeight = Math.min(this.containment.height - (tbBorderWidth + paddingTop), maxHeight); options.maxWidth = Math.min(this.containment.width - lrBorderWidth, options.maxWidth); } for (var i = 0; i < dimensions.length; i++) { var value = options[dimensions[i]] || ""; if (value != Infinity) { wrapper.css(dimensions[i], value); } } if (maxHeight != Infinity) { this.element.css("maxHeight", maxHeight); } if (width) { wrapper.outerWidth(constrain(width, options.minWidth, options.maxWidth)); } else { wrapper.outerWidth(""); } if (height) { wrapper.outerHeight(constrain(height, options.minHeight, options.maxHeight)); } else { wrapper.outerHeight(""); } if (!options.visible) { wrapper.removeClass(INLINE_FLEX).hide(); } if (sizeClass && SIZE[sizeClass]) { wrapper.addClass(SIZE[sizeClass]); } }, _position: function() { var wrapper = this.wrapper, position = this.options.position, containmentTop, containmentLeft; this._updateBoundaries(); if (this.containment) { position.top = position.top || 0; position.left = position.left || 0; containmentTop = position.top.toString().indexOf("%") > 0 ? parseInt(this.containment.height * (parseFloat(position.top) / 100), 10) : position.top; containmentLeft = position.left.toString().indexOf("%") > 0 ? parseInt(this.containment.width * (parseFloat(position.left) / 100), 10) : position.left; position.top = constrain(containmentTop, this.minTop, this.maxTop); position.left = constrain(containmentLeft, this.minLeft, this.maxLeft); } if (position.top && position.top.toString().indexOf("px") > 0) { position.top = Number(position.top.replace("px", "")); } if (position.left && position.left.toString().indexOf("px") > 0) { position.left = Number(position.left.replace("px", "")); } if (position.top === 0) { position.top = position.top.toString(); } if (position.left === 0) { position.left = position.left.toString(); } wrapper.css({ top: position.top || "", left: position.left || "" }); }, _updateBoundaries: function() { var containment = this.containment; if (!containment) { return null; } containment.width = containment.innerWidth(); containment.height = containment.innerHeight(); if (parseInt(containment.width, 10) > containment[0].clientWidth) { containment.width -= kendo.support.scrollbar(); } if (parseInt(containment.height, 10) > containment[0].clientHeight) { containment.height -= kendo.support.scrollbar(); } containment.position = getPosition(containment[0]); if (this._isPinned) { this.minTop = this.minLeft = -Infinity; this.maxTop = this.maxLeft = Infinity; } else { this.minTop = containment.scrollTop(); this.minLeft = containment.scrollLeft(); this.maxLeft = this.minLeft + containment.width - outerWidth(this.wrapper, true); this.maxTop = this.minTop + containment.height - outerHeight(this.wrapper, true); } }, _animationOptions: function(id) { var animation = this.options.animation; var basicAnimation = { open: { effects: {} }, close: { hide: true, effects: {} } }; return animation && animation[id] || basicAnimation[id]; }, _resize: function() { kendo.resize(this.element.children()); }, _resizable: function() { var resizable = this.options.resizable; var wrapper = this.wrapper; if (this.resizing) { wrapper .off("dblclick" + NS) .children(KWINDOWRESIZEHANDLES).remove(); this.resizing.destroy(); this.resizing = null; } if (resizable) { wrapper.on("dblclick" + NS, KWINDOWTITLEBAR, (function(e) { if (!$(e.target).closest(".k-window-titlebar-action").length) { this.toggleMaximization(); } }).bind(this)); each("n e s w se sw ne nw".split(" "), function(index, handler) { wrapper.append(templates.resizeHandle(handler)); }); this.resizing = new WindowResizing(this); } wrapper = null; }, _draggable: function() { var draggable = this.options.draggable; if (this.dragging) { this.dragging.destroy(); this.dragging = null; } if (draggable) { this.dragging = new WindowDragging(this, draggable.dragHandle || KWINDOWTITLEBAR, draggable.clickMoveClick); } }, _actions: function() { var options = this.options; var actions = options.actions; var pinned = options.pinned; var titlebar = this.wrapper.children(KWINDOWTITLEBAR); var container = titlebar.find(".k-window-titlebar-actions"); var windowSpecificCommands = [ "minimize", "maximize" ]; var icons = { "maximize": "window", "refresh": "arrow-rotate-cw", "custom": "gear" }; var icon; actions = $.map(actions, function(action) { action = pinned && action.toLowerCase() === "pin" ? "unpin" : action; icon = icons[action.toLowerCase()] || ""; return { name: (windowSpecificCommands.indexOf(action.toLowerCase()) > -1) ? "window-" + action : action, icon: action.toLowerCase() == "close" ? "x" : icon }; }); container.html(kendo.render(templates.action, actions)); }, setOptions: function(options) { var that = this; var sizeClass = that.options.size; var doc = this.containment && !that._isPinned ? this.containment : $(document); // make a deep extend over options.position telerik/kendo-ui-core#844 var cachedOptions = JSON.parse(JSON.stringify(options)); that.wrapper.removeClass(kendo.getValidCssClass("k-window-", "themeColor", that.options.themeColor)); extend(options.position, that.options.position); extend(options.position, cachedOptions.position); that._containerScrollTop = doc.scrollTop(); that._containerScrollLeft = doc.scrollLeft(); Widget.fn.setOptions.call(that, options); var scrollable = that.options.scrollable !== false; that.restore(); if (typeof options.title !== "undefined") { that.title(options.title); } that.wrapper.removeClass(SIZE[sizeClass]); that._dimensions(); that._position(); that._resizable(); that._draggable(); that._actions(); if (that.options.themeColor && that.options.themeColor !== "none") { that.wrapper.addClass(kendo.getValidCssClass("k-window-", "themeColor", that.options.themeColor)); } if (typeof options.modal !== "undefined") { var visible = that.options.visible !== false; that._enableDocumentScrolling(); that._overlay(options.modal && visible); } that.element.css(OVERFLOW, scrollable ? "" : "hidden"); }, events: [ OPEN, ACTIVATE, DEACTIVATE, CLOSE, MINIMIZE, MAXIMIZE, REFRESH, RESTORE, RESIZESTART, RESIZE, RESIZEEND, DRAGSTART, DRAGEND, KENDOKEYDOWN, ERROR ], options: { name: "Window", animation: { open: { effects: { zoom: { direction: "in" }, fade: { direction: "in" } }, duration: 350 }, close: { effects: { zoom: { direction: "out", properties: { scale: 0.7 } }, fade: { direction: "out" } }, duration: 350, hide: true } }, title: "", themeColor: "", actions: ["Close"], autoFocus: true, modal: false, size: "auto", resizable: true, draggable: true, minWidth: 90, minHeight: 50, maxWidth: Infinity, maxHeight: Infinity, pinned: false, scrollable: true, position: {}, content: null, visible: null, height: null, width: null, appendTo: "body", isMaximized: false, isMinimized: false }, _closable: function() { return $.inArray("close", $.map(this.options.actions, function(x) { return x.toLowerCase(); })) > -1; }, _keydownContent: function(e) { var that = this, keys = kendo.keys, keyCode = e.keyCode; if (keyCode == keys.ESC && that._closable()) { e.stopPropagation(); that._close(false); } }, _keydown: function(e) { var that = this, options = that.options, keys = kendo.keys, keyCode = e.keyCode, wrapper = that.wrapper, offset, handled, distance = 10, isMaximized = options.isMaximized, isMinimized = options.isMinimized, newWidth, newHeight, w, h; if (keyCode == keys.ESC && that._closable()) { e.stopPropagation(); that._close(false); } if (e.target != e.currentTarget || that._closing) { return; } // Refresh if (e.altKey && keyCode == 82) {// Alt + R that.refresh(); } // Pin/Unpin if (e.altKey && keyCode == 80) {// Alt + P if (that.options.pinned) { that.unpin(); } else { that.pin(); } } // Maximize/Restore/Miminimize if (e.altKey && keyCode == keys.UP) { if (isMinimized) { that.restore(); that.wrapper.trigger("focus"); } else if (!isMaximized) { that.maximize(); that.wrapper.trigger("focus"); } } else if (e.altKey && keyCode == keys.DOWN) { if (!isMinimized && !isMaximized) { that.minimize(); that.wrapper.trigger("focus"); } else if (isMaximized) { that.restore(); that.wrapper.trigger("focus"); } } offset = kendo.getOffset(wrapper); if (that.containment && !that._isPinned) { offset = that.options.position; } if (options.draggable && !e.ctrlKey && !e.altKey && !isMaximized) { that._updateBoundaries(); if (keyCode == keys.UP) { offset.top = constrain(offset.top - distance, that.minTop, that.maxTop); handled = wrapper.css("top", offset.top); } else if (keyCode == keys.DOWN) { offset.top = constrain(offset.top + distance, that.minTop, that.maxTop); handled = wrapper.css("top", offset.top); } else if (keyCode == keys.LEFT) { offset.left = constrain(offset.left - distance, that.minLeft, that.maxLeft); handled = wrapper.css("left", offset.left); } else if (keyCode == keys.RIGHT) { offset.left = constrain(offset.left + distance, that.minLeft, that.maxLeft); handled = wrapper.css("left", offset.left); } } if (options.resizable && e.ctrlKey && !isMaximized && !isMinimized) { if (keyCode == keys.UP) { handled = true; newHeight = wrapper.outerHeight() - distance; } else if (keyCode == keys.DOWN) { handled = true; if (that.containment && !that._isPinned) { newHeight = Math.min(wrapper.outerHeight() + distance, that.containment.height - offset.top - toInt(wrapper, "padding-top") - toInt(wrapper, "borderBottomWidth") - toInt(wrapper, "borderTopWidth")); } else { newHeight = wrapper.outerHeight() + distance; } } else if (keyCode == keys.LEFT) { handled = true; newWidth = wrapper.outerWidth() - distance; } else if (keyCode == keys.RIGHT) { handled = true; if (that.containment && !that._isPinned) { newWidth = Math.min(wrapper.outerWidth() + distance, that.containment.width - offset.left - toInt(wrapper, "borderLeftWidth") - toInt(wrapper, "borderRightWidth")); } else { newWidth = wrapper.outerWidth() + distance; } } if (handled) { w = constrain(newWidth, options.minWidth, options.maxWidth); h = constrain(newHeight, options.minHeight, options.maxHeight); if (!isNaN(w)) { wrapper.outerWidth(w); that.options.width = w + "px"; } if (!isNaN(h)) { wrapper.outerHeight(h); that.options.height = h + "px"; } that.resize(); } } if (handled) { e.preventDefault(); } }, _overlay: function(visible) { var overlay = this.containment ? this.containment.children(KOVERLAY) : this.appendTo.children(KOVERLAY), wrapper = this.wrapper, display = visible ? "inline-flex" : "none", zIndex = parseInt(wrapper.css(ZINDEX), 10) - 1; if (!overlay.length) { overlay = $("<div class='k-overlay' />"); } overlay .insertBefore(wrapper[0]) .css({ zIndex: zIndex, display: display }); if (this.options.modal.preventScroll && !this.containment) { this._stopDocumentScrolling(); } return overlay; }, _actionForIcon: function(icon) { var iconClass = /\bk(-svg)?-i(-\w+)+\b/.exec(icon[0].className)[0]; return { "x": "_close", "window": "maximize", "window-minimize": "minimize", "window-restore": "restore", "arrow-rotate-cw": "refresh", "pin": "pin", "unpin": "unpin" }[iconClass.replace(/(k-i-|k-svg-i-)/, "")]; }, _windowActionHandler: function(e) { if (this._closing) { return; } var icon = $(e.target).closest(".k-window-titlebar-action").find(".k-icon,.k-svg-icon"); var action = this._actionForIcon(icon); if (action) { e.preventDefault(); this[action](); return false; } }, _modals: function() { var that = this, windowElements = $(KWINDOW + VISIBLE), windowInstance, modals = []; for (var i = 0; i < windowElements.length; i += 1) { windowInstance = that._object($(windowElements[i])); if (windowInstance && windowInstance.options && windowInstance.options.modal && windowInstance.options.visible && windowInstance.options.appendTo === that.options.appendTo && (!windowInstance.containment || (that.containment && windowInstance.containment[0] === that.containment[0]))) { modals.push(windowInstance.wrapper[0]); } } modals.sort(function(a, b) { return a.style.zIndex - b.style.zIndex; }); that = null; return $(modals); }, _object: function(element) { var content = element.children(KWINDOWCONTENT); var widget = content.getKendoWindow(); if (widget) { return widget; } return undefined$1; }, center: function() { var that = this, position = that.options.position, wrapper = that.wrapper, documentWindow = $(window), scrollTop = 0, scrollLeft = 0, newTop, newLeft; if (that.options.isMaximized) { return that; } if (that.options.pinned && !that._isPinned) { that.pin(); } if (!that.options.pinned) { scrollTop = documentWindow.scrollTop(); scrollLeft = documentWindow.scrollLeft(); } if (this.containment && !that.options.pinned) { newTop = this.minTop + (this.maxTop - this.minTop) / 2; newLeft = this.minLeft + (this.maxLeft - this.minLeft) / 2; } else { that._scrollIsAppended = true; newLeft = scrollLeft + Math.max(0, (documentWindow.width() - wrapper.outerWidth()) / 2); newTop = scrollTop + Math.max(0, (documentWindow.height() - wrapper.outerHeight() - toInt(wrapper, "paddingTop")) / 2); } wrapper.css({ left: newLeft, top: newTop }); position.top = newTop; position.left = newLeft; return that; }, title: function(title) { var that = this, value, encoded = true, wrapper = that.wrapper, titleBar = wrapper.children(KWINDOWTITLEBAR), titleElement = titleBar.children(KWINDOWTITLE); if (!arguments.length) { return titleElement.html(); } if ($.isPlainObject(title)) { value = typeof title.text !== "undefined" ? title.text : ""; encoded = title.encoded !== false; } else { value = title; } if (value === false) { wrapper.addClass("k-window-titleless"); wrapper.css("padding-top", 0); titleBar.remove(); } else { if (!titleBar.length) { wrapper.prepend(templates.titlebar({ title: encoded ? kendo.htmlEncode(value) : value })); that._actions(); titleBar = wrapper.children(KWINDOWTITLEBAR); } else { titleElement.html(encoded ? kendo.htmlEncode(value) : value); } } that.options.title = value; return that; }, content: function(html, data) { var content = this.wrapper.children(KWINDOWCONTENT), scrollContainer = content.children(".km-scroll-container"); content = scrollContainer[0] ? scrollContainer : content; if (!defined(html)) { return content.html(); } kendo.destroy(this.element.children()); content.empty().html(html); return this; }, open: function() { var that = this, wrapper = that.wrapper, options = that.options, showOptions = this._animationOptions("open"), contentElement = wrapper.children(KWINDOWCONTENT), overlay, otherModalsVisible, containmentContext = this.containment && !that._isPinned, doc = containmentContext ? this.containment : $(document); if (!that.trigger(OPEN)) { if (that._closing) { wrapper.kendoStop(true, true); } that._closing = false; that.toFront(); if (options.autoFocus) { that.wrapper.trigger("focus"); } options.visible = true; if (options.modal) { otherModalsVisible = !!that._modals().length; overlay = that._overlay(otherModalsVisible); overlay.kendoStop(true, true); if (showOptions.duration && kendo.effects.Fade && !otherModalsVisible) { var overlayFx = kendo.fx(overlay).fadeIn(); overlayFx.duration(showOptions.duration || 0); overlayFx.endValue(0.5); overlayFx.play(); } else { overlay.css("opacity", 0.5); } overlay.show(); $(window).on("focus" + MODAL_NS, function() { if (wrapper.data("isFront") && !$(document.activeElement).closest(wrapper).length) { that.wrapper.trigger("focus"); } }); } if (!wrapper.is(VISIBLE)) { contentElement.css(OVERFLOW, HIDDEN); that.wrapper.find(TITLEBAR_BUTTONSSELECTOR).addClass("k-button-flat"); wrapper.css({ display: "inline-flex" }); wrapper.kendoStop().kendoAnimate({ effects: showOptions.effects, duration: showOptions.duration, complete: this._activate.bind(this) }); } } if (options.isMaximized) { that._containerScrollTop = doc.scrollTop(); that._containerScrollLeft = doc.scrollLeft(); that._stopDocumentScrolling(); } if (this.options.pinned && !this._isPinned) { this.pin(); } return that; }, _activate: function() { var scrollable = this.options.scrollable !== false; if (this.options.autoFocus) { this.wrapper.trigger("focus"); } this.element.css(OVERFLOW, scrollable ? "" : "hidden"); kendo.resize(this.element.children()); this.trigger(ACTIVATE); }, _removeOverlay: function(suppressAnimation) { var modals = this._modals(); var options = this.options; var hideOverlay = options.modal && !modals.length; var hideOptions = this._animationOptions("close"); if (hideOverlay) { if (!suppressAnimation && hideOptions.duration && kendo.effects.Fade) { var overlayFx = kendo.fx(options.modal ? this._overlay(true) : $(undefined$1)).fadeOut(); overlayFx.duration(hideOptions.duration || 0); overlayFx.startValue(0.5); overlayFx.play(); } else { this._overlay(false).remove(); } if (options.modal.preventScroll) { this._enableDocumentScrolling(); } } else if (modals.length) { this._object(modals.last())._overlay(true); if (options.modal.preventScroll) { this._stopDocumentScrolling(); } } }, _close: function(systemTriggered) { var that = this, wrapper = that.wrapper, options = that.options, showOptions = this._animationOptions("open"), hideOptions = this._animationOptions("close"), containmentContext = this.containment && !that._isPinned, doc = containmentContext ? this.containment : $(document), defaultPrevented; if (that._closing) { return; } defaultPrevented = that.trigger(CLOSE, { userTriggered: !systemTriggered }); that._closing = !defaultPrevented; if (wrapper.is(VISIBLE) && !defaultPrevented) { options.visible = false; $(KWINDOW).each(function(i, element) { var contentElement = $(element).children(KWINDOWCONTENT); // Remove overlay set by toFront if (element != wrapper && contentElement.find("> ." + KCONTENTFRAME).length > 0) { contentElement.children(KOVERLAY).remove(); } }); this._removeOverlay(); // Prevent close animation from stopping that.wrapper.find(TITLEBAR_BUTTONSSELECTOR).removeClass("k-button-flat"); wrapper.kendoStop().kendoAnimate({ effects: hideOptions.effects || showOptions.effects, reverse: hideOptions.reverse === true, duration: hideOptions.duration, complete: this._deactivate.bind(this) }); $(window).off(MODAL_NS); } if (that.options.isMaximized) { that._enableDocumentScrolling(); if (that._containerScrollTop && that._containerScrollTop > 0) { doc.scrollTop(that._containerScrollTop); } if (that._containerScrollLeft && that._containerScrollLeft > 0) { doc.scrollLeft(that._containerScrollLeft); } } if (that.options.iframe) { that.wrapper.trigger("blur"); } }, _deactivate: function() { var that = this; that.wrapper .removeClass(INLINE_FLEX) .hide() .css("opacity", ""); that.trigger(DEACTIVATE); if (that.options.modal) { var lastModal = that._object(that._modals().last()); if (lastModal) { lastModal.toFront(); } } }, close: function() { this._close(true); return this; }, _actionable: function(element) { return $(element).is(`${TITLEBAR_BUTTONSSELECTOR}, :input, a, .k-input, .k-icon, .k-svg-icon, .k-svg-icon>svg, .k-svg-icon>svg>path, .k-icon-button, [role='gridcell'], .k-input-inner, .k-input-value-text`); }, _shouldFocus: function(target) { var active = activeElement(), element = this.wrapper; return this.options.autoFocus && !$(active).is(element) && !this._actionable(target) && (!element.find(active).length || !element.find(target).length); }, toFront: function(e, avoidFocus) { var that = this, wrapper = that.wrapper, currentWindow = wrapper[0], containmentContext = that.containment && !that._isPinned, openAnimation = this._animationOptions("open"), zIndex = +wrapper.css(ZINDEX), originalZIndex = zIndex, target = (e && e.target) || null; $(KWINDOW).each(function(i, element) { var windowObject = $(element), zIndexNew = windowObject.css(ZINDEX), contentElement = windowObject.children(KWINDOWCONTENT); if (!isNaN(zIndexNew)) { zIndex = Math.max(+zIndexNew, zIndex); } wrapper.data("isFront", element == currentWindow); // Add overlay to windows with iframes and lower z-index to prevent // trapping of events when resizing / dragging if (element != currentWindow && contentElement.find("." + KCONTENTFRAME).length && !contentElement.find(KOVERLAY).length) { contentElement.append(templates.overlay); } }); if (!wrapper[0].style.zIndex || originalZIndex < zIndex) { wrapper.css(ZINDEX, zIndex + 2); } that.element.find("> .k-overlay").remove(); if (that._shouldFocus(target)) { if (!avoidFocus) { setTimeout(function() { that.wrapper.trigger("focus"); }, openAnimation ? openAnimation.duration : 0); } var scrollTop = containmentContext ? that.containment.scrollTop() : $(window).scrollTop(), windowTop = parseInt(wrapper.position().top, 10); if (!that.options.pinned && windowTop > 0 && windowTop < scrollTop) { if (scrollTop > 0) { $(window).scrollTop(windowTop); } else { wrapper.css("top", scrollTop); } } } wrapper = null; return that; }, toggleMaximization: function() { if (this._closing) { return this; } return this[this.options.isMaximized ? "restore" : "maximize"](); }, restore: function() { var that = this; var options = that.options; var minHeight = options.minHeight; var restoreOptions = that.restoreOptions; var shouldRestrictTop; var container = that.containment && !that._isPinned ? that.containment : $(document); if (!options.isMaximized && !options.isMinimized) { return that; } if (minHeight && minHeight != Infinity) { that.wrapper.css("min-height", minHeight); } if (restoreOptions && !options.isMaximized) { restoreOptions.height = constrain(restoreOptions.height, that.options.minHeight, that.options.maxHeight); shouldRestrictTop = options.position.top + parseInt(restoreOptions.height, 10) > that.maxTop; if (shouldRestrictTop) { options.position.top = constrain(options.position.top, that.minTop, that.maxTop - parseInt(restoreOptions.height, 10));