| |
| |
| |
| |
| |
| |
|
|
| var Piwik_Popover = (function () { |
| var container = false; |
| var isOpen = false; |
| var closeCallback = false; |
| var isProgrammaticClose = false; |
| var scrollTopPosition = 0; |
| var ajaxLoadingRequest = null; |
| var createContainer = function () { |
| if (container === false) { |
| container = $(document.createElement('div')).attr('id', 'Piwik_Popover'); |
| } |
| if (!$('#Piwik_Popover_Wrapper').length) { |
| $(document.createElement('div')).attr('id', 'Piwik_Popover_Wrapper').appendTo('body'); |
| } |
| }; |
|
|
| var openPopover = function (title, dialogClass) { |
| createContainer(); |
|
|
| var options = |
| { |
| title: title, |
| modal: true, |
| width: 1050, |
| resizable: false, |
| autoOpen: true, |
| classes: { |
| "ui-dialog": 'ui-dialog--responsive', |
| }, |
| appendTo: '#Piwik_Popover_Wrapper', |
| open: function (event, ui) { |
| if (dialogClass) { |
| $(this).parent().addClass(dialogClass).attr('style', ''); |
| } |
|
|
| $('.ui-widget-overlay').on('click.popover', function () { |
| |
| broadcast.resetPopoverStack(); |
| container.dialog('close'); |
| }); |
|
|
| |
| |
| |
| scrollTopPosition = $(window).scrollTop(); |
| $('#root').css({ |
| position: 'fixed', |
| height: $(window).height + scrollTopPosition, |
| width: '100%', |
| top: -scrollTopPosition |
| }); |
|
|
| window.scrollTo(0, 0); |
| }, |
| close: function (event, ui) { |
| container.find('div.jqplot-target').trigger('piwikDestroyPlot'); |
| container[0].innerHTML = ''; |
| container.dialog('destroy').remove(); |
|
|
| if (ajaxLoadingRequest) { |
| ajaxLoadingRequest.abort(); |
| } |
|
|
| $('.ui-widget-overlay').off('click.popover'); |
| isOpen = false; |
| require('piwik/UI').UIControl.cleanupUnusedControls(); |
| if (typeof closeCallback == 'function') { |
| closeCallback(); |
| closeCallback = false; |
| } |
|
|
| |
| |
| $('body > .ui-tooltip').remove(); |
|
|
| |
| |
| if (!isProgrammaticClose || isEscapeKey(event)) { |
| broadcast.propagateNewPopoverParameter(false); |
| } |
|
|
| $('#root').css({ |
| position: '', |
| height: '', |
| width: '', |
| top: '' |
| }); |
|
|
| window.scrollTo(0, scrollTopPosition); |
| } |
| }; |
|
|
| container.dialog(options); |
|
|
| |
| container.data( "uiDialog" )._title = function(title) { |
| title.html( this.options.title ); |
| }; |
|
|
| isOpen = true; |
| }; |
|
|
| return { |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| showLoading: function (popoverName, popoverSubject, height, dialogClass) { |
| var loading = $(document.createElement('div')).addClass('Piwik_Popover_Loading'); |
|
|
| var loadingMessage = popoverSubject ? translations.General_LoadingPopoverFor : |
| translations.General_LoadingPopover; |
|
|
| loadingMessage = sprintf(loadingMessage, popoverName); |
|
|
| var p1 = $(document.createElement('p')).addClass('Piwik_Popover_Loading_Name'); |
| loading.append(p1.text(loadingMessage)); |
|
|
| var p2; |
| if (popoverSubject) { |
| popoverSubject = piwikHelper.addBreakpointsToUrl(popoverSubject); |
| p1.addClass('Piwik_Popover_Loading_NameWithSubject'); |
| p2 = $(document.createElement('p')).addClass('Piwik_Popover_Loading_Subject'); |
| loading.append(p2.html(popoverSubject)); |
| } |
|
|
| if (height) { |
| loading.height(height); |
| } |
|
|
| if (!isOpen) { |
| openPopover(null, dialogClass); |
| } |
|
|
| this.setContent(loading); |
| this.setTitle(''); |
|
|
| if (height) { |
| var offset = loading.height() - p1.outerHeight(); |
| if (popoverSubject) { |
| offset -= p2.outerHeight(); |
| } |
| var spacingEl = $(document.createElement('div')); |
| spacingEl.height(Math.round(offset / 2)); |
| loading.prepend(spacingEl); |
| } |
|
|
| return container; |
| }, |
|
|
| |
| |
| |
| |
| |
| addHelpButton: function (helpUrl) { |
| if (!isOpen) { |
| return; |
| } |
|
|
| var titlebar = container.parent().find('.ui-dialog-titlebar'); |
|
|
| var button = $(document.createElement('a')).addClass('ui-dialog-titlebar-help'); |
| button.attr({href: helpUrl, target: '_blank'}); |
|
|
| titlebar.append(button); |
| }, |
|
|
| |
| setTitle: function (titleHtml) { |
| var titleText = piwikHelper.htmlDecode(titleHtml); |
| if (titleText.length > 60) { |
| titleHtml = $('<span>').attr('class', 'tooltip').attr('title', titleText).html(titleHtml); |
| } |
| container.dialog('option', 'title', titleHtml); |
| try { |
| $('.tooltip', container.parentNode).tooltip('destroy'); |
| } catch (e) {} |
| if (titleText.length > 60) { |
| $('.tooltip', container.parentNode).tooltip({track: true, items: '.tooltip'}); |
| } |
| }, |
|
|
| |
| setContent: function (html) { |
| if (typeof closeCallback == 'function') { |
| closeCallback(); |
| closeCallback = false; |
| } |
|
|
| container.html(html); |
|
|
| container.children().each(function (i, childNode) { |
| piwikHelper.compileVueEntryComponents(childNode); |
| }); |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| showError: function (title, message, backLabel) { |
| var error = $(document.createElement('div')).addClass('Piwik_Popover_Error'); |
|
|
| var p = $(document.createElement('p')).addClass('Piwik_Popover_Error_Title'); |
| error.append(p.html(title)); |
|
|
| if (message) { |
| p = $(document.createElement('p')).addClass('Piwik_Popover_Error_Message'); |
| error.append(p.html(message)); |
| } |
|
|
| if (backLabel) { |
| var back = $(document.createElement('a')).addClass('Piwik_Popover_Error_Back'); |
| back.attr('href', '#').click(function () { |
| history.back(); |
| return false; |
| }); |
| error.append(back.html(backLabel)); |
| } |
|
|
| if (!isOpen) { |
| openPopover(); |
| } |
|
|
| this.setContent(error); |
| }, |
|
|
| |
| |
| |
| |
| |
| onClose: function (callback) { |
| closeCallback = callback; |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| close: function () { |
| if (isOpen) { |
| isProgrammaticClose = true; |
| container.dialog('close'); |
| isProgrammaticClose = false; |
| } |
| }, |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| createPopupAndLoadUrl: function (url, loadingName, dialogClass, ajaxRequest) { |
| |
| var box = Piwik_Popover.showLoading(loadingName, null, null, dialogClass); |
|
|
| var callback = function (html) { |
| function setPopoverTitleIfOneFoundInContainer() { |
| var title = $('h1,h2', container); |
| if (title.length == 1) { |
| Piwik_Popover.setTitle(title.text()); |
| $(title).hide(); |
| } |
| } |
|
|
| Piwik_Popover.setContent(html); |
| setPopoverTitleIfOneFoundInContainer(); |
| }; |
|
|
| if ('undefined' === typeof ajaxRequest) { |
| ajaxRequest = new ajaxHelper(); |
| } |
| ajaxRequest.addParams(piwikHelper.getArrayFromQueryString(url), 'get'); |
| ajaxRequest.setCallback(callback); |
| ajaxRequest.setFormat('html'); |
| ajaxRequest.send(); |
|
|
| ajaxLoadingRequest = ajaxRequest; |
| }, |
|
|
| isOpen: function() { |
| return isOpen; |
| } |
| }; |
| })(); |
|
|