els = els || ".togetherjs-window, .togetherjs-modal, .togetherjs-notification";
els = $(els);
els = els.filter(":visible");
els.filter(":not(.togetherjs-notification)").hide();
getModalBackground().hide();
var windows = [];
els.each(function (index, element) {
element = $(element);
windows.push(element);
var bound = element.data("boundTo");
if (! bound) {
return;
}
bound = $(bound);
bound.addClass("togetherjs-animated").addClass("togetherjs-color-pulse");
setTimeout(function () {
bound.removeClass("togetherjs-color-pulse").removeClass("togetherjs-animated");
}, ANIMATION_DURATION+10);
element.data("boundTo", null);
bound.removeClass("togetherjs-active");
if (element.hasClass("togetherjs-notification")) {
element.fadeOut().promise().then(function () {
this.hide();
});
}
});
$("#togetherjs-window-pointer-right, #togetherjs-window-pointer-left").hide();
if (onClose) {
onClose();
onClose = null;
}
if (windows.length) {
session.emit("hide-window", windows);
}
};
windowing.showNotification = function (element, options) {
element = $(element);
options = options || {};
assert(false);
};
windowing.toggle = function (el) {
el = $(el);
if (el.is(":visible")) {
windowing.hide(el);
} else {
windowing.show(el);
}
};
function bindEvents(el) {
el.find(".togetherjs-close, .togetherjs-dismiss").click(function (event) {
var w = $(event.target).closest(".togetherjs-window, .togetherjs-modal, .togetherjs-notification");
windowing.hide(w);
event.stopPropagation();
return false;
});
}
function getModalBackground() {
if (getModalBackground.element) {
return getModalBackground.element;
}
var background = $("#togetherjs-modal-background");
assert(background.length);
getModalBackground.element = background;
background.click(function () {
windowing.hide();
});
return background;
}
var modalEscape = {
bind: function () {
$(document).keydown(modalEscape.onKeydown);
},
unbind: function () {
$(document).unbind("keydown", modalEscape.onKeydown);
},
onKeydown: function (event) {
if (event.which == 27) {
windowing.hide();
}
}
};
session.on("close", function () {
modalEscape.unbind();
});
session.on("new-element", function (el) {
bindEvents(el);
});
return windowing;
});