// Closure in charge of taking a set of notifications and displaying them in an area defined by a jquery element. // Usage: NotificationDisplay($('#someArea')).populateWith(notificationArray) function NotificationsDisplay(area) { // private vars var displayArea = area var templateElem = $('#notificationTemplate'); // private methods function createNotificationDisplay(notification, copyFunc) { var container = templateElem.clone().attr('id', 'notif_' + notification.Id).css('display', 'block') TextNotificationMapper(container).mapToElement(notification) container.find('[name=copy]').click(function() { copyFunc(notification) }) return container; } // Closure constructor var f = function() { } // Public methods f.populateWith = function(notifications) { displayArea.empty() for (var i in notifications) { var elem = createNotificationDisplay(notifications[i], CopyManager($('#copyOrderArea')).setTemplate); displayArea.append(elem) } } return f; }