From: Stas Vilchik Date: Mon, 28 Dec 2015 15:25:42 +0000 (+0100) Subject: improve js build X-Git-Tag: 5.4-M3~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=632808520028fb412b93ff277719db848c2af59f;p=sonarqube.git improve js build --- diff --git a/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js b/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js index 723265766ad..20e4789ba4e 100644 --- a/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js +++ b/server/sonar-web/src/main/js/components/source-viewer/measures-overlay.js @@ -30,9 +30,58 @@ export default ModalView.extend({ }); }, + initPieChart: function () { + var trans = function (left, top) { + return 'translate(' + left + ', ' + top + ')'; + }; + + var defaults = { + size: 40, + thickness: 8, + color: '#1f77b4', + baseColor: '#e6e6e6' + }; + + this.$('.js-pie-chart').each(function () { + var data = [ + $(this).data('value'), + $(this).data('max') - $(this).data('value') + ], + options = _.defaults($(this).data(), defaults), + radius = options.size / 2; + + var container = d3.select(this), + svg = container.append('svg') + .attr('width', options.size) + .attr('height', options.size), + plot = svg.append('g') + .attr('transform', trans(radius, radius)), + arc = d3.svg.arc() + .innerRadius(radius - options.thickness) + .outerRadius(radius), + pie = d3.layout.pie() + .sort(null) + .value(function (d) { + return d; + }), + colors = function (i) { + return i === 0 ? options.color : options.baseColor; + }, + sectors = plot.selectAll('path') + .data(pie(data)); + + sectors.enter() + .append('path') + .style('fill', function (d, i) { + return colors(i); + }) + .attr('d', arc); + }); + }, + onRender: function () { ModalView.prototype.onRender.apply(this, arguments); - this.$('.js-pie-chart').pieChart(); + this.initPieChart(); this.$('.js-test-list').scrollTop(this.testsScroll); }, diff --git a/server/sonar-web/src/main/js/libs/graphics/pie-chart.js b/server/sonar-web/src/main/js/libs/graphics/pie-chart.js deleted file mode 100644 index 241ed8764f4..00000000000 --- a/server/sonar-web/src/main/js/libs/graphics/pie-chart.js +++ /dev/null @@ -1,52 +0,0 @@ -(function ($) { - - function trans (left, top) { - return 'translate(' + left + ', ' + top + ')'; - } - - var defaults = { - size: 40, - thickness: 8, - color: '#1f77b4', - baseColor: '#e6e6e6' - }; - - $.fn.pieChart = function () { - $(this).each(function () { - var data = [ - $(this).data('value'), - $(this).data('max') - $(this).data('value') - ], - options = _.defaults($(this).data(), defaults), - radius = options.size / 2; - - var container = d3.select(this), - svg = container.append('svg') - .attr('width', options.size) - .attr('height', options.size), - plot = svg.append('g') - .attr('transform', trans(radius, radius)), - arc = d3.svg.arc() - .innerRadius(radius - options.thickness) - .outerRadius(radius), - pie = d3.layout.pie() - .sort(null) - .value(function (d) { - return d; - }), - colors = function (i) { - return i === 0 ? options.color : options.baseColor; - }, - sectors = plot.selectAll('path') - .data(pie(data)); - - sectors.enter() - .append('path') - .style('fill', function (d, i) { - return colors(i); - }) - .attr('d', arc); - }); - }; - -})(window.jQuery); diff --git a/server/sonar-web/src/main/js/libs/sonar.js b/server/sonar-web/src/main/js/libs/sonar.js index bcb5e244e1a..f57126da119 100644 --- a/server/sonar-web/src/main/js/libs/sonar.js +++ b/server/sonar-web/src/main/js/libs/sonar.js @@ -2,12 +2,9 @@ require('script!./translate.js'); require('script!./third-party/jquery-ui.js'); require('script!./third-party/select2.js'); require('script!./third-party/keymaster.js'); -require('script!./third-party/numeral.js'); -require('script!./third-party/numeral-languages.js'); require('script!./third-party/bootstrap/tooltip.js'); require('script!./third-party/bootstrap/dropdown.js'); require('script!./select2-jquery-ui-fix.js'); -require('script!./graphics/pie-chart.js'); require('script!./sortable.js'); require('script!./inputs.js'); require('script!./jquery-isolated-scroll.js'); diff --git a/server/sonar-web/src/main/js/libs/third-party/jquery.mockjax.js b/server/sonar-web/src/main/js/libs/third-party/jquery.mockjax.js deleted file mode 100755 index b935290ff58..00000000000 --- a/server/sonar-web/src/main/js/libs/third-party/jquery.mockjax.js +++ /dev/null @@ -1,764 +0,0 @@ -/*! jQuery Mockjax - * A Plugin providing simple and flexible mocking of ajax requests and responses - * - * Version: 2.0.1 - * Home: https://github.com/jakerella/jquery-mockjax - * Copyright (c) 2015 Jordan Kasper, formerly appendTo; - * NOTE: This repository was taken over by Jordan Kasper (@jakerella) October, 2014 - * - * Dual licensed under the MIT or GPL licenses. - * http://opensource.org/licenses/MIT OR http://www.gnu.org/licenses/gpl-2.0.html - */ -(function(root, factory) { - 'use strict'; - - // AMDJS module definition - if ( typeof define === 'function' && define.amd && define.amd.jQuery ) { - define(['jquery'], function($) { - return factory($, root); - }); - - // CommonJS module definition - } else if ( typeof exports === 'object') { - - // NOTE: To use Mockjax as a Node module you MUST provide the factory with - // a valid version of jQuery and a window object (the global scope): - // var mockjax = require('jquery.mockjax')(jQuery, window); - - module.exports = factory; - - // Global jQuery in web browsers - } else { - return factory(root.jQuery || root.$, root); - } -}(this, function($, window) { - 'use strict'; - - var _ajax = $.ajax, - mockHandlers = [], - mockedAjaxCalls = [], - unmockedAjaxCalls = [], - CALLBACK_REGEX = /=\?(&|$)/, - jsc = (new Date()).getTime(); - - - // Parse the given XML string. - function parseXML(xml) { - if ( window.DOMParser === undefined && window.ActiveXObject ) { - window.DOMParser = function() { }; - DOMParser.prototype.parseFromString = function( xmlString ) { - var doc = new ActiveXObject('Microsoft.XMLDOM'); - doc.async = 'false'; - doc.loadXML( xmlString ); - return doc; - }; - } - - try { - var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' ); - if ( $.isXMLDoc( xmlDoc ) ) { - var err = $('parsererror', xmlDoc); - if ( err.length === 1 ) { - throw new Error('Error: ' + $(xmlDoc).text() ); - } - } else { - throw new Error('Unable to parse XML'); - } - return xmlDoc; - } catch( e ) { - var msg = ( e.name === undefined ? e : e.name + ': ' + e.message ); - $(document).trigger('xmlParseError', [ msg ]); - return undefined; - } - } - - // Check if the data field on the mock handler and the request match. This - // can be used to restrict a mock handler to being used only when a certain - // set of data is passed to it. - function isMockDataEqual( mock, live ) { - var identical = true; - // Test for situations where the data is a querystring (not an object) - if (typeof live === 'string') { - // Querystring may be a regex - return $.isFunction( mock.test ) ? mock.test(live) : mock === live; - } - $.each(mock, function(k) { - if ( live[k] === undefined ) { - identical = false; - return identical; - } else { - if ( typeof live[k] === 'object' && live[k] !== null ) { - if ( identical && $.isArray( live[k] ) ) { - identical = $.isArray( mock[k] ) && live[k].length === mock[k].length; - } - identical = identical && isMockDataEqual(mock[k], live[k]); - } else { - if ( mock[k] && $.isFunction( mock[k].test ) ) { - identical = identical && mock[k].test(live[k]); - } else { - identical = identical && ( mock[k] === live[k] ); - } - } - } - }); - - return identical; - } - - // See if a mock handler property matches the default settings - function isDefaultSetting(handler, property) { - return handler[property] === $.mockjaxSettings[property]; - } - - // Check the given handler should mock the given request - function getMockForRequest( handler, requestSettings ) { - // If the mock was registered with a function, let the function decide if we - // want to mock this request - if ( $.isFunction(handler) ) { - return handler( requestSettings ); - } - - // Inspect the URL of the request and check if the mock handler's url - // matches the url for this ajax request - if ( $.isFunction(handler.url.test) ) { - // The user provided a regex for the url, test it - if ( !handler.url.test( requestSettings.url ) ) { - return null; - } - } else { - // Look for a simple wildcard '*' or a direct URL match - var star = handler.url.indexOf('*'); - if (handler.url !== requestSettings.url && star === -1 || - !new RegExp(handler.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, '\\$&').replace(/\*/g, '.+')).test(requestSettings.url)) { - return null; - } - } - - // Inspect the request headers submitted - if ( handler.requestHeaders ) { - //No expectation for headers, do not mock this request - if (requestSettings.headers === undefined) { - return null; - } else { - var headersMismatch = false; - $.each(handler.requestHeaders, function(key, value) { - var v = requestSettings.headers[key]; - if(v !== value) { - headersMismatch = true; - return false; - } - }); - //Headers do not match, do not mock this request - if (headersMismatch) { - return null; - } - } - } - - // Inspect the data submitted in the request (either POST body or GET query string) - if ( handler.data ) { - if ( ! requestSettings.data || !isMockDataEqual(handler.data, requestSettings.data) ) { - // They're not identical, do not mock this request - return null; - } - } - // Inspect the request type - if ( handler && handler.type && - handler.type.toLowerCase() !== requestSettings.type.toLowerCase() ) { - // The request type doesn't match (GET vs. POST) - return null; - } - - return handler; - } - - function isPosNum(value) { - return typeof value === 'number' && value >= 0; - } - - function parseResponseTimeOpt(responseTime) { - if ($.isArray(responseTime) && responseTime.length === 2) { - var min = responseTime[0]; - var max = responseTime[1]; - if(isPosNum(min) && isPosNum(max)) { - return Math.floor(Math.random() * (max - min)) + min; - } - } else if(isPosNum(responseTime)) { - return responseTime; - } - return DEFAULT_RESPONSE_TIME; - } - - // Process the xhr objects send operation - function _xhrSend(mockHandler, requestSettings, origSettings) { - - // This is a substitute for < 1.4 which lacks $.proxy - var process = (function(that) { - return function() { - return (function() { - // The request has returned - this.status = mockHandler.status; - this.statusText = mockHandler.statusText; - this.readyState = 1; - - var finishRequest = function () { - this.readyState = 4; - - var onReady; - // Copy over our mock to our xhr object before passing control back to - // jQuery's onreadystatechange callback - if ( requestSettings.dataType === 'json' && ( typeof mockHandler.responseText === 'object' ) ) { - this.responseText = JSON.stringify(mockHandler.responseText); - } else if ( requestSettings.dataType === 'xml' ) { - if ( typeof mockHandler.responseXML === 'string' ) { - this.responseXML = parseXML(mockHandler.responseXML); - //in jQuery 1.9.1+, responseXML is processed differently and relies on responseText - this.responseText = mockHandler.responseXML; - } else { - this.responseXML = mockHandler.responseXML; - } - } else if (typeof mockHandler.responseText === 'object' && mockHandler.responseText !== null) { - // since jQuery 1.9 responseText type has to match contentType - mockHandler.contentType = 'application/json'; - this.responseText = JSON.stringify(mockHandler.responseText); - } else { - this.responseText = mockHandler.responseText; - } - if( typeof mockHandler.status === 'number' || typeof mockHandler.status === 'string' ) { - this.status = mockHandler.status; - } - if( typeof mockHandler.statusText === 'string') { - this.statusText = mockHandler.statusText; - } - // jQuery 2.0 renamed onreadystatechange to onload - onReady = this.onreadystatechange || this.onload; - - // jQuery < 1.4 doesn't have onreadystate change for xhr - if ( $.isFunction( onReady ) ) { - if( mockHandler.isTimeout) { - this.status = -1; - } - onReady.call( this, mockHandler.isTimeout ? 'timeout' : undefined ); - } else if ( mockHandler.isTimeout ) { - // Fix for 1.3.2 timeout to keep success from firing. - this.status = -1; - } - }; - - // We have an executable function, call it to give - // the mock handler a chance to update it's data - if ( $.isFunction(mockHandler.response) ) { - // Wait for it to finish - if ( mockHandler.response.length === 2 ) { - mockHandler.response(origSettings, function () { - finishRequest.call(that); - }); - return; - } else { - mockHandler.response(origSettings); - } - } - - finishRequest.call(that); - }).apply(that); - }; - })(this); - - if ( mockHandler.proxy ) { - // We're proxying this request and loading in an external file instead - _ajax({ - global: false, - url: mockHandler.proxy, - type: mockHandler.proxyType, - data: mockHandler.data, - dataType: requestSettings.dataType === 'script' ? 'text/plain' : requestSettings.dataType, - complete: function(xhr) { - mockHandler.responseXML = xhr.responseXML; - mockHandler.responseText = xhr.responseText; - // Don't override the handler status/statusText if it's specified by the config - if (isDefaultSetting(mockHandler, 'status')) { - mockHandler.status = xhr.status; - } - if (isDefaultSetting(mockHandler, 'statusText')) { - mockHandler.statusText = xhr.statusText; - } - this.responseTimer = setTimeout(process, parseResponseTimeOpt(mockHandler.responseTime)); - } - }); - } else { - // type === 'POST' || 'GET' || 'DELETE' - if ( requestSettings.async === false ) { - // TODO: Blocking delay - process(); - } else { - this.responseTimer = setTimeout(process, parseResponseTimeOpt(mockHandler.responseTime)); - } - } - } - - // Construct a mocked XHR Object - function xhr(mockHandler, requestSettings, origSettings, origHandler) { - // Extend with our default mockjax settings - mockHandler = $.extend(true, {}, $.mockjaxSettings, mockHandler); - - if (typeof mockHandler.headers === 'undefined') { - mockHandler.headers = {}; - } - if (typeof requestSettings.headers === 'undefined') { - requestSettings.headers = {}; - } - if ( mockHandler.contentType ) { - mockHandler.headers['content-type'] = mockHandler.contentType; - } - - return { - status: mockHandler.status, - statusText: mockHandler.statusText, - readyState: 1, - open: function() { }, - send: function() { - origHandler.fired = true; - _xhrSend.call(this, mockHandler, requestSettings, origSettings); - }, - abort: function() { - clearTimeout(this.responseTimer); - }, - setRequestHeader: function(header, value) { - requestSettings.headers[header] = value; - }, - getResponseHeader: function(header) { - // 'Last-modified', 'Etag', 'content-type' are all checked by jQuery - if ( mockHandler.headers && mockHandler.headers[header] ) { - // Return arbitrary headers - return mockHandler.headers[header]; - } else if ( header.toLowerCase() === 'last-modified' ) { - return mockHandler.lastModified || (new Date()).toString(); - } else if ( header.toLowerCase() === 'etag' ) { - return mockHandler.etag || ''; - } else if ( header.toLowerCase() === 'content-type' ) { - return mockHandler.contentType || 'text/plain'; - } - }, - getAllResponseHeaders: function() { - var headers = ''; - // since jQuery 1.9 responseText type has to match contentType - if (mockHandler.contentType) { - mockHandler.headers['Content-Type'] = mockHandler.contentType; - } - $.each(mockHandler.headers, function(k, v) { - headers += k + ': ' + v + '\n'; - }); - return headers; - } - }; - } - - // Process a JSONP mock request. - function processJsonpMock( requestSettings, mockHandler, origSettings ) { - // Handle JSONP Parameter Callbacks, we need to replicate some of the jQuery core here - // because there isn't an easy hook for the cross domain script tag of jsonp - - processJsonpUrl( requestSettings ); - - requestSettings.dataType = 'json'; - if(requestSettings.data && CALLBACK_REGEX.test(requestSettings.data) || CALLBACK_REGEX.test(requestSettings.url)) { - createJsonpCallback(requestSettings, mockHandler, origSettings); - - // We need to make sure - // that a JSONP style response is executed properly - - var rurl = /^(\w+:)?\/\/([^\/?#]+)/, - parts = rurl.exec( requestSettings.url ), - remote = parts && (parts[1] && parts[1] !== location.protocol || parts[2] !== location.host); - - requestSettings.dataType = 'script'; - if(requestSettings.type.toUpperCase() === 'GET' && remote ) { - var newMockReturn = processJsonpRequest( requestSettings, mockHandler, origSettings ); - - // Check if we are supposed to return a Deferred back to the mock call, or just - // signal success - if(newMockReturn) { - return newMockReturn; - } else { - return true; - } - } - } - return null; - } - - // Append the required callback parameter to the end of the request URL, for a JSONP request - function processJsonpUrl( requestSettings ) { - if ( requestSettings.type.toUpperCase() === 'GET' ) { - if ( !CALLBACK_REGEX.test( requestSettings.url ) ) { - requestSettings.url += (/\?/.test( requestSettings.url ) ? '&' : '?') + - (requestSettings.jsonp || 'callback') + '=?'; - } - } else if ( !requestSettings.data || !CALLBACK_REGEX.test(requestSettings.data) ) { - requestSettings.data = (requestSettings.data ? requestSettings.data + '&' : '') + (requestSettings.jsonp || 'callback') + '=?'; - } - } - - // Process a JSONP request by evaluating the mocked response text - function processJsonpRequest( requestSettings, mockHandler, origSettings ) { - // Synthesize the mock request for adding a script tag - var callbackContext = origSettings && origSettings.context || requestSettings, - // If we are running under jQuery 1.5+, return a deferred object - newMock = ($.Deferred) ? (new $.Deferred()) : null; - - // If the response handler on the moock is a function, call it - if ( mockHandler.response && $.isFunction(mockHandler.response) ) { - - mockHandler.response(origSettings); - - - } else if ( typeof mockHandler.responseText === 'object' ) { - // Evaluate the responseText javascript in a global context - $.globalEval( '(' + JSON.stringify( mockHandler.responseText ) + ')'); - - } else if (mockHandler.proxy) { - - // This handles the unique case where we have a remote URL, but want to proxy the JSONP - // response to another file (not the same URL as the mock matching) - _ajax({ - global: false, - url: mockHandler.proxy, - type: mockHandler.proxyType, - data: mockHandler.data, - dataType: requestSettings.dataType === 'script' ? 'text/plain' : requestSettings.dataType, - complete: function(xhr) { - $.globalEval( '(' + xhr.responseText + ')'); - completeJsonpCall( requestSettings, mockHandler, callbackContext, newMock ); - } - }); - - return newMock; - - } else { - $.globalEval( '(' + mockHandler.responseText + ')'); - } - - completeJsonpCall( requestSettings, mockHandler, callbackContext, newMock ); - - return newMock; - } - - function completeJsonpCall( requestSettings, mockHandler, callbackContext, newMock ) { - var json; - - // Successful response - setTimeout(function() { - jsonpSuccess( requestSettings, callbackContext, mockHandler ); - jsonpComplete( requestSettings, callbackContext ); - }, parseResponseTimeOpt( mockHandler.responseTime )); - - if ( newMock ) { - try { - json = $.parseJSON( mockHandler.responseText ); - } catch (err) { /* just checking... */ } - - newMock.resolveWith( callbackContext, [json || mockHandler.responseText] ); - } - } - - - // Create the required JSONP callback function for the request - function createJsonpCallback( requestSettings, mockHandler, origSettings ) { - var callbackContext = origSettings && origSettings.context || requestSettings; - var jsonp = requestSettings.jsonpCallback || ('jsonp' + jsc++); - - // Replace the =? sequence both in the query string and the data - if ( requestSettings.data ) { - requestSettings.data = (requestSettings.data + '').replace(CALLBACK_REGEX, '=' + jsonp + '$1'); - } - - requestSettings.url = requestSettings.url.replace(CALLBACK_REGEX, '=' + jsonp + '$1'); - - - // Handle JSONP-style loading - window[ jsonp ] = window[ jsonp ] || function() { - jsonpSuccess( requestSettings, callbackContext, mockHandler ); - jsonpComplete( requestSettings, callbackContext ); - // Garbage collect - window[ jsonp ] = undefined; - - try { - delete window[ jsonp ]; - } catch(e) {} - - }; - } - - // The JSONP request was successful - function jsonpSuccess(requestSettings, callbackContext, mockHandler) { - // If a local callback was specified, fire it and pass it the data - if ( requestSettings.success ) { - requestSettings.success.call( callbackContext, mockHandler.responseText || '', 'success', {} ); - } - - // Fire the global callback - if ( requestSettings.global ) { - (requestSettings.context ? $(requestSettings.context) : $.event).trigger('ajaxSuccess', [{}, requestSettings]); - } - } - - // The JSONP request was completed - function jsonpComplete(requestSettings, callbackContext) { - if ( requestSettings.complete ) { - requestSettings.complete.call( callbackContext, { - statusText: 'success', - status: 200 - } , 'success' ); - } - - // The request was completed - if ( requestSettings.global ) { - (requestSettings.context ? $(requestSettings.context) : $.event).trigger('ajaxComplete', [{}, requestSettings]); - } - - // Handle the global AJAX counter - if ( requestSettings.global && ! --$.active ) { - $.event.trigger( 'ajaxStop' ); - } - } - - - // The core $.ajax replacement. - function handleAjax( url, origSettings ) { - var mockRequest, requestSettings, mockHandler, overrideCallback; - - // If url is an object, simulate pre-1.5 signature - if ( typeof url === 'object' ) { - origSettings = url; - url = undefined; - } else { - // work around to support 1.5 signature - origSettings = origSettings || {}; - origSettings.url = url; - } - - // Extend the original settings for the request - requestSettings = $.ajaxSetup({}, origSettings); - requestSettings.type = requestSettings.method = requestSettings.method || requestSettings.type; - - // Generic function to override callback methods for use with - // callback options (onAfterSuccess, onAfterError, onAfterComplete) - overrideCallback = function(action, mockHandler) { - var origHandler = origSettings[action.toLowerCase()]; - return function() { - if ( $.isFunction(origHandler) ) { - origHandler.apply(this, [].slice.call(arguments)); - } - mockHandler['onAfter' + action](); - }; - }; - - // Iterate over our mock handlers (in registration order) until we find - // one that is willing to intercept the request - for(var k = 0; k < mockHandlers.length; k++) { - if ( !mockHandlers[k] ) { - continue; - } - - mockHandler = getMockForRequest( mockHandlers[k], requestSettings ); - if(!mockHandler) { - // No valid mock found for this request - continue; - } - - mockedAjaxCalls.push(requestSettings); - - // If logging is enabled, log the mock to the console - $.mockjaxSettings.log( mockHandler, requestSettings ); - - - if ( requestSettings.dataType && requestSettings.dataType.toUpperCase() === 'JSONP' ) { - if ((mockRequest = processJsonpMock( requestSettings, mockHandler, origSettings ))) { - // This mock will handle the JSONP request - return mockRequest; - } - } - - - // Removed to fix #54 - keep the mocking data object intact - //mockHandler.data = requestSettings.data; - - mockHandler.cache = requestSettings.cache; - mockHandler.timeout = requestSettings.timeout; - mockHandler.global = requestSettings.global; - - // In the case of a timeout, we just need to ensure - // an actual jQuery timeout (That is, our reponse won't) - // return faster than the timeout setting. - if ( mockHandler.isTimeout ) { - if ( mockHandler.responseTime > 1 ) { - origSettings.timeout = mockHandler.responseTime - 1; - } else { - mockHandler.responseTime = 2; - origSettings.timeout = 1; - } - } - - // Set up onAfter[X] callback functions - if ( $.isFunction( mockHandler.onAfterSuccess ) ) { - origSettings.success = overrideCallback('Success', mockHandler); - } - if ( $.isFunction( mockHandler.onAfterError ) ) { - origSettings.error = overrideCallback('Error', mockHandler); - } - if ( $.isFunction( mockHandler.onAfterComplete ) ) { - origSettings.complete = overrideCallback('Complete', mockHandler); - } - - copyUrlParameters(mockHandler, origSettings); - - /* jshint loopfunc:true */ - (function(mockHandler, requestSettings, origSettings, origHandler) { - - mockRequest = _ajax.call($, $.extend(true, {}, origSettings, { - // Mock the XHR object - xhr: function() { return xhr( mockHandler, requestSettings, origSettings, origHandler ); } - })); - })(mockHandler, requestSettings, origSettings, mockHandlers[k]); - /* jshint loopfunc:true */ - - return mockRequest; - } - - // We don't have a mock request - unmockedAjaxCalls.push(origSettings); - if($.mockjaxSettings.throwUnmocked === true) { - throw new Error('AJAX not mocked: ' + origSettings.url); - } - else { // trigger a normal request - return _ajax.apply($, [origSettings]); - } - } - - /** - * Copies URL parameter values if they were captured by a regular expression - * @param {Object} mockHandler - * @param {Object} origSettings - */ - function copyUrlParameters(mockHandler, origSettings) { - //parameters aren't captured if the URL isn't a RegExp - if (!(mockHandler.url instanceof RegExp)) { - return; - } - //if no URL params were defined on the handler, don't attempt a capture - if (!mockHandler.hasOwnProperty('urlParams')) { - return; - } - var captures = mockHandler.url.exec(origSettings.url); - //the whole RegExp match is always the first value in the capture results - if (captures.length === 1) { - return; - } - captures.shift(); - //use handler params as keys and capture resuts as values - var i = 0, - capturesLength = captures.length, - paramsLength = mockHandler.urlParams.length, - //in case the number of params specified is less than actual captures - maxIterations = Math.min(capturesLength, paramsLength), - paramValues = {}; - for (i; i < maxIterations; i++) { - var key = mockHandler.urlParams[i]; - paramValues[key] = captures[i]; - } - origSettings.urlParams = paramValues; - } - - - // Public - - $.extend({ - ajax: handleAjax - }); - - var DEFAULT_RESPONSE_TIME = 500; - - - $.mockjaxSettings = { - //url: null, - //type: 'GET', - log: function( mockHandler, requestSettings ) { - if ( mockHandler.logging === false || - ( typeof mockHandler.logging === 'undefined' && $.mockjaxSettings.logging === false ) ) { - return; - } - if ( window.console && console.log ) { - var message = 'MOCK ' + requestSettings.type.toUpperCase() + ': ' + requestSettings.url; - var request = $.ajaxSetup({}, requestSettings); - - if (typeof console.log === 'function') { - console.log(message, request); - } else { - try { - console.log( message + ' ' + JSON.stringify(request) ); - } catch (e) { - console.log(message); - } - } - } - }, - logging: true, - status: 200, - statusText: 'OK', - responseTime: DEFAULT_RESPONSE_TIME, - isTimeout: false, - throwUnmocked: false, - contentType: 'text/plain', - response: '', - responseText: '', - responseXML: '', - proxy: '', - proxyType: 'GET', - - lastModified: null, - etag: '', - headers: { - etag: 'IJF@H#@923uf8023hFO@I#H#', - 'content-type' : 'text/plain' - } - }; - - $.mockjax = function(settings) { - var i = mockHandlers.length; - mockHandlers[i] = settings; - return i; - }; - $.mockjax.clear = function(i) { - if ( i || i === 0 ) { - mockHandlers[i] = null; - } else { - mockHandlers = []; - } - mockedAjaxCalls = []; - unmockedAjaxCalls = []; - }; - $.mockjax.handler = function(i) { - if ( arguments.length === 1 ) { - return mockHandlers[i]; - } - }; - $.mockjax.mockedAjaxCalls = function() { - return mockedAjaxCalls; - }; - $.mockjax.unfiredHandlers = function() { - var results = []; - for (var i=0, len=mockHandlers.length; i= 20) ? 'ste' : 'de'; - }, - currency: { - symbol: '€ ' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('be-nl', language); - } -}()); -/*! - * numeral.js language configuration - * language : simplified chinese - * author : badplum : https://github.com/badplum - */ -(function () { - var language = { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: '千', - million: '百万', - billion: '十亿', - trillion: '兆' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '¥' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('chs', language); - } -}()); - -/*! - * numeral.js language configuration - * language : czech (cs) - * author : Anatoli Papirovski : https://github.com/apapirovski - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tis.', - million: 'mil.', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: 'Kč' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('cs', language); - } -}()); - -/*! - * numeral.js language configuration - * language : danish denmark (dk) - * author : Michael Storgaard : https://github.com/mstorgaard - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mio', - billion: 'mia', - trillion: 'b' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'DKK' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('da-dk', language); - } -}()); -/*! - * numeral.js language configuration - * language : German in Switzerland (de-ch) - * author : Michael Piefel : https://github.com/piefel (based on work from Marco Krage : https://github.com/sinky) - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'CHF' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('de-ch', language); - } -}()); -/*! - * numeral.js language configuration - * language : German (de) – generally useful in Germany, Austria, Luxembourg, Belgium - * author : Marco Krage : https://github.com/sinky - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('de', language); - } -}()); -/*! - * numeral.js language configuration - * language : english united kingdom (uk) - * author : Dan Ristic : https://github.com/dristic - */ -(function () { - var language = { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: '£' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('en-gb', language); - } -}()); -/*! - * numeral.js language configuration - * language : spanish Spain - * author : Hernan Garcia : https://github.com/hgarcia - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (b === 1 || b === 3) ? 'er' : - (b === 2) ? 'do' : - (b === 7 || b === 0) ? 'mo' : - (b === 8) ? 'vo' : - (b === 9) ? 'no' : 'to'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('es', language); - } -}()); - -/*! - * numeral.js language configuration - * language : spanish - * author : Hernan Garcia : https://github.com/hgarcia - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'mm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (b === 1 || b === 3) ? 'er' : - (b === 2) ? 'do' : - (b === 7 || b === 0) ? 'mo' : - (b === 8) ? 'vo' : - (b === 9) ? 'no' : 'to'; - }, - currency: { - symbol: '$' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('es', language); - } -}()); - -/*! - * numeral.js language configuration - * language : Estonian - * author : Illimar Tambek : https://github.com/ragulka - * - * Note: in Estonian, abbreviations are always separated - * from numbers with a space - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: ' tuh', - million: ' mln', - billion: ' mld', - trillion: ' trl' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('et', language); - } -}()); - -/*! - * numeral.js language configuration - * language : Finnish - * author : Sami Saada : https://github.com/samitheberber - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'M', - billion: 'G', - trillion: 'T' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('fi', language); - } -}()); - -/*! - * numeral.js language configuration - * language : french (Canada) (fr-CA) - * author : Léo Renaud-Allaire : https://github.com/renaudleo - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'M', - billion: 'G', - trillion: 'T' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: '$' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('fr-CA', language); - } -}()); -/*! - * numeral.js language configuration - * language : french (fr-ch) - * author : Adam Draper : https://github.com/adamwdraper - */ -(function () { - var language = { - delimiters: { - thousands: '\'', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: 'CHF' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('fr-ch', language); - } -}()); - -/*! - * numeral.js language configuration - * language : french (fr) - * author : Adam Draper : https://github.com/adamwdraper - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return number === 1 ? 'er' : 'e'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('fr', language); - } -}()); -/*! - * numeral.js language configuration - * language : Hungarian (hu) - * author : Peter Bakondy : https://github.com/pbakondy - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'E', // ezer - million: 'M', // millió - billion: 'Mrd', // milliárd - trillion: 'T' // trillió - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: ' Ft' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('hu', language); - } -}()); -/*! - * numeral.js language configuration - * language : italian Italy (it) - * author : Giacomo Trombi : http://cinquepunti.it - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'mila', - million: 'mil', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return 'º'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('it', language); - } -}()); -/*! - * numeral.js language configuration - * language : japanese - * author : teppeis : https://github.com/teppeis - */ -(function () { - var language = { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: '千', - million: '百万', - billion: '十億', - trillion: '兆' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '¥' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('ja', language); - } -}()); - -/*! - * numeral.js language configuration - * language : netherlands-dutch (nl-nl) - * author : Dave Clayton : https://github.com/davedx - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal : ',' - }, - abbreviations: { - thousand : 'k', - million : 'mln', - billion : 'mrd', - trillion : 'bln' - }, - ordinal : function (number) { - var remainder = number % 100; - return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de'; - }, - currency: { - symbol: '€ ' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('nl-nl', language); - } -}()); -/*! - * numeral.js language configuration - * language : polish (pl) - * author : Dominik Bulaj : https://github.com/dominikbulaj - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tys.', - million: 'mln', - billion: 'mld', - trillion: 'bln' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: 'PLN' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('pl', language); - } -}()); -/*! - * numeral.js language configuration - * language : portuguese brazil (pt-br) - * author : Ramiro Varandas Jr : https://github.com/ramirovjr - */ -(function () { - var language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'mil', - million: 'milhões', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - return 'º'; - }, - currency: { - symbol: 'R$' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('pt-br', language); - } -}()); -/*! - * numeral.js language configuration - * language : portuguese (pt-pt) - * author : Diogo Resende : https://github.com/dresende - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal : function (number) { - return 'º'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('pt-pt', language); - } -}()); - -// numeral.js language configuration -// language : Russian for the Ukraine (ru-UA) -// author : Anatoli Papirovski : https://github.com/apapirovski -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тыс.', - million: 'млн', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - // not ideal, but since in Russian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return '.'; - }, - currency: { - symbol: '\u20B4' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('ru-UA', language); - } -}()); - -/*! - * numeral.js language configuration - * language : russian (ru) - * author : Anatoli Papirovski : https://github.com/apapirovski - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тыс.', - million: 'млн', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - // not ideal, but since in Russian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return '.'; - }, - currency: { - symbol: 'руб.' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('ru', language); - } -}()); - -/*! - * numeral.js language configuration - * language : slovak (sk) - * author : Ahmed Al Hafoudh : http://www.freevision.sk - */ -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'tis.', - million: 'mil.', - billion: 'b', - trillion: 't' - }, - ordinal: function () { - return '.'; - }, - currency: { - symbol: '€' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('sk', language); - } -}()); - -/*! - * numeral.js language configuration - * language : thai (th) - * author : Sathit Jittanupat : https://github.com/jojosati - */ -(function () { - var language = { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'พัน', - million: 'ล้าน', - billion: 'พันล้าน', - trillion: 'ล้านล้าน' - }, - ordinal: function (number) { - return '.'; - }, - currency: { - symbol: '฿' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('th', language); - } -}()); - -/*! - * numeral.js language configuration - * language : turkish (tr) - * author : Ecmel Ercan : https://github.com/ecmel, Erhan Gundogan : https://github.com/erhangundogan, Burak Yiğit Kaya: https://github.com/BYK - */ -(function () { - var suffixes = { - 1: '\'inci', - 5: '\'inci', - 8: '\'inci', - 70: '\'inci', - 80: '\'inci', - - 2: '\'nci', - 7: '\'nci', - 20: '\'nci', - 50: '\'nci', - - 3: '\'üncü', - 4: '\'üncü', - 100: '\'üncü', - - 6: '\'ncı', - - 9: '\'uncu', - 10: '\'uncu', - 30: '\'uncu', - - 60: '\'ıncı', - 90: '\'ıncı' - }, - language = { - delimiters: { - thousands: '.', - decimal: ',' - }, - abbreviations: { - thousand: 'bin', - million: 'milyon', - billion: 'milyar', - trillion: 'trilyon' - }, - ordinal: function (number) { - if (number === 0) { // special case for zero - return '\'ıncı'; - } - - var a = number % 10, - b = number % 100 - a, - c = number >= 100 ? 100 : null; - - return suffixes[a] || suffixes[b] || suffixes[c]; - }, - currency: { - symbol: '\u20BA' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('tr', language); - } -}()); - -// numeral.js language configuration -// language : Ukrainian for the Ukraine (uk-UA) -// author : Michael Piefel : https://github.com/piefel (with help from Tetyana Kuzmenko) -(function () { - var language = { - delimiters: { - thousands: ' ', - decimal: ',' - }, - abbreviations: { - thousand: 'тис.', - million: 'млн', - billion: 'млрд', - trillion: 'блн' - }, - ordinal: function () { - // not ideal, but since in Ukrainian it can taken on - // different forms (masculine, feminine, neuter) - // this is all we can do - return ''; - }, - currency: { - symbol: '\u20B4' - } - }; - - // Node - if (typeof module !== 'undefined' && module.exports) { - module.exports = language; - } - // Browser - if (typeof window !== 'undefined' && this.numeral && this.numeral.language) { - this.numeral.language('uk-UA', language); - } -}()); diff --git a/server/sonar-web/src/main/js/libs/third-party/numeral.js b/server/sonar-web/src/main/js/libs/third-party/numeral.js deleted file mode 100755 index c21f99de789..00000000000 --- a/server/sonar-web/src/main/js/libs/third-party/numeral.js +++ /dev/null @@ -1,679 +0,0 @@ -/*! - * numeral.js - * version : 1.5.3 - * author : Adam Draper - * license : MIT - * http://adamwdraper.github.com/Numeral-js/ - */ - -(function () { - - /************************************ - Constants - ************************************/ - - var numeral, - VERSION = '1.5.3', - // internal storage for language config files - languages = {}, - currentLanguage = 'en', - zeroFormat = null, - defaultFormat = '0,0', - // check for nodeJS - hasModule = (typeof module !== 'undefined' && module.exports); - - - /************************************ - Constructors - ************************************/ - - - // Numeral prototype object - function Numeral (number) { - this._value = number; - } - - /** - * Implementation of toFixed() that treats floats more like decimals - * - * Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present - * problems for accounting- and finance-related software. - */ - function toFixed (value, precision, roundingFunction, optionals) { - var power = Math.pow(10, precision), - optionalsRegExp, - output; - - //roundingFunction = (roundingFunction !== undefined ? roundingFunction : Math.round); - // Multiply up by precision, round accurately, then divide and use native toFixed(): - output = (roundingFunction(value * power) / power).toFixed(precision); - - if (optionals) { - optionalsRegExp = new RegExp('0{1,' + optionals + '}$'); - output = output.replace(optionalsRegExp, ''); - } - - return output; - } - - /************************************ - Formatting - ************************************/ - - // determine what type of formatting we need to do - function formatNumeral (n, format, roundingFunction) { - var output; - - // figure out what kind of format we are dealing with - if (format.indexOf('$') > -1) { // currency!!!!! - output = formatCurrency(n, format, roundingFunction); - } else if (format.indexOf('%') > -1) { // percentage - output = formatPercentage(n, format, roundingFunction); - } else if (format.indexOf(':') > -1) { // time - output = formatTime(n, format); - } else { // plain ol' numbers or bytes - output = formatNumber(n._value, format, roundingFunction); - } - - // return string - return output; - } - - // revert to number - function unformatNumeral (n, string) { - var stringOriginal = string, - thousandRegExp, - millionRegExp, - billionRegExp, - trillionRegExp, - suffixes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], - bytesMultiplier = false, - power; - - if (string.indexOf(':') > -1) { - n._value = unformatTime(string); - } else { - if (string === zeroFormat) { - n._value = 0; - } else { - if (languages[currentLanguage].delimiters.decimal !== '.') { - string = string.replace(/\./g,'').replace(languages[currentLanguage].delimiters.decimal, '.'); - } - - // see if abbreviations are there so that we can multiply to the correct number - thousandRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.thousand + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - millionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.million + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - billionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.billion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - trillionRegExp = new RegExp('[^a-zA-Z]' + languages[currentLanguage].abbreviations.trillion + '(?:\\)|(\\' + languages[currentLanguage].currency.symbol + ')?(?:\\))?)?$'); - - // see if bytes are there so that we can multiply to the correct number - for (power = 0; power <= suffixes.length; power++) { - bytesMultiplier = (string.indexOf(suffixes[power]) > -1) ? Math.pow(1024, power + 1) : false; - - if (bytesMultiplier) { - break; - } - } - - // do some math to create our number - n._value = ((bytesMultiplier) ? bytesMultiplier : 1) * ((stringOriginal.match(thousandRegExp)) ? Math.pow(10, 3) : 1) * ((stringOriginal.match(millionRegExp)) ? Math.pow(10, 6) : 1) * ((stringOriginal.match(billionRegExp)) ? Math.pow(10, 9) : 1) * ((stringOriginal.match(trillionRegExp)) ? Math.pow(10, 12) : 1) * ((string.indexOf('%') > -1) ? 0.01 : 1) * (((string.split('-').length + Math.min(string.split('(').length-1, string.split(')').length-1)) % 2)? 1: -1) * Number(string.replace(/[^0-9\.]+/g, '')); - - // round if we are talking about bytes - n._value = (bytesMultiplier) ? Math.ceil(n._value) : n._value; - } - } - return n._value; - } - - function formatCurrency (n, format, roundingFunction) { - var symbolIndex = format.indexOf('$'), - openParenIndex = format.indexOf('('), - minusSignIndex = format.indexOf('-'), - space = '', - spliceIndex, - output; - - // check for space before or after currency - if (format.indexOf(' $') > -1) { - space = ' '; - format = format.replace(' $', ''); - } else if (format.indexOf('$ ') > -1) { - space = ' '; - format = format.replace('$ ', ''); - } else { - format = format.replace('$', ''); - } - - // format the number - output = formatNumber(n._value, format, roundingFunction); - - // position the symbol - if (symbolIndex <= 1) { - if (output.indexOf('(') > -1 || output.indexOf('-') > -1) { - output = output.split(''); - spliceIndex = 1; - if (symbolIndex < openParenIndex || symbolIndex < minusSignIndex){ - // the symbol appears before the "(" or "-" - spliceIndex = 0; - } - output.splice(spliceIndex, 0, languages[currentLanguage].currency.symbol + space); - output = output.join(''); - } else { - output = languages[currentLanguage].currency.symbol + space + output; - } - } else { - if (output.indexOf(')') > -1) { - output = output.split(''); - output.splice(-1, 0, space + languages[currentLanguage].currency.symbol); - output = output.join(''); - } else { - output = output + space + languages[currentLanguage].currency.symbol; - } - } - - return output; - } - - function formatPercentage (n, format, roundingFunction) { - var space = '', - output, - value = n._value * 100; - - // check for space before % - if (format.indexOf(' %') > -1) { - space = ' '; - format = format.replace(' %', ''); - } else { - format = format.replace('%', ''); - } - - output = formatNumber(value, format, roundingFunction); - - if (output.indexOf(')') > -1 ) { - output = output.split(''); - output.splice(-1, 0, space + '%'); - output = output.join(''); - } else { - output = output + space + '%'; - } - - return output; - } - - function formatTime (n) { - var hours = Math.floor(n._value/60/60), - minutes = Math.floor((n._value - (hours * 60 * 60))/60), - seconds = Math.round(n._value - (hours * 60 * 60) - (minutes * 60)); - return hours + ':' + ((minutes < 10) ? '0' + minutes : minutes) + ':' + ((seconds < 10) ? '0' + seconds : seconds); - } - - function unformatTime (string) { - var timeArray = string.split(':'), - seconds = 0; - // turn hours and minutes into seconds and add them all up - if (timeArray.length === 3) { - // hours - seconds = seconds + (Number(timeArray[0]) * 60 * 60); - // minutes - seconds = seconds + (Number(timeArray[1]) * 60); - // seconds - seconds = seconds + Number(timeArray[2]); - } else if (timeArray.length === 2) { - // minutes - seconds = seconds + (Number(timeArray[0]) * 60); - // seconds - seconds = seconds + Number(timeArray[1]); - } - return Number(seconds); - } - - function formatNumber (value, format, roundingFunction) { - var negP = false, - signed = false, - optDec = false, - abbr = '', - abbrK = false, // force abbreviation to thousands - abbrM = false, // force abbreviation to millions - abbrB = false, // force abbreviation to billions - abbrT = false, // force abbreviation to trillions - abbrForce = false, // force abbreviation - bytes = '', - ord = '', - abs = Math.abs(value), - suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], - min, - max, - power, - w, - precision, - thousands, - d = '', - neg = false; - - // check if number is zero and a custom zero format has been set - if (value === 0 && zeroFormat !== null) { - return zeroFormat; - } else { - // see if we should use parentheses for negative number or if we should prefix with a sign - // if both are present we default to parentheses - if (format.indexOf('(') > -1) { - negP = true; - format = format.slice(1, -1); - } else if (format.indexOf('+') > -1) { - signed = true; - format = format.replace(/\+/g, ''); - } - - // see if abbreviation is wanted - if (format.indexOf('a') > -1) { - // check if abbreviation is specified - abbrK = format.indexOf('aK') >= 0; - abbrM = format.indexOf('aM') >= 0; - abbrB = format.indexOf('aB') >= 0; - abbrT = format.indexOf('aT') >= 0; - abbrForce = abbrK || abbrM || abbrB || abbrT; - - // check for space before abbreviation - if (format.indexOf(' a') > -1) { - abbr = ' '; - format = format.replace(' a', ''); - } else { - format = format.replace('a', ''); - } - - if (abs >= Math.pow(10, 12) && !abbrForce || abbrT) { - // trillion - abbr = abbr + languages[currentLanguage].abbreviations.trillion; - value = value / Math.pow(10, 12); - } else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9) && !abbrForce || abbrB) { - // billion - abbr = abbr + languages[currentLanguage].abbreviations.billion; - value = value / Math.pow(10, 9); - } else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6) && !abbrForce || abbrM) { - // million - abbr = abbr + languages[currentLanguage].abbreviations.million; - value = value / Math.pow(10, 6); - } else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3) && !abbrForce || abbrK) { - // thousand - abbr = abbr + languages[currentLanguage].abbreviations.thousand; - value = value / Math.pow(10, 3); - } - } - - // see if we are formatting bytes - if (format.indexOf('b') > -1) { - // check for space before - if (format.indexOf(' b') > -1) { - bytes = ' '; - format = format.replace(' b', ''); - } else { - format = format.replace('b', ''); - } - - for (power = 0; power <= suffixes.length; power++) { - min = Math.pow(1024, power); - max = Math.pow(1024, power+1); - - if (value >= min && value < max) { - bytes = bytes + suffixes[power]; - if (min > 0) { - value = value / min; - } - break; - } - } - } - - // see if ordinal is wanted - if (format.indexOf('o') > -1) { - // check for space before - if (format.indexOf(' o') > -1) { - ord = ' '; - format = format.replace(' o', ''); - } else { - format = format.replace('o', ''); - } - - ord = ord + languages[currentLanguage].ordinal(value); - } - - if (format.indexOf('[.]') > -1) { - optDec = true; - format = format.replace('[.]', '.'); - } - - w = value.toString().split('.')[0]; - precision = format.split('.')[1]; - thousands = format.indexOf(','); - - if (precision) { - if (precision.indexOf('[') > -1) { - precision = precision.replace(']', ''); - precision = precision.split('['); - d = toFixed(value, (precision[0].length + precision[1].length), roundingFunction, precision[1].length); - } else { - d = toFixed(value, precision.length, roundingFunction); - } - - w = d.split('.')[0]; - - if (d.split('.')[1].length) { - d = languages[currentLanguage].delimiters.decimal + d.split('.')[1]; - } else { - d = ''; - } - - if (optDec && Number(d.slice(1)) === 0) { - d = ''; - } - } else { - w = toFixed(value, null, roundingFunction); - } - - // format number - if (w.indexOf('-') > -1) { - w = w.slice(1); - neg = true; - } - - if (thousands > -1) { - w = w.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + languages[currentLanguage].delimiters.thousands); - } - - if (format.indexOf('.') === 0) { - w = ''; - } - - return ((negP && neg) ? '(' : '') + ((!negP && neg) ? '-' : '') + ((!neg && signed) ? '+' : '') + w + d + ((ord) ? ord : '') + ((abbr) ? abbr : '') + ((bytes) ? bytes : '') + ((negP && neg) ? ')' : ''); - } - } - - /************************************ - Top Level Functions - ************************************/ - - numeral = function (input) { - if (numeral.isNumeral(input)) { - input = input.value(); - } else if (input === 0 || typeof input === 'undefined') { - input = 0; - } else if (!Number(input)) { - input = numeral.fn.unformat(input); - } - - return new Numeral(Number(input)); - }; - - // version number - numeral.version = VERSION; - - // compare numeral object - numeral.isNumeral = function (obj) { - return obj instanceof Numeral; - }; - - // This function will load languages and then set the global language. If - // no arguments are passed in, it will simply return the current global - // language key. - numeral.language = function (key, values) { - if (!key) { - return currentLanguage; - } - - if (key && !values) { - if(!languages[key]) { - return; - } - currentLanguage = key; - } - - if (values || !languages[key]) { - loadLanguage(key, values); - } - - return numeral; - }; - - // This function provides access to the loaded language data. If - // no arguments are passed in, it will simply return the current - // global language object. - numeral.languageData = function (key) { - if (!key) { - return languages[currentLanguage]; - } - - if (!languages[key]) { - throw new Error('Unknown language : ' + key); - } - - return languages[key]; - }; - - numeral.language('en', { - delimiters: { - thousands: ',', - decimal: '.' - }, - abbreviations: { - thousand: 'k', - million: 'm', - billion: 'b', - trillion: 't' - }, - ordinal: function (number) { - var b = number % 10; - return (~~ (number % 100 / 10) === 1) ? 'th' : - (b === 1) ? 'st' : - (b === 2) ? 'nd' : - (b === 3) ? 'rd' : 'th'; - }, - currency: { - symbol: '$' - } - }); - - numeral.zeroFormat = function (format) { - zeroFormat = typeof(format) === 'string' ? format : null; - }; - - numeral.defaultFormat = function (format) { - defaultFormat = typeof(format) === 'string' ? format : '0.0'; - }; - - /************************************ - Helpers - ************************************/ - - function loadLanguage(key, values) { - languages[key] = values; - } - - /************************************ - Floating-point helpers - ************************************/ - - // The floating-point helper functions and implementation - // borrows heavily from sinful.js: http://guipn.github.io/sinful.js/ - - /** - * Array.prototype.reduce for browsers that don't support it - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce#Compatibility - */ - if ('function' !== typeof Array.prototype.reduce) { - Array.prototype.reduce = function (callback, opt_initialValue) { - 'use strict'; - - if (null === this || 'undefined' === typeof this) { - // At the moment all modern browsers, that support strict mode, have - // native implementation of Array.prototype.reduce. For instance, IE8 - // does not support strict mode, so this check is actually useless. - throw new TypeError('Array.prototype.reduce called on null or undefined'); - } - - if ('function' !== typeof callback) { - throw new TypeError(callback + ' is not a function'); - } - - var index, - value, - length = this.length >>> 0, - isValueSet = false; - - if (1 < arguments.length) { - value = opt_initialValue; - isValueSet = true; - } - - for (index = 0; length > index; ++index) { - if (this.hasOwnProperty(index)) { - if (isValueSet) { - value = callback(value, this[index], index, this); - } else { - value = this[index]; - isValueSet = true; - } - } - } - - if (!isValueSet) { - throw new TypeError('Reduce of empty array with no initial value'); - } - - return value; - }; - } - - - /** - * Computes the multiplier necessary to make x >= 1, - * effectively eliminating miscalculations caused by - * finite precision. - */ - function multiplier(x) { - var parts = x.toString().split('.'); - if (parts.length < 2) { - return 1; - } - return Math.pow(10, parts[1].length); - } - - /** - * Given a variable number of arguments, returns the maximum - * multiplier that must be used to normalize an operation involving - * all of them. - */ - function correctionFactor() { - var args = Array.prototype.slice.call(arguments); - return args.reduce(function (prev, next) { - var mp = multiplier(prev), - mn = multiplier(next); - return mp > mn ? mp : mn; - }, -Infinity); - } - - - /************************************ - Numeral Prototype - ************************************/ - - - numeral.fn = Numeral.prototype = { - - clone : function () { - return numeral(this); - }, - - format : function (inputString, roundingFunction) { - return formatNumeral(this, - inputString ? inputString : defaultFormat, - (roundingFunction !== undefined) ? roundingFunction : Math.round - ); - }, - - unformat : function (inputString) { - if (Object.prototype.toString.call(inputString) === '[object Number]') { - return inputString; - } - return unformatNumeral(this, inputString ? inputString : defaultFormat); - }, - - value : function () { - return this._value; - }, - - valueOf : function () { - return this._value; - }, - - set : function (value) { - this._value = Number(value); - return this; - }, - - add : function (value) { - var corrFactor = correctionFactor.call(null, this._value, value); - function cback(accum, curr, currI, O) { - return accum + corrFactor * curr; - } - this._value = [this._value, value].reduce(cback, 0) / corrFactor; - return this; - }, - - subtract : function (value) { - var corrFactor = correctionFactor.call(null, this._value, value); - function cback(accum, curr, currI, O) { - return accum - corrFactor * curr; - } - this._value = [value].reduce(cback, this._value * corrFactor) / corrFactor; - return this; - }, - - multiply : function (value) { - function cback(accum, curr, currI, O) { - var corrFactor = correctionFactor(accum, curr); - return (accum * corrFactor) * (curr * corrFactor) / - (corrFactor * corrFactor); - } - this._value = [this._value, value].reduce(cback, 1); - return this; - }, - - divide : function (value) { - function cback(accum, curr, currI, O) { - var corrFactor = correctionFactor(accum, curr); - return (accum * corrFactor) / (curr * corrFactor); - } - this._value = [this._value, value].reduce(cback); - return this; - }, - - difference : function (value) { - return Math.abs(numeral(this._value).subtract(value).value()); - } - - }; - - /************************************ - Exposing Numeral - ************************************/ - - // CommonJS module is defined - if (hasModule) { - module.exports = numeral; - } - - /*global ender:false */ - if (typeof ender === 'undefined') { - // here, `this` means `window` in the browser, or `global` on the server - // add `numeral` as a global object via a string identifier, - // for Closure Compiler 'advanced' mode - this['numeral'] = numeral; - } - - /*global define:false */ - if (typeof define === 'function' && define.amd) { - define([], function () { - return numeral; - }); - } -}).call(this); diff --git a/server/sonar-web/src/main/js/main/app.js b/server/sonar-web/src/main/js/main/app.js index a68bf42b4b0..4923f61bbf7 100644 --- a/server/sonar-web/src/main/js/main/app.js +++ b/server/sonar-web/src/main/js/main/app.js @@ -5,6 +5,7 @@ import Backbone from 'backbone'; import Marionette from 'backbone.marionette'; import 'whatwg-fetch'; import moment from 'moment'; +import numeral from 'numeral'; import './processes'; import Navigation from './nav/app'; @@ -66,6 +67,8 @@ window.require = (module) => { return Marionette; case 'moment': return moment; + case 'numeral': + return numeral; default: return null; } diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb index d59aae33a7b..950d46ca853 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/views/layouts/_head.html.erb @@ -42,7 +42,6 @@ var baseUrl = '<%= ApplicationController.root_context -%>'; var $j = jQuery.noConflict(); $j(document).ready(function () {$j('.open-modal').modal()}); - numeral.language(window.pageLang);