@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1,304 lines (1,059 loc) • 85.4 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(1392);
/***/ }),
/***/ 3:
/***/ (function(module, exports) {
module.exports = function() { throw new Error("define cannot be used indirect"); };
/***/ }),
/***/ 1038:
/***/ (function(module, exports) {
module.exports = require("./kendo.popup");
/***/ }),
/***/ 1061:
/***/ (function(module, exports) {
module.exports = require("./kendo.draganddrop");
/***/ }),
/***/ 1392:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(f, define){
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(1061), __webpack_require__(1038)], __WEBPACK_AMD_DEFINE_FACTORY__ = (f), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
})(function(){
var __meta__ = { // jshint ignore:line
id: "window",
name: "Window",
category: "web",
description: "The Window widget displays content in a modal or non-modal HTML window.",
depends: [ "draganddrop", "popup" ],
features: [ {
id: "window-fx",
name: "Animation",
description: "Support for animation",
depends: [ "fx" ]
} ]
};
(function($, undefined) {
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,
proxy = $.proxy,
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",
KCONTENTFRAME = "k-content-frame",
LOADING = "k-i-loading",
KHOVERSTATE = "k-state-hover",
KFOCUSEDSTATE = "k-state-focused",
MAXIMIZEDSTATE = "k-window-maximized",
// constants
VISIBLE = ":visible",
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",
ERROR = "error",
OVERFLOW = "overflow",
DATADOCOVERFLOWRULE = "original-overflow-rule",
ZINDEX = "zIndex",
MINIMIZE_MAXIMIZE = ".k-window-actions .k-i-window-minimize,.k-window-actions .k-i-window-maximize",
KPIN = ".k-i-pin",
KUNPIN = ".k-i-unpin",
PIN_UNPIN = KPIN + "," + KUNPIN,
TITLEBAR_BUTTONS = ".k-window-titlebar .k-window-action",
REFRESHICON = ".k-window-titlebar .k-i-refresh",
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,
isVisible = false,
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 || position.left === undefined)) {
if (element.is(VISIBLE)) {
offset = element.offset();
isVisible = true;
} else {
visibility = element.css("visibility");
display = element.css("display");
element.css({ visibility: HIDDEN, display: "" });
offset = element.offset();
element.css({ visibility: visibility, display: display });
}
if (position.top === undefined) {
position.top = offset.top;
}
if (position.left === undefined) {
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-content") || !wrapper[0]) {
element.addClass("k-window-content k-content");
that._createWindow(element, options);
wrapper = that.wrapper = element.closest(KWINDOW);
that.title(that.options.title);
that._dimensions();
}
that.minTop = that.minLeft = -Infinity;
that.maxTop = that.maxLeft = Infinity;
that._position();
if (content) {
that.refresh(content);
}
if (options.visible) {
that.toFront();
}
windowContent = wrapper.children(KWINDOWCONTENT);
that._tabindex(windowContent);
if (options.visible && options.modal) {
that._overlay(wrapper.is(VISIBLE)).css({ opacity: 0.5 });
}
wrapper
.on("mouseenter" + NS, TITLEBAR_BUTTONS, proxy(that._buttonEnter, that))
.on("mouseleave" + NS, TITLEBAR_BUTTONS, proxy(that._buttonLeave, that))
.on("click" + NS, "> " + TITLEBAR_BUTTONS, proxy(that._windowActionHandler, that))
.on("keydown" + NS, proxy(that._keydown, that))
.on("focus" + NS, proxy(that._focus, that))
.on("blur" + NS, proxy(that._blur, that));
windowContent
.on("keydown" + NS, proxy(that._keydown, that))
.on("focus" + NS, proxy(that._focus, that))
.on("blur" + NS, proxy(that._blur, 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.children(KWINDOWTITLEBAR)
.children(KWINDOWTITLE)
.attr("id", id);
windowContent
.attr({
"role": "dialog",
"aria-labelledby": id
});
}
wrapper.add(wrapper.children(".k-resize-handle," + KWINDOWTITLEBAR))
.on("mousedown" + NS, proxy(that.toFront, that));
that.touchScroller = kendo.touchScroller(element);
that._resizeHandler = proxy(that._onDocumentResize, 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 windowContent.data("isFront");
};
}
},
_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.width(constrain(width, options.minWidth, options.maxWidth));
}
else {
wrapper.width("");
}
if (height) {
wrapper.height(constrain(height, options.minHeight, options.maxHeight));
}
else {
wrapper.height("");
}
if (!options.visible) {
wrapper.hide();
}
if (sizeClass && SIZE[sizeClass]) {
wrapper.addClass(SIZE[sizeClass]);
}
},
_position: function() {
var wrapper = this.wrapper,
position = this.options.position;
this._updateBoundaries();
if (this.containment) {
position.top = Math.min(this.minTop + (position.top || 0), this.maxTop);
position.left = Math.min(this.minLeft + (position.left || 0), this.maxLeft);
}
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, proxy(function(e) {
if (!$(e.target).closest(".k-window-action").length) {
this.toggleMaximization();
}
}, 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);
}
},
_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-actions");
var windowSpecificCommands = [ "maximize", "minimize" ];
actions = $.map(actions, function(action) {
action = pinned && action.toLowerCase() === "pin" ? "unpin" : action;
return { name: (windowSpecificCommands.indexOf(action.toLowerCase()) > - 1) ? "window-" + action : action };
});
container.html(kendo.render(templates.action, actions));
},
setOptions: function(options) {
var that = this;
var sizeClass = that.options.size;
// make a deep extend over options.position telerik/kendo-ui-core#844
var cachedOptions = JSON.parse(JSON.stringify(options));
extend(options.position, that.options.position);
extend(options.position, cachedOptions.position);
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 (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,
RESIZESTART,
RESIZE,
RESIZEEND,
DRAGSTART,
DRAGEND,
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: "",
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;
},
_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.element.focus();
} else if (!isMaximized) {
that.maximize();
that.element.focus();
}
} else if (e.altKey && keyCode == keys.DOWN){
if (!isMinimized && !isMaximized) {
that.minimize();
that.wrapper.focus();
} else if (isMaximized) {
that.restore();
that.element.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.height() - distance;
} else if (keyCode == keys.DOWN) {
handled = true;
if (that.containment && !that._isPinned) {
newHeight = Math.min(wrapper.height() + distance,
that.containment.height - offset.top - toInt(wrapper, "padding-top") -
toInt(wrapper, "borderBottomWidth") - toInt(wrapper, "borderTopWidth"));
} else {
newHeight = wrapper.height() + distance;
}
} if (keyCode == keys.LEFT) {
handled = true;
newWidth = wrapper.width() - distance;
} else if (keyCode == keys.RIGHT) {
handled = true;
if (that.containment && !that._isPinned) {
newWidth = Math.min(wrapper.width() + distance,
that.containment.width - offset.left -
toInt(wrapper, "borderLeftWidth") - toInt(wrapper, "borderRightWidth"));
} else {
newWidth = wrapper.width() + distance;
}
}
if (handled) {
w = constrain(newWidth, options.minWidth, options.maxWidth);
h = constrain(newHeight, options.minHeight, options.maxHeight);
if (!isNaN(w)) {
wrapper.width(w);
that.options.width = w + "px";
}
if (!isNaN(h)) {
wrapper.height(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;
if (!overlay.length) {
overlay = $("<div class='k-overlay' />");
}
overlay
.insertBefore(wrapper[0])
.toggle(visible)
.css(ZINDEX, parseInt(wrapper.css(ZINDEX), 10) - 1);
if (this.options.modal.preventScroll && !this.containment) {
this._stopDocumentScrolling();
}
return overlay;
},
_actionForIcon: function(icon) {
var iconClass = /\bk-i(-\w+)+\b/.exec(icon[0].className)[0];
return {
"k-i-close": "_close",
"k-i-window-maximize": "maximize",
"k-i-window-minimize": "minimize",
"k-i-window-restore": "restore",
"k-i-refresh": "refresh",
"k-i-pin": "pin",
"k-i-unpin": "unpin"
}[iconClass];
},
_windowActionHandler: function (e) {
if (this._closing) {
return;
}
var icon = $(e.target).closest(".k-window-action").find(".k-icon");
var action = this._actionForIcon(icon);
if (action) {
e.preventDefault();
this[action]();
return false;
}
},
_modals: function() {
var that = this;
var zStack = $(KWINDOW).filter(function() {
var dom = $(this);
var object = that._object(dom);
var options = object && object.options;
return options && options.modal && options.visible && options.appendTo === that.options.appendTo && dom.is(VISIBLE);
}).sort(function(a, b){
return +$(a).css("zIndex") - +$(b).css("zIndex");
});
that = null;
return zStack;
},
_object: function(element) {
var content = element.children(KWINDOWCONTENT);
var widget = kendo.widgetInstance(content);
if (widget) {
return widget;
}
return undefined;
},
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.width()) / 2);
newTop = scrollTop + Math.max(0, (documentWindow.height() - wrapper.height() - 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),
titleBarHeight,
display, visibility;
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");
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);
}
visibility = wrapper.css("visibility");
display = wrapper.css("display");
if (visibility === HIDDEN) {
wrapper.css({ display: "" });
titleBarHeight = parseInt(outerHeight(titleBar), 10);
wrapper.css({ display: display });
} else {
wrapper.css({ visibility: HIDDEN, display: "" });
titleBarHeight = parseInt(outerHeight(titleBar), 10);
wrapper.css({ visibility: visibility, display: display });
}
wrapper.css("padding-top", titleBarHeight);
titleBar.css("margin-top", -titleBarHeight);
}
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();
}
this.angular("cleanup", function(){
return { elements: content.children() };
});
kendo.destroy(this.element.children());
content.empty().html(html);
this.angular("compile", function(){
var a = [];
for (var i = content.length; --i >= 0;) {
a.push({ dataItem: data });
}
return {
elements: content.children(),
data: a
};
});
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.element.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 (contentElement.data("isFront") && !$(document.activeElement).closest(contentElement).length) {
that.element.focus();
}
});
}
if (!wrapper.is(VISIBLE)) {
contentElement.css(OVERFLOW, HIDDEN);
wrapper.show().kendoStop().kendoAnimate({
effects: showOptions.effects,
duration: showOptions.duration,
complete: proxy(this._activate, 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.element.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 overlay = options.modal ? this._overlay(true) : $(undefined);
var hideOptions = this._animationOptions("close");
if (hideOverlay) {
if (!suppressAnimation && hideOptions.duration && kendo.effects.Fade) {
var overlayFx = kendo.fx(overlay).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();
wrapper.kendoStop().kendoAnimate({
effects: hideOptions.effects || showOptions.effects,
reverse: hideOptions.reverse === true,
duration: hideOptions.duration,
complete: proxy(this._deactivate, 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);
}
}
},
_deactivate: function () {
var that = this;
that.wrapper.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_BUTTONS + "," + TITLEBAR_BUTTONS + " .k-icon,:input,a");
},
_shouldFocus: function(target) {
var active = activeElement(),
element = this.element;
return this.options.autoFocus &&
!$(active).is(element) &&
!this._actionable(target) &&
(!element.find(active).length || !element.find(target).length);
},
toFront: function (e) {
var that = this,
wrapper = that.wrapper,
currentWindow = wrapper[0],
containmentContext = that.containment && !that._isPinned,
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);
}
contentElement.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 > 0) {
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 (that.isMinimized()) {
that.wrapper.focus();
} else if ($(target).is(KOVERLAY)) {
setTimeout(function(){
that.element.focus();
});
} else {
that.element.focus();
}
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));
extend(restoreOptions, {
left: options.position.left,
top: options.position.top
});
}
}
that.w