META-INF.resources.primefaces.core.core.dialog.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of primefaces Show documentation
Show all versions of primefaces Show documentation
PrimeFaces is one of the most popular UI libraries in Java EE Ecosystem and widely used by software companies, world renowned brands, banks, financial institutions, insurance companies, universities and more.
if (!PrimeFaces.dialog) {
PrimeFaces.dialog = {};
PrimeFaces.dialog.DialogHandler = {
openDialog: function(cfg) {
var rootWindow = this.findRootWindow(),
dialogId = cfg.sourceComponentId + '_dlg';
if(rootWindow.document.getElementById(dialogId)) {
return;
}
var dialogWidgetVar = cfg.sourceComponentId.replace(/:/g, '_') + '_dlgwidget',
styleClass = cfg.options.styleClass||'',
dialogDOM = $('')
.append('');
}
if(cfg.options.minimizable) {
titlebar.append('');
}
if(cfg.options.maximizable) {
titlebar.append('');
}
dialogDOM.append(' ');
dialogDOM.appendTo(rootWindow.document.body);
var dialogFrame = dialogDOM.find('iframe'),
symbol = cfg.url.indexOf('?') === -1 ? '?' : '&',
frameURL = cfg.url.indexOf('pfdlgcid') === -1 ? cfg.url + symbol + 'pfdlgcid=' + cfg.pfdlgcid: cfg.url,
frameWidth = cfg.options.contentWidth||640;
dialogFrame.width(frameWidth);
if(cfg.options.iframeTitle) {
dialogFrame.attr('title', cfg.options.iframeTitle);
}
dialogFrame.on('load', function() {
var $frame = $(this),
headerElement = $frame.contents().find('title'),
isCustomHeader = false;
if(cfg.options.headerElement) {
var customHeaderId = PrimeFaces.escapeClientId(cfg.options.headerElement),
customHeaderElement = dialogFrame.contents().find(customHeaderId);
if(customHeaderElement.length) {
headerElement = customHeaderElement;
isCustomHeader = true;
}
}
if(!$frame.data('initialized')) {
PrimeFaces.cw.call(rootWindow.PrimeFaces, 'DynamicDialog', dialogWidgetVar, {
id: dialogId,
position: cfg.options.position||'center',
sourceComponentId: cfg.sourceComponentId,
sourceWidgetVar: cfg.sourceWidgetVar,
onHide: function() {
var $dialogWidget = this,
dialogFrame = this.content.children('iframe');
if(dialogFrame.get(0).contentWindow.PrimeFaces) {
this.destroyIntervalId = setInterval(function() {
if(dialogFrame.get(0).contentWindow.PrimeFaces.ajax.Queue.isEmpty()) {
clearInterval($dialogWidget.destroyIntervalId);
dialogFrame.attr('src','about:blank');
$dialogWidget.jq.remove();
}
}, 10);
}
else {
dialogFrame.attr('src','about:blank');
$dialogWidget.jq.remove();
}
rootWindow.PF[dialogWidgetVar] = undefined;
},
modal: cfg.options.modal,
blockScroll: cfg.options.blockScroll,
resizable: cfg.options.resizable,
hasIframe: true,
draggable: cfg.options.draggable,
width: cfg.options.width,
height: cfg.options.height,
minimizable: cfg.options.minimizable,
maximizable: cfg.options.maximizable,
headerElement: cfg.options.headerElement,
responsive: cfg.options.responsive,
closeOnEscape: cfg.options.closeOnEscape
});
}
var title = rootWindow.PF(dialogWidgetVar).titlebar.children('span.ui-dialog-title');
if(headerElement.length > 0) {
if(isCustomHeader) {
title.append(headerElement);
headerElement.show();
}
else {
title.text(headerElement.text());
}
dialogFrame.attr('title', title.text());
}
//adjust height
var frameHeight = null;
if(cfg.options.contentHeight)
frameHeight = cfg.options.contentHeight;
else
frameHeight = $frame.get(0).contentWindow.document.body.scrollHeight + (PrimeFaces.env.browser.webkit ? 5 : 25);
$frame.css('height', frameHeight);
// fix #1290 - dialogs are not centered vertically
dialogFrame.data('initialized', true);
rootWindow.PF(dialogWidgetVar).show();
})
.attr('src', frameURL);
},
closeDialog: function(cfg) {
var rootWindow = this.findRootWindow(),
dlgs = $(rootWindow.document.body).children('div.ui-dialog[data-pfdlgcid="' + cfg.pfdlgcid +'"]').not('[data-queuedforremoval]'),
dlgsLength = dlgs.length,
dlg = dlgs.eq(dlgsLength - 1),
parentDlg = dlgsLength > 1 ? dlgs.eq(dlgsLength - 2) : null,
dlgWidget = rootWindow.PF(dlg.data('widget')),
sourceWidgetVar = dlgWidget.cfg.sourceWidgetVar,
sourceComponentId = dlgWidget.cfg.sourceComponentId,
dialogReturnBehavior = null,
windowContext = null;
dlg.attr('data-queuedforremoval', true);
if(parentDlg) {
var parentDlgFrame = parentDlg.find('> .ui-dialog-content > iframe').get(0),
windowContext = parentDlgFrame.contentWindow||parentDlgFrame;
sourceWidget = windowContext.PF(sourceWidgetVar);
}
else {
windowContext = rootWindow;
}
if(sourceWidgetVar) {
var sourceWidget = windowContext.PF(sourceWidgetVar);
dialogReturnBehavior = sourceWidget.cfg.behaviors ? sourceWidget.cfg.behaviors['dialogReturn']: null;
}
else if(sourceComponentId) {
var dialogReturnBehaviorStr = $(windowContext.document.getElementById(sourceComponentId)).data('dialogreturn');
if(dialogReturnBehaviorStr) {
dialogReturnBehavior = windowContext.eval('(function(ext){this.' + dialogReturnBehaviorStr + '})');
}
}
if(dialogReturnBehavior) {
var ext = {
params: [
{name: sourceComponentId + '_pfdlgcid', value: cfg.pfdlgcid}
]
};
dialogReturnBehavior.call(windowContext, ext);
}
dlgWidget.hide();
},
showMessageInDialog: function(msg) {
if(!this.messageDialog) {
var messageDialogDOM = $('')
.append(' ' +
'')
.appendTo(document.body);
PrimeFaces.cw('Dialog', 'primefacesmessagedialog', {
id: 'primefacesmessagedlg',
modal:true,
draggable: false,
resizable: false,
showEffect: 'fade',
hideEffect: 'fade'
});
this.messageDialog = PF('primefacesmessagedialog');
this.messageDialog.titleContainer = this.messageDialog.titlebar.children('span.ui-dialog-title');
}
var escape = msg.escape !== false;
var summaryHtml = msg.summary ? msg.summary.split(/\r\n|\n|\r/g).map(function(line) { return escape ? PrimeFaces.escapeHTML(line) : line; }).join("
") : "";
this.messageDialog.titleContainer.html(summaryHtml);
var detailHtml = msg.detail ? msg.detail.split(/\r\n|\n|\r/g).map(function(line) { return escape ? PrimeFaces.escapeHTML(line) : line; }).join("
") : "";
this.messageDialog.content.html('').append('').append(detailHtml);
this.messageDialog.show();
},
confirm: function(msg) {
if(PrimeFaces.confirmDialog) {
PrimeFaces.confirmSource = (typeof(msg.source) === 'string') ? $(PrimeFaces.escapeClientId(msg.source)) : $(msg.source);
PrimeFaces.confirmDialog.showMessage(msg);
}
else {
PrimeFaces.warn('No global confirmation dialog available.');
}
},
findRootWindow: function() {
var w = window;
while(w.frameElement) {
var parent = w.parent;
if (parent.PF === undefined) {
break;
}
w = parent;
};
return w;
}
};
}
');
var titlebar = dialogDOM.children('.ui-dialog-titlebar');
if(cfg.options.closable !== false) {
titlebar.append('