diff options
Diffstat (limited to 'themes/default/common.js')
-rw-r--r-- | themes/default/common.js | 93 |
1 files changed, 59 insertions, 34 deletions
diff --git a/themes/default/common.js b/themes/default/common.js index 95a3cb82ff..ccb28b4ffe 100644 --- a/themes/default/common.js +++ b/themes/default/common.js @@ -47,6 +47,42 @@ piwikHelper.findSWFGraph = function(name) { return null; } +piwikHelper.showAjaxError = function( string, errorDivID ) +{ + errorDivID = errorDivID || 'ajaxError'; + $('#'+errorDivID).html(string).show(); +} + +piwikHelper.hideAjaxError = function(errorDivID) +{ + errorDivID = errorDivID || 'ajaxError'; + $('#'+errorDivID).hide(); +} + +piwikHelper.showAjaxLoading = function(loadingDivID) +{ + loadingDivID = loadingDivID || 'ajaxLoading'; + $('#'+loadingDivID).show(); +} +piwikHelper.hideAjaxLoading = function(loadingDivID) +{ + loadingDivID = loadingDivID || 'ajaxLoading'; + $('#'+loadingDivID).hide(); +} + +piwikHelper.getStandardAjaxConf = function(loadingDivID, errorDivID) +{ + piwikHelper.showAjaxLoading(loadingDivID); + piwikHelper.hideAjaxError(errorDivID); + var ajaxRequest = {}; + ajaxRequest.type = 'GET'; + ajaxRequest.url = 'index.php'; + ajaxRequest.dataType = 'json'; + ajaxRequest.error = piwikHelper.ajaxHandleError; + ajaxRequest.success = function(response) { piwikHelper.ajaxHandleResponse(response, loadingDivID, errorDivID); }; + return ajaxRequest; +} + piwikHelper.redirectToUrl = function(url) { window.location = url; } @@ -59,55 +95,44 @@ piwikHelper.ajaxHandleError = function() }, 2000); } -piwikHelper.ajaxShowError = function( string ) -{ - $('#ajaxError').html(string).show(); -} - -piwikHelper.ajaxHideError = function() -{ - $('#ajaxError').hide(); -} - -piwikHelper.ajaxHandleResponse = function(response) +piwikHelper.ajaxHandleResponse = function(response, loadingDivID, errorDivID) { if(response.result == "error") { - piwikHelper.ajaxShowError(response.message); + piwikHelper.hideAjaxLoading(loadingDivID); + piwikHelper.showAjaxError(response.message, errorDivID); } else { - window.location.reload(); + // add updated=1 to the URL so that a "Your changes have been saved" message is displayed + var urlToRedirect = String(window.location.pathname) + String(window.location.search); + updatedUrl = 'updated=1'; + if(urlToRedirect.search(new RegExp(updatedUrl)) == -1) + { + urlToRedirect += '&' + updatedUrl; + } + var currentHashStr = window.location.hash; + if(currentHashStr.length > 0) { + urlToRedirect += currentHashStr; + } + piwikHelper.redirectToUrl(urlToRedirect); } - piwikHelper.toggleAjaxLoading(); -} - -piwikHelper.toggleAjaxLoading = function() -{ - $('#ajaxLoading').toggle(); } -piwikHelper.getStandardAjaxConf = function() -{ - var ajaxRequest = {}; - ajaxRequest.type = 'GET'; - ajaxRequest.url = 'index.php'; - ajaxRequest.dataType = 'json'; - ajaxRequest.error = piwikHelper.ajaxHandleError; - ajaxRequest.success = piwikHelper.ajaxHandleResponse; - return ajaxRequest; -} - -// Scrolls the window to the jquery element 'elem' if necessary. -// "time" specifies the duration of the animation in ms +/** + * Scrolls the window to the jquery element 'elem' + * if the top of the element is not currently visible on screen + * @param elem Selector for the DOM node to scroll to, eg. '#myDiv' + * @param time Specifies the duration of the animation in ms + */ piwikHelper.lazyScrollTo = function(elem, time) { var elemTop = $(elem).offset().top; - //only scroll the page if the graph is not visible + // only scroll the page if the graph is not visible if(elemTop < $(window).scrollTop() || elemTop > $(window).scrollTop()+$(window).height()) { - //scroll the page smoothly to the graph + // scroll the page smoothly to the graph $.scrollTo(elem, time); } } |